void handleReceiveInterrupt() { while(!QUEUE_FULL(uint8_t, &listener.serial->receiveQueue)) { uint8_t byte; uint32_t received = UART_Receive(UART1_DEVICE, &byte, 1, NONE_BLOCKING); if(received > 0) { QUEUE_PUSH(uint8_t, &listener.serial->receiveQueue, byte); if(QUEUE_FULL(uint8_t, &listener.serial->receiveQueue)) { pauseReceive(); } } else { break; } } }
int uTaskMessageSendIsr( IN uTask_T *pTask, IN int Id, IN void *pData ) { /* The task and handler must be valid */ if (pTask && pTask->Handler) { if (!QUEUE_FULL(gCore.IsrQ)) { Tcb_T Tcb; Tcb.Flags = TCB_FLAGS_ISR; Tcb.pTask = pTask; Tcb.Id = Id; Tcb.pMsg = pData; Tcb.Expire = uTaskGetTick(); QUEUE_PUT(gCore.IsrQ, Tcb); return UTASK_S_OK; } } return UTASK_E_FAIL; }
bool_t PutNextCBusTransactionImpl(cbus_req_t *pReq) { if (QUEUE_FULL(CBusQueue)) { return false; } CBusQueue.queue[CBusQueue.tail] = *pReq; ADVANCE_QUEUE_TAIL(CBusQueue) return true; }
bool_t PutPriorityCBusTransactionImpl(cbus_req_t *pReq) { if (QUEUE_FULL(CBusQueue)) { TX_DEBUG_PRINT(("MhlTx Queque is full\n")); return false; } RETREAT_QUEUE_HEAD(CBusQueue) CBusQueue.queue[CBusQueue.head] = *pReq; return true; }
void readFromSerial(SerialDevice* device, bool (*callback)(uint8_t*)) { if(device != NULL) { if(!QUEUE_EMPTY(uint8_t, &device->receiveQueue)) { processQueue(&device->receiveQueue, callback); if(!QUEUE_FULL(uint8_t, &device->receiveQueue)) { resumeReceive(); } } } }
END_TEST START_TEST (test_enqueue_full) { for(int i = 0; i < 512; i++) { QUEUE_PUSH(uint8_t, &queue, (uint8_t) 128); } fail_unless(QUEUE_FULL(uint8_t, &queue)); char* message = "a message"; bool result = conditionalEnqueue(&queue, (uint8_t*)message, 10); fail_if(result); }
// TODO see if we can do this with interrupts on the chipKIT // http://www.chipkit.org/forum/viewtopic.php?f=7&t=1088 void readFromSerial(SerialDevice* device, bool (*callback)(uint8_t*)) { if(device != NULL) { int bytesAvailable = ((HardwareSerial*)device->controller)->available(); if(bytesAvailable > 0) { for(int i = 0; i < bytesAvailable && !QUEUE_FULL(uint8_t, &device->receiveQueue); i++) { char byte = ((HardwareSerial*)device->controller)->read(); QUEUE_PUSH(uint8_t, &device->receiveQueue, (uint8_t) byte); } processQueue(&device->receiveQueue, callback); } } }
END_TEST START_TEST (test_full_clears) { for(int i = 0; i < 512; i++) { QUEUE_PUSH(uint8_t, &queue, (uint8_t) 128); } fail_unless(QUEUE_FULL(uint8_t, &queue)); callbackStatus = false; processQueue(&queue, callback); fail_unless(called); fail_unless(QUEUE_EMPTY(uint8_t, &queue)); }