teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
takeru0x1103
Date:
Wed Dec 05 01:43:55 2018 +0000
Revision:
20:0394e15412c3
Parent:
19:4b0fe9a5ec38
Child:
21:78302ecdb661
1205_?????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takeru0x1103 19:4b0fe9a5ec38 1
takeru0x1103 16:05b9e44889f1 2 #include "globalFlags.h"
takeru0x1103 19:4b0fe9a5ec38 3 #define STATE_BUF_SIZ 8
takeru0x1103 16:05b9e44889f1 4
takeru0x1103 16:05b9e44889f1 5 DigitalOut led1(LED1);
takeru0x1103 16:05b9e44889f1 6 DigitalOut led2(LED2);
takeru0x1103 16:05b9e44889f1 7 DigitalOut led3(LED3);
takeru0x1103 16:05b9e44889f1 8 DigitalOut led4(LED4);
takeru0x1103 8:1ca49cb18290 9
takeru0x1103 19:4b0fe9a5ec38 10 char g_CmdBuf[G_CMD_BUF_SIZ] ;// コマンド受け渡しバッファ
takeru0x1103 17:f9610f3cfa1b 11 bool gf_CmdPrs = false;
takeru0x1103 19:4b0fe9a5ec38 12
takeru0x1103 19:4b0fe9a5ec38 13 typPrintFlag gf_Print ;//
takeru0x1103 19:4b0fe9a5ec38 14 typPrintFlag gf_Mon ;//
takeru0x1103 19:4b0fe9a5ec38 15 typCalFlag gf_Cal ;//
takeru0x1103 20:0394e15412c3 16 //typChkFlag gf_Chk ;//チェックフラグ
takeru0x1103 19:4b0fe9a5ec38 17 typAccel gf_AxReq[2] ={0,} ;//アクセル更新
takeru0x1103 19:4b0fe9a5ec38 18 typAccel gf_MtReq[4] ={0,} ;//モーター更新
takeru0x1103 19:4b0fe9a5ec38 19 bool gf_AttCntEna ;//姿勢制御イネーブル
takeru0x1103 19:4b0fe9a5ec38 20
takeru0x1103 20:0394e15412c3 21
takeru0x1103 19:4b0fe9a5ec38 22 GlobalFlags gf;
takeru0x1103 19:4b0fe9a5ec38 23
takeru0x1103 19:4b0fe9a5ec38 24 //===========================================
takeru0x1103 19:4b0fe9a5ec38 25 //コンストラクタ
takeru0x1103 19:4b0fe9a5ec38 26 //===========================================
takeru0x1103 19:4b0fe9a5ec38 27 GlobalFlags::GlobalFlags(){
takeru0x1103 19:4b0fe9a5ec38 28 //初期ステート
takeru0x1103 19:4b0fe9a5ec38 29 state = WAKEUP;
takeru0x1103 19:4b0fe9a5ec38 30 //ステートキュー初期化
takeru0x1103 19:4b0fe9a5ec38 31 for(int i=0; i<STATE_QUE_SIZ; i++){
takeru0x1103 19:4b0fe9a5ec38 32 stateQueue[i] = NONE;
takeru0x1103 19:4b0fe9a5ec38 33 }
takeru0x1103 19:4b0fe9a5ec38 34 rp = wp = 0;//先頭を指す
takeru0x1103 19:4b0fe9a5ec38 35 full = false;//最初はエンプティ
takeru0x1103 19:4b0fe9a5ec38 36 empty = true;
takeru0x1103 19:4b0fe9a5ec38 37 }
takeru0x1103 19:4b0fe9a5ec38 38
takeru0x1103 19:4b0fe9a5ec38 39 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 40 //ステートのFIFOにプッシュする
takeru0x1103 19:4b0fe9a5ec38 41 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 42 bool GlobalFlags::push(enmHbState iState){
takeru0x1103 19:4b0fe9a5ec38 43 if(full){
takeru0x1103 19:4b0fe9a5ec38 44 return false;//FFULLフラグが立ってら入力を受け付けない
takeru0x1103 19:4b0fe9a5ec38 45 }else{
takeru0x1103 19:4b0fe9a5ec38 46 stateQueue[wp] = iState;//キューに突っ込んで
takeru0x1103 19:4b0fe9a5ec38 47 wp = (wp==STATE_QUE_SIZ) ? 0 : wp+1;//ライトポインタを進める
takeru0x1103 19:4b0fe9a5ec38 48 full = (wp == rp)? true : false; //次ライト予定の場所がリードポインタに追いついたらFULLを立てる
takeru0x1103 19:4b0fe9a5ec38 49 empty = false;
takeru0x1103 19:4b0fe9a5ec38 50 return true;
takeru0x1103 19:4b0fe9a5ec38 51 }
takeru0x1103 19:4b0fe9a5ec38 52 }
takeru0x1103 19:4b0fe9a5ec38 53
takeru0x1103 19:4b0fe9a5ec38 54 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 55 //ステートFIFOから次の予約ステートを引き抜く
takeru0x1103 19:4b0fe9a5ec38 56 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 57 bool GlobalFlags::pull(){
takeru0x1103 19:4b0fe9a5ec38 58 if(empty){
takeru0x1103 19:4b0fe9a5ec38 59 return false;//EMPTYだったら引き抜けない
takeru0x1103 19:4b0fe9a5ec38 60 }else{
takeru0x1103 19:4b0fe9a5ec38 61 state = stateQueue[rp];//リードポインタの指すデータをステートに移す
takeru0x1103 19:4b0fe9a5ec38 62 stateQueue[rp] = NONE;//バッファを消す
takeru0x1103 19:4b0fe9a5ec38 63 rp = (rp==STATE_QUE_SIZ) ? 0 : rp+1;//リードポインタを進める
takeru0x1103 19:4b0fe9a5ec38 64 full = false; //フルではなくなる
takeru0x1103 19:4b0fe9a5ec38 65 empty = (stateQueue[rp] == NONE) ? true : false;//次にリードする場所がNONEだったらEMPTYを立てる
takeru0x1103 19:4b0fe9a5ec38 66 return true;
takeru0x1103 19:4b0fe9a5ec38 67 }
takeru0x1103 19:4b0fe9a5ec38 68 }
takeru0x1103 19:4b0fe9a5ec38 69
takeru0x1103 19:4b0fe9a5ec38 70