📄 scu_am.lst
字号:
470 2
471 2 TI = 0;
472 2 TB8 = 1; // Set 'Command' bit
473 2 SBUF = Slave_ID;
474 2 }
475 1 else
476 1 {
477 2 // Message_byte_G is 1, send the data byte
478 2 Timeout = 0;
479 2 while ((++Timeout) && (TI == 0));
480 2
481 2 if (Timeout == 0)
482 2 {
483 3 // usart did not respond - error
484 3 Error_code_G = ERROR_USART_TI;
485 3 return;
486 3 }
487 2
488 2 TI = 0;
489 2 TB8 = 0;
C51 COMPILER V6.10 SCU_AM 04/18/2001 17:09:25 PAGE 9
490 2 SBUF = Tick_message_data_G[SLAVE_INDEX];
491 2 }
492 1
493 1 // Data sent - return
494 1 }
495
496
497 /*------------------------------------------------------------------*-
498
499 SCU_A_MASTER_Process_Ack()
500
501 Make sure the slave (SLAVE_ID) has acknowledged the previous
502 message that was sent. If it has, extract the message data
503 from the USART hardware: if not, call the appropriate error
504 handler.
505
506 Slave_index - The index of the slave.
507
508 RETURNS: RETURN_NORMAL - Ack received (data in Ack_message_data_G)
509 RETURN_ERROR - No ack received (-> no data)
510
511 -*------------------------------------------------------------------*/
512
513 bit SCU_A_MASTER_Process_Ack(const tByte Slave_index)
514 {
515 1 tByte Message_contents;
516 1 tByte Slave_ID;
517 1
518 1 // First time this is called there is no ack tick to check
519 1 // - we simply return 'OK'
520 1 if (First_ack_G)
521 1 {
522 2 First_ack_G = 0;
523 2 return RETURN_NORMAL;
524 2 }
525 1
526 1 // Find the slave ID for this slave
527 1 Slave_ID = (tByte) Current_Slave_IDs_G[Slave_index];
528 1
529 1 // Data should already be in the buffer
530 1 if (RI == 0)
531 1 {
532 2 // Slave has not replied to last tick message
533 2
534 2 // Set error LED
535 2 Network_error_pin = NETWORK_ERROR;
536 2
537 2 return RETURN_ERROR;
538 2 }
539 1
540 1 // There is data - get it
541 1 Message_contents = (tByte) SBUF;
542 1 RI = 0;
543 1
544 1 // This is the reply to the last message
545 1 // - reverse the message byte interpretation
546 1 if (Message_byte_G == 1)
547 1 {
548 2 // Check the 'command bit' is set
549 2 if (RB8 == 1)
550 2 {
551 3 // Check that the ID is correct
C51 COMPILER V6.10 SCU_AM 04/18/2001 17:09:25 PAGE 10
552 3 if (Slave_ID == (tByte) Message_contents)
553 3 {
554 4 // Required Ack message was received
555 4 return RETURN_NORMAL;
556 4 }
557 3 }
558 2
559 2 // Something is wrong...
560 2
561 2 // Set error LED
562 2 Network_error_pin = NETWORK_ERROR;
563 2
564 2 return RETURN_ERROR;
565 2 }
566 1 else
567 1 {
568 2 // There *ARE* data available
569 2 // Extract the data from the slave message
570 2 //
571 2 // NOTE: We *assume* these data are OK
572 2 // - you may wish to send crucial data twice, etc.
573 2 Ack_message_data_G[Slave_index] = Message_contents;
574 2
575 2 return RETURN_NORMAL; // return the slave data
576 2 }
577 1 }
578
579 /*------------------------------------------------------------------*-
580
581 SCU_A_MASTER_Reset_the_Network()
582
583 This function resets (that is, restarts) the whole network.
584
585 -*------------------------------------------------------------------*/
586 void SCU_A_MASTER_Reset_the_Network(void)
587 {
588 1 EA = 0; // Disable interrupts
589 1 while(1); // Watchdog will time out
590 1 }
591
592 /*------------------------------------------------------------------*-
593
594 SCU_A_MASTER_Shut_Down_the_Network()
595
596 This function shuts down the whole network.
597
598 -*------------------------------------------------------------------*/
599 void SCU_A_MASTER_Shut_Down_the_Network(void)
600 {
601 1 EA = 0; // Disable interrupts
602 1
603 1 Network_error_pin = NETWORK_ERROR;
604 1 SCH_Report_Status(); // Sch not running - do this manually
605 1
606 1 while(1)
607 1 {
608 2 SCU_A_MASTER_Watchdog_Refresh();
609 2 }
610 1 }
611
612
613 /*------------------------------------------------------------------*-
C51 COMPILER V6.10 SCU_AM 04/18/2001 17:09:25 PAGE 11
614
615 SCU_A_MASTER_Enter_Safe_State()
616
617 This is the state enterted by the system when:
618 (1) The node is powered up or reset
619 (2) The Master node cannot detect a slave
620 (3) The network has an error
621
622 Try to ensure that the system is in a 'safe' state in these
623 circumstances.
624
625 -*------------------------------------------------------------------*/
626 void SCU_A_MASTER_Enter_Safe_State(void)
627 {
628 1 // USER DEFINED - Edit as required
629 1 TRAFFIC_LIGHTS_Display_Safe_Output();
630 1 }
631
632 /*------------------------------------------------------------------*-
633
634 SCU_A_MASTER_Watchdog_Init()
635
636 This function sets up the watchdog timer.
637
638 If the Master fails (or other error develop),
639 no tick messages will arrive, and the scheduler
640 will stop.
641
642 To detect this situation, we have a (hardware) watchdog
643 running in the slave. This watchdog - which should be set to
644 overflow at around 100ms - is used to set the system into a
645 known (safe) state. The slave will then wait (indefinitely)
646 for the problem to be resolved.
647
648 NOTE: The slave will not be generating Ack messages in these
649 circumstances. The Master (if running) will therefore be aware
650 that there is a problem.
651
652 -*------------------------------------------------------------------*/
653 void SCU_A_MASTER_Watchdog_Init(void)
654 {
655 1 // INIT NOT REQUIRED FOR 1232 EXTERNAL WATCHDOG
656 1 // - May be required wwith different watchdog hardware
657 1 //
658 1 // Edit as required
659 1 }
660
661
662 /*------------------------------------------------------------------*-
663
664 SCU_A_MASTER_Watchdog_Refresh()
665
666 Feed the external (1232) watchdog.
667
668 Timeout is between ~60 and 250 ms (hardware dependent)
669
670 Assumes external 1232 watchdog
671
672 -*------------------------------------------------------------------*/
673 void SCU_A_MASTER_Watchdog_Refresh(void) reentrant
674 {
675 1 // Change the state of the watchdog pin
C51 COMPILER V6.10 SCU_AM 04/18/2001 17:09:25 PAGE 12
676 1 if (WATCHDOG_state_G == 1)
677 1 {
678 2 WATCHDOG_state_G = 0;
679 2 WATCHDOG_pin = 0;
680 2 }
681 1 else
682 1 {
683 2 WATCHDOG_state_G = 1;
684 2 WATCHDOG_pin = 1;
685 2 }
686 1 }
687
688
689 /*------------------------------------------------------------------*-
690 ---- END OF FILE -------------------------------------------------
691 -*------------------------------------------------------------------*/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 775 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 8 15
IDATA SIZE = ---- ----
BIT SIZE = 3 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -