teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Thu Jan 24 13:21:01 2019 +0000
Revision:
43:156199c2f9b6
Parent:
42:cc8501b824ba
Child:
45:3b51dd26b579
20190124 Modify for 45inc.; Add to varialble servo step val , Blink LED when pressing up-down sw in HOVER State.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takeru0x1103 19:4b0fe9a5ec38 1
takeru0x1103 16:05b9e44889f1 2 #include "globalFlags.h"
takeru0x1103 16:05b9e44889f1 3
MasashiNomura 22:24c9c2dedca9 4 //モニタ用LED
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
MasashiNomura 40:debe99e228d3 10 //状態表示用
MasashiNomura 41:45c982b1c5b6 11 DigitalOut DO_01(p21);//R
MasashiNomura 41:45c982b1c5b6 12 DigitalOut DO_02(p22);//G
MasashiNomura 41:45c982b1c5b6 13 DigitalOut DO_03(p23);//B
MasashiNomura 40:debe99e228d3 14
MasashiNomura 33:eb260dbfc22a 15 //モーターアクセル用アナログ入力
MasashiNomura 33:eb260dbfc22a 16 AnalogIn AinAxl(p20);
takeru0x1103 21:78302ecdb661 17
MasashiNomura 38:24ee50452755 18 // //エンジンスロットル用アナログ入力
MasashiNomura 38:24ee50452755 19 // AnalogIn AinThrottle(p19);
MasashiNomura 36:2cc739c7e4cb 20
takeru0x1103 19:4b0fe9a5ec38 21 char g_CmdBuf[G_CMD_BUF_SIZ] ;// コマンド受け渡しバッファ
MasashiNomura 22:24c9c2dedca9 22 bool gf_CmdPrs;
takeru0x1103 19:4b0fe9a5ec38 23
MasashiNomura 22:24c9c2dedca9 24 bool gf_Armed ;//アーミングフラグ
MasashiNomura 23:79e20be4bc5b 25 bool gf_Dbg ;//デバッグタスク起動フラグ
MasashiNomura 37:d51dacb4c30f 26 //bool gf_fs_stat ;//強制遷移フラグ
MasashiNomura 37:d51dacb4c30f 27 bool gf_StopMot ;//モーターの強制停止 サーボ全閉
MasashiNomura 37:d51dacb4c30f 28 bool gf_FromActiveStat ;//モーターの強制停止 サーボ全閉が動作時に発生したかどうか
MasashiNomura 25:f3a6e7eec9c3 29
MasashiNomura 43:156199c2f9b6 30 bool gf_BlinkLED;
MasashiNomura 43:156199c2f9b6 31
MasashiNomura 41:45c982b1c5b6 32 typPrintFlg gf_Print ;//
MasashiNomura 41:45c982b1c5b6 33 typPrintFlg gf_Mon ;//
takeru0x1103 19:4b0fe9a5ec38 34 typCalFlag gf_Cal ;//
MasashiNomura 41:45c982b1c5b6 35 //typDbgPrintFlg gf_DbgPrint ;//デバッグ用
MasashiNomura 22:24c9c2dedca9 36 typAccel gf_AxReq[2] ;//アクセル更新フラグ
MasashiNomura 42:cc8501b824ba 37 typAccel gf_AxReqH[2] ;//浮上時アクセル値更新フラグ
MasashiNomura 43:156199c2f9b6 38 typAccel gf_AxStepReq[2] ;//アクセル用サーボ動作ステップ値更新フラグ
MasashiNomura 32:7f4145cc3551 39 typAxlRpm gf_MtReq[4] ;//モーター姿勢制御更新フラグ
MasashiNomura 29:eb3d72dd94aa 40 typAxlRpm gf_MtReqOfs[4] ;//モーターオフセット更新フラグ
MasashiNomura 29:eb3d72dd94aa 41 typAxlRpm gf_MtReqDct[8] ;//ダイレクト(FPGA関数直接呼び出し)モーター更新フラグ
MasashiNomura 32:7f4145cc3551 42 typAxlRpm gf_MtReqU[4] ;//モーターユーザー更新フラグ
MasashiNomura 32:7f4145cc3551 43
MasashiNomura 42:cc8501b824ba 44 typSWCmd gf_SwCmd; //スイッチが押されたことを模擬するフラグ
MasashiNomura 42:cc8501b824ba 45
MasashiNomura 22:24c9c2dedca9 46 enmHbState gf_State = SLEEP;
MasashiNomura 36:2cc739c7e4cb 47 bool gf_StateEnt ;//状態遷移後、最初であることを示す
takeru0x1103 19:4b0fe9a5ec38 48
MasashiNomura 24:c5945aaae777 49 bool gf_PidParaUpdate ;//PID Pp,P,I,Dの係数アップデートフラグ
MasashiNomura 24:c5945aaae777 50 typPidPara g_PidPara ;//PID Pp,P,I,Dの係数の外部設定用
takeru0x1103 20:0394e15412c3 51
MasashiNomura 36:2cc739c7e4cb 52 // bool gf_MotParaUpdate[4] ;//モーターのパラメータ値更新フラグ
MasashiNomura 36:2cc739c7e4cb 53 // typMotPara g_MotPara[4];
MasashiNomura 25:f3a6e7eec9c3 54
MasashiNomura 22:24c9c2dedca9 55 void initFlags(){
MasashiNomura 22:24c9c2dedca9 56 memset(g_CmdBuf,0x0,sizeof(g_CmdBuf));
MasashiNomura 22:24c9c2dedca9 57 gf_CmdPrs = false;
MasashiNomura 22:24c9c2dedca9 58 gf_Armed = false;
MasashiNomura 22:24c9c2dedca9 59 gf_Dbg = false;
MasashiNomura 25:f3a6e7eec9c3 60 gf_StopMot = false;
MasashiNomura 43:156199c2f9b6 61
MasashiNomura 43:156199c2f9b6 62 gf_BlinkLED = false;
MasashiNomura 25:f3a6e7eec9c3 63
MasashiNomura 41:45c982b1c5b6 64 // gf_Print.flg = 0;
MasashiNomura 41:45c982b1c5b6 65 // gf_Mon.flg = 0;
MasashiNomura 41:45c982b1c5b6 66 gf_Print.d1.flg = 0;
MasashiNomura 41:45c982b1c5b6 67 gf_Print.d2.flg = 0;
MasashiNomura 39:1b76f7df8804 68
MasashiNomura 22:24c9c2dedca9 69 gf_Cal.flg = 0;
MasashiNomura 26:732bc37fbefd 70
MasashiNomura 41:45c982b1c5b6 71 //gf_DbgPrint.flg = 0;
MasashiNomura 26:732bc37fbefd 72
MasashiNomura 43:156199c2f9b6 73 // engine
MasashiNomura 43:156199c2f9b6 74 for(int i = 0; i < 2; ++i){
MasashiNomura 43:156199c2f9b6 75 gf_AxReq[i].dt = 0;
MasashiNomura 43:156199c2f9b6 76 gf_AxReqH[i].dt = 0;
MasashiNomura 43:156199c2f9b6 77 gf_AxStepReq[i].bf.req = false;
MasashiNomura 43:156199c2f9b6 78 gf_AxStepReq[i].bf.val = 100;
MasashiNomura 43:156199c2f9b6 79 }
MasashiNomura 43:156199c2f9b6 80
MasashiNomura 27:ff63c23bc689 81 for(int i=0; i<4;++i){
MasashiNomura 32:7f4145cc3551 82 gf_MtReq[i].req = false;
MasashiNomura 32:7f4145cc3551 83 gf_MtReq[i].val = 0;
MasashiNomura 32:7f4145cc3551 84 gf_MtReqOfs[i].req = false;
MasashiNomura 32:7f4145cc3551 85 gf_MtReqOfs[i].val = 0;
MasashiNomura 32:7f4145cc3551 86 gf_MtReqU[i].req = false;
MasashiNomura 32:7f4145cc3551 87 gf_MtReqU[i].val = 0;
MasashiNomura 27:ff63c23bc689 88 }
MasashiNomura 27:ff63c23bc689 89 for(int i = 0; i < 8; ++i){
MasashiNomura 32:7f4145cc3551 90 gf_MtReqDct[i].req = false;
MasashiNomura 32:7f4145cc3551 91 gf_MtReqDct[i].val = 0;
MasashiNomura 27:ff63c23bc689 92 }
MasashiNomura 42:cc8501b824ba 93
MasashiNomura 42:cc8501b824ba 94 gf_SwCmd.dt = 0;
MasashiNomura 42:cc8501b824ba 95
MasashiNomura 22:24c9c2dedca9 96 gf_State = SLEEP;
MasashiNomura 36:2cc739c7e4cb 97 gf_StateEnt = false;
MasashiNomura 27:ff63c23bc689 98 g_PidPara.PP = 2;
MasashiNomura 32:7f4145cc3551 99 g_PidPara.P = 0;
MasashiNomura 25:f3a6e7eec9c3 100 g_PidPara.I = 0;
MasashiNomura 24:c5945aaae777 101 g_PidPara.D = 0;
MasashiNomura 24:c5945aaae777 102 g_PidPara.IMax = 2000;
MasashiNomura 24:c5945aaae777 103 g_PidPara.IMin = -2000;
MasashiNomura 36:2cc739c7e4cb 104 // for(int i = 0; i < 4; ++i){
MasashiNomura 36:2cc739c7e4cb 105 // gf_MotParaUpdate[i] = false;
MasashiNomura 36:2cc739c7e4cb 106 // g_MotPara[i].limit_hi = LIM_MOT_INP_MAX;
MasashiNomura 36:2cc739c7e4cb 107 // g_MotPara[i].limit_low = LIM_MOT_INP_MIN;
MasashiNomura 36:2cc739c7e4cb 108 // }
MasashiNomura 22:24c9c2dedca9 109 }
MasashiNomura 35:3779201b4c73 110
MasashiNomura 41:45c982b1c5b6 111 void setDOCol(eLedCol col)
MasashiNomura 41:45c982b1c5b6 112 {
MasashiNomura 41:45c982b1c5b6 113 switch(col){
MasashiNomura 41:45c982b1c5b6 114 case WHITE:
MasashiNomura 42:cc8501b824ba 115 DO_01 = 1;
MasashiNomura 42:cc8501b824ba 116 DO_02 = 1;
MasashiNomura 42:cc8501b824ba 117 DO_03 = 1;
MasashiNomura 41:45c982b1c5b6 118 break;
MasashiNomura 41:45c982b1c5b6 119 case RED:
MasashiNomura 42:cc8501b824ba 120 DO_01 = 1;
MasashiNomura 41:45c982b1c5b6 121 DO_02 = 0;
MasashiNomura 41:45c982b1c5b6 122 DO_03 = 0;
MasashiNomura 41:45c982b1c5b6 123 break;
MasashiNomura 41:45c982b1c5b6 124 case GREEN:
MasashiNomura 41:45c982b1c5b6 125 DO_01 = 0;
MasashiNomura 42:cc8501b824ba 126 DO_02 = 1;
MasashiNomura 41:45c982b1c5b6 127 DO_03 = 0;
MasashiNomura 41:45c982b1c5b6 128 break;
MasashiNomura 41:45c982b1c5b6 129 case BLUE:
MasashiNomura 41:45c982b1c5b6 130 DO_01 = 0;
MasashiNomura 41:45c982b1c5b6 131 DO_02 = 0;
MasashiNomura 42:cc8501b824ba 132 DO_03 = 1;
MasashiNomura 42:cc8501b824ba 133 break;
MasashiNomura 42:cc8501b824ba 134 case YELLOW:
MasashiNomura 42:cc8501b824ba 135 DO_01 = 1;
MasashiNomura 42:cc8501b824ba 136 DO_02 = 1;
MasashiNomura 42:cc8501b824ba 137 DO_03 = 0;
MasashiNomura 42:cc8501b824ba 138 break;
MasashiNomura 42:cc8501b824ba 139 case PURPLE:
MasashiNomura 42:cc8501b824ba 140 DO_01 = 1;
MasashiNomura 42:cc8501b824ba 141 DO_02 = 0;
MasashiNomura 42:cc8501b824ba 142 DO_03 = 1;
MasashiNomura 42:cc8501b824ba 143 break;
MasashiNomura 42:cc8501b824ba 144 case LIGHT_BLUE:
MasashiNomura 42:cc8501b824ba 145 DO_01 = 0;
MasashiNomura 42:cc8501b824ba 146 DO_02 = 1;
MasashiNomura 42:cc8501b824ba 147 DO_03 = 1;
MasashiNomura 42:cc8501b824ba 148 break;
MasashiNomura 42:cc8501b824ba 149 case BLK_WHITE:
MasashiNomura 42:cc8501b824ba 150 DO_01 = !DO_01;
MasashiNomura 42:cc8501b824ba 151 DO_02 = !DO_02;
MasashiNomura 41:45c982b1c5b6 152 DO_03 = !DO_03;
MasashiNomura 41:45c982b1c5b6 153 break;
MasashiNomura 42:cc8501b824ba 154 case BLK_RED:
MasashiNomura 42:cc8501b824ba 155 DO_01 = !DO_01;
MasashiNomura 42:cc8501b824ba 156 DO_02 = 0;
MasashiNomura 42:cc8501b824ba 157 DO_03 = 0;
MasashiNomura 42:cc8501b824ba 158 break;
MasashiNomura 42:cc8501b824ba 159 case BLK_GREEN:
MasashiNomura 42:cc8501b824ba 160 DO_01 = 0;
MasashiNomura 42:cc8501b824ba 161 DO_02 = !DO_02;
MasashiNomura 42:cc8501b824ba 162 DO_03 = 0;
MasashiNomura 42:cc8501b824ba 163 break;
MasashiNomura 42:cc8501b824ba 164 case BLK_BLUE:
MasashiNomura 42:cc8501b824ba 165 DO_01 = 0;
MasashiNomura 42:cc8501b824ba 166 DO_02 = 0;
MasashiNomura 42:cc8501b824ba 167 DO_03 = !DO_03;
MasashiNomura 42:cc8501b824ba 168 break;
MasashiNomura 42:cc8501b824ba 169 case BLK_YELLOW:
MasashiNomura 41:45c982b1c5b6 170 DO_01 = !DO_01;
MasashiNomura 41:45c982b1c5b6 171 DO_02 = !DO_02;
MasashiNomura 41:45c982b1c5b6 172 DO_03 = 0;
MasashiNomura 41:45c982b1c5b6 173 break;
MasashiNomura 42:cc8501b824ba 174 case BLK_PURPLE:
MasashiNomura 41:45c982b1c5b6 175 DO_01 = !DO_01;
MasashiNomura 41:45c982b1c5b6 176 DO_02 = 0;
MasashiNomura 41:45c982b1c5b6 177 DO_03 = !DO_03;
MasashiNomura 41:45c982b1c5b6 178 break;
MasashiNomura 42:cc8501b824ba 179 case BLK_LIGHT_BLUE:
MasashiNomura 41:45c982b1c5b6 180 DO_01 = 0;
MasashiNomura 41:45c982b1c5b6 181 DO_02 = !DO_02;
MasashiNomura 41:45c982b1c5b6 182 DO_03 = !DO_03;
MasashiNomura 41:45c982b1c5b6 183 break;
MasashiNomura 41:45c982b1c5b6 184 case OFF:
MasashiNomura 41:45c982b1c5b6 185 default:
MasashiNomura 41:45c982b1c5b6 186 DO_01 = 0;//R
MasashiNomura 41:45c982b1c5b6 187 DO_02 = 0;//G
MasashiNomura 41:45c982b1c5b6 188 DO_03 = 0;//B
MasashiNomura 41:45c982b1c5b6 189 break;
MasashiNomura 41:45c982b1c5b6 190 }
MasashiNomura 41:45c982b1c5b6 191 }
MasashiNomura 41:45c982b1c5b6 192
MasashiNomura 41:45c982b1c5b6 193 void setDO4LED(enmHbState stat)
MasashiNomura 41:45c982b1c5b6 194 {
MasashiNomura 41:45c982b1c5b6 195 if(stat == NONE)
MasashiNomura 41:45c982b1c5b6 196 {// 消灯
MasashiNomura 41:45c982b1c5b6 197 setDOCol(OFF);
MasashiNomura 41:45c982b1c5b6 198 }
MasashiNomura 41:45c982b1c5b6 199 else if(stat == SLEEP)
MasashiNomura 41:45c982b1c5b6 200 {//YELLOW
MasashiNomura 41:45c982b1c5b6 201 setDOCol(YELLOW);
MasashiNomura 41:45c982b1c5b6 202 }
MasashiNomura 41:45c982b1c5b6 203 else if(stat == WAKEUP || stat == STANDBY)
MasashiNomura 41:45c982b1c5b6 204 {//BLUE
MasashiNomura 41:45c982b1c5b6 205 setDOCol(BLUE);
MasashiNomura 41:45c982b1c5b6 206 }
MasashiNomura 41:45c982b1c5b6 207 else if(stat == IDLE)
MasashiNomura 41:45c982b1c5b6 208 {//GREEN
MasashiNomura 41:45c982b1c5b6 209 setDOCol(GREEN);
MasashiNomura 41:45c982b1c5b6 210 }
MasashiNomura 41:45c982b1c5b6 211 else if(stat == TAKE_OFF || stat == HOVER || stat == DRIVE || stat == GROUND || stat == EMGGND)
MasashiNomura 41:45c982b1c5b6 212 {//PURPLE
MasashiNomura 43:156199c2f9b6 213 if(gf_BlinkLED){
MasashiNomura 43:156199c2f9b6 214 setDOCol(BLK_PURPLE);
MasashiNomura 43:156199c2f9b6 215 gf_BlinkLED = false;
MasashiNomura 43:156199c2f9b6 216 }
MasashiNomura 43:156199c2f9b6 217 else{
MasashiNomura 43:156199c2f9b6 218 setDOCol(PURPLE);
MasashiNomura 43:156199c2f9b6 219 }
MasashiNomura 41:45c982b1c5b6 220 }
MasashiNomura 42:cc8501b824ba 221 else if(stat == CHK_EG_ENT || stat == CHK_EG_MID || stat == CHK_EG_EXIT)
MasashiNomura 41:45c982b1c5b6 222 {//LIGHT BLUE
MasashiNomura 41:45c982b1c5b6 223 setDOCol(LIGHT_BLUE);
MasashiNomura 41:45c982b1c5b6 224 }
MasashiNomura 42:cc8501b824ba 225 else if(stat == CHK_EG_F || stat == CHK_EG_R )
MasashiNomura 42:cc8501b824ba 226 {//BLK_LIGHT BLUE
MasashiNomura 42:cc8501b824ba 227 setDOCol(BLK_LIGHT_BLUE);
MasashiNomura 42:cc8501b824ba 228 }
MasashiNomura 41:45c982b1c5b6 229 else if(stat == CHK_ENT || stat == CHK_MOT || stat == CHK_AXL || stat == CHK_ATT || stat == CHK_EXIT)
MasashiNomura 41:45c982b1c5b6 230 {//WHITE
MasashiNomura 41:45c982b1c5b6 231 setDOCol(WHITE);
MasashiNomura 41:45c982b1c5b6 232 }
MasashiNomura 41:45c982b1c5b6 233 else/* if(stat == MOT_STOP)*/
MasashiNomura 41:45c982b1c5b6 234 {
MasashiNomura 41:45c982b1c5b6 235 setDOCol(RED);
MasashiNomura 41:45c982b1c5b6 236 }
MasashiNomura 41:45c982b1c5b6 237 }
MasashiNomura 41:45c982b1c5b6 238
MasashiNomura 43:156199c2f9b6 239 //void blinkLED(enmHbState stat){
MasashiNomura 43:156199c2f9b6 240
MasashiNomura 43:156199c2f9b6 241 //}
MasashiNomura 43:156199c2f9b6 242
MasashiNomura 22:24c9c2dedca9 243 void setState(enmHbState stat){
MasashiNomura 22:24c9c2dedca9 244 // ありえない遷移を排除
MasashiNomura 22:24c9c2dedca9 245 if(gf_State == SLEEP){if(stat != WAKEUP) return;}
MasashiNomura 22:24c9c2dedca9 246 if(gf_State == WAKEUP){if(stat != STANDBY) return;}
MasashiNomura 22:24c9c2dedca9 247 if(gf_State == STANDBY){if(stat !=IDLE) return;}
MasashiNomura 23:79e20be4bc5b 248 if(gf_State == IDLE){if(stat != TAKE_OFF && stat != SLEEP) return;}
MasashiNomura 23:79e20be4bc5b 249 if(gf_State == TAKE_OFF){if(stat != HOVER && stat != GROUND) return;}
MasashiNomura 22:24c9c2dedca9 250 if(gf_State == GROUND){if(stat != IDLE) return;}
MasashiNomura 22:24c9c2dedca9 251 if(gf_State == HOVER){if(stat != DRIVE && stat != GROUND) return;}
MasashiNomura 22:24c9c2dedca9 252 if(gf_State == DRIVE){if(stat != HOVER && stat != EMGGND) return;}
MasashiNomura 22:24c9c2dedca9 253 if(gf_State == EMGGND){if(stat != IDLE) return;}
MasashiNomura 22:24c9c2dedca9 254
MasashiNomura 23:79e20be4bc5b 255 sp.printf("state: %d\r\n",stat);
MasashiNomura 22:24c9c2dedca9 256 gf_State = stat;
MasashiNomura 36:2cc739c7e4cb 257 gf_StateEnt = true;
MasashiNomura 22:24c9c2dedca9 258 }
MasashiNomura 23:79e20be4bc5b 259 void setStateF(enmHbState stat){
MasashiNomura 23:79e20be4bc5b 260 sp.printf("state: %d\r\n",stat);
MasashiNomura 23:79e20be4bc5b 261 enmHbState tmp;
MasashiNomura 25:f3a6e7eec9c3 262 if((UINT16)stat > MOT_STOP){
MasashiNomura 23:79e20be4bc5b 263 tmp = SLEEP;
MasashiNomura 23:79e20be4bc5b 264 }
MasashiNomura 23:79e20be4bc5b 265 else
MasashiNomura 23:79e20be4bc5b 266 {
MasashiNomura 23:79e20be4bc5b 267 tmp = stat;
MasashiNomura 23:79e20be4bc5b 268 }
MasashiNomura 23:79e20be4bc5b 269 gf_State = tmp;
MasashiNomura 36:2cc739c7e4cb 270 gf_StateEnt = true;
MasashiNomura 23:79e20be4bc5b 271 }
MasashiNomura 37:d51dacb4c30f 272
MasashiNomura 37:d51dacb4c30f 273 bool isActiveState(){
MasashiNomura 37:d51dacb4c30f 274 if(gf_State >= IDLE && gf_State <= EMGGND){
MasashiNomura 37:d51dacb4c30f 275 return true;
MasashiNomura 37:d51dacb4c30f 276 }
MasashiNomura 37:d51dacb4c30f 277 else {
MasashiNomura 37:d51dacb4c30f 278 return false;
MasashiNomura 37:d51dacb4c30f 279 }
MasashiNomura 37:d51dacb4c30f 280 }
MasashiNomura 37:d51dacb4c30f 281
takeru0x1103 21:78302ecdb661 282 /*
takeru0x1103 19:4b0fe9a5ec38 283 //===========================================
takeru0x1103 19:4b0fe9a5ec38 284 //コンストラクタ
takeru0x1103 19:4b0fe9a5ec38 285 //===========================================
takeru0x1103 19:4b0fe9a5ec38 286 GlobalFlags::GlobalFlags(){
takeru0x1103 19:4b0fe9a5ec38 287 //初期ステート
takeru0x1103 21:78302ecdb661 288 state = SLEEP;
takeru0x1103 19:4b0fe9a5ec38 289 //ステートキュー初期化
takeru0x1103 19:4b0fe9a5ec38 290 for(int i=0; i<STATE_QUE_SIZ; i++){
takeru0x1103 19:4b0fe9a5ec38 291 stateQueue[i] = NONE;
MasashiNomura 33:eb260dbfc22a 292 }
takeru0x1103 19:4b0fe9a5ec38 293 rp = wp = 0;//先頭を指す
takeru0x1103 19:4b0fe9a5ec38 294 full = false;//最初はエンプティ
takeru0x1103 19:4b0fe9a5ec38 295 empty = true;
takeru0x1103 19:4b0fe9a5ec38 296 }
takeru0x1103 19:4b0fe9a5ec38 297
takeru0x1103 21:78302ecdb661 298
takeru0x1103 19:4b0fe9a5ec38 299 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 300 //ステートのFIFOにプッシュする
takeru0x1103 19:4b0fe9a5ec38 301 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 302 bool GlobalFlags::push(enmHbState iState){
takeru0x1103 19:4b0fe9a5ec38 303 if(full){
takeru0x1103 19:4b0fe9a5ec38 304 return false;//FFULLフラグが立ってら入力を受け付けない
takeru0x1103 19:4b0fe9a5ec38 305 }else{
takeru0x1103 19:4b0fe9a5ec38 306 stateQueue[wp] = iState;//キューに突っ込んで
takeru0x1103 19:4b0fe9a5ec38 307 wp = (wp==STATE_QUE_SIZ) ? 0 : wp+1;//ライトポインタを進める
takeru0x1103 19:4b0fe9a5ec38 308 full = (wp == rp)? true : false; //次ライト予定の場所がリードポインタに追いついたらFULLを立てる
takeru0x1103 19:4b0fe9a5ec38 309 empty = false;
takeru0x1103 19:4b0fe9a5ec38 310 return true;
takeru0x1103 19:4b0fe9a5ec38 311 }
takeru0x1103 19:4b0fe9a5ec38 312 }
takeru0x1103 19:4b0fe9a5ec38 313
takeru0x1103 19:4b0fe9a5ec38 314 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 315 //ステートFIFOから次の予約ステートを引き抜く
takeru0x1103 19:4b0fe9a5ec38 316 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 317 bool GlobalFlags::pull(){
takeru0x1103 19:4b0fe9a5ec38 318 if(empty){
takeru0x1103 19:4b0fe9a5ec38 319 return false;//EMPTYだったら引き抜けない
takeru0x1103 19:4b0fe9a5ec38 320 }else{
takeru0x1103 19:4b0fe9a5ec38 321 state = stateQueue[rp];//リードポインタの指すデータをステートに移す
takeru0x1103 19:4b0fe9a5ec38 322 stateQueue[rp] = NONE;//バッファを消す
takeru0x1103 19:4b0fe9a5ec38 323 rp = (rp==STATE_QUE_SIZ) ? 0 : rp+1;//リードポインタを進める
takeru0x1103 19:4b0fe9a5ec38 324 full = false; //フルではなくなる
takeru0x1103 19:4b0fe9a5ec38 325 empty = (stateQueue[rp] == NONE) ? true : false;//次にリードする場所がNONEだったらEMPTYを立てる
takeru0x1103 19:4b0fe9a5ec38 326 return true;
takeru0x1103 19:4b0fe9a5ec38 327 }
takeru0x1103 19:4b0fe9a5ec38 328 }
takeru0x1103 21:78302ecdb661 329 */
takeru0x1103 19:4b0fe9a5ec38 330
MasashiNomura 33:eb260dbfc22a 331