Download COMPLETE EMBEDDED SOLUTIONS
Transcript
THE CMX MULTI-TASKING EXECUTIVE
UART MANAGER FUNCTIONS
The K_Get_Char function
The K_Get_Char allows a task that owns the receiver to retrieve a character from the
receive buffer if there is one available. The parameter passed to the K_Get_Char
function is the address where the task would like the character to be copied to. If the
receive buffer has one or more characters in its buffer, then only one character will be
placed at the destination address.
If the receive buffer is empty, indicating either no characters have been received by the
UART or that all characters that have been received and retrieved, then no character
will be placed into the destination address.
The task will be returned to immediately with the value specifying the number of
characters transferred. If the return value is zero, no character was retrieved. Otherwise
the task will receive a count of one indicating one character was retrieved. Once a
character has been retrieved, the tail pointer of the receive buffer is incremented and the
receive buffer count_in variable is decremented.
This is an example of the K_Get_Char function:
Called
Tasks.
#include <cxfuncs.h> /* has function prototype */
word16 K_Get_Char(void *); /* this is the function prototype */
unsigned char *DEST_PTR; /* this may be local or global, and will be the location that
the function puts the character. */
unsigned short COUNT; /* this will specify the number of characters retrieved from
buffer. */
COUNT = K_Get_Char(DEST_PTR);
Passed
DEST_PTR = the address where this function will place the character.
unsigned char recv_array[80];
/* this will receive up to 80 characters, could be local if user wants or could just be a
depth of 1 in this case for this function only returns one character at the most. */
void task1(void)
{
unsigned short count; /* local */
unsigned char c;
106