void rt_pop_req (void) { /* Process an ISR post service requests. */ struct OS_XCB *p_CB; P_TCB next; U32 idx; os_tsk.run->state = READY; rt_put_rdy_first (os_tsk.run); idx = os_psq->last; while (os_psq->count) { p_CB = os_psq->q[idx].id; if (p_CB->cb_type == TCB) { /* Is of TCB type */ rt_evt_psh ((P_TCB)p_CB, (U16)os_psq->q[idx].arg); } else if (p_CB->cb_type == MCB) { /* Is of MCB type */ rt_mbx_psh ((P_MCB)p_CB, (void *)os_psq->q[idx].arg); } else { /* Must be of SCB type */ rt_sem_psh ((P_SCB)p_CB); } if (++idx == os_psq->size) { idx = 0U; } rt_dec (&os_psq->count); } os_psq->last = (U8)idx; next = rt_get_first (&os_rdy); rt_switch_req (next); }
OS_RESULT rt_mbx_wait (OS_ID mailbox, void **message, U16 timeout) { /* Receive a message; possibly wait for it */ P_MCB p_MCB = mailbox; P_TCB p_TCB; /* If a message is available in the fifo buffer */ /* remove it from the fifo buffer and return. */ if (p_MCB->count) { *message = p_MCB->msg[p_MCB->last]; if (++p_MCB->last == p_MCB->size) { p_MCB->last = 0; } if (p_MCB->state == 2) { /* A task is waiting to send message */ p_TCB = rt_get_first ((P_XCB)p_MCB); if (p_MCB->p_lnk == NULL) { p_MCB->state = 0; } #ifdef __CMSIS_RTOS rt_ret_val(p_TCB, 0/*osOK*/); #else rt_ret_val(p_TCB, OS_R_OK); #endif p_MCB->msg[p_MCB->first] = p_TCB->msg; if (++p_MCB->first == p_MCB->size) { p_MCB->first = 0; } rt_rmv_dly (p_TCB); rt_dispatch (p_TCB); } else { rt_dec (&p_MCB->count); } return (OS_R_OK); } /* No message available: wait for one */ if (timeout == 0) { return (OS_R_TMO); } if (p_MCB->p_lnk != NULL) { rt_put_prio ((P_XCB)p_MCB, os_tsk.run); } else { p_MCB->p_lnk = os_tsk.run; os_tsk.run->p_lnk = NULL; os_tsk.run->p_rlnk = (P_TCB)p_MCB; /* Task is waiting to receive a message */ p_MCB->state = 1; } rt_block(timeout, WAIT_MBX); #ifndef __CMSIS_RTOS os_tsk.run->msg = message; #endif return (OS_R_TMO); }
OS_RESULT isr_mbx_receive (OS_ID mailbox, void **message) { /* Receive a message in the interrupt function. The interrupt function */ /* should not wait for a message since this would block the rtx os. */ P_MCB p_MCB = mailbox; if (p_MCB->count) { /* A message is available in the fifo buffer. */ *message = p_MCB->msg[p_MCB->last]; if (p_MCB->state == 2) { /* A task is locked waiting to send message */ rt_psq_enq (p_MCB, 0); rt_psh_req (); } rt_dec (&p_MCB->count); if (++p_MCB->last == p_MCB->size) { p_MCB->last = 0; } return (OS_R_MBX); } return (OS_R_OK); }