State_Machine.LST
上传用户:gxz1972
上传日期:2019-09-13
资源大小:323k
文件大小:34k
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 1
- C51 COMPILER V7.02b, COMPILATION OF MODULE STATE_MACHINE
- OBJECT MODULE PLACED IN State_Machine.OBJ
- COMPILER INVOKED BY: C:KeilC51BINc51.exe State_Machine.c DB OE
- stmt level source
- 1 //-----------------------------------------------------------------------------
- 2 // USB_ISR.c
- 3 //-----------------------------------------------------------------------------
- 4 // Copyright 2007 Vson Technology, Inc.
- 5 // http://www.usbmcu.com
- 6 //
- 7 // Program Description:
- 8 //
- 9 //
- 10 //
- 11 //
- 12 //
- 13 // MCU: C8051F347
- 14 // Tool chain: Keil C51 7.50 / Keil EVAL C51
- 15 // Silicon Laboratories IDE version 2.6
- 16 // Command Line:
- 17 // Project Name: TR1000
- 18 //
- 19 //
- 20 // Release 1.0
- 21 // -All changes by Brin Cai
- 22 // -24 JUL 2007
- 23 //
- 24 //
- 25 //update date: 2007.08.13 ADC solution bit change(10bit--->12bit)
- 26 //-----------------------------------------------------------------------------
- 27 // Includes
- 28 //-----------------------------------------------------------------------------
- 29
- 30 #include "Include_H.h"
- 31
- 32 //-----------------------------------------------------------------------------
- 33 // State_Machine
- 34 //-----------------------------------------------------------------------------
- 35 //
- 36 // Return Value : None
- 37 // Parameters : None
- 38 //
- 39 // Determine new state and act on current state
- 40 //-----------------------------------------------------------------------------
- 41 void State_Machine(void)
- 42 {
- 43 1
- 44 1
- 45 1 switch (M_State)
- 46 1 {
- 47 2
- 48 2 case
- 49 2 USB_RESET_STATUS:
- 50 2 EA = 0;
- 51 2 USBReset();
- 52 2 M_State = WAIT_OPEN_DEVICE_STATUS;
- 53 2 EA = 1;
- 54 2 break;
- 55 2
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 2
- 56 2 case
- 57 2 EP0_HANDLER_STATUS: // Stay in Wait State
- 58 2 EA = 0;
- 59 2 Endpoint0();
- 60 2 EA = 1;
- 61 2 break;
- 62 2
- 63 2 case
- 64 2 WAIT_OPEN_DEVICE_STATUS: // Stay in Wait State
- 65 2 break;
- 66 2
- 67 2 case
- 68 2 DEVICE_IDLE_STATUS: // Stay in Idle State
- 69 2 break;
- 70 2
- 71 2
- 72 2 case
- 73 2 RX_CONFIG_DATA_FROM_HOST_STATUS: // Receive the Config Data
- 74 2
- 75 2 //if (bitInterruptFlag == 1)
- 76 2 {
- 77 3 EA = 0;
- 78 3 RxConfigDataFromHost();//BulkOrInterruptOut(&gEp2OutStatus);//EP2 Out Status
- 79 3 EA = 1;
- 80 3 M_State = TX_CONFIG_RESPONSE_TO_HOST_STATUS;
- 81 3 }
- 82 2 break;
- 83 2
- 84 2 case
- 85 2 TX_CONFIG_RESPONSE_TO_HOST_STATUS: // Response Host After receive the Config Data
- 86 2 //if (bitInterruptFlag == 1)
- 87 2 {
- 88 3 EA = 0;
- 89 3 TxConfigResponse2Host(0x00);
- 90 3 EA = 1;
- 91 3 M_State = DEVICE_IDLE_STATUS;
- 92 3 //bitInterruptFlag = 0;
- 93 3 }
- 94 2 break;
- 95 2 case
- 96 2 TX_TEACHER_KEY_DATA_TO_HOST_STATUS: // transmit key data to the host
- 97 2 if (gbitRfReceivedDataFlag == 1)
- 98 2 {
- 99 3 EA = 0;
- 100 3 TxTeacherKeyData2Host();
- 101 3 EA = 1;
- 102 3 //M_State = TX_TOUCHPAD_DATA_TO_HOST_STATUS;
- 103 3 gbitRfReceivedDataFlag = 0;
- 104 3 }
- 105 2 break;
- 106 2 case
- 107 2 TX_TOUCHPAD_DATA_TO_HOST_STATUS: // transmit touch pad data to the host
- 108 2 //if (bitInterruptFlag == 1)
- 109 2 if (gbitRfReceivedDataFlag == 1)
- 110 2 {
- 111 3 EA = 0;
- 112 3 TxTouchPadData2Host();
- 113 3 EA = 1;
- 114 3 //M_State = TX_CONFIG_RESPONSE_TO_HOST_STATUS;
- 115 3 gbitRfReceivedDataFlag = 0;
- 116 3 }
- 117 2 break;
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 3
- 118 2 case
- 119 2 TX_STUDENT_KEY_DATA_TO_HOST_STATUS: // transmit key data to the host
- 120 2 if (gbitRfReceivedDataFlag == 1)
- 121 2 {
- 122 3 EA = 0;
- 123 3 TxStudentKeyData2Host();
- 124 3 EA = 1;
- 125 3 //M_State = TX_TOUCHPAD_DATA_TO_HOST_STATUS;
- 126 3 gbitRfReceivedDataFlag = 0;
- 127 3 }
- 128 2 break;
- 129 2 case
- 130 2 TX_STUDENT_EXAM_DATA_TO_HOST_STATUS: // transmit key data to the host
- 131 2 if (gbitRfReceivedDataFlag == 1)
- 132 2 {
- 133 3 EA = 0;
- 134 3 TxStudentExamData2Host();
- 135 3 EA = 1;
- 136 3 //M_State = TX_TOUCHPAD_DATA_TO_HOST_STATUS;
- 137 3 gbitRfReceivedDataFlag = 0;
- 138 3 }
- 139 2 break;
- 140 2
- 141 2
- 142 2 default:
- 143 2 //M_State = ERROR_STATUS; // Unknown State, stay in Error State
- 144 2 break;
- 145 2 }//switch
- 146 1
- 147 1 }
- 148
- 149 void TxConfigResponse2Host(unsigned char ResponseResult)
- 150 {
- 151 1 data BYTE i;
- 152 1 sbitLED = 0;
- 153 1 for (i = 0; i < 64; i++)
- 154 1 {
- 155 2 gaucTxData2HostBuffer[i]=0;
- 156 2 }
- 157 1 gaucTxData2HostBuffer[0] = 0x00;
- 158 1 gaucTxData2HostBuffer[1] = 0x04;//单包传输 最后一个分包 12 字节
- 159 1 gaucTxData2HostBuffer[2] = ResponseResult;
- 160 1 gaucTxData2HostBuffer[3] = 2;
- 161 1 gaucTxData2HostBuffer[4] = 0;
- 162 1 gaucTxData2HostBuffer[5] = 0;
- 163 1 gaucTxData2HostBuffer[6] = 7;
- 164 1 gaucTxData2HostBuffer[7] = 1;
- 165 1 gaucTxData2HostBuffer[8] = 0;
- 166 1 gaucTxData2HostBuffer[9] = 1;
- 167 1 gaucTxData2HostBuffer[10] = 0;
- 168 1 gaucTxData2HostBuffer[11] = 0x55;
- 169 1 // Place Config response packet (0x00) on the OUT FIFO
- 170 1 BulkOrInterruptIn (&gEp1InStatus, (BYTE*)&gaucTxData2HostBuffer, 64);
- 171 1 sbitLED = 1;
- 172 1 }
- 173
- 174 void TxTeacherKeyData2Host(void)
- 175 {
- 176 1 data BYTE i;
- 177 1 sbitLED = 0;
- 178 1 for (i = 0; i < 64; i++)
- 179 1 {
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 4
- 180 2 gaucTxData2HostBuffer[i]=0;
- 181 2 }
- 182 1 /*
- 183 1 gaucTxData2HostBuffer[0] = 0x01;
- 184 1 gaucTxData2HostBuffer[1] = 0x30;//单包传输 最后一个分包 12 字节
- 185 1 gaucTxData2HostBuffer[2] = 0xaa;
- 186 1 gaucTxData2HostBuffer[3] = 0x55;
- 187 1 gaucTxData2HostBuffer[4] = 0xaa;
- 188 1 gaucTxData2HostBuffer[5] = 0x55;
- 189 1 gaucTxData2HostBuffer[6] = 0x00;
- 190 1 gaucTxData2HostBuffer[7] = 0x01;
- 191 1
- 192 1 gaucTxData2HostBuffer[8] = 0xaa;
- 193 1 gaucTxData2HostBuffer[9] = 0x55;
- 194 1 gaucTxData2HostBuffer[10] = 0xaa;
- 195 1 gaucTxData2HostBuffer[11] = 0x55;
- 196 1 gaucTxData2HostBuffer[12] = 0x00;
- 197 1 gaucTxData2HostBuffer[13] = 0x01;
- 198 1 */
- 199 1
- 200 1 gaucTxData2HostBuffer[0] = 0x01;
- 201 1 gaucTxData2HostBuffer[1] = 0x14;
- 202 1
- 203 1 if ((gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] & BIT7) == BIT7)
- 204 1 {
- 205 2 gaucTxData2HostBuffer[2] = 0x80;
- 206 2 }
- 207 1 else
- 208 1 {
- 209 2 gaucTxData2HostBuffer[2] = 0x00;
- 210 2 }
- 211 1
- 212 1 gaucTxData2HostBuffer[3] = gaucRxDataFromRfBuffer[2] & 0x7f;
- 213 1 gaucTxData2HostBuffer[4] = gaucRxDataFromRfBuffer[3];
- 214 1 gaucTxData2HostBuffer[5] = gaucRxDataFromRfBuffer[4];
- 215 1 gaucTxData2HostBuffer[6] = gaucRxDataFromRfBuffer[7];
- 216 1 gaucTxData2HostBuffer[7] = gaucRxDataFromRfBuffer[8];
- 217 1
- 218 1 if (gaucRxDataFromRfBuffer[6] != gucPacketCount)
- 219 1 {
- 220 2 BulkOrInterruptIn (&gEp1InStatus, (BYTE*)&gaucTxData2HostBuffer, 64);
- 221 2 gucPacketCount = gaucRxDataFromRfBuffer[6];
- 222 2 }
- 223 1 sbitLED = 1;
- 224 1
- 225 1 }
- 226
- 227 void TxTouchPadData2Host(void)
- 228 {
- 229 1 data BYTE i;
- 230 1 sbitLED = 0;
- 231 1 for (i = 0; i < 64; i++)
- 232 1 {
- 233 2 gaucTxData2HostBuffer[i]=0;
- 234 2 }
- 235 1 /*
- 236 1 gaucTxData2HostBuffer[0] = 0x02;
- 237 1 gaucTxData2HostBuffer[1] = 0x14;
- 238 1 gaucTxData2HostBuffer[2] = 0x00;
- 239 1 gaucTxData2HostBuffer[3] = 0x01;
- 240 1 gaucTxData2HostBuffer[4] = 0x00;
- 241 1 gaucTxData2HostBuffer[5] = 0x01;
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 5
- 242 1 gaucTxData2HostBuffer[6] = 0x00;
- 243 1 */
- 244 1
- 245 1 gaucTxData2HostBuffer[0] = 0x02;
- 246 1 gaucTxData2HostBuffer[1] = 0x14;
- 247 1
- 248 1 if ((gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] & BIT7) == BIT7)
- 249 1 {
- 250 2 gaucTxData2HostBuffer[2] = 0x80;
- 251 2 }
- 252 1 else
- 253 1 {
- 254 2 gaucTxData2HostBuffer[2] = 0x00;
- 255 2 }
- 256 1
- 257 1 gaucTxData2HostBuffer[3] = gaucRxDataFromRfBuffer[2] & 0x7f;
- 258 1 gaucTxData2HostBuffer[4] = gaucRxDataFromRfBuffer[3];
- 259 1 gaucTxData2HostBuffer[5] = gaucRxDataFromRfBuffer[4];
- 260 1 gaucTxData2HostBuffer[6] = gaucRxDataFromRfBuffer[5] & 0x0f;//0x03;//(10bit-->12bit)
- 261 1 gaucTxData2HostBuffer[7] = gaucRxDataFromRfBuffer[6];
- 262 1 gaucTxData2HostBuffer[8] = gaucRxDataFromRfBuffer[7] & 0x0f;//0x03;//(10bit-->12bit)
- 263 1 gaucTxData2HostBuffer[9] = gaucRxDataFromRfBuffer[8];
- 264 1 if ((gaucRxDataFromRfBuffer[5] & BIT6) == BIT6)
- 265 1 gaucTxData2HostBuffer[10] = 0x01;
- 266 1 else
- 267 1 gaucTxData2HostBuffer[10] = 0x00;
- 268 1
- 269 1 if ((gaucRxDataFromRfBuffer[5] & BIT5) == BIT5)
- 270 1 gaucTxData2HostBuffer[10] |= BIT1;
- 271 1 else
- 272 1 gaucTxData2HostBuffer[10] &= ~BIT1;
- 273 1
- 274 1 //BulkOrInterruptIn (&gEp1InStatus, (BYTE*)&gaucTxData2HostBuffer, 64);
- 275 1 if (gaucTxData2HostBuffer[3] != gucPacketCount)
- 276 1 {
- 277 2 BulkOrInterruptIn (&gEp1InStatus, (BYTE*)&gaucTxData2HostBuffer, 64);
- 278 2 gucPacketCount = gaucTxData2HostBuffer[3];
- 279 2 }
- 280 1 sbitLED = 1;
- 281 1 }
- 282
- 283 /*
- 284 //=============================================================================================
- 285 void TxStudentKeyData2Host(void)
- 286 {
- 287 data BYTE i;
- 288 sbitLED = 0;
- 289
- 290
- 291 gaucTxData2HostBuffer[0] = 0x03; //student key data
- 292 gaucTxData2HostBuffer[1] = 0x14;
- 293
- 294 if ((gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] & BIT7) == BIT7)
- 295 {
- 296 gaucTxData2HostBuffer[2] = 0x80;
- 297 }
- 298 else
- 299 {
- 300 gaucTxData2HostBuffer[2] = 0x00;
- 301 }
- 302
- 303 //最高位用于区别学生机和教师机 bit7-- 1:教师机地址 0:学生机地址
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 6
- 304 gaucTxData2HostBuffer[3] = gaucRxDataFromRfBuffer[2] & 0x7f;
- 305 gaucTxData2HostBuffer[4] = gaucRxDataFromRfBuffer[3];
- 306 gaucTxData2HostBuffer[5] = gaucRxDataFromRfBuffer[4];
- 307
- 308 //收集数据阶段
- 309 if ((gaucRxDataFromRfBuffer[5] & 0x3f) != gucPacketCount)
- 310 {
- 311 if (gaucRxDataFromRfBuffer[6] != 0)
- 312 {
- 313 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucRxDataFromRfBuffer[6];
- 314 }
- 315
- 316 if (gaucRxDataFromRfBuffer[7] != 0)
- 317 {
- 318 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucRxDataFromRfBuffer[7];
- 319 }
- 320
- 321 if (gaucRxDataFromRfBuffer[8] != 0)
- 322 {
- 323 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucRxDataFromRfBuffer[8];
- 324 }
- 325
- 326 //收据数据阶段,最后一个包不存储包序号
- 327 //if ((gaucRxDataFromRfBuffer[5] & BIT7) == BIT7) //bit7=1 有后续包
- 328 {
- 329 gucPacketCount = (gaucRxDataFromRfBuffer[5] & 0x3f);
- 330 }
- 331
- 332
- 333 //发送数据阶段:有最后一个包标志,且包序号不同,则发送数据
- 334 if ((gaucRxDataFromRfBuffer[5] & BIT7) != BIT7)
- 335 {
- 336 //if ((gaucRxDataFromRfBuffer[5] & 0x3f) != gucPacketCount)
- 337 {
- 338 BulkOrInterruptIn (&gEp1InStatus, (BYTE*)&gaucTxData2HostBuffer, 64);
- 339 //gucPacketCount = (gaucRxDataFromRfBuffer[5] & 0x3f);
- 340 gucStudentKeyDataCount = 6;
- 341 for (i = 0; i < 64; i++)
- 342 {
- 343 gaucTxData2HostBuffer[i]=0;
- 344 }
- 345 }
- 346 }//if
- 347
- 348 }
- 349
- 350
- 351
- 352 sbitLED = 1;
- 353
- 354 }//end of void TxStudentKeyData2Host(void)
- 355
- 356 */
- 357
- 358
- 359 //=============================================================================================
- 360 void TxStudentKeyData2Host(void)
- 361 {
- 362 1 data BYTE i;
- 363 1
- 364 1 bit bitNewDataPacketFlag = 0;
- 365 1
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 7
- 366 1 sbitLED = 0;
- 367 1
- 368 1
- 369 1
- 370 1 //收集数据阶段
- 371 1 bitNewDataPacketFlag = CompareStudentIdandPacketCount();
- 372 1
- 373 1 //bitNewDataPacketFlag = 1;
- 374 1
- 375 1 if ( bitNewDataPacketFlag )
- 376 1 {
- 377 2 bitNewDataPacketFlag = 0;
- 378 2 InsertNewId();
- 379 2 if ( (gaucRxDataFromRfBuffer[5] & BIT7) == BIT7 ) //不是最后一包
- 380 2 {
- 381 3 SaveFirtstPacketData();
- 382 3 }//if
- 383 2
- 384 2
- 385 2 //发送数据阶段:有最后一个包标志,且包序号不同,则发送数据
- 386 2 else
- 387 2 //if ( (gaucRxDataFromRfBuffer[5] & BIT7) != BIT7 ) //是最后一包
- 388 2 {
- 389 3
- 390 3 for (i = 0; i < 64; i++)
- 391 3 {
- 392 4 gaucTxData2HostBuffer[i]=0;
- 393 4 }
- 394 3
- 395 3
- 396 3 gucStudentKeyDataCount = 6;
- 397 3
- 398 3 gaucTxData2HostBuffer[0] = 0x03; //student key data
- 399 3 gaucTxData2HostBuffer[1] = 0x14;
- 400 3
- 401 3 if ((gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] & BIT7) == BIT7)
- 402 3 {
- 403 4 gaucTxData2HostBuffer[2] = 0x80;
- 404 4 }
- 405 3 else
- 406 3 {
- 407 4 gaucTxData2HostBuffer[2] = 0x00;
- 408 4 }
- 409 3
- 410 3 //最高位用于区别学生机和教师机 bit7-- 1:教师机地址 0:学生机地址
- 411 3 gaucTxData2HostBuffer[3] = gaucRxDataFromRfBuffer[2] & 0x7f;
- 412 3 gaucTxData2HostBuffer[4] = gaucRxDataFromRfBuffer[3];
- 413 3 gaucTxData2HostBuffer[5] = gaucRxDataFromRfBuffer[4];
- 414 3
- 415 3
- 416 3
- 417 3
- 418 3 if (0 != gaucStudentIdBuffer[gpucStudentIdBufferPoint][3])
- 419 3 {
- 420 4 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucStudentIdBuffer[gpucStudentIdBufferPoint][3];
- 421 4 }
- 422 3
- 423 3 if (0 != gaucStudentIdBuffer[gpucStudentIdBufferPoint][4])
- 424 3 {
- 425 4 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucStudentIdBuffer[gpucStudentIdBufferPoint][4];
- 426 4 }
- 427 3
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 8
- 428 3 if (0 != gaucStudentIdBuffer[gpucStudentIdBufferPoint][5])
- 429 3 {
- 430 4 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucStudentIdBuffer[gpucStudentIdBufferPoint][5];
- 431 4 }
- 432 3
- 433 3 if (gaucRxDataFromRfBuffer[6] != 0)
- 434 3 {
- 435 4 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucRxDataFromRfBuffer[6];
- 436 4 }
- 437 3
- 438 3 if (gaucRxDataFromRfBuffer[7] != 0)
- 439 3 {
- 440 4 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucRxDataFromRfBuffer[7];
- 441 4 }
- 442 3
- 443 3 if (gaucRxDataFromRfBuffer[8] != 0)
- 444 3 {
- 445 4 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucRxDataFromRfBuffer[8];
- 446 4 }
- 447 3
- 448 3 gaucTxData2HostBuffer[13] = (gaucRxDataFromRfBuffer[5] & 0x3f);
- 449 3
- 450 3 BulkOrInterruptIn (&gEp1InStatus, (BYTE*)&gaucTxData2HostBuffer, 64);
- 451 3
- 452 3
- 453 3 ClearCurrentFirstPacketData();
- 454 3
- 455 3
- 456 3 }//else
- 457 2 }//if
- 458 1
- 459 1
- 460 1
- 461 1 sbitLED = 1;
- 462 1
- 463 1 }//end of void TxStudentKeyData2Host(void)
- 464
- 465 //=============================================================================================
- 466 void TxStudentExamData2Host(void)
- 467 {
- 468 1 data BYTE i;
- 469 1 sbitLED = 0;
- 470 1
- 471 1
- 472 1 gaucTxData2HostBuffer[0] = 0x04; //student Exam data
- 473 1 //gaucTxData2HostBuffer[1] = 0x14;
- 474 1
- 475 1 if ((gaucRxDataFromRfBuffer[COUNT_BASE + (COUNT_BASE + RF_PADLOAD)*0 + 0] & BIT7) == BIT7)
- 476 1 {
- 477 2 gaucTxData2HostBuffer[2] = 0x80;
- 478 2 }
- 479 1 else
- 480 1 {
- 481 2 gaucTxData2HostBuffer[2] = 0x00;
- 482 2 }
- 483 1
- 484 1 if (gucStudentKeyDataCount == 6) //数据包的第一个数据记录学生机ID号
- 485 1 {
- 486 2 gaucTxData2HostBuffer[3] = gaucRxDataFromRfBuffer[2] & 0x7f;
- 487 2 gaucTxData2HostBuffer[4] = gaucRxDataFromRfBuffer[3];
- 488 2 gaucTxData2HostBuffer[5] = gaucRxDataFromRfBuffer[4];
- 489 2 }
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 9
- 490 1
- 491 1 if (gaucTxData2HostBuffer[5] != gaucRxDataFromRfBuffer[4]) //ID变化,学生交卷被其他学生干扰
- 492 1 {
- 493 2 gucStudentKeyDataCount = 6; //重新收集数据
- 494 2 for (i = 0; i < 64; i++)
- 495 2 {
- 496 3 gaucTxData2HostBuffer[i]=0;
- 497 3 }
- 498 2 }
- 499 1
- 500 1
- 501 1
- 502 1
- 503 1 if ((gaucRxDataFromRfBuffer[5] & 0x3f) != gucPacketCount) //包序号相同,则丢弃
- 504 1 {
- 505 2 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucRxDataFromRfBuffer[5] & 0x3f;//| 0xc0;
- 506 2 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucRxDataFromRfBuffer[6];
- 507 2 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucRxDataFromRfBuffer[7];
- 508 2 gaucTxData2HostBuffer[gucStudentKeyDataCount++] = gaucRxDataFromRfBuffer[8];
- 509 2
- 510 2 if ((gaucRxDataFromRfBuffer[5] & BIT7) == BIT7) //bit7=1 有后续包
- 511 2 {
- 512 3 gucPacketCount = (gaucRxDataFromRfBuffer[5] & 0x3f); //有后续包,则记录包序号
- 513 3 if (gucStudentKeyDataCount == 62)
- 514 3 {
- 515 4 gbitBulkMultiPackageTxFlag = 1;
- 516 4 gaucTxData2HostBuffer[1] = 61;
- 517 4 gaucTxData2HostBuffer[1] <<= 2;
- 518 4 gaucTxData2HostBuffer[1] |= BIT0; //bit 0--0:单包传输, 1:分包传输
- 519 4 gaucTxData2HostBuffer[1] |= BIT1; //bit 1--0:最后一个分包,1:有后续包
- 520 4 BulkOrInterruptIn (&gEp1InStatus, (BYTE*)&gaucTxData2HostBuffer, 64); //上传数据
- 521 4 gucPacketCount = (gaucRxDataFromRfBuffer[5] & 0x3f); //记录包序号
- 522 4 gucStudentKeyDataCount = 6; //下一包数据从gaucTxData2HostBuffer[6]开始存储
- 523 4 for (i = 0; i < 64; i++)
- 524 4 {
- 525 5 gaucTxData2HostBuffer[i]=0;
- 526 5 }//for
- 527 4 }//if
- 528 3 }//if
- 529 2
- 530 2
- 531 2 }//if
- 532 1
- 533 1
- 534 1 if ((gaucRxDataFromRfBuffer[5] & BIT7) != BIT7) //包序号第7位,bit7=0-无后续包 bit7=1-有后续包
- 535 1 {
- 536 2 if ((gaucRxDataFromRfBuffer[5] & 0x3f) != gucPacketCount) //无后续包且包序号不等,则上传数据
- 537 2 {
- 538 3 gaucTxData2HostBuffer[1] = 61;
- 539 3 gaucTxData2HostBuffer[1] <<= 2;
- 540 3 if (gbitBulkMultiPackageTxFlag == 1)
- 541 3 {
- 542 4 gaucTxData2HostBuffer[1] |= BIT0; //bit 0--0:单包传输, 1:分包传输
- 543 4 }
- 544 3 else
- 545 3 {
- 546 4 gaucTxData2HostBuffer[1] &= ~BIT0; //bit 0--0:单包传输, 1:分包传输
- 547 4 }
- 548 3
- 549 3 gaucTxData2HostBuffer[1] &= ~BIT1; //bit 1--0:最后一个分包,1:有后续包
- 550 3 BulkOrInterruptIn (&gEp1InStatus, (BYTE*)&gaucTxData2HostBuffer, 64); //上传数据
- 551 3 gucPacketCount = (gaucRxDataFromRfBuffer[5] & 0x3f); //记录包序号
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 10
- 552 3 gucStudentKeyDataCount = 6; //下一包数据从gaucTxData2HostBuffer[6]开始存储
- 553 3 for (i = 0; i < 64; i++)
- 554 3 {
- 555 4 gaucTxData2HostBuffer[i]=0;
- 556 4 }
- 557 3 }
- 558 2 }
- 559 1
- 560 1 sbitLED = 1;
- 561 1
- 562 1 }//end of void TxStudentExamData2Host(void)
- 563
- 564
- 565
- 566 //=============================================================================================
- 567 //接收频道配置数据:4 Byte
- 568 //=============================================================================================
- 569 void RxConfigDataFromHost(void)
- 570 {
- 571 1 data BYTE i;
- 572 1
- 573 1 BulkOrInterruptOut(&gEp2OutStatus);//EP2 Out Status
- 574 1 if (gaucTempStorage[0] == 0x00 )
- 575 1 {
- 576 2 for (i=0; i<4; i++)
- 577 2 {
- 578 3 gaucRfConfigData0[i] = gaucTempStorage[i+2];
- 579 3 gaucRfConfigData0[i] <<= 1;
- 580 3 gaucRfConfigData0[i] |= BIT0;//接收模式
- 581 3 }
- 582 2
- 583 2 RF_DATA_PORT_OUT_INITIAL;
- 584 2 //Initial();
- 585 2 nRF2401Configuration();
- 586 2 RF_DATA_PORT_IN_INITIAL;
- 587 2
- 588 2 }
- 589 1
- 590 1 }//end of RxConfigDataFromHost
- 591
- 592
- 593 //=============================================================================================
- 594 //比较ID号和包序号 返回值:1.bitNewDataPacketFlag 2. 缓冲器指针gpucStudentIdBufferPoint
- 595 //=============================================================================================
- 596 bit CompareStudentIdandPacketCount(void)
- 597 {
- 598 1 data BYTE i;
- 599 1 //data BYTE j;
- 600 1 bit bitNewDataPacketFlag = 0;
- 601 1
- 602 1 for (i=0; i<cstStuIdBufIndexMax; i++)
- 603 1 {
- 604 2
- 605 2 if ( (0 == gaucStudentIdBuffer[i][0]) && (0 == gaucStudentIdBuffer[i][1]) )
- 606 2 {
- 607 3 //比较到队尾,没有相等的,说明是新数据
- 608 3 gpucStudentIdBufferPoint = i;
- 609 3 bitNewDataPacketFlag = 1;
- 610 3 break;
- 611 3
- 612 3 }//if
- 613 2
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 11
- 614 2 else
- 615 2 {
- 616 3 if ( (gaucStudentIdBuffer[i][0] == gaucRxDataFromRfBuffer[3])
- 617 3 && (gaucStudentIdBuffer[i][1] == gaucRxDataFromRfBuffer[4]) )
- 618 3 {
- 619 4 if (gaucStudentIdBuffer[i][2] == (gaucRxDataFromRfBuffer[5] & 0x3f) )
- 620 4 {
- 621 5 bitNewDataPacketFlag = 0;
- 622 5 break;
- 623 5 }
- 624 4 else
- 625 4 {
- 626 5 bitNewDataPacketFlag = 1;
- 627 5 gpucStudentIdBufferPoint = i;
- 628 5 break;
- 629 5 }
- 630 4
- 631 4 }
- 632 3
- 633 3 }//else
- 634 2
- 635 2
- 636 2 }//for
- 637 1
- 638 1 return bitNewDataPacketFlag;
- 639 1 }//end of CompareStudentIdandPacketCount
- 640
- 641
- 642 //=============================================================================================
- 643 //插入新Id和数据
- 644 //=============================================================================================
- 645 void InsertNewId(void)
- 646 {
- 647 1 //data BYTE i;
- 648 1 //data BYTE j;
- 649 1
- 650 1 gaucStudentIdBuffer[gpucStudentIdBufferPoint][0] = gaucRxDataFromRfBuffer[3]; //ID号 高字节
- 651 1 gaucStudentIdBuffer[gpucStudentIdBufferPoint][1] = gaucRxDataFromRfBuffer[4]; //ID号 低字节
- 652 1 gaucStudentIdBuffer[gpucStudentIdBufferPoint][2] = gaucRxDataFromRfBuffer[5] & 0x3f; //包序号
- 653 1
- 654 1 }//end of InsertNewIdandData
- 655
- 656 void SaveFirtstPacketData(void) //分包传输时,保存第一包数据
- 657 {
- 658 1 //data BYTE i;
- 659 1 //data BYTE j;
- 660 1 gaucStudentIdBuffer[gpucStudentIdBufferPoint][3] = gaucRxDataFromRfBuffer[6]; //data
- 661 1 gaucStudentIdBuffer[gpucStudentIdBufferPoint][4] = gaucRxDataFromRfBuffer[7]; //data
- 662 1 gaucStudentIdBuffer[gpucStudentIdBufferPoint][5] = gaucRxDataFromRfBuffer[8]; //data
- 663 1
- 664 1 }//end of InsertNewIdandData
- 665
- 666 void ClearCurrentFirstPacketData(void)
- 667 {
- 668 1 gaucStudentIdBuffer[gpucStudentIdBufferPoint][3] = 0; //data
- 669 1 gaucStudentIdBuffer[gpucStudentIdBufferPoint][4] = 0; //data
- 670 1 gaucStudentIdBuffer[gpucStudentIdBufferPoint][5] = 0; //data
- 671 1 }
- 672
- 673 void ClearStudentIdBuffer(void)
- 674 {
- 675 1 data BYTE i;
- C51 COMPILER V7.02b STATE_MACHINE 11/30/2007 14:07:16 PAGE 12
- 676 1 data BYTE j;
- 677 1
- 678 1 for (i=0; i<cstStuIdBufIndexMax; i++)
- 679 1 {
- 680 2 for (j=0; j<6; j++)
- 681 2 {
- 682 3 gaucStudentIdBuffer[i][j] = 0;
- 683 3 }
- 684 2 }
- 685 1
- 686 1
- 687 1 } //end of ClearStudentIdBuffer
- 688
- 689
- 690 /*
- 691 void ClearCurrentStudentIdandData(void)
- 692 {
- 693 data BYTE i;
- 694
- 695 for (i=0; i<6; i++)
- 696 {
- 697 gaucStudentIdBuffer[gpucStudentIdBufferPoint][i] = 0;
- 698 }
- 699 }
- 700 */
- 701
- 702 //-----------------------------------------------------------------------------
- 703 // End Of File
- 704 //-----------------------------------------------------------------------------
- MODULE INFORMATION: STATIC OVERLAYABLE
- CODE SIZE = 1466 ----
- CONSTANT SIZE = ---- ----
- XDATA SIZE = ---- ----
- PDATA SIZE = ---- ----
- DATA SIZE = ---- ----
- IDATA SIZE = ---- ----
- BIT SIZE = ---- 2
- END OF MODULE INFORMATION.
- C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)