/* Function to read a message from queue with timeout */ int IPC_popMsgTout(void *data, int tout) { struct ipc_queue *qrd = &q_ipc[CPUID_CURR]; int raise_event = QUEUE_IS_FULL(qrd); if (!QUEUE_IS_VALID(qrd)) { return QUEUE_ERROR; } if ((tout == 0) && QUEUE_IS_EMPTY(qrd)) { return QUEUE_EMPTY; } while (QUEUE_IS_EMPTY(qrd)) { if (IPC_EventHandler(IPC_EVENT_WAIT_RX, CPUID_CURR, tout) && (tout > 0)) { return QUEUE_TIMEOUT; } } /* Pop the queue Item */ memcpy(data, qrd->data + ((qrd->tail & (qrd->count - 1)) * qrd->size), qrd->size); qrd->tail++; if (raise_event) { ipc_send_signal(); } return QUEUE_VALID; }
/* Function to push a message into queue with timeout */ int IPC_pushMsgTout(uint16_t cpuid, const void *data, int tout) { struct ipc_queue *qwr = &q_ipc[cpuid]; /* Check if write queue is initialized */ if (!QUEUE_IS_VALID(qwr)) { return QUEUE_ERROR; } if ((tout == 0) && QUEUE_IS_FULL(qwr)) { return QUEUE_FULL; } /* Wait for read queue to have some data */ while (QUEUE_IS_FULL(qwr)) { if (IPC_EventHandler(IPC_EVENT_WAIT_TX, cpuid, tout) && (tout > 0)) { return QUEUE_TIMEOUT; } } memcpy(qwr->data + ((qwr->head & (qwr->count - 1)) * qwr->size), data, qwr->size); qwr->head++; ipc_send_signal(); return QUEUE_INSERT; }
// --------------------------------------------------------------------------- // Push a message into queue with timeout int IPC_pushMsgTout(const void *data, int tout) { // Check if write queue is initialized if (!QUEUE_IS_VALID(qwr)) { return QUEUE_ERROR; } if (tout == 0) { // Check if queue is full if (QUEUE_IS_FULL(qwr)) { return QUEUE_FULL; } } else if (tout < 0) { // Wait for read queue to have some data //ipc_wait_event(QUEUE_IS_FULL(qwr), event_tx); } else { // Wait for read queue to have some data //ipc_wait_event_tout(QUEUE_IS_FULL(qwr), tout, event_tx); if (tout == 0) { return QUEUE_TIMEOUT; } } memcpy(qwr->data + ((qwr->head & (qwr->count - 1)) * qwr->size), data, qwr->size); qwr->head++; ipc_send_signal(); return QUEUE_INSERT; }
// --------------------------------------------------------------------------- // Get number of pending items in queue int IPC_msgPending(int queue_write) { struct ipc_queue *q = queue_write ? qwr : qrd; if (!QUEUE_IS_VALID(q)) return QUEUE_ERROR; return QUEUE_DATA_COUNT(q); }
/* Get number of pending items in queue */ int IPC_msgPending(uint16_t cpu) { struct ipc_queue *q = &q_ipc[cpu]; if (!QUEUE_IS_VALID(q)) { return QUEUE_ERROR; } return QUEUE_DATA_COUNT(q); }
// --------------------------------------------------------------------------- // Read a message from queue with timeout int IPC_popMsgTout(void *data, int tout) { #ifdef EVENT_ON_RX int raise_event = QUEUE_IS_FULL(qrd); #endif if (!QUEUE_IS_VALID(qrd)) { return QUEUE_ERROR; } if (tout == 0) { // Check if read queue is empty if (QUEUE_IS_EMPTY(qrd)) { return QUEUE_EMPTY; } } else if (tout < 0) { // Wait for read queue to have some data //ipc_wait_event(QUEUE_IS_EMPTY(qrd), event_rx); } else { // Wait for event or timeout //ipc_wait_event_tout(QUEUE_IS_EMPTY(qrd), tout, event_rx); if (tout == 0) { return QUEUE_TIMEOUT; } } // Pop the queue Item memcpy(data, qrd->data + ((qrd->tail & (qrd->count - 1)) * qrd->size), qrd->size); qrd->tail++; #ifdef EVENT_ON_RX if (raise_event) { ipc_send_signal(); } #endif return QUEUE_VALID; }