//............................................................................ void QActive::postLIFO(QEvent const *e) { QF_INT_LOCK_KEY_ QF_INT_LOCK_(); if (e->dynamic_ != (uint8_t)0) { ++((QEvent *)e)->dynamic_; } QF_INT_UNLOCK_(); Q_ALLEGE(OSQPostFront((OS_EVENT *)m_eQueue, (void *)e) == OS_NO_ERR); }
//======================================================== //Function Name:msgQSend //Syntax: INT32S msgQSend(MSG_Q_ID msgQId, INT32U msg_id, void *para, INT32U nParaByte, INT32U priority) //Purpose: send a message to a message queue //Note: //Parameters: MSG_Q_ID msgQId /* message queue on which to send */ // INT32U msg_id /* message id */ // void *para /* message to send */ // INT32U nParaByte /* byte number of para buffer */ // INT32U priority /* MSG_PRI_NORMAL or MSG_PRI_URGENT */ //Return: -1 if faile // 0 success //======================================================= INT32S msgQSend(MSG_Q_ID msgQId, INT32U msg_id, void *para, INT32U nParaByte, INT32U priority) { INT8U ret; INT32U i; INT8U *pMsg = msgQId->pMsgPool; INT32U maxMsgLength = msgQId->maxMsgLength; INT32U maxMsgs = msgQId->maxMsgs; if(nParaByte > maxMsgLength) /* too many parameter */ { #if MSG_Q_DEBUG == 1 DBG_PRINT("msg send err:message size is too large\r\n"); #endif return -1; } MSG_Q_LOCK(); /* find a free message */ for(i = 0; i < maxMsgs; i++) { if(*(INT32U*)pMsg == 0) break; pMsg += (maxMsgLength + 4); } if(i == maxMsgs) /* not enough message */ { MSG_Q_UNLOCK(); #if MSG_Q_DEBUG == 1 DBG_PRINT("msg send err:allocate message block faile\r\n"); #endif return -1; } *(INT32U*)pMsg = msg_id; if(nParaByte) { gp_memcpy((INT8S*)(pMsg + 4), (INT8S*)para, nParaByte); } if(priority == MSG_PRI_NORMAL) ret = OSQPost(msgQId->pEvent, (void *)pMsg); else ret = OSQPostFront(msgQId->pEvent, (void *)pMsg); #if MSG_Q_DEBUG == 1 if(ret) { DBG_PRINT("msg send err:post message faile\r\n"); } #endif MSG_Q_UNLOCK(); return (INT32S)ret; }
/* ******************************************************************************* ** ** This function sends a message to a given mailqueue. ** ******************************************************************************* */ RTOS_Status RTOS_MailqueueSendFront( RTOS_Mailqueue mailqueue, RTOS_Message message ) { if( ! RTOS_MailqueueIsValid( mailqueue ) ) return( RTOS_MAILQUEUE_FAILURE ); if( ! RTOS_MessageIsValid( message ) ) return( RTOS_MESSAGE_FAILURE ); if( OSQPostFront( (OS_EVENT*)mailqueue, (void*) message ) != OS_NO_ERR ) return( RTOS_FAILURE ); return( RTOS_OK ); }
/*..........................................................................*/ void QActive_postLIFO(QActive *me, QEvent const *e) { QF_INT_LOCK_KEY_ QF_INT_LOCK_(); QS_BEGIN_NOLOCK_(QS_QF_ACTIVE_POST_LIFO, QS_aoObj_, me) QS_TIME_(); /* timestamp */ QS_SIG_(e->sig); /* the signal of this event */ QS_OBJ_(me); /* this active object */ QS_U8_(EVT_POOL_ID(e)); /* the pool Id of the event */ QS_U8_(EVT_REF_CTR(e)); /* the ref count of the event */ QS_EQC_(0); /* number of free entries (unknown) */ QS_EQC_(0); /* min number of free entries (unknown) */ QS_END_NOLOCK_() if (EVT_POOL_ID(e) != (uint8_t)0) { /* is it a pool event? */ EVT_INC_REF_CTR(e); /* increment the reference counter */ } QF_INT_UNLOCK_(); Q_ALLEGE(OSQPostFront((OS_EVENT *)me->eQueue, (void *)e) == OS_NO_ERR); }
void midiDecode(void* pdata) { INT8U err; INT8U msg; INT8U msg2; INT8U msg3; int hi4, lo4; while (1) { //Clear the messages hi4 =0; lo4 = 0; // *msg = *msg2 = *msg3 = 0; msg = (INT8U) OSQPend(qsemMsg, 0, &err); if (err == OS_TIMEOUT) printf("Q Timeout\n"); else if (err == OS_ERR_PEND_ISR) printf("Q Pend in ISR\n"); //printf("%i\n", msg); lo4 = msg & 15; hi4 = msg >> 4; switch(hi4) { case 9: while(1){ //printf("Note On, Channel %i ", lo4); msg2 = (INT8U) OSQPend(qsemMsg, 0, &err); //printf("Note %i On with ", msg2); if (msg2 > 127){ OSQPostFront(qsemMsg, (void*) msg2); break; } msg3 = (INT8U) OSQPend(qsemMsg, 0, &err); //printf(" Velocity = %i\n", msg3); if (msg3 == 0){ int i; for (i = 0; i < 6; i++){ if ((*note_table[i] & NOTE_MASK) == msg2){ *note_table[i] = *note_table[i] & NOTE_MASK; //printf("%d\n", *note_table[i]); } } }else{ int i; for (i = 0; i < 6; i++){ // printf("%X\n", *note_table[i]); if ((*note_table[i] & VELOCITY_MASK) == 0){ *note_table[i] = (msg3 << 12) | msg2; break; } } } } break; case 8: //printf("Note Off, Channel %i ", lo4); msg2 = (INT8U) OSQPend(qsemMsg, 0, &err); //printf(" Note: %i ", msg2); msg3 = (INT8U) OSQPend(qsemMsg, 0, &err); //printf(" Velocity: %i\n", msg3); break; case 10: //printf("After Touch, Channel %i ", lo4); msg2 = (INT8U) OSQPend(qsemMsg, 0, &err); //printf(" Note: %i ", msg2); msg3 = (INT8U) OSQPend(qsemMsg, 0, &err); //printf(" Pressure: %i\n", msg3); break; case 11: //printf("Control Change, Channel %i", lo4); msg2 = (INT8U) OSQPend(qsemMsg, 0, &err); //printf(" Controller: %i ", msg2); msg3 = (INT8U) OSQPend(qsemMsg, 0, &err); //printf(" Value: %i\n", msg3); if(msg2 == 123){ int i; for (i=0;i<6;i++){ *note_table[i] = 0; } } break; case 13: //printf("After-Touch, Channel %i", lo4); msg2 = (INT8U) OSQPend(qsemMsg, 0, &err); //printf(" Pressure: %i\n", msg2); break; case 15: //printf("Channel Mode Message, Channel %i", lo4); msg2 = (INT8U) OSQPend(qsemMsg, 0, &err); //printf(" Controller: %i ", msg2); msg3 = (INT8U) OSQPend(qsemMsg, 0, &err); //printf(" Value: %i\n", msg3); break; default: break; } } }