// Try to post the "msg" to the mailbox. signed char _sys_mbox_trypost(sys_mbox_t *mbox, void *msg) { u8_t ubErr; ubErr = ubErr; // remove warning if(msg == NULL ) msg = (void*)&pvNullPointer; if((ubErr = OSQPost( (*mbox)->pQ, msg)) != OS_ERR_NONE) return ERR_MEM; return ERR_OK; }
/* ******************************************************************************* ** ** This function sends a message to a given mailqueue. ** ******************************************************************************* */ RTOS_Status RTOS_MailqueueSend( RTOS_Mailqueue mailqueue, RTOS_Message message ) { if( ! RTOS_MailqueueIsValid( mailqueue ) ) return( RTOS_MAILQUEUE_FAILURE ); if( ! RTOS_MessageIsValid( message ) ) return( RTOS_MESSAGE_FAILURE ); if( OSQPost( (OS_EVENT*)mailqueue, (void*) message ) != OS_NO_ERR ) return( RTOS_FAILURE ); return( RTOS_OK ); }
/* ********************************************************************************************************* * App_Task_KEY() * * Description : This is an example of an application task. * * Argument(s) : p_arg is the argument passed to 'App_Task_KEY()' by 'OSTaskCreate()'. * * Return(s) : none. * * Caller(s) : This is a task. * * Notes : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not * used. The compiler should not generate any code for this statement. ********************************************************************************************************* */ static void App_Task_KEY (void *p_arg) { OS_ERR os_err; CPU_TS ts; (void)p_arg; while (DEF_TRUE) { OSTimeDly ((OS_TICK )1, (OS_OPT )OS_OPT_TIME_DLY, (OS_ERR *)&os_err); while (BSP_SW_Read (BSP_SW_1) == DEF_ON) { OSTimeDly(1, OS_OPT_TIME_HMSM_STRICT, &os_err); } //OS_CRITICAL_ENTER(); OSQPost((OS_Q *)&AppQ, /* sends a message to another task using the message queue AppQ. */ (void *)1, /* sends a fixed message of value "1". */ (OS_MSG_SIZE)sizeof(void *), (OS_OPT )OS_OPT_POST_FIFO, (OS_ERR *)&os_err); OSMutexPend((OS_MUTEX *)&AppMutex, /* waits on the mutual exclusion semaphore. */ (OS_TICK )0, (OS_OPT )OS_OPT_PEND_BLOCKING, (CPU_TS *)&ts, (OS_ERR *)&os_err); /* Access shared resource */ OSMutexPost((OS_MUTEX *)&AppMutex, /* must call OSMutexPost() to release the mutex. */ (OS_OPT )OS_OPT_POST_NONE, (OS_ERR *)&os_err); //BSP_LED_Toggle(BSP_LED_RED); //OSTimeDlyResume(&App_Task_LED_TCB, &os_err); while (BSP_SW_Read (BSP_SW_1) == DEF_OFF) { OSTimeDly(1, OS_OPT_TIME_HMSM_STRICT, &os_err); } OSTimeDlyHMSM(0, 0, 0, 50, OS_OPT_TIME_HMSM_STRICT, &os_err); /* Suspend the task execution for 50 milliseconds. */ } }
static void AppTaskObj0 (void *p_arg) { OS_ERR os_err; (void)p_arg; while (DEF_TRUE) { #if (OS_CFG_SEM_EN > 0u) OSSemPost(&AppTaskObjSem, OS_OPT_POST_1, &os_err); #endif #if (OS_CFG_MUTEX_EN > 0u) OSMutexPend(&AppTaskObjMutex, 0, OS_OPT_PEND_BLOCKING, 0, &os_err); OSTimeDlyHMSM( 0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &os_err); OSMutexPost(&AppTaskObjMutex, OS_OPT_POST_NONE, &os_err); #endif #if (OS_CFG_Q_EN > 0u) OSQPost( &AppTaskObjQ, (void *) 1u, 1u, OS_OPT_POST_FIFO, &os_err); #endif #if (OS_CFG_FLAG_EN > 0u) OSFlagPost(&AppTaskObjFlag, DEF_BIT_00, OS_OPT_POST_FLAG_SET, &os_err); #endif OSTimeDlyHMSM( 0u, 0u, 0u, 10u, OS_OPT_TIME_HMSM_STRICT, &os_err); APP_TRACE_INFO(("Object test task 0 running ....\n")); } }
/* * sss_exec_command() * * This routine is called whenever we have new, valid receive data from our * sss connection. It will parse through the data simply looking for valid * commands to the sss server. * * Incoming commands to talk to the board LEDs are handled by sending the * MicroC/OS-II SSSLedCommandQ a pointer to the value we received. * * If the user wishes to quit, we set the "close" member of our SSSConn * struct, which will be looked at back in sss_handle_receive() when it * comes time to see whether to close the connection or not. */ void sss_exec_command(SSSConn* conn) { int bytes_to_process = conn->rx_wr_pos - conn->rx_rd_pos; char tx_buf[SSS_TX_BUF_SIZE]; char *tx_wr_pos = tx_buf; INT8U error_code; /* * "SSSCommand" is declared static so that the data will reside * in the BSS segment. This is done because a pointer to the data in * SSSCommand * will be passed via SSSLedCommandQ to the LEDManagementTask. * Therefore SSSCommand cannot be placed on the stack of the * SSSSimpleSocketServerTask, since the LEDManagementTask does not * have access to the stack of the SSSSimpleSocketServerTask. */ static INT32U SSSCommand; SSSCommand = CMD_LEDS_BIT_0_TOGGLE; while(bytes_to_process--) { SSSCommand = toupper(*(conn->rx_rd_pos++)); if(SSSCommand >= ' ' && SSSCommand <= '~') { tx_wr_pos += sprintf(tx_wr_pos, "--> Simple Socket Server Command %c.\n", (char)SSSCommand); if (SSSCommand == CMD_QUIT) { tx_wr_pos += sprintf(tx_wr_pos,"Terminating connection.\n\n\r"); conn->close = 1; } else { error_code = OSQPost(SSSLEDCommandQ, (void *)SSSCommand); alt_SSSErrorHandler(error_code, 0); } } } send(conn->fd, tx_buf, tx_wr_pos - tx_buf, 0); return; }
void OSPrintf(const char *fmt,...)//post massage to UartQ { char *pUartBuf; INT8U err; va_list ap; pUartBuf=OSMemGet(pUartMem,&err);//Reqire a Mem for Msg va_start(ap,fmt); vsprintf(pUartBuf,fmt,ap);//Msg formate va_end(ap); //Uart_SendString(string); OSQPost(pUart_Q,pUartBuf);//Post Msg }
void network_no_signal(void) { INT8U err = 0; INT8S res = 0; gd_msg_t *send_msg = NULL; gd_network_task_t *network_task = &gd_system.network_task; OSSemPend(gd_system.gm_operate_sem, GD_SEM_TIMEOUT, &err); res = at_csq(); OSSemPost(gd_system.gm_operate_sem); network_task->link_info[0].link_state = GD_LINK_STATE_IDLE; network_task->link_info[1].link_state = GD_LINK_STATE_IDLE; network_task->link_info[2].link_state = GD_LINK_STATE_IDLE; gd_system.state = GD_STATE_STANDBY; gd_msg_malloc(&send_msg); send_msg->data = (void*)NULL; if(err == OS_NO_ERR) { if(res>=0 && res<=31) { send_msg->type = GD_MSG_TCP_CONNECT; OSQPost(gd_system.network_task.q_network, (void*)send_msg); } else { //no signal //... // OSQFlush(gd_system.network_task.q_network); send_msg->type = GD_MSG_GM_NO_SIGNAL; OSQPost(gd_system.network_task.q_network, (void*)send_msg); } } }
void OSPrintf(const char *fmt,...)//post massage to UartQ { INT8U *pUartBuf; INT8U err; va_list ap; pUartBuf=OSMemGet(pUartMem,&err);// Reqire a Mem for Msg va_start(ap,fmt); vsprintf(pUartBuf,fmt,ap); // Msg formate,处理打印信息 va_end(ap); OSQPost(pUart_Q,pUartBuf); // Post Msg,将打印信息post给pUart_Q }
/** * Definition of the UART isr */ void ISRUART(void* context, unsigned int id) { unsigned int stat; INT8U chr; //get serial status stat = IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE); //character receiving if (stat & ALTERA_AVALON_UART_STATUS_RRDY_MSK) { //Check if UART is ready to offer access to the RXDATA register chr = IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE); IOWR_ALTERA_AVALON_UART_STATUS(UART_0_BASE, 0); //clear the status bits again OSQPost(uartQsem, (void*) chr); //write new char in que } IOWR_ALTERA_AVALON_UART_STATUS(UART_0_BASE, 0); //reset interrupt }
void send_to_radio_queue(const opQueueElem_t *opQueueNewElemPtr) { static OS_ERR os_err; static opQueueElem_t *opQueueDestElemPtr = NULL; if(opQueueNewElemPtr->operation != RADIO_OP_NONE) { opQueueDestElemPtr = &opQueueStruct.opQueueElem[opQueueStruct.queueElemNb]; if(++opQueueStruct.queueElemNb >= OP_QUEUE_SIZE) { opQueueStruct.queueElemNb = 0; } *opQueueDestElemPtr = *opQueueNewElemPtr; OSQPost(&opQueue, opQueueDestElemPtr, sizeof(*opQueueDestElemPtr), OS_OPT_POST_FIFO + OS_OPT_POST_ALL, &os_err); } }
/* prio:10 */ static void task2(void *pdata) { char *m1 = "task2 message1"; char *m2 = "task2 message2"; char *m3 = "task2 message3"; char *m4 = "task2 message4"; while(1) { sys_mutex_lock(&sys_mutex); dprintf("task2,%s\r\n",pdata); #if 0 dprintf("task2 post m1\r\n"); OSQPost(mbox, m1); dprintf("task2 post m2\r\n"); OSQPost(mbox, m2); dprintf("task2 post m3\r\n"); OSQPost(mbox, m3); dprintf("task2 post m4\r\n"); OSQPost(mbox, m4); #endif dprintf("task2 post message1\r\n"); sys_mbox_post(&sys_mbox, m1); dprintf("task2 post message2\r\n"); sys_mbox_post(&sys_mbox, m2); dprintf("task2 post message3\r\n"); sys_mbox_post(&sys_mbox, m3); dprintf("task2 post message4\r\n"); sys_mbox_post(&sys_mbox, m4); sys_mutex_unlock(&sys_mutex); //OSTaskSuspend(OS_PRIO_SELF); //sys_sem_wait(&sys_sem); //OSTaskResume(9); } }
void task_parallet(void *pdata) { INT8U err; pblock = (parallet_msg_t *)OSMemGet(g_hParalletRxMem, &err); if (err != OS_NO_ERR) { while(1) { p_err("%s err", __FUNCTION__); OSTimeDlyHMSM(0,0,1,0); } } else { memset(&pblock->u8Buf, 0, sizeof(pblock->u8Buf)); pblock->len = 0; pblock->fst = 0; pblock->end = 0; } //while (1) // OSTimeDly(1); while (1) { //OSSemPend(sem_udp_rec_flag,0,&err); if (pblock->fst != 0) { pblock->end = os_time_get(); if (pblock->end - pblock->fst > 1000) { OSQPost(hParalletMsgQueue, (void *)pblock); pblock = (parallet_msg_t *)OSMemGet(g_hParalletRxMem, &err); if (OS_NO_ERR == err) { memset(&pblock->u8Buf, 0, sizeof(pblock->u8Buf)); pblock->len = 0; pblock->fst = 0; pblock->end = 0; } } } OSTimeDly(1); } }
/********************************************************************************************************* ** Function name: ScanPPCoinChannel ** Descriptions: 扫描并行硬币器通道,注意只能在Time1定时中断中扫描 ** input parameters: 无 ** output parameters: 将扫描到的值送入并行脉冲硬币器专用消息队列 ** Returned value: 无 *********************************************************************************************************/ void ScanPPCoinChannel(void) { unsigned int Rchannel; unsigned char CurChannel,Temp; static unsigned char PreChannel; static unsigned char PreStatus ; Rchannel = GETPPCOIN_CHL1()<<0; Rchannel |= GETPPCOIN_CHL2()<<1; Rchannel |= GETPPCOIN_CHL3()<<2; Rchannel |= GETPPCOIN_CHL4()<<3; Rchannel |= GETPPCOIN_CHL5()<<4; Rchannel |= GETPPCOIN_CHL6()<<5; Temp = (unsigned char)(~Rchannel); Temp &= 0x3F; switch(Temp) { case 0x00 : if(PreStatus == 0x01) { PreStatus = 0x00; PostParallelCoinChannel = PreChannel; OSQPost(QPChannel,(void *)&PostParallelCoinChannel); } PreChannel = 0x00; CurChannel = 0x00; break; case 0x01 : CurChannel = 0x06; break; case 0x02 : CurChannel = 0x05; break; case 0x04 : CurChannel = 0x04; break; case 0x08 : CurChannel = 0x03; break; case 0x10 : CurChannel = 0x02; break; case 0x20 : CurChannel = 0x01; break; default : CurChannel = 0x00; break; } if(PreStatus == 0x00) { if((PreChannel > 0x00)&(PreChannel == CurChannel)) PreStatus = 0x01; else PreChannel = CurChannel; } }
// Posts the "msg" to the mailbox. void _sys_mbox_post(sys_mbox_t *mbox, void *msg) { u8_t ubErr,i=0; ubErr = ubErr; // remove warning if(msg == NULL ) msg = (void*)&pvNullPointer; while((i<10) && ((ubErr = OSQPost( (*mbox)->pQ, msg)) != OS_ERR_NONE)) { i++;//if full, try 10 times OSTimeDly(5); } //if (i==10) printf("sys_mbox_post error!\n"); }
static void test_task1(void* p_arg) { p_arg = p_arg; while(1) { while(OS_NO_ERR != OSQPost(p_queue, (void*)(data))){ OSTimeDly(5); } printk("give %d ", data); data ++; } }
/* Posts the "msg" to the mailbox */ void sys_mbox_post(sys_mbox_t mbox, void *msg) { u8_t i=0; if( msg == NULL ) { msg = (void*)&pvNullPointer; } while((i<10) && (( OSQPost( mbox->pQ, msg)) != OS_ERR_NONE)) { i++; /* if full, try 10 times */ OSTimeDly(5); } /*if (i==10) printf("sys_mbox_post error!\n"); */ }
static void AFE_DFT_Callback(void *pCBParam, uint32_t Event, void *pArg) { OSIntEnter(); if (pADI_AFE->AFE_DFT_RESULT_REAL != pADI_AFE->AFE_DFT_RESULT_REAL & 0xFF || pADI_AFE->AFE_DFT_RESULT_IMAG != pADI_AFE->AFE_DFT_RESULT_IMAG & 0xFF) { FAIL("lost data"); } pend_dft_results.parts.magnitude = pADI_AFE->AFE_DFT_RESULT_REAL; pend_dft_results.parts.phase = pADI_AFE->AFE_DFT_RESULT_IMAG; if (OS_ERR_NONE != OSQPost(dft_queue, pend_dft_results.pointer)) { FAIL("AFE_DFT_Callback: OSQPost"); } OSIntExit(); }
/* void network_heart_beat(void) { INT8S res = 0; static INT8U counter = 50; INT32U heartbeat_len; INT8U err; INT8U gd_heart_beat[92]; INT8U i = 0; gd_msg_t *send_msg = NULL; gd_network_task_t *network_task = &gd_system.network_task; if(gd_system.state == GD_STATE_ONLINE) { counter++; if(counter > 50) { OSSemPend(gd_system.gm_operate_sem, GD_SEM_TIMEOUT, &err); if(err == OS_NO_ERR) { res = at_csq(); if(res>=0 && res<=31) { heartbeat_len = gd_heart_beat_init(GD_DEVID, GD_DEVMAC, NULL, 0, (u8)res, gd_heart_beat); for(i=0; i<network_task->link_count; i++) { res = gprs_tcpip_send(gd_heart_beat, heartbeat_len, i); if(res == 0) { fail_tick = 0; } else { // Send error fail_tick++; if(fail_tick >= (NETWORK_FAIL_COUNT * network_task->link_count)) { fail_tick = 0; gd_msg_malloc(&send_msg); send_msg->data = (void*)NULL; send_msg->type = GD_MSG_GM_RESET; OSQPost(gd_system.network_task.q_network, (void*)send_msg); break; } } } } else { //no signal //... fail_tick = 0; // OSQFlush(gd_system.network_task.q_network); gd_msg_malloc(&send_msg); send_msg->data = (void*)NULL; send_msg->type = GD_MSG_GM_NO_SIGNAL; OSQPost(gd_system.network_task.q_network, (void*)send_msg); return; } } OSSemPost(gd_system.gm_operate_sem); counter = 0; } gd_msg_malloc(&send_msg); send_msg->type = GD_MSG_SEND_HEARTBEAT; send_msg->data = (void*)NULL; OSQPost(gd_system.network_task.q_network, (void*)send_msg); } } */ void heart_beat(void) { INT32U heartbeat_len; INT8U err; INT8U gd_heart_beat[92]; INT8U i = 0; INT8S res = 0; gd_msg_t *send_msg = NULL; gd_network_task_t *network_task = &gd_system.network_task; OSSemPend(gd_system.gm_operate_sem, GD_SEM_TIMEOUT, &err); if(err == OS_NO_ERR) { res = at_csq(); if(res>=0 && res<=31) { heartbeat_len = gd_heart_beat_init(GD_DEVID, GD_DEVMAC, NULL, 0, (u8)res, gd_heart_beat); for(i=0; i<network_task->link_count; i++) { res = gprs_tcpip_send(gd_heart_beat, heartbeat_len, i); if(res == 0) { } else { // Send error } } } else { //no signal // OSQFlush(gd_system.network_task.q_network); gd_msg_malloc(&send_msg); send_msg->data = (void*)NULL; send_msg->type = GD_MSG_GM_NO_SIGNAL; OSQPost(gd_system.network_task.q_network, (void*)send_msg); } } OSSemPost(gd_system.gm_operate_sem); }
static void serial_irq_0(void* context, alt_u32 id) { unsigned int stat; INT8U chr; //get serial status stat = IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE); //character Rx if (stat & ALTERA_AVALON_UART_STATUS_RRDY_MSK) { chr = IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE); IOWR_ALTERA_AVALON_UART_STATUS(UART_0_BASE, 0); if (chr != 254) { OSQPost(qsemMsg, (void*) chr); } } IOWR_ALTERA_AVALON_UART_STATUS(UART_0_BASE, 0); }
void state_handling_entry(void *para) { INT32U msg_id, prev_state; INT8U err; msg_id = 0; state_handling_init(); OSQPost(StateHandlingQ, (void *) STATE_STARTUP); while(1) { prev_state = msg_id; msg_id = (INT32U) OSQPend(StateHandlingQ, 0, &err); if((!msg_id) || (err != OS_NO_ERR)) { continue; } present_state = msg_id & 0x1FF; switch(msg_id & 0x1FF) { case STATE_STARTUP: state_startup_entry((void *) &prev_state); break; case STATE_VIDEO_PREVIEW: state_video_preview_entry((void *) &prev_state); break; case STATE_VIDEO_RECORD: state_video_record_entry((void *) &prev_state, msg_id); break; case STATE_AUDIO_RECORD: //state_audio_record_entry((void *) &prev_state); break; case STATE_BROWSE: state_browse_entry((void *) &prev_state, (msg_id & 0xFFFF0000)>>16); msg_id &= 0x0000ffff; break; case STATE_THUMBNAIL: state_thumbnail_entry((void *) &prev_state); break; case STATE_SETTING: state_setting_entry((void *) &prev_state); break; default: break; } } }
int msgsnd(msg_q_t msgid, void *msgbuf) { INT8U perr; if (0 == msgid) { p_err("msgsnd: msgid err"); return - 1; } perr = OSQPost((OS_EVENT*)msgid, (void*)msgbuf); if (perr == OS_ERR_NONE) return 0; else if (perr == OS_ERR_Q_FULL) return 1; p_err("msgsnd: err %d", perr); return - 1; }
static void DoubleKeyTask (void* pdata) { INT8U err; while (1) { OSSemPend (os_sem_double, DOUBLE_INTERVAL, &err); if (err == OS_TIMEOUT) { OSTaskDel (KEY_DOUBLE_TASK_PRIO); } else { key_hook (TYPE_KEY_DOUBLE<<24 | change); OSQPost (os_q_key_msg, (void*)(TYPE_KEY_DOUBLE<<24 | change)); OSTaskDel (KEY_DOUBLE_TASK_PRIO); } } }
void Task (void *pdata) { unsigned int rand_num; INT8U err; INT8U pos_x, pos_y = 0; FILE* fp; //used for storing information to data.dat char str_send[10]; char str_sum[10]; char filename[25]; static int value[10]; //values send used for calculate the average for (;;) { GetDate(filename); strcat(filename, "Sd.dat"); fp = fopen(filename,"a"); OSSemPend(RandomSem, 0, &err); rand_num = random(500); OSSemPost(RandomSem); sprintf(str_send,"%5d",rand_num); OSQPost(MSGQ,str_send); pos_x = *(INT8U*)pdata - '0'; fprintf(fp,"%s",str_send); PC_DispStr(pos_x*6+5, pos_y + 2, str_send, DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); value[pos_x] = (int)rand_num; //if this group of value are gotten, sum and average it if (pos_x == 9) { memset(str_sum,0,sizeof(str_sum)); sprintf(str_sum,"%6.2f",(float)sum(value,10)/10.0); //show sum col PC_DispStr(68, 2 + pos_y, str_sum, DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY); fprintf(fp,"%8s\n%6s",str_sum," "); memset(value,0,sizeof(value)); } if (pos_y == 7) pos_y = 0; OSTimeDlyHMSM(0,0,1,0); pos_y ++; ///start next row fclose(fp); } }
static void test3_1_T1(void *data) { data = data; /* to remove warning that data is never used */ unsigned char exit_err=0; int msg_ev=1; static OSMsg msg; memset((char*)&msg, 0, sizeof(OSMsg)); STTBX_Print(("\n 3.1.4 Post a Queue to Task 2\n")); exit_err = print_debug_post_queue(OSQPost(MsgQueueA,&msg,TASK_1_PRIO,TASK_2_PRIO,msg_ev),OS_NO_ERR); if(exit_err) ; //return(exit_err); //return(FALSE); }
//任务1的任务函数 void task1_task(void *p_arg) { u8 key; OS_ERR err; u8 num; u8 *pbuf; static u8 msg_num; pbuf=mymalloc(SRAMIN,10); //申请内存 while(1) { key = KEY_Scan(0); //扫描按键 switch(key) { case KEY1_PRES: OSSemPost(&Test_Sem1,OS_OPT_POST_1,&err);//发送信号量1 break; case KEY0_PRES: OSSemPost(&Test_Sem2,OS_OPT_POST_1,&err);//发送信号量2 case WKUP_PRES: msg_num++; sprintf((char*)pbuf,"ALIENTEK %d",msg_num); //发送消息 OSQPost((OS_Q* )&Test_Q, (void* )pbuf, (OS_MSG_SIZE)10, (OS_OPT )OS_OPT_POST_FIFO, (OS_ERR* )&err); break; } num++; if(num==50) { num=0; LED0=~LED0; } OSTimeDlyHMSM(0,0,0,10,OS_OPT_TIME_PERIODIC,&err); //延时10ms } }
/********************************************************************************************************* ** Function name: ScanSPCoinChannel ** Descriptions: 扫描串行硬币器通道,注意只能在Time1定时中断中扫描 ** input parameters: 无 ** output parameters: 将扫描到的值送入串行脉冲硬币器专用消息队列 ** Returned value: 无 *********************************************************************************************************/ void ScanSPCoinChannel(void) { unsigned char CurStatus; static unsigned char PreStatus ; FIO2DIR &= (~SERIALCOIN_IN); CurStatus = (unsigned char)GETSERIALCON_CHL(); switch(CurStatus) { case 0x00 : if(PreStatus == 0x01) { PostSerialCoinChannel[serialCoinIndex] = 0x01; OSQPost(QSChannel,(void *)&PostSerialCoinChannel[serialCoinIndex]); serialCoinIndex = (++serialCoinIndex) % SERIALCOIN_CHANNEL_QUEUE_SIZE; } PreStatus = CurStatus; break; case 0x01 : PreStatus = CurStatus; break; default : break; } }
bool detect_net_input_event(void * data) { // message * msg = (message *)data; u16 Stat; Stat = 0x0000; //得到最新的C6状态 Stat = CBUS_RecTwoByte(STAT); if((0x0000 != Stat))// && (0x0010 != Stat)) { // msg->id = MSG_NET_INPUT; // msg->data.val = Stat; pStatReportMsg.MsgType=StateRpType; pStatReportMsg.Data.Val=Stat; LWIP_DEBUGF(CML_DEBUG,("sata %04x\n\n",Stat)); OSQPost(pAppMsgQ,&pStatReportMsg); return 1; } else { return 0; } }
void task1(void *data){ data = data; inittimer(); INT8U errmutex, errq; while(1){ PORTC=~(1<<0); u1txstr("\nTask1"); OSMutexPend(mymutex, 0, &errmutex); if(err == OS_NO_ERR){ errq=OSQPost(myq, mymsg); if(errq == OS_NO_ERR){ u1txstr("\nMessage transferred to Queue"); } else if(errq == OS_Q_FULL){ u1txstr("\nQueue is full!"); } } OSMutexPost(mymutex); //u1txstr("\nMutex released by Task 1"); OSTimeDly(61); } }
/********************************************************************************************************* ** 函数名称: ethernetif_linkoutput ** 函数名称: ethernetif_linkoutput ** ** 功能描述: 完成实际的信息包发送 ** ** 输 入: struct netif * netif ,其指定IP信息包将被发送的哪一个网卡接口上 ** 输 入: struct pbuf * p ,其保存着将要发送的IP信息包 ** ** 输 出: err_t 0: 发送成功 -1: 发送失败 ** ** 全局变量: ** 调用模块: 无 ** ** 作 者: LiJin ** 日 期: 2009年8月22日 ** 备 注: **------------------------------------------------------------------------------------------------------- ** 修改人: ** 日 期: ** 备 注: **------------------------------------------------------------------------------------------------------ ********************************************************************************************************/ err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) { struct eth_tx_msg msg; struct eth_device* enetif; INT8U ret = OS_NO_ERR; enetif = (struct eth_device*)netif->state; /* send a message to eth tx thread */ msg.netif = netif; msg.buf = p; // rt_mb_send(ð_tx_thread_mb, (rt_uint32_t) &msg); ret = OSQPost( pTxMsgQueue, &msg ); /* waiting for ack */ // rt_sem_take(&(enetif->tx_ack), RT_WAITING_FOREVER); OSSemPend( enetif->tx_ack ,0, &ret); if(ret == OS_NO_ERR) return ERR_OK; return ERR_OK; }
/*FUNCTION********************************************************************** * * Function Name : OSA_MsgQPut * Description : This function is used to put a message to a message queue. * Return kStatus_OSA_Success if the message is put successfully, otherwise * return kStatus_OSA_Error. * *END**************************************************************************/ osa_status_t OSA_MsgQPut(msg_queue_handler_t handler, void* pMessage) { OS_ERR err; void *localMsg; int32_t *from_ptr, *to_ptr; uint32_t msg_size = handler->size; /* In this case, the message is saved into internal memory */ localMsg = OSMemGet(&(handler->mem), &err); if (!localMsg) { return kStatus_OSA_Error; } /* Copy msg to localMsg. */ from_ptr = (int32_t*)pMessage; to_ptr = (int32_t*)localMsg; while (msg_size--) { *to_ptr++ = *from_ptr++; } OSQPost(&(handler->queue), localMsg, handler->size*sizeof(int32_t), OS_OPT_POST_FIFO, &err); if (OS_ERR_NONE != err) { OSMemPut(&(handler->mem), localMsg, &err); return kStatus_OSA_Error; } return kStatus_OSA_Success; }