Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
userTask.cpp
- Committer:
- takeru0x1103
- Date:
- 2018-12-01
- Revision:
- 18:5aa48aec9cae
- Parent:
- 17:f9610f3cfa1b
- Child:
- 20:0394e15412c3
File content as of revision 18:5aa48aec9cae:
//RTOS関連 #include "FreeRTOS.h" #include "task.h" #include "queue.h" #include "globalFlags.h" #include "HbManager.h" #include "hbCommand.h" #include "uart.h" #include "fpga.h" //タスクハンドル(停止とか再開に必要) static xTaskHandle tskHandle[3]={NULL,}; //タスク停止 //------------------ static void taskStop(int iId){ sp.printf("Task[%d] Stop\r\n" , iId); vTaskSuspend(tskHandle[iId]);//タスクを止める } //タスク再開 //------------------ static void taskStart(int iId){ sp.printf("Task[%d] Start!!\r\n" , iId); vTaskResume(tskHandle[iId]);//タスク再開 } //======================================================== //ホバーバイク制御タスク //======================================================== void taskHbControl(void *pvParameters){ int8_t *pcTaskName; portTickType xLastWakeTime; HbManager hb; pcTaskName = (int8_t *) pvParameters; xLastWakeTime = xTaskGetTickCount(); // while(1){ led1=!led1; hb.getAttitude();//現在角度読み出し hb.controlAttitude();//姿勢制御 hb.controlMotor();//モーター指令出し hb.controlEngine();//エンジン回転数読み出し //表示フラグを落とす(けどモニタフラグが立ってる箇所は残る) if(gf_Print.flg!=0){ gf_Print.flg=gf_Mon.flg; sp.printf("\r\n"); } //次の周期まで待つ vTaskDelayUntil(&xLastWakeTime, 20 / portTICK_RATE_MS ); } } //======================================================== //コマンド解析タスク //======================================================== void taskCmdParser(void *pvParameters){ int8_t *pcTaskName; portTickType xLastWakeTime; pcTaskName = (int8_t *) pvParameters; xLastWakeTime = xTaskGetTickCount(); static bool runFlg = true; vTaskDelay(300);//制御タスクを先に走らせたいので待たす while(1){ led2=!led2; //コマンド解釈 commandParse(); if(runFlg){// if(gf_Chk.flg != 0){//チェックフラグが何かたってた sp.printf("Enter debug \r\n"); taskStop(0);//制御タスクを止める taskStart(2);//デバッグタスク再開 runFlg = false; } }else{ if(gf_Chk.flg == 0){ sp.printf("Exit debug \r\n"); taskStop(2);//デバッグタスクを止める taskStart(0);//制御タスク再開 runFlg = true; } } //次の周期まで待つ vTaskDelayUntil(&xLastWakeTime, 100 / portTICK_RATE_MS ); } } //======================================================== //デバッグ用タスク //======================================================== void taskDebug(void *pvParameters){ int8_t *pcTaskName; portTickType xLastWakeTime; pcTaskName = (int8_t *) pvParameters; xLastWakeTime = xTaskGetTickCount(); taskStop(2); while(1){ if(gf_Chk.flg != 0){ led3= 1; fpgaMotorChk(); led3= 0; } //タスク停止させて次の周期まで待つ taskStop(2); } } //------------------------------------------------------------- //初期化:タスク登録 //------------------------------------------------------------- void taskInit(){ portBASE_TYPE TaskRtn; //制御タスク TaskRtn= xTaskCreate(taskHbControl, (signed portCHAR *)"Task50Hz", 192, NULL, 2, &tskHandle[0]); if(TaskRtn==pdTRUE){printf("Hoverbike Control task Set\r\n");} //コマンド解析タスク TaskRtn= xTaskCreate(taskCmdParser, (signed portCHAR *)"TaskParser", 192, NULL, 1, &tskHandle[1]); if(TaskRtn==pdTRUE){printf("Command Parser task Set\r\n");} //デバッグタスク TaskRtn= xTaskCreate(taskDebug, (signed portCHAR *)"TaskDebug", 192, NULL, 0, &tskHandle[2]); if(TaskRtn==pdTRUE){printf("Debug Parser task Set\r\n");} //RTOSカーネルの起動 vTaskStartScheduler(); }