teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
takeru0x1103
Date:
Sat Dec 01 14:03:08 2018 +0000
Revision:
18:5aa48aec9cae
Parent:
17:f9610f3cfa1b
Child:
20:0394e15412c3
??????????PID????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takeru0x1103 1:15ab74f0d0f1 1 //RTOS関連
takeru0x1103 1:15ab74f0d0f1 2 #include "FreeRTOS.h"
takeru0x1103 1:15ab74f0d0f1 3 #include "task.h"
takeru0x1103 1:15ab74f0d0f1 4 #include "queue.h"
takeru0x1103 17:f9610f3cfa1b 5 #include "globalFlags.h"
takeru0x1103 17:f9610f3cfa1b 6 #include "HbManager.h"
takeru0x1103 18:5aa48aec9cae 7 #include "hbCommand.h"
takeru0x1103 18:5aa48aec9cae 8 #include "uart.h"
takeru0x1103 18:5aa48aec9cae 9 #include "fpga.h"
takeru0x1103 1:15ab74f0d0f1 10
takeru0x1103 18:5aa48aec9cae 11 //タスクハンドル(停止とか再開に必要)
takeru0x1103 18:5aa48aec9cae 12 static xTaskHandle tskHandle[3]={NULL,};
takeru0x1103 1:15ab74f0d0f1 13
takeru0x1103 18:5aa48aec9cae 14 //タスク停止
takeru0x1103 18:5aa48aec9cae 15 //------------------
takeru0x1103 18:5aa48aec9cae 16 static void taskStop(int iId){
takeru0x1103 18:5aa48aec9cae 17 sp.printf("Task[%d] Stop\r\n" , iId);
takeru0x1103 18:5aa48aec9cae 18 vTaskSuspend(tskHandle[iId]);//タスクを止める
takeru0x1103 18:5aa48aec9cae 19 }
takeru0x1103 18:5aa48aec9cae 20
takeru0x1103 18:5aa48aec9cae 21 //タスク再開
takeru0x1103 18:5aa48aec9cae 22 //------------------
takeru0x1103 18:5aa48aec9cae 23 static void taskStart(int iId){
takeru0x1103 18:5aa48aec9cae 24 sp.printf("Task[%d] Start!!\r\n" , iId);
takeru0x1103 18:5aa48aec9cae 25 vTaskResume(tskHandle[iId]);//タスク再開
takeru0x1103 18:5aa48aec9cae 26 }
takeru0x1103 18:5aa48aec9cae 27
takeru0x1103 18:5aa48aec9cae 28 //========================================================
takeru0x1103 17:f9610f3cfa1b 29 //ホバーバイク制御タスク
takeru0x1103 18:5aa48aec9cae 30 //========================================================
takeru0x1103 17:f9610f3cfa1b 31 void taskHbControl(void *pvParameters){
takeru0x1103 17:f9610f3cfa1b 32 int8_t *pcTaskName;
takeru0x1103 17:f9610f3cfa1b 33 portTickType xLastWakeTime;
takeru0x1103 17:f9610f3cfa1b 34 HbManager hb;
takeru0x1103 8:1ca49cb18290 35
takeru0x1103 1:15ab74f0d0f1 36 pcTaskName = (int8_t *) pvParameters;
takeru0x1103 1:15ab74f0d0f1 37 xLastWakeTime = xTaskGetTickCount();
takeru0x1103 8:1ca49cb18290 38
takeru0x1103 18:5aa48aec9cae 39 //
takeru0x1103 1:15ab74f0d0f1 40 while(1){
takeru0x1103 16:05b9e44889f1 41 led1=!led1;
takeru0x1103 18:5aa48aec9cae 42
takeru0x1103 18:5aa48aec9cae 43 hb.getAttitude();//現在角度読み出し
takeru0x1103 18:5aa48aec9cae 44 hb.controlAttitude();//姿勢制御
takeru0x1103 18:5aa48aec9cae 45 hb.controlMotor();//モーター指令出し
takeru0x1103 18:5aa48aec9cae 46 hb.controlEngine();//エンジン回転数読み出し
takeru0x1103 18:5aa48aec9cae 47
takeru0x1103 18:5aa48aec9cae 48
takeru0x1103 18:5aa48aec9cae 49 //表示フラグを落とす(けどモニタフラグが立ってる箇所は残る)
takeru0x1103 18:5aa48aec9cae 50 if(gf_Print.flg!=0){
takeru0x1103 18:5aa48aec9cae 51 gf_Print.flg=gf_Mon.flg;
takeru0x1103 18:5aa48aec9cae 52 sp.printf("\r\n");
takeru0x1103 18:5aa48aec9cae 53 }
takeru0x1103 1:15ab74f0d0f1 54
takeru0x1103 1:15ab74f0d0f1 55 //次の周期まで待つ
takeru0x1103 1:15ab74f0d0f1 56 vTaskDelayUntil(&xLastWakeTime, 20 / portTICK_RATE_MS );
takeru0x1103 1:15ab74f0d0f1 57 }
takeru0x1103 1:15ab74f0d0f1 58 }
takeru0x1103 18:5aa48aec9cae 59 //========================================================
takeru0x1103 17:f9610f3cfa1b 60 //コマンド解析タスク
takeru0x1103 18:5aa48aec9cae 61 //========================================================
takeru0x1103 17:f9610f3cfa1b 62 void taskCmdParser(void *pvParameters){
takeru0x1103 17:f9610f3cfa1b 63 int8_t *pcTaskName;
takeru0x1103 17:f9610f3cfa1b 64 portTickType xLastWakeTime;
takeru0x1103 17:f9610f3cfa1b 65
takeru0x1103 17:f9610f3cfa1b 66 pcTaskName = (int8_t *) pvParameters;
takeru0x1103 17:f9610f3cfa1b 67 xLastWakeTime = xTaskGetTickCount();
takeru0x1103 17:f9610f3cfa1b 68
takeru0x1103 18:5aa48aec9cae 69 static bool runFlg = true;
takeru0x1103 18:5aa48aec9cae 70
takeru0x1103 18:5aa48aec9cae 71 vTaskDelay(300);//制御タスクを先に走らせたいので待たす
takeru0x1103 18:5aa48aec9cae 72
takeru0x1103 17:f9610f3cfa1b 73 while(1){
takeru0x1103 17:f9610f3cfa1b 74 led2=!led2;
takeru0x1103 18:5aa48aec9cae 75 //コマンド解釈
takeru0x1103 17:f9610f3cfa1b 76 commandParse();
takeru0x1103 18:5aa48aec9cae 77
takeru0x1103 18:5aa48aec9cae 78 if(runFlg){//
takeru0x1103 18:5aa48aec9cae 79 if(gf_Chk.flg != 0){//チェックフラグが何かたってた
takeru0x1103 18:5aa48aec9cae 80 sp.printf("Enter debug \r\n");
takeru0x1103 18:5aa48aec9cae 81 taskStop(0);//制御タスクを止める
takeru0x1103 18:5aa48aec9cae 82 taskStart(2);//デバッグタスク再開
takeru0x1103 18:5aa48aec9cae 83 runFlg = false;
takeru0x1103 18:5aa48aec9cae 84 }
takeru0x1103 18:5aa48aec9cae 85 }else{
takeru0x1103 18:5aa48aec9cae 86 if(gf_Chk.flg == 0){
takeru0x1103 18:5aa48aec9cae 87 sp.printf("Exit debug \r\n");
takeru0x1103 18:5aa48aec9cae 88 taskStop(2);//デバッグタスクを止める
takeru0x1103 18:5aa48aec9cae 89 taskStart(0);//制御タスク再開
takeru0x1103 18:5aa48aec9cae 90 runFlg = true;
takeru0x1103 18:5aa48aec9cae 91 }
takeru0x1103 18:5aa48aec9cae 92 }
takeru0x1103 18:5aa48aec9cae 93
takeru0x1103 17:f9610f3cfa1b 94 //次の周期まで待つ
takeru0x1103 17:f9610f3cfa1b 95 vTaskDelayUntil(&xLastWakeTime, 100 / portTICK_RATE_MS );
takeru0x1103 17:f9610f3cfa1b 96 }
takeru0x1103 17:f9610f3cfa1b 97 }
takeru0x1103 18:5aa48aec9cae 98 //========================================================
takeru0x1103 18:5aa48aec9cae 99 //デバッグ用タスク
takeru0x1103 18:5aa48aec9cae 100 //========================================================
takeru0x1103 18:5aa48aec9cae 101 void taskDebug(void *pvParameters){
takeru0x1103 18:5aa48aec9cae 102 int8_t *pcTaskName;
takeru0x1103 18:5aa48aec9cae 103 portTickType xLastWakeTime;
takeru0x1103 18:5aa48aec9cae 104
takeru0x1103 18:5aa48aec9cae 105 pcTaskName = (int8_t *) pvParameters;
takeru0x1103 18:5aa48aec9cae 106 xLastWakeTime = xTaskGetTickCount();
takeru0x1103 18:5aa48aec9cae 107
takeru0x1103 18:5aa48aec9cae 108 taskStop(2);
takeru0x1103 18:5aa48aec9cae 109
takeru0x1103 18:5aa48aec9cae 110 while(1){
takeru0x1103 18:5aa48aec9cae 111 if(gf_Chk.flg != 0){
takeru0x1103 18:5aa48aec9cae 112 led3= 1;
takeru0x1103 18:5aa48aec9cae 113 fpgaMotorChk();
takeru0x1103 18:5aa48aec9cae 114 led3= 0;
takeru0x1103 18:5aa48aec9cae 115 }
takeru0x1103 18:5aa48aec9cae 116
takeru0x1103 18:5aa48aec9cae 117 //タスク停止させて次の周期まで待つ
takeru0x1103 18:5aa48aec9cae 118 taskStop(2);
takeru0x1103 18:5aa48aec9cae 119 }
takeru0x1103 18:5aa48aec9cae 120 }
takeru0x1103 17:f9610f3cfa1b 121
takeru0x1103 1:15ab74f0d0f1 122 //-------------------------------------------------------------
takeru0x1103 17:f9610f3cfa1b 123 //初期化:タスク登録
takeru0x1103 1:15ab74f0d0f1 124 //-------------------------------------------------------------
takeru0x1103 1:15ab74f0d0f1 125 void taskInit(){
takeru0x1103 1:15ab74f0d0f1 126 portBASE_TYPE TaskRtn;
takeru0x1103 17:f9610f3cfa1b 127
takeru0x1103 18:5aa48aec9cae 128 //制御タスク
takeru0x1103 18:5aa48aec9cae 129 TaskRtn= xTaskCreate(taskHbControl, (signed portCHAR *)"Task50Hz", 192, NULL, 2, &tskHandle[0]);
takeru0x1103 17:f9610f3cfa1b 130 if(TaskRtn==pdTRUE){printf("Hoverbike Control task Set\r\n");}
takeru0x1103 18:5aa48aec9cae 131
takeru0x1103 18:5aa48aec9cae 132 //コマンド解析タスク
takeru0x1103 18:5aa48aec9cae 133 TaskRtn= xTaskCreate(taskCmdParser, (signed portCHAR *)"TaskParser", 192, NULL, 1, &tskHandle[1]);
takeru0x1103 17:f9610f3cfa1b 134 if(TaskRtn==pdTRUE){printf("Command Parser task Set\r\n");}
takeru0x1103 8:1ca49cb18290 135
takeru0x1103 18:5aa48aec9cae 136 //デバッグタスク
takeru0x1103 18:5aa48aec9cae 137 TaskRtn= xTaskCreate(taskDebug, (signed portCHAR *)"TaskDebug", 192, NULL, 0, &tskHandle[2]);
takeru0x1103 18:5aa48aec9cae 138 if(TaskRtn==pdTRUE){printf("Debug Parser task Set\r\n");}
takeru0x1103 18:5aa48aec9cae 139
takeru0x1103 18:5aa48aec9cae 140 //RTOSカーネルの起動
takeru0x1103 1:15ab74f0d0f1 141 vTaskStartScheduler();
takeru0x1103 1:15ab74f0d0f1 142 }
takeru0x1103 1:15ab74f0d0f1 143
takeru0x1103 1:15ab74f0d0f1 144