29 #if !defined(PIOS_INCLUDE_CHIBIOS)
30 #error "pios_queue.c requires PIOS_INCLUDE_CHIBIOS"
33 #if defined(PIOS_INCLUDE_CHIBIOS)
44 #if !defined(PIOS_QUEUE_MAX_WAITERS)
45 #define PIOS_QUEUE_MAX_WAITERS 2
63 if (queuep->mpb == NULL) {
67 chPoolInit(&queuep->mp, item_size, NULL);
68 chPoolLoadArray(&queuep->mp, queuep->mpb, queue_length + PIOS_QUEUE_MAX_WAITERS);
72 chMBInit(&queuep->mb, mb_buf, queue_length);
103 void *buf = chPoolAlloc(&queuep->mp);
107 memcpy(buf, itemp, queuep->mp.mp_object_size);
111 timeout = TIME_INFINITE;
112 else if (timeout_ms == 0)
113 timeout = TIME_IMMEDIATE;
115 timeout = MS2ST(timeout_ms);
117 msg_t result = chMBPost(&queuep->mb, (msg_t)buf, timeout);
119 if (result != RDY_OK)
121 chPoolFree(&queuep->mp, buf);
142 void *buf = chPoolAllocI(&queuep->mp);
145 chSysUnlockFromIsr();
149 memcpy(buf, itemp, queuep->mp.mp_object_size);
151 msg_t result = chMBPostI(&queuep->mb, (msg_t)buf);
153 if (result != RDY_OK)
155 chPoolFreeI(&queuep->mp, buf);
156 chSysUnlockFromIsr();
160 chSysUnlockFromIsr();
182 timeout = TIME_INFINITE;
183 else if (timeout_ms == 0)
184 timeout = TIME_IMMEDIATE;
186 timeout = MS2ST(timeout_ms);
188 msg_t result = chMBFetch(&queuep->mb, &buf, timeout);
190 if (result != RDY_OK)
193 memcpy(itemp, (
void*)buf, queuep->mp.mp_object_size);
195 chPoolFree(&queuep->mp, (
void*)buf);
211 return queuep->mp.mp_object_size;
struct pios_queue * PIOS_Queue_Create(size_t queue_length, size_t item_size)
Main PiOS header to include all the compiled in PiOS options.
bool PIOS_Queue_Send_FromISR(struct pios_queue *queuep, const void *itemp, bool *wokenp)
bool PIOS_Queue_Send(struct pios_queue *queuep, const void *itemp, uint32_t timeout_ms)
bool PIOS_Queue_Receive(struct pios_queue *queuep, void *itemp, uint32_t timeout_ms)
void * PIOS_malloc_no_dma(size_t size)
void PIOS_Queue_Delete(struct pios_queue *queuep)
#define PIOS_QUEUE_TIMEOUT_MAX
size_t PIOS_Queue_GetItemSize(struct pios_queue *queuep)
void PIOS_free(void *buf)
#define PIOS_Assert(test)