static portTASK_FUNCTION(AppTask, pvParameters) { (void)pvParameters; /* not used */ RTC1_TTIME time; RTC1_TDATE date; if (RTC1_GetRTCTimeDate(&time, &date)==ERR_OK) { TmDt1_SetDate((uint16_t)date.year+2000, date.month, date.day); TmDt1_SetTime(time.hour, time.min, time.sec, 0); } else { for(;;) {} /* error */ } (void)NEO_ClearAllPixel(); (void)NEO_TransferPixels(); #if HAS_CLOCK (void)NEOL_PixelTrail(0x00, 0x00, 0xFF, NEO_PIXEL_FIRST, NEO_PIXEL_LAST, 8, 25, 20); (void)NEOL_PixelTrail(0x00, 0xff, 0x00, NEO_PIXEL_FIRST, NEO_PIXEL_LAST, 16, 25, 15); (void)NEOL_PixelTrail(0x00, 0x50, 0xff, NEO_PIXEL_FIRST, NEO_PIXEL_LAST, 16, 25, 10); CLOCK_Init(); #endif for(;;) { #if HAS_ELEVATOR Elevator(); FRTOS1_vTaskDelay(1000/portTICK_RATE_MS); #else CLOCK_Update(); FRTOS1_vTaskDelay(50/portTICK_RATE_MS); #endif } /* for */ }
static portTASK_FUNCTION(RNetTask, pvParameters) { uint32_t cntr; uint8_t msgCntr; (void)pvParameters; /* not used */ if (RAPP_SetThisNodeAddr(RNWK_ADDR_BROADCAST)!=ERR_OK) { /* set a default address */ for(;;); /* "ERR: Failed setting node address" */ } cntr = 0; /* initialize LED counter */ msgCntr = 0; /* initialize message counter */ appState = RNETA_INITIAL; /* initialize state machine state */ for(;;) { Process(); /* process state machine */ cntr++; if (cntr==100) { /* with an RTOS 10 ms/100 Hz tick rate, this is every second */ LED3_On(); /* blink blue LED for 20 ms */ RAPP_SendPayloadDataBlock(&msgCntr, sizeof(msgCntr), RAPP_MSG_TYPE_PING, RNWK_ADDR_BROADCAST, RPHY_PACKET_FLAGS_NONE); msgCntr++; cntr = 0; FRTOS1_vTaskDelay(20/portTICK_RATE_MS); LED3_Off(); /* blink blue LED */ } FRTOS1_vTaskDelay(10/portTICK_RATE_MS); } /* for */ }
static portTASK_FUNCTION(TraceTask, pvParameters) { static unsigned char buf[128]; /* global buffer, to reduce stack size. We want to send things in one piece */ (void)pvParameters; for(;;) { if (traceChannel==TRACE_TO_NONE) { FRTOS1_vTaskDelay(1000/portTICK_RATE_MS); } else if (traceChannel==TRACE_TO_SHELL) { buf[0] = '\0'; UTIL1_strcat(buf, sizeof(buf), (unsigned char*)" => "); if (traceAccel) { int16_t x, y, z; ACCEL_GetValues(&x, &y, &z); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)" X:"); UTIL1_strcatNum16sFormatted(buf, sizeof(buf), x, ' ', 6); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"; Y:"); UTIL1_strcatNum16sFormatted(buf, sizeof(buf), y, ' ', 6); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"; Z:"); UTIL1_strcatNum16sFormatted(buf, sizeof(buf), z, ' ', 6); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n"); CLS1_SendStr(&buf[0], CLS1_GetStdio()->stdOut); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } FRTOS1_vTaskDelay(25/portTICK_RATE_MS); } } }
static portTASK_FUNCTION(Button, pvParameters) { CLS1_ConstStdIOType *io = CLS1_GetStdio(); (void)pvParameters; /* parameter not used */ for(;;) { /* check push button switch: turns on/off cooling immediately */ if (SW2_GetVal()==0) { /* button pressed */ FRTOS1_vTaskDelay(10/portTICK_RATE_MS); /* debounce */ if (SW2_GetVal()==0) { /* still pressed */ while(SW2_GetVal()==0) { /* wait until released */ FRTOS1_vTaskDelay(10/portTICK_RATE_MS); /* debounce */ } DisableScheduler(io); if (isPumpOn) { /* pump is on, toggle it */ SetCooling(FALSE, io); /* turn cooling off */ mySchedule.isSchedulerOn = TRUE; /* turn scheduler on again */ } else { SetCooling(TRUE, io); /* turn cooling on */ } } } FRTOS1_vTaskDelay(50/portTICK_RATE_MS); } /* for */ }
static void CheckButton(void) { uint32_t timeTicks; /* time in ticks */ #define BUTTON_CNT_MS 100 /* iteration count for button */ bool autoCalibrate = FALSE; if (SW1_GetVal()==0) { /* button pressed */ /* short press (1 beep): start or stop line following if calibrated * 1 s press (2 beep): calibrate manually * 2 s press (3 beep): calibrate with auto-move * 3 s press (4 beep or more): clear path * */ FRTOS1_vTaskDelay(50/portTICK_RATE_MS); /* simple debounce */ if (SW1_GetVal()==0) { /* still pressed */ LEDG_On(); timeTicks = 0; while(SW1_GetVal()==0 && timeTicks<=6000/BUTTON_CNT_MS) { FRTOS1_vTaskDelay(BUTTON_CNT_MS/portTICK_RATE_MS); if ((timeTicks%(1000/BUTTON_CNT_MS))==0) { #if PL_HAS_BUZZER BUZ_Beep(300, 200); #endif } timeTicks++; } /* wait until released */ autoCalibrate = FALSE; if (timeTicks<1000/BUTTON_CNT_MS) { /* less than 1 second */ CLS1_SendStr((unsigned char*)"button press.\r\n", CLS1_GetStdio()->stdOut); StateMachine(TRUE); /* <1 s, short button press, according to state machine */ } else if (timeTicks>=(1000/BUTTON_CNT_MS) && timeTicks<(2000/BUTTON_CNT_MS)) { CLS1_SendStr((unsigned char*)"calibrate.\r\n", CLS1_GetStdio()->stdOut); APP_StateStartCalibrate(); /* 1-2 s: start calibration by hand */ } else if (timeTicks>=(2000/BUTTON_CNT_MS) && timeTicks<(3000/BUTTON_CNT_MS)) { CLS1_SendStr((unsigned char*)"auto calibrate.\r\n", CLS1_GetStdio()->stdOut); APP_StateStartCalibrate(); /* 2-3 s: start auto calibration */ autoCalibrate = TRUE; } else if (timeTicks>=(3000/BUTTON_CNT_MS)) { CLS1_SendStr((unsigned char*)"delete solution.\r\n", CLS1_GetStdio()->stdOut); MAZE_ClearSolution(); } while (SW1_GetVal()==0) { /* wait until button is released */ FRTOS1_vTaskDelay(BUTTON_CNT_MS/portTICK_RATE_MS); } if (autoCalibrate) { CLS1_SendStr((unsigned char*)"start auto-calibration...\r\n", CLS1_GetStdio()->stdOut); /* perform automatic calibration */ WAIT1_WaitOSms(1500); /* wait some time */ TURN_Turn(TURN_LEFT90); TURN_Turn(TURN_RIGHT90); TURN_Turn(TURN_RIGHT90); TURN_Turn(TURN_LEFT90); TURN_Turn(TURN_STOP); APP_StateStopCalibrate(); CLS1_SendStr((unsigned char*)"auto-calibration finished.\r\n", CLS1_GetStdio()->stdOut); } } } /* if */ }
static portTASK_FUNCTION(Fight_modus, pvParameters) { #if PL_HAS_DRIVE DRV_EnableDisable(FALSE); DRV_EnableDisablePos(FALSE); #endif fight_state = FIND_ENEMY; FRTOS1_vTaskDelay(100/TRG_TICKS_MS); for(;;) { FRTOS1_vTaskDelay(10/TRG_TICKS_MS); FightmodusV2(); } }
/** * \brief FreeRTOS task */ static portTASK_FUNCTION(MyTask, pvParameters) { (void)pvParameters; /* parameter not used */ for(;;) { LED1_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); LED2_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); LED3_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); LED4_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } /* for */ }
static portTASK_FUNCTION(SoundTask, pvParameters) { (void)pvParameters; /* avoid compiler warning */ for(;;) { SOUND_SetFreqHz(freqSounder); SOUND_Enable(); FRTOS1_vTaskDelay(80/portTICK_RATE_MS); SOUND_Disable(); FRTOS1_vTaskDelay(80/portTICK_RATE_MS); SOUND_Enable(); FRTOS1_vTaskDelay(80/portTICK_RATE_MS); SOUND_Disable(); FRTOS1_vTaskSuspend(NULL); /* put itself to sleep */ } }
static portTASK_FUNCTION(LineTask, pvParameters) { (void)pvParameters; /* not used */ for(;;) { if (LF_stopIt) { ChangeState(STATE_STOP); LF_stopIt = FALSE; } StateMachine(); if (LF_IsFollowing()) { FRTOS1_vTaskDelay(5/portTICK_RATE_MS); } else { FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } } }
static void PlayMIDI(void) { int instrument, note; VS1_MIDI_SetBank(0, 0); for(instrument=0; instrument<127; instrument++) { VS1_MIDI_SetInstrument(0, instrument); for(note=30; note<40; note++) { VS1_MIDI_NoteOn(0, note, 127); FRTOS1_vTaskDelay(200/portTICK_RATE_MS); VS1_MIDI_NoteOff(0, note, 127); FRTOS1_vTaskDelay(50/portTICK_RATE_MS); } FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } }
static void AppTask(void *pvParameters) { (void)pvParameters; /* parameter not used */ for(;;) { LED1_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } }
static portTASK_FUNCTION(ShellTask, pvParameters) { #if PL_HAS_SD_CARD bool cardMounted = FALSE; static FAT1_FATFS fileSystemObject; #endif unsigned char buf[48]; (void)pvParameters; /* not used */ buf[0] = '\0'; (void)CLS1_ParseWithCommandTable((unsigned char*)CLS1_CMD_HELP, CLS1_GetStdio(), CmdParserTable); for(;;) { #if PL_HAS_SD_CARD (void)FAT1_CheckCardPresence(&cardMounted, 0 /* volume */, &fileSystemObject, CLS1_GetStdio()); if (cardMounted) { //SD_GreenLed_On(); //SD_RedLed_Off(); } else { //SD_GreenLed_Off(); //SD_RedLed_On(); } #endif (void)CLS1_ReadAndParseWithCommandTable(buf, sizeof(buf), CLS1_GetStdio(), CmdParserTable); FRTOS1_vTaskDelay(50/portTICK_RATE_MS); LEDG_Neg(); } }
static portTASK_FUNCTION(RoboTask, pvParameters) { uint16_t cm; (void)pvParameters; /* not used */ for(;;) { cm = MeasureCm(); LEDR_Neg(); if (runIt && cm != 0) { if (cm<10) { /* back up! */ MOT_SetSpeedPercent(MOT_GetMotorA(), -40); MOT_SetSpeedPercent(MOT_GetMotorB(), -40); } else if (cm>=10 && cm<=15) { /* stand still */ MOT_SetSpeedPercent(MOT_GetMotorA(), 0); MOT_SetSpeedPercent(MOT_GetMotorB(), 0); } else if (cm>15 && cm<=40) { MOT_SetSpeedPercent(MOT_GetMotorA(), 50); MOT_SetSpeedPercent(MOT_GetMotorB(), 50); } else if (cm>40 && cm<80) { MOT_SetSpeedPercent(MOT_GetMotorA(), 80); MOT_SetSpeedPercent(MOT_GetMotorB(), 80); } else { /* nothing in range */ MOT_SetSpeedPercent(MOT_GetMotorA(), 0); MOT_SetSpeedPercent(MOT_GetMotorB(), 0); } } FRTOS1_vTaskDelay(50/portTICK_RATE_MS); } }
static portTASK_FUNCTION(Task4, pvParameters) { (void)pvParameters; /* parameter not used */ for(;;) { LED4_Neg(); FRTOS1_vTaskDelay(800/portTICK_RATE_MS); } }
static portTASK_FUNCTION(TaskRunner, pvParameters) { RUNNER_WindowDesc *ui = (RUNNER_WindowDesc*)pvParameters; char_t buf[I2C_RUNNER_I2C_MSG_SIZE]; uint8_t cnt; bool errorCond; appWp = ui; #if PL_APP_MODE_I2C_LCD I2C_ClearBuffers(); #endif ResetRunnerDisplayList(); RUNNER_listLastRecords = TRUE; /* request getting runners */ cnt = 0; for (;;) { I2C_SendCmd(); errorCond = FALSE; while (I2C_GetRunnerMessage(buf, sizeof(buf))==ERR_OK) { /* message received, process as many and as fast as possible */ if (ParseNewRunnerMsg(buf)!=ERR_OK) { errorCond = TRUE; /* flag error */ } } /* while */ DisplayRunners(ui); if (errorCond) { UI1_DrawFilledBox(&appWp->window, 120, 8, 5, 5, UI1_COLOR_RED); } else { UI1_DrawFilledBox(&appWp->window, 120, 8, 5, 5, UI1_COLOR_BLUE); } FRTOS1_vTaskDelay(100/portTICK_RATE_MS); cnt++; UI1_DrawFilledBox(&appWp->window, 110, 8, 5, 5, cnt<10?UI1_COLOR_BLUE:UI1_COLOR_GREEN); if (cnt==20) { cnt=0; } } /* for */ }
static portTASK_FUNCTION(StateMachineTask, pvParameters) { (void)pvParameters; /* not used */ for(;;) { StateMachine_Run(); FRTOS1_vTaskDelay(10/portTICK_RATE_MS); } }
static portTASK_FUNCTION(MainTask, pvParameters) { uint16_t msCnt; (void) pvParameters; /* parameter not used */ #if PL_HAS_ACCEL ACCEL_LowLevelInit(); #endif for (;;) { EVNT_HandleEvent(APP_EvntHandler); #if PL_HAS_KEYS && !PL_HAS_KBI KEY_Scan(); /* poll keys */ #endif FRTOS1_vTaskDelay(20/portTICK_RATE_MS); msCnt += 20; if (msCnt > 280) { #if PL_HAS_ULTRASONIC (void)US_Measure_us(); /* Measure distance */ #endif msCnt = 0; } } }
void I2C_StoreCmd(void) { #if PL_HAS_UI unsigned char buf[32]; uint8_t strSize; #if PL_HAS_RUNNER buf[0] = '@'; buf[1] = '\0'; RUNNER_GetCmdString(buf, sizeof(buf)); #elif PL_HAS_SLIDER SLIDER_GetCmdString(buf, sizeof(buf)); #else buf[0] = '\0'; #endif if (buf[0]!='\0') { uint8_t cnt=3; while(cnt>0 && memDevice.u.data.cmdLength!=0) { /* poll cmdLength: this will be set to zero by the master if it is ok to place the string */ FRTOS1_vTaskDelay(50/portTICK_RATE_MS); /* give master some time to clear the flasg */ cnt--; } if (cnt==0) { /* timeout. Will loose that command. Not ideal, but simple :-) */ return; /* get out here */ } strSize = (uint8_t)(UTIL1_strlen(buf)+1); /* size of string including zero byte */ if (strSize>sizeof(memDevice.u.data.cmd)) { strSize = sizeof(memDevice.u.data.cmd); } EnterCritical(); memDevice.u.data.cmdLength = strSize; UTIL1_strcpy(memDevice.u.data.cmd, sizeof(memDevice.u.data.cmd), buf); ExitCritical(); } #endif /* PL_HAS_UI */ }
static portTASK_FUNCTION(MainTask, pvParameters) { (void)pvParameters; for(;;) { LED1_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } }
void GetConnection(void) { typedef enum { GetCon1, Passed, Error } GetConState_Type; GetConState_Type GetConState = GetCon1; while (GetConState != Passed) { switch (GetConState) { case GetCon1: SendSim900("AT+GetConnection\r\n"); if (CompareString(buffer, "ok", 2)) { //are the same FRTOS1_xSemaphoreGive(SuccessLedMutex); GetConState = Passed; } break; default: GetConState = Error; break; } FRTOS1_vTaskDelay( GET_CONNECTION_STATEMACHINE_DELAY_MS/portTICK_PERIOD_MS); } }
static portTASK_FUNCTION(AppTask, pvParameters) { (void)pvParameters; /* not used */ for(;;) { LED1_Neg(); FRTOS1_vTaskDelay(500/portTICK_RATE_MS); } /* for */ }
static portTASK_FUNCTION(DriveTask, pvParameters) { (void)pvParameters; /* parameter not used */ bool prevOn; //traceLabel usrEvent; prevOn = DRV_SpeedOn; #if PL_HAS_RTOS_TRACE //usrEvent = xTraceOpenLabel("drive"); #endif for(;;) { #if PL_HAS_RTOS_TRACE //RTOSTRC1_vTraceUserEvent(usrEvent); #endif /*! \todo extend this for your own needs and with a position PID */ TACHO_CalcSpeed(); if (prevOn && !DRV_SpeedOn) { /* turned off */ MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_LEFT), 0); MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_RIGHT), 0); PID_Start(); /* reset values */ } else if (DRV_SpeedOn) { PID_Speed(TACHO_GetSpeed(TRUE), DRV_SpeedLeft, TRUE); /* left */ PID_Speed(TACHO_GetSpeed(FALSE), DRV_SpeedRight, FALSE); /* right */ } prevOn = DRV_SpeedOn; FRTOS1_vTaskDelay(2/portTICK_RATE_MS); } /* for */ }
void BootUpModule(void) { typedef enum { Bootup1, Passed, Error } BootUpState_Type; BootUpState_Type BootUpState = Bootup1; while (BootUpState != Passed) { switch (BootUpState) { case Bootup1: SendSim900("AT+Bootup\r\n"); if (CompareString(buffer, "OK", 2)) { //are the same FRTOS1_xSemaphoreGive(SuccessLedMutex); BootUpState = Passed; } break; default: BootUpState = Error; break; } FRTOS1_vTaskDelay(BOOTUP_STATEMACHINE_DELAY_MS/portTICK_PERIOD_MS); } }
static void Play(MIDI_MusicTrack *tracks, unsigned int nofTracks) { int itemNo; uint8_t channel; uint32_t currTimeMs; TickType_t startTicks; unsigned int nofFinished; /* init defaults */ for(channel=0;channel<nofTracks;channel++) { VS1_MIDI_SetBank(channel, 0); VS1_MIDI_SetInstrument(channel, VS1_MIDI_INSTR_Default); VS1_MIDI_SetVolume(channel, 127); } startTicks = FRTOS1_xTaskGetTickCount(); itemNo = 0; for(;;) { /* breaks */ currTimeMs = (FRTOS1_xTaskGetTickCount()-startTicks)/portTICK_RATE_MS; #if 0 if (currTimeMs>15000) { break; } #endif nofFinished = 0; for(channel=0;channel<nofTracks;channel++) { if (!PlayTrackItem(&tracks[channel], currTimeMs, channel)) { nofFinished++; } } if (nofFinished==nofTracks) { /* all finished */ break; } FRTOS1_vTaskDelay(1/portTICK_RATE_MS); itemNo++; } }
static portTASK_FUNCTION(ReflTask, pvParameters) { (void)pvParameters; /* not used */ for(;;) { REF_StateMachine(); FRTOS1_vTaskDelay(10/TRG_TICKS_MS); } }
static portTASK_FUNCTION(MainTask, pvParameters) { (void)pvParameters; /* not used */ #if PL_HAS_TSS Configure(); /* initialize TSS library */ #endif for(;;) { #if PL_HAS_TSS TSS_Task(); /* call TSS library to process touches */ #else CheckButton(); #endif #if PL_APP_FOLLOW_OBSTACLE FollowObstacle(); #endif #if PL_HAS_LED_BLUE LEDB_Neg(); #endif #if PL_HAS_RADIO (void)RADIO_Handle(); #endif #if PL_HAS_EVENTS EVNT_HandleEvent(RADIO_AppHandleEvent); #endif StateMachine(FALSE); FRTOS1_vTaskDelay(10/portTICK_RATE_MS); } }
void ACCEL_StopAccelDemo(void) { EVNT1_SetEvent(EVNT1_APP_MODE_CHANGE); /* request to close application */ while(EVNT1_GetEvent(EVNT1_APP_MODE_CHANGE)) { /* wait until task has killed itself */ FRTOS1_vTaskDelay(50/portTICK_RATE_MS); } APP_SetApplicationMode(APP_MODE_MAIN_MENU); }
static portTASK_FUNCTION(vSlaveTask, pvParameters) { for(;;) { xSemaphoreGive(MySemTest); FRTOS1_vTaskDelay(500); } }
static void ReflTask (void *pvParameters) { (void)pvParameters; /* not used */ // SQUEUE_SendString("Reflectance task started!\r\n"); for(;;) { REF_StateMachine(); FRTOS1_vTaskDelay(10/portTICK_RATE_MS); } }
static portTASK_FUNCTION(RadioTask, pvParameters) { (void)pvParameters; /* not used */ (void)RADIO_PowerUp(); for(;;) { (void)RADIO_Process(); FRTOS1_vTaskDelay(5/portTICK_RATE_MS); } }