/******************************************************************************* * Procedure: rx_task * Purpose: Task that processes serial input from Nordic RF chip. * Passed: * * Returned: nothing * Globals: none * * Date: Author: Comments: * 2014-09-19 Neal Shurmantine initial revision *******************************************************************************/ void *rx_task(void * param) { int numbytes; bool process; char ser_rx_buff[1]; QInit(RECEIVE_SIZE,&RxQueue, RxData); URX_WaitTime = NORMAL_RECEIVE_WAIT_TIME; uint16_t tick_count = 0; printf("rx_task\n"); while(1) { OS_TaskSleep(URX_WaitTime); ++tick_count; #ifdef USE_ME if ((tick_count % 100) == 1) printf("."); if ((tick_count % 500) == 1) printf("\n"); #endif process = false; do { numbytes = read(nordic_fp, ser_rx_buff, 1); if (numbytes != 0) { printf("%02x ",(uint8_t)ser_rx_buff[0]); process = true; QInsert(ser_rx_buff[0], &RxQueue); } } while (numbytes != 0); if (process == true) { OS_EventSet(ActiveEventHandle,ActiveEventBit); } } }
BOOL QInsertAtHead( PQUEUE Queue, LPVOID Object) /*++ Routine Description: This function inserts one item at the HEAD of the queue. Of course, this violates queue semantics...but this can be useful at times. Arguments: Queue -- The queue into which to insert Object. Object -- A void pointer to the object being inserted. Return Value: TRUE -- The object was successfully inserted at the head of the queue. FALSE -- There were too many items already in the queue; one item must be removed in order to insert another. --*/ { BOOL ReturnValue; // holds the return value EnterCriticalSection(&Queue->CrSec); // If the queue is full, set the return value to FALSE and do // nothing; if not, update the indices appropriately and set the // return value to TRUE. if((Queue->Tail == Queue->Head) && (Queue->Head != Q_NULL)){ ReturnValue = FALSE; } else { if (Queue->Head == Q_NULL) { // The queue was empty, so just use QInsert. QInsert(Queue, Object); } if (Queue->Head == 0) { Queue->Head = MAX_QUEUE_SIZE - 1; } else { Queue->Head = Queue->Head - 1; } Queue->QueueArray[Queue->Head] = Object; ReturnValue = TRUE; } LeaveCriticalSection(&Queue->CrSec); return(ReturnValue); }