📄 sppisr.lst
字号:
253 2 sppRFStateFunc = TXACK_CRC8;
254 2 } else {
255 2 sppIntData.pTXI->status = SPP_TX_ACK_INVALID;
256 2 FSM_TRY_RESTART_TX();
257 2 }
258 1 }
259
260 void TXACK_CRC8 (void) {
261 1 FAST_CRC8(RF_RECEIVE_BYTE(), sppIntData.crc8);
262 1 if (sppIntData.crc8 == CRC_OK) {
263 2 sppIntData.pTXI->flags ^= SPP_SEQUENCE_BIT; // Toggle the packet sequence number bit
264 2 sppIntData.pTXI->status = SPP_TX_FINISHED;
265 2 FSM_RESET();
266 2 } else {
267 2 sppIntData.pTXI->status = SPP_TX_ACK_INVALID;
268 2 FSM_TRY_RESTART_TX();
269 2 }
270 1 }
271
272
273
274
275 //----------------------------------------------------------------------------
276 // RX FUNCTIONS
277 //----------------------------------------------------------------------------
278 void RX_WAIT (void) {
279 1 // Drop the sync byte
280 1 RF_LOCK_AVERAGE_FILTER(TRUE);
281 1 sppIntData.mode = SPP_RX_MODE;
282 1 sppRFStateFunc = RX_DAB;
283 1 }
284
285 void RX_DAB (void) {
286 1 sppIntData.pRXI->status = SPP_RX_RECEIVING;
287 1 FAST_CRC8_INIT(sppIntData.crc8);
288 1 FAST_CRC8(RF_RECEIVE_BYTE(), sppIntData.crc8);
289 1 if ((RF_RECEIVE_BYTE() == sppSettings.myAddress) || (RF_RECEIVE_BYTE() == SPP_BROADCAST)) {
290 2 sppRFStateFunc = RX_SAB;
291 2 } else {
292 2 FSM_RESTART_RX();
293 2 }
294 1 }
295
296 void RX_SAB (void) {
297 1 sppIntData.pRXI->source = RF_RECEIVE_BYTE();
298 1 FAST_CRC8(RF_RECEIVE_BYTE(), sppIntData.crc8);
299 1 sppRFStateFunc = RX_DATA_LEN;
300 1 }
301
302 void RX_DATA_LEN (void) {
C51 COMPILER V7.08 SPPISR 11/25/2008 21:39:38 PAGE 6
303 1 sppIntData.pRXI->dataLen = RF_RECEIVE_BYTE();
304 1 FAST_CRC8(RF_RECEIVE_BYTE(), sppIntData.crc8);
305 1 sppRFStateFunc = RX_FLAG;
306 1 }
307
308 void RX_FLAG (void) {
309 1 sppIntData.pRXI->flags = RF_RECEIVE_BYTE();
310 1 FAST_CRC8(RF_RECEIVE_BYTE(), sppIntData.crc8);
311 1 sppRFStateFunc = RX_CRC8_HEADER;
312 1 }
313
314 void RX_CRC8_HEADER (void) {
315 1 FAST_CRC8(RF_RECEIVE_BYTE(), sppIntData.crc8);
316 1 sppIntData.counter = 0;
317 1
318 1 if (sppIntData.crc8 == CRC_OK) {
319 2 if (sppIntData.pRXI->dataLen == 0) {
320 3 SPP_DISABLE_TIMEOUT();
321 3 if (sppIntData.pRXI->flags & SPP_ACK_REQ) {
322 4 SPP_FAST_POWER_UP_TX();
323 4 sppRFStateFunc = RXACK_START;
324 4 } else {
325 4 sppIntData.pRXI->status = SPP_RX_FINISHED;
326 4 FSM_RESET();
327 4 }
328 3 } else if (sppIntData.pRXI->dataLen > sppIntData.pRXI->maxDataLen) {
329 3 sppIntData.pRXI->status = SPP_RX_TOO_LONG;
330 3 FSM_RESET();
331 3 } else {
332 3 sppRFStateFunc = RX_DBX_START;
333 3 }
334 2 } else {
335 2 FSM_RESTART_RX();
336 2 }
337 1 }
338
339 void RX_DBX_START (void) {
340 1 sppIntData.pRXI->pDataBuffer[sppIntData.counter] = RF_RECEIVE_BYTE();
341 1 FAST_CRC16_INIT(sppIntData.crc16);
342 1 FAST_CRC16(RF_RECEIVE_BYTE(), sppIntData.crc16);
343 1 sppIntData.counter = 1;
344 1 if (sppIntData.counter == sppIntData.pRXI->dataLen) {
345 2 sppRFStateFunc = RX_CRC16_DATA_H;
346 2 } else {
347 2 sppRFStateFunc = RX_DBX;
348 2 }
349 1 }
350
351 void RX_DBX (void) {
352 1 sppIntData.pRXI->pDataBuffer[sppIntData.counter] = RF_RECEIVE_BYTE();
353 1 FAST_CRC16(RF_RECEIVE_BYTE(), sppIntData.crc16);
354 1 sppIntData.counter++;
355 1 if (sppIntData.counter == sppIntData.pRXI->dataLen) {
356 2 sppRFStateFunc = RX_CRC16_DATA_H;
357 2 }
358 1 }
359
360 void RX_CRC16_DATA_H (void) {
361 1 FAST_CRC16(RF_RECEIVE_BYTE(), sppIntData.crc16);
362 1 sppRFStateFunc = RX_CRC16_DATA_L;
363 1 }
364
C51 COMPILER V7.08 SPPISR 11/25/2008 21:39:38 PAGE 7
365 void RX_CRC16_DATA_L (void) {
366 1 FAST_CRC16(RF_RECEIVE_BYTE(), sppIntData.crc16);
367 1 if (sppIntData.crc16 == CRC_OK) {
368 2 SPP_DISABLE_TIMEOUT();
369 2 if (sppIntData.pRXI->flags & SPP_ACK_REQ) {
370 3 SPP_FAST_POWER_UP_TX();
371 3 sppRFStateFunc = RXACK_START;
372 3 } else {
373 3 FSM_RESET();
374 3 sppIntData.pRXI->status = SPP_RX_FINISHED;
375 3 }
376 2 } else {
377 2 FSM_RESTART_RX();
378 2 }
379 1 }
380
381
382
383
384 //----------------------------------------------------------------------------
385 // RXACK FUNCTIONS
386 //----------------------------------------------------------------------------
387 void RXACK_START (void) {
388 1 sppIntData.mode = SPP_RXACK_MODE;
389 1 sppIntData.pRXI->status = SPP_RX_ACKING;
390 1 sppIntData.counter = sppSettings.txPreambleByteCount - 1;
391 1 RF_SEND_BYTE (RF_PREAMBLE_BYTE);
392 1 sppRFStateFunc = RXACK_PREAMBLE;
393 1 }
394
395 void RXACK_PREAMBLE (void) {
396 1 RF_SEND_BYTE (RF_PREAMBLE_BYTE);
397 1 if (!--sppIntData.counter) {
398 2 sppRFStateFunc = RXACK_SYNC;
399 2 }
400 1 }
401
402 void RXACK_SYNC (void) {
403 1 RF_SEND_BYTE (RF_SUITABLE_SYNC_BYTE);
404 1 sppRFStateFunc = RXACK_DAB;
405 1 }
406
407 void RXACK_DAB (void) {
408 1 RF_SEND_BYTE (sppIntData.pRXI->source);
409 1 FAST_CRC8_INIT(sppIntData.crc8);
410 1 FAST_CRC8(sppIntData.pRXI->source, sppIntData.crc8);
411 1 sppRFStateFunc = RXACK_SAB;
412 1 }
413
414 void RXACK_SAB (void) {
415 1 RF_SEND_BYTE (sppSettings.myAddress);
416 1 FAST_CRC8(sppSettings.myAddress, sppIntData.crc8);
417 1 sppRFStateFunc = RXACK_DATA_LEN;
418 1 }
419
420 void RXACK_DATA_LEN (void) {
421 1 RF_SEND_BYTE (0);
422 1 FAST_CRC8(0, sppIntData.crc8);
423 1 sppRFStateFunc = RXACK_FLAG;
424 1 }
425
426 void RXACK_FLAG (void) {
C51 COMPILER V7.08 SPPISR 11/25/2008 21:39:38 PAGE 8
427 1 RF_SEND_BYTE (SPP_ACK);
428 1 FAST_CRC8(SPP_ACK, sppIntData.crc8);
429 1 sppRFStateFunc = RXACK_CRC8;
430 1 }
431
432 void RXACK_CRC8 (void) {
433 1 RF_SEND_BYTE (sppIntData.crc8);
434 1 sppIntData.counter = SPP_ZEROPAD_COUNT;
435 1 sppRFStateFunc = RXACK_ZEROPAD;
436 1 }
437
438 void RXACK_ZEROPAD (void) {
439 1 RF_SEND_BYTE (0);
440 1 if (!--sppIntData.counter) {
441 2 sppIntData.pRXI->status = SPP_RX_FINISHED;
442 2 FSM_RESET();
443 2 }
444 1 }
445
446
447 //----------------------------------------------------------------------------
448 // void RF_ISR (void) interrupt INUM_RF
449 //
450 // Description:
451 // RF interrupt service routine
452 // Runs the SPP finite state machine
453 //
454 // The packet sequence bit:
455 // TX: Toggle when finished (sppIntData.pTXI->status = SPP_TX_FINISHED).
456 // RX: The user application must examine the sequence bit.
457 //----------------------------------------------------------------------------
458 void RF_ISR (void) interrupt INUM_RF {
459 1
460 1 INT_GLOBAL_ENABLE (INT_OFF);
461 1 INT_SETFLAG (INUM_RF, INT_CLR);
462 1
463 1 if (sppIntData.mode != SPP_IDLE_MODE) {
464 2 sppRFStateFunc();
465 2 }
466 1
467 1 INT_GLOBAL_ENABLE (INT_ON);
468 1 return;
469 1 } // RF_ISR
470
471
472
473
474 //----------------------------------------------------------------------------
475 // void sppTimeout(void)
476 //
477 // Description:
478 // Timeout
479 // Callback from sxpTimer: TIMER3_ISR()
480 //----------------------------------------------------------------------------
481 void sppTimeout(void) {
482 1 INT_GLOBAL_ENABLE (INT_OFF);
483 1 if (sppIntData.mode & SPP_TXACK_MODE) {
484 2 FSM_TRY_RESTART_TX();
485 2 sppIntData.pTXI->status = SPP_TX_ACK_TIMEOUT;
486 2 } else if (sppIntData.mode & SPP_RX_MODE) {
487 2 if (sppIntData.pRXI->status == SPP_RX_WAITING) {
488 3 FSM_RESET();
C51 COMPILER V7.08 SPPISR 11/25/2008 21:39:38 PAGE 9
489 3 sppIntData.pRXI->status = SPP_RX_TIMEOUT;
490 3 } else {
491 3 SPP_ENABLE_TIMEOUT(2); // Try again later (don't mess up the reception)
492 3 }
493 2 }
494 1 INT_GLOBAL_ENABLE (INT_ON);
495 1 } // sppTimeout
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 3158 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 18 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
EDATA SIZE = ---- ----
HDATA SIZE = ---- ----
XDATA CONST SIZE = ---- ----
FAR CONST SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -