CQueueType Queue_Head(CQueue &q) { assert(Queue_IsEmpty(q) == false); if (Queue_IsEmpty(q)) { return CQueueType(); } return q.pData[q.head]; }
CQueueType Queue_Tail(CQueue &q) { assert(Queue_IsEmpty(q) == false); if (Queue_IsEmpty(q)) { return CQueueType(); } return q.pData[q.tail]; }
CQueueType Queue_Dequeue(CQueue &q) { assert(Queue_IsEmpty(q) == false); if (Queue_IsEmpty(q)) { return CQueueType(); } --q.size; q.head %= q.capacity; return q.pData[q.head++]; }
void SPI_Transfer(spi_configuration* configuration, uint8_t* output, uint8_t* input, uint8_t length, completion_handler handler) { if (Queue_IsFull(operationQueue)) { return; } bool isIdle; ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { isIdle = Queue_IsEmpty(operationQueue); } operation* o = Queue_Head(operationQueue); o->configuration = configuration; o->output = output; o->input = input; o->length = length; o->handler = handler; Queue_AdvanceHead(operationQueue); if (isIdle) // just check some register bit instead of isIdle? { // power up peripheral PowerManager_RequestResource(PROCESSOR_RESOURCE_IO_CLOCK); // don't let it sleep ExecuteOperation(); } }