/* ********************************************************************************************************* * App_Task_LED() * * 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_LED (void *p_arg) { OS_ERR os_err; void *p_msg; OS_MSG_SIZE msg_size; CPU_TS ts; CPU_TS ts_delta; (void) p_arg; p_arg = p_arg; while (DEF_TRUE) { p_msg = OSQPend((OS_Q *)&AppQ, /* starts by waiting for messages to be sent through the message queue AppQ. */ (OS_TICK )0, (OS_OPT )OS_OPT_PEND_BLOCKING, (OS_MSG_SIZE *)&msg_size, /* The size of the message. */ (CPU_TS *)&ts, /* contain the timestamp of when the message was sent. */ (OS_ERR *)&os_err); ts_delta = OS_TS_GET() - ts; BSP_LED_Toggle(BSP_LED_GREEN); OSTimeDlyHMSM(0, 0, 1, 0, OS_OPT_TIME_HMSM_STRICT, &os_err); } }
void task_scan(void *p_arg) { OS_ERR err; OS_MSG_SIZE size; CPU_TS ts; CMD_STRU *msg; while (1) { msg = (CMD_STRU*)OSQPend(&ScanQ, 0, OS_OPT_PEND_BLOCKING, &size, &ts, &err); switch (msg->cmd_word & 0x00ff) { case MOD_SCAN_CMD_SET_INC: break; case MOD_SCAN_CMD_SET_X: break; case MOD_SCAN_CMD_SET_Y: break; case MOD_SCAN_CMD_INC_X: break; case MOD_SCAN_CMD_INC_Y: break; case MOD_SCAN_CMD_DEC_X: break; case MOD_SCAN_CMD_DEC_Y: break; } } }
int msgrcv(msg_q_t msgid, void **msgbuf, unsigned int timeout) { INT8U perr; if (0 == msgid) { p_err("msgrcv: msgid err"); return - 1; } if ((timeout > 0) && (timeout < 1000uL / OS_TICKS_PER_SEC)) timeout = 1000uL / OS_TICKS_PER_SEC; timeout = timeout * OS_TICKS_PER_SEC / 1000uL; *msgbuf = OSQPend((OS_EVENT*)msgid, (INT32U)timeout, &perr); if (perr == OS_ERR_NONE) return 0; else if (perr == OS_ERR_TIMEOUT) return 1; p_err("msgrcv: err %d", perr); return - 1; }
void BuzzerTask(void *pData) { while(1) { BYTE err; void *p = OSQPend(&BuzzerQueue, 0, &err); if(p != NULL) { int buzz_mode = (int)p; switch(buzz_mode) { case BUZZ_OFF: Buzzer = 0; iprintf("Buzzer turned OFF \r\n"); break; case BUZZ_NORMAL: Buzzer = 1; // Buzzer turn ON iprintf("Buzzer turned ON \r\n"); OSTimeDly(1); Buzzer = 0; iprintf("Buzzer turned OFF \r\n"); break; case BUZZ_DPM_CONNECT: iprintf("DPM is connected \r\n"); Buzzer = 1; OSTimeDly(1); Buzzer = 0; OSTimeDly(3); Buzzer = 1; OSTimeDly(1); Buzzer = 0; break; case BUZZ_DPM_DISCONNECT: iprintf("DPM disconnected \r\n"); Buzzer = 1; OSTimeDly(1); Buzzer = 0; OSTimeDly(3); Buzzer = 1; OSTimeDly(1); Buzzer = 0; break; case BUZZ_ALARM: iprintf("ALARM! \r\n"); Buzzer = 1; OSTimeDly(5); Buzzer = 0; OSTimeDly(3); Buzzer = 1; OSTimeDly(5); Buzzer = 0; OSTimeDly(3); Buzzer = 1; OSTimeDly(5); Buzzer = 0; OSTimeDly(3); break; case BUZZ_SUCCESS: iprintf("SUCCESS \r\n"); Buzzer = 1; OSTimeDly(9); Buzzer = 0; break; default: break; } } else OSTimeDly(20); } }
/* Display Read/Write status to the LCD that is changed based on a signal from the Switch task */ void taskLCD(void* pdata) { alt_up_character_lcd_dev * char_lcd_dev; // open the Character LCD port char_lcd_dev = alt_up_character_lcd_open_dev("/dev/character_lcd_0"); if (char_lcd_dev == NULL) alt_printf("Error: could not open character LCD device\n"); else alt_printf("Opened character LCD device\n"); while (1) { if (OSQPend(SWQ, 0, &err) == SW_WRITE) { /* Initialize the character display */ alt_up_character_lcd_init(char_lcd_dev); /* Write "WRITE" in the second row */ char second_row[] = "WRITE\0"; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1); alt_up_character_lcd_string(char_lcd_dev, second_row); } else { alt_up_character_lcd_init(char_lcd_dev); /* Write "READ" in the first row */ alt_up_character_lcd_string(char_lcd_dev, "READ"); } OSTimeDlyHMSM(0, 0, 0, 50); } }
//======================================================== //Function Name:msgQReceive //Syntax: INT32S msgQReceive(MSG_Q_ID msgQId, INT32U *msg_id, void *para, INT32U maxParaNByte) //Purpose: receive a message from a message queue //Note: //Parameters: MSG_Q_ID msgQId /* message queue on which to send */ // INT32U *msg_id /* message id */ // void *para /* message and type received */ // INT32U maxNByte /* message size */ //Return: -1: if faile // 0: success //======================================================= INT32S msgQReceive(MSG_Q_ID msgQId, INT32U *msg_id, void *para, INT32U maxParaNByte) { INT8U err; void *pMsg; pMsg = OSQPend(msgQId->pEvent, 0, &err); if (err!=0 || !pMsg) { #if MSG_Q_DEBUG == 1 DBG_PRINT("msg receive err:pend message fail\r\n"); #endif return -1; } MSG_Q_LOCK(); if(maxParaNByte > msgQId->maxMsgLength) { MSG_Q_UNLOCK(); #if MSG_Q_DEBUG == 1 DBG_PRINT("msg receive err:message size is too large\r\n"); #endif return -1; } *msg_id = *(INT32U*)pMsg; if(maxParaNByte && para) { gp_memcpy((INT8S*)para, (INT8S*)pMsg + 4, maxParaNByte); } *(INT32U*)pMsg = 0; /* free message */ MSG_Q_UNLOCK(); return 0; }
/* ethernet buffer */ void eth_rx_thread_entry(void* parameter) { struct eth_device* device; INT8U err = 0; while (1) { device = OSQPend( pRxMsgQueue , 0,&err); if ( err == OS_NO_ERR) { struct pbuf *p; /* receive all of buffer */ while (1) { p = device->eth_rx(device); if (p != RT_NULL) { /* notify to upper layer */ eth_input(p, device->netif); } else break; } } } }
// Blocking on a message queue void WaitOn(Queue queue) { INT8U err; OSQPend(queue, 0, &err); // char error[1]; // if (err == OS_ERR_NONE) // { // error[0] = 'A'; // } // else if (err == OS_ERR_Q_FULL) // { // error[0] = 'B'; // } // else if (err == OS_ERR_EVENT_TYPE) // { // error[0] = 'C'; // } // else if (err == OS_ERR_PEVENT_NULL) // { // error[0] = 'D'; // } // else // { // error[0] = 'E'; // } }
//等待邮箱中的消息 //*mbox:消息邮箱 //*msg:消息 //timeout:超时时间,如果timeout为0的话,就一直等待 //返回值:当timeout不为0时如果成功的话就返回等待的时间, // 失败的话就返回超时SYS_ARCH_TIMEOUT u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) { u8_t ucErr; u32_t ucos_timeout,timeout_new; void *temp; sys_mbox_t m_box=*mbox; if(timeout!=0) { ucos_timeout=(timeout*OS_TICKS_PER_SEC)/1000; //转换为节拍数,因为UCOS延时使用的是节拍数,而LWIP是用ms if(ucos_timeout<1)ucos_timeout=1;//至少1个节拍 }else ucos_timeout = 0; timeout = OSTimeGet(); //获取系统时间 temp=OSQPend(m_box->pQ,(u16_t)ucos_timeout,&ucErr); //请求消息队列,等待时限为ucos_timeout if(msg!=NULL) { if(temp==(void*)&pvNullPointer)*msg = NULL; //因为lwip发送空消息的时候我们使用了pvNullPointer指针,所以判断pvNullPointer指向的值 else *msg=temp; //就可知道请求到的消息是否有效 } if(ucErr==OS_ERR_TIMEOUT)timeout=SYS_ARCH_TIMEOUT; //请求超时 else { LWIP_ASSERT("OSQPend ",ucErr==OS_ERR_NONE); timeout_new=OSTimeGet(); if (timeout_new>timeout) timeout_new = timeout_new - timeout;//算出请求消息或使用的时间 else timeout_new = 0xffffffff - timeout + timeout_new; timeout=timeout_new*1000/OS_TICKS_PER_SEC + 1; } return timeout; }
/*********************************************************************//** * @author * @brief * @date * @version 1.0 * @description * @param[in] None. * @param[out] None. * @return * **********************************************************************/ uint8_t SrcOnOff_WaitForSignal(void) { uint8_t err; uint8_t *msg; msg = (uint8_t*)OSQPend(srcOnOffQ,0,&err); return *msg; }
/* ethernet buffer */ void eth_tx_thread_entry(void* parameter) { struct eth_tx_msg* msg; INT8U err = 0; while (1) { msg = OSQPend( pTxMsgQueue , 0,&err); if ( err == OS_NO_ERR) { struct eth_device* enetif; RT_ASSERT(msg->netif != RT_NULL); RT_ASSERT(msg->buf != RT_NULL); enetif = (struct eth_device*)msg->netif->state; if (enetif != RT_NULL) { /* call driver's interface */ if (enetif->eth_tx(enetif, msg->buf) != OS_TRUE) { // rt_kprintf("transmit eth packet failed\n"); } } /* send ack */ // rt_sem_release(&(enetif->tx_ack)); OSSemPost(enetif->tx_ack ); } } }
static void lwIPInterruptTask(void *pvArg) { u8_t err; pvArg = pvArg; // // Loop forever. // while(1) { // // Wait until the semaphore has been signalled. // pvArg = OSQPend(LwIP_NetISR_Sem, 0, &err); // // Processes any packets waiting to be sent or received. // stellarisif_interrupt(&g_sNetIF); // // Re-enable the Ethernet interrupts. // EthernetIntEnable(ETH_BASE, ETH_INT_RX | ETH_INT_TX); } }
/* 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. * * ********************************************************************************************************* */ void APP_TaskThree(void *p_arg) { OS_ERR err = OS_ERR_NONE; char indxChar; char MsgSize; char *pMsgContent; static char taskStringBuffer[APPDEF_LCD_TXT_SIZE+1U] = {'u','C','/','O','S','-','3','\0'}; static int ringPos = 0; (void)p_arg; /* Note(1) */ while (1) { /* Task body, always written as an infinite loop */ /* Turn previous ring segment off */ SegmentLCD_ARing(ringPos, 0); /* Increase ring position variable */ if (8u == ++ringPos) { ringPos = 0; /* 3bit overflow */ } /* Turn updated ring segment on */ SegmentLCD_ARing(ringPos, 1); /* Non-blocking reception of a message */ pMsgContent = OSQPend((OS_Q *) pSerialQueObj, (OS_TICK ) 0U, (OS_OPT ) OS_OPT_PEND_NON_BLOCKING, (OS_MSG_SIZE *)&MsgSize, (CPU_TS *) 0U, (OS_ERR *)&err); /* If a valid message was received... */ if ((void *)0 != pMsgContent) { /* ...shift left the whole string by one... */ for (indxChar = 0; indxChar < APPDEF_LCD_TXT_SIZE; indxChar++) { taskStringBuffer[indxChar] = taskStringBuffer[indxChar+1]; } /* ...and concatenate the new character to the end. */ taskStringBuffer[APPDEF_LCD_TXT_SIZE-1] = *pMsgContent; /* Write the string on serial port (USART0) */ printf("\nBuffer: %s", taskStringBuffer); /* Write the string on LCD */ SegmentLCD_Write(taskStringBuffer); } /* Delay task for 1 system tick (uC/OS-II suspends this task and executes * the next most important task) */ OSTimeDly(1U, OS_OPT_TIME_DLY, &err); } }
/* * Checks the infrared receive queue for new readings. * @return OK when a new reading is received and processed without error */ Status CommandHandler::checkInfraredReceive() { INT8U status; int level = (int)OSQPend(infraredReceiveQueue, 0, &status); if (status != OS_NO_ERR) { return ERR_INFRARED; } else { return processInfraredReceive(level); } }
/*********************************************************************//** * @author * @brief * @date * @version 1.0 * @description * @param[in] None. * @param[out] None. * @return * **********************************************************************/ uint8_t IHD_WaitForSignal(uint8_t *msg) { uint8_t err; uint8_t *buff; //OSSemPend(dailyMeterSem,0,&err); buff = (uint8_t*)OSQPend(IHD_Q,0,&err); //memcpy(); return err; }
/** * returning current Byte on the UART */ INT8U serialRead(INT16U timeout) { INT8U err = OS_NO_ERR; INT8U rx = (INT8U) OSQPend(uartQsem, timeout, &err); //reading latest byte out of OS Message Que if (err != 0) { printf("Serial Read Error: %d\n", err); } return rx; }
void OutboundThread(void) { WINDOW *local ; /* INITIALIZATION: Paint the local window. Create a */ /* mailbox object to receive keystroke codes from the */ /* keyboard ISR. Initialize the keyboard hardware. */ /* Point interrupt vector 33 at the keyboard ISR. */ /* Unmask the IRQ line in the 8259 PIC. */ local = WindowCreate("Local", 0, 10, 0, 79) ; KeyboardInit() ; /* SerialInit have a guard inside to prevent multiple initializations */ SerialInit() ; for (;;) { BYTE8 err, scan_code ; char ascii ; /* Suspend this thread (let it "sleep") until a */ /* keyboard interrupt posts something to our */ /* mailbox. But first position the cursor */ /* at the next character position as a prompt. */ WindowSelect(local) ; scan_code = ((unsigned) OSQPend(kybd_queue, 0, &err)) & 0xFF ; if (scan_code & 0x80) continue ; /* Key up */ /* The keyboard ISR just woke us up. scan_code */ /* is the keystroke that occurred. First check */ /* to see if it simply changes state, like caps */ /* lock, shift, ctrl, or alt. Then convert the */ /* scancode to ascii using the current state. */ if (SetsKybdState(scan_code)) continue ; ascii = ScanCode2Ascii(scan_code) & 0xFF ; if (!isprint(ascii) && !iscntrl(ascii)) continue ; /* Display the character in the local window. */ WindowPutChar(local, ascii) ; SendPacket(1, &ascii, 1) ; if (ascii == '\r') { static char linefeed = '\n' ; WindowPutChar(local, linefeed) ; SendPacket(1, &linefeed, 1) ; } } }
void echoTask(void* pdata) { void* packet; INT8U err; printf("Echo Task :: started!\n"); while(1) { packet = OSQPend(receiveQueue, 0, &err); printf("Echo Task :: echoing packet!\n"); OSQPost(sendQueue, packet); } }
static void AppTaskObj1 (void *p_arg) { OS_ERR os_err; OS_MSG_SIZE msg_size; (void)p_arg; while (DEF_TRUE) { #if (OS_CFG_SEM_EN > 0u) OSSemPend(&AppTaskObjSem, 0, OS_OPT_PEND_BLOCKING, 0, &os_err); #endif #if (OS_CFG_MUTEX_EN > 0u) OSMutexPend(&AppTaskObjMutex, 0, OS_OPT_PEND_BLOCKING, 0, &os_err); OSMutexPost(&AppTaskObjMutex, OS_OPT_POST_NONE, &os_err); #endif #if (OS_CFG_Q_EN > 0u) OSQPend(&AppTaskObjQ, 0, OS_OPT_PEND_BLOCKING, &msg_size, 0, &os_err); #endif #if (OS_CFG_FLAG_EN > 0u) OSFlagPend(&AppTaskObjFlag, DEF_BIT_00, 0, OS_OPT_PEND_FLAG_SET_ALL + OS_OPT_PEND_FLAG_CONSUME + OS_OPT_PEND_BLOCKING, 0, &os_err); #endif OSTimeDlyHMSM( 0u, 0u, 0u, 10u, OS_OPT_TIME_HMSM_STRICT, &os_err); APP_TRACE_INFO(("Object test task 1 running ....\n")); } }
/* Controllers the IR emitter based on the value of the pushbutton. */ void ir_task(void* pdata) { INT8U err; while (1) { int status = (int)OSQPend(queue, WAIT_FOREVER, &err) - IR_PUSHBUTTON_MESSAGE; if (err == OS_NO_ERR) { printf("IR: %d\n", status); IOWR_ALTERA_AVALON_PIO_DATA(IR_EMITTER_BASE, status); } } }
Q_MSG *DEV_rptPoll(void) { uint8 err; Q_MSG *msg = NULL; msg = (Q_MSG *)OSQPend(dev_Q_r,2,&err); if(err == OS_NO_ERR){ return msg; } else{ return NULL; } }
/********************************************************************************************************* ** Function name: ReadParallelCoinAcceptor ** Descriptions: 读取并行硬币器通道值 ** input parameters: 无 ** output parameters: 无 ** Returned value: 硬币器通道:0x00-未投币;0x01~0x06相应的通道有投币 *********************************************************************************************************/ unsigned char ReadParallelCoinAcceptor(void) { unsigned char err; unsigned char *Pchannel; Pchannel = (unsigned char *)OSQPend(QPChannel,5,&err); if(err == OS_NO_ERR) { return *Pchannel; } else return 0x00; }
void FileReceive_Task (void) { INT8U err; Config_Struct *revConf; while (1) { revConf=(Config_Struct *)OSQPend(ConfigQueueHead, 0, &err); File_Create_TpConfig( revConf ); NVIC_SystemReset(); } }
/* Prints "Hello World" and sleeps for three seconds */ void task2(void* pdata) { INT8U err = OS_NO_ERR; void * data; double frontL, frontR, right, left,distance; //int command=-1; static double angle = 0; pt * position; pt * leftCoord; pt * rightCoord; int *count; count=COUNT_BASE; pt currentPosition; int *power=(int*) GO_BASE; //set up start delay so data does not reset on start up while(*power!=1) { OSTimeDlyHMSM(0, 0, 1, 0); } *count=0; currentPosition.x=0; currentPosition.y=0; position=calloc(1000,sizeof(pt)); leftCoord=calloc(1000,sizeof(pt)); rightCoord=calloc(1000,sizeof(pt)); *POSITION_BASE=position; *RIGHT_COORD_BASE=rightCoord; *LEFT_COORD_BASE=leftCoord; int command; //sets teh user set locations in sdram in memeory with new poitners of 1000 data points while (1) { data = OSQPend(NewData, 0, &err); sscanf((char*) data, "%lf %lf %lf %lf %lf", &frontL, &frontR, &right, &left, &distance); angle+=processDataNC(frontL, frontR, left,right); //set up in no compas(NC) returns assumed angle change and commsn rover in function //command=processDatA(frontL,frontR,left,right,compass); //this function uses the compass and returns with the drive command for hte motors position[*count]=convert(distance, angle + 90, currentPosition); //updates positon currentPosition.x=position[*count].x; currentPosition.y=position[*count].y; rightCoord[*count]=convert(right, angle, currentPosition); leftCoord[*count]=convert(left, angle + 180,currentPosition); *count=*count+1; OSTimeDlyHMSM(0, 0, 0, 50); } }
/********************************************************************************************************* ** Function name: ReadSerialPluseCoinAcceptor ** Descriptions: 读取串行硬币器通道值 ** input parameters: 无 ** output parameters: 无 ** Returned value: 硬币器通道:0x00-未投币;0x01收到一个脉冲, *********************************************************************************************************/ unsigned char ReadSerialPluseCoinAcceptor(void) { unsigned char err; unsigned char *Schannel; Schannel = (unsigned char *)OSQPend(QSChannel,5,&err); if(err == OS_NO_ERR) { //Trace("\r\nSchannel...%d\r\n",*Schannel); return *Schannel; } else return 0x00; }
void Task1 (void *pdata) { char *msg; INT8U err; pdata = pdata; for (;;) { msg = (char *)OSQPend(MsgQueue, 0, &err); PC_DispStr(70, 13, msg, DISP_FGND_YELLOW + DISP_BGND_BLUE); OSTimeDlyHMSM(0, 0, 0, 100); } }
void receive_task2(void* pdata) { INT8U return_code = OS_NO_ERR; INT32U *msg; while (1) { msg = (INT32U *)OSQPend(msgqueue, 0, &return_code); alt_ucosii_check_return_code(return_code); number_of_messages_received_task2++; OSTimeDlyHMSM(0, 0, 1, 0); } }
opQueueElem_t *receive_from_radio_queue(void) { static OS_ERR os_err; static OS_MSG_SIZE msg_size; opQueueElem_t *opQueueElemPtr = OSQPend(&opQueue, 10, OS_OPT_PEND_BLOCKING, &msg_size, NULL, &os_err); //opQueueStruct.queueElemNb--; if(os_err == OS_ERR_TIMEOUT) { opQueueElemPtr = NULL; } return opQueueElemPtr; }
/* * This function waits for a message to be sent to a queue */ extern status_t msgQReceive ( MSG_Q_ID msgQId,/* a pointer to the event control block associated with the desired queue */ int32_t timeout, /* ticks to wait */ void **pmsg /* a pointer to the message to recv */ ) { uint8_t err; *pmsg = OSQPend (msgQId, timeout, &err); if (err == OS_NO_ERR) return OK; return ERROR; }
void Task1 (void *pdata) { char *msg; INT8U err; pdata = pdata; for (;;) { //returns the pointer to the message, MsgQueue is the queue being created using MsgQueue = OSQCreate(&MsgQueueTbl[0], MSG_QUEUE_SIZE); msg = (char *)OSQPend(MsgQueue, 0, &err); //wait forever for a message to arrive PC_DispStr(70, 13, msg, DISP_FGND_YELLOW + DISP_BGND_BLUE); //display the message when it arrives OSTimeDlyHMSM(0, 0, 0, 100); //delayed for 100ms to allow you to see the message received } }