/** Post a message to an mbox - may not fail * -> blocks if full, only used from tasks not from ISR * @param mbox mbox to posts the message * @param msg message to post (ATTENTION: can be NULL) */ void sys_mbox_post(sys_mbox_t *mbox, void *msg) { uint32_t mail; mail = (uint32_t)msg; mbox_post(mbox, &mail); }
// La función de entrada de un thread siempre debe tener este prototipo // pero esto no impide recibir argumentos "complejos" y devolver cualquier tipo // de resultado void* client_thread (void* ptr) { struct client_arg* arg; int i; message_t* msg; arg = (struct client_arg*) ptr; fprintf(logfile,"NEW client of type %d with period %d \n",arg->m_type, arg->period); for (i=0;i<arg->n_messages; i++) { if ( ( msg=new_message(arg->m_type ) ) == NULL ) { fprintf(stderr,"Error when creating message\n"); pthread_exit(NULL); } // Post message to mailbox mbox_post( arg->mbox, msg); // Wait for server to finish the work sys_sem_wait(msg->op_completed); // We can process and free the message process_answer(msg); free_message(msg); // Sleep for period seconds before the next message sleep(arg->period); } return NULL; }
static void serial_isr_func(int n) { uint32_t c; c = serial_getc(); mbox_post(&console_mbox, &c); }
/** Try to post a message to an mbox - may fail if full or ISR * @param mbox mbox to posts the message * @param msg message to post (ATTENTION: can be NULL) */ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) { int ret; uint32_t mail; mail = (uint32_t)msg; ret = mbox_post(mbox, &mail); if(ret == ROK) return ERR_OK; else return ERR_MEM; }
int shutdown_server() { message_t* msg; serv_up = 0; // Create NONE message if ( ( msg=new_message(NONE ) ) == NULL ) { fprintf(logfile,"Error when creating NONE message\n"); return -1; } // Post it message to mailbox mbox_post( mbox, msg); // Wait for server to finish the work counting_sem_wait(msg->op_completed); // Ignore answer if (msg != NULL) free_message(msg); return 0; }
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) { if (!mbox) return EINVAL; return mbox_post(*mbox, msg, -1); }
void sys_mbox_post(sys_mbox_t *mbox, void *msg) { if (!!mbox) mbox_post(*mbox, msg, 0); }
/// Put a Message to a Queue. /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. /// \param[in] info message information. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS. osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec) { return mbox_post(queue_id, &info); }