⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scu_bm.lst

📁 PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont This code is copyright (c) 200
💻 LST
📖 第 1 页 / 共 3 页
字号:
 472   3               return;
 473   3               } 
 474   2      
 475   2            TI = 0;                                            
 476   2            TB8 = 1;  // Set 'Command' bit
 477   2            SBUF = Slave_ID;
 478   2            }
 479   1         else
 480   1            {
 481   2            // Message_byte_G is 1, send the data byte 
 482   2            Timeout = 0;
 483   2            while ((++Timeout) && (TI == 0));  
 484   2      
 485   2            if (Timeout == 0)
 486   2               {
 487   3               // usart did not respond - error
 488   3               Error_code_G = ERROR_USART_TI; 
 489   3               return;
C51 COMPILER V6.10  SCU_BM                                                                 04/18/2001 17:23:01 PAGE 9   

 490   3               } 
 491   2      
 492   2            TI = 0;
 493   2            TB8 = 0;
 494   2            SBUF = Tick_message_data_G[SLAVE_INDEX];
 495   2            }
 496   1       
 497   1         // Data sent - return
 498   1         }
 499          
 500          
 501          /*------------------------------------------------------------------*-
 502          
 503            SCU_B_MASTER_Process_Ack()
 504          
 505            Make sure the slave (SLAVE_ID) has acknowledged the previous
 506            message that was sent.  If it has, extract the message data
 507            from the USART hardware: if not, call the appropriate error
 508            handler.
 509          
 510            Slave_index - The index of the slave. 
 511          
 512            RETURNS:  RETURN_NORMAL - Ack received (data in Ack_message_data_G)
 513                      RETURN_ERROR  - No ack received (-> no data)
 514          
 515          -*------------------------------------------------------------------*/
 516          
 517          bit SCU_B_MASTER_Process_Ack(const tByte Slave_index) 
 518             {
 519   1         tByte Message_contents;
 520   1         tByte Slave_ID;
 521   1      
 522   1         // First time this is called there is no ack tick to check 
 523   1         // - we simply return 'OK'
 524   1         if (First_ack_G)
 525   1            {
 526   2            First_ack_G = 0;
 527   2            return RETURN_NORMAL;
 528   2            }
 529   1      
 530   1         // Find the slave ID for this slave 
 531   1         Slave_ID = (tByte) Current_Slave_IDs_G[Slave_index];
 532   1      
 533   1         // Data should already be in the buffer
 534   1         if (RI == 0)
 535   1            {
 536   2            // Slave has not replied to last tick message
 537   2      
 538   2            // Set error LED
 539   2            Network_error_pin = NETWORK_ERROR;
 540   2      
 541   2            return RETURN_ERROR;
 542   2            } 
 543   1      
 544   1         // There is data - get it
 545   1         Message_contents = (tByte) SBUF;
 546   1         RI = 0;
 547   1      
 548   1         // This is the reply to the last message 
 549   1         // - reverse the message byte interpretation 
 550   1         if (Message_byte_G == 1)
 551   1            {
C51 COMPILER V6.10  SCU_BM                                                                 04/18/2001 17:23:01 PAGE 10  

 552   2            // Check the 'command bit' is set
 553   2            if (RB8 == 1)
 554   2               {
 555   3               // Check that the ID is correct
 556   3               if (Slave_ID == (tByte) Message_contents)
 557   3                  {
 558   4                  // Required Ack message was received
 559   4                  return RETURN_NORMAL;
 560   4                  }
 561   3               }
 562   2      
 563   2             // Something is wrong...
 564   2      
 565   2             // Set error LED
 566   2             Network_error_pin = NETWORK_ERROR;
 567   2      
 568   2             return RETURN_ERROR;
 569   2             }
 570   1          else
 571   1             {  
 572   2             // There *ARE* data available 
 573   2             // Extract the data from the slave message
 574   2             //
 575   2             // NOTE: We *assume* these data are OK
 576   2             // - you may wish to send crucial data twice, etc.
 577   2             Ack_message_data_G[Slave_index] = Message_contents;
 578   2        
 579   2             return RETURN_NORMAL;  // return the slave data
 580   2             }
 581   1         }
 582          
 583          /*------------------------------------------------------------------*-
 584          
 585            SCU_B_MASTER_Reset_the_Network()
 586          
 587            This function resets (that is, restarts) the whole network.
 588          
 589          -*------------------------------------------------------------------*/
 590          void SCU_B_MASTER_Reset_the_Network(void)
 591             {
 592   1         EA = 0;   // Disable interrupts
 593   1         while(1); // Watchdog will time out
 594   1         }
 595          
 596          /*------------------------------------------------------------------*-
 597          
 598            SCU_B_MASTER_Shut_Down_the_Network()
 599          
 600            This function shuts down the whole network.
 601          
 602          -*------------------------------------------------------------------*/
 603          void SCU_B_MASTER_Shut_Down_the_Network(void)
 604             {
 605   1         EA = 0; // Disable interrupts
 606   1      
 607   1         Network_error_pin = NETWORK_ERROR;
 608   1         SCH_Report_Status(); // Sch not running - do this manually
 609   1      
 610   1         while(1)
 611   1            {
 612   2            SCU_B_MASTER_Watchdog_Refresh();
 613   2            }
C51 COMPILER V6.10  SCU_BM                                                                 04/18/2001 17:23:01 PAGE 11  

 614   1         }
 615          
 616          
 617          /*------------------------------------------------------------------*-
 618          
 619            SCU_B_MASTER_Enter_Safe_State()
 620          
 621            This is the state enterted by the system when:
 622            (1) The node is powered up or reset
 623            (2) The Master node cannot detect a slave
 624            (3) The network has an error
 625          
 626            Try to ensure that the system is in a 'safe' state in these 
 627            circumstances.
 628          
 629          -*------------------------------------------------------------------*/
 630          void SCU_B_MASTER_Enter_Safe_State(void)
 631             {
 632   1         // USER DEFINED - Edit as required
 633   1         TRAFFIC_LIGHTS_Display_Safe_Output();
 634   1         } 
 635          
 636          /*------------------------------------------------------------------*-
 637          
 638            SCU_B_MASTER_Watchdog_Init()
 639          
 640            This function sets up the watchdog timer.
 641          
 642            If the Master fails (or other error develop), 
 643            no tick messages will arrive, and the scheduler
 644            will stop.  
 645          
 646            To detect this situation, we have a (hardware) watchdog
 647            running in the slave.  This watchdog - which should be set to
 648            overflow at around 100ms - is used to set the system into a
 649            known (safe) state.  The slave will then wait (indefinitely)
 650            for the problem to be resolved.
 651          
 652            NOTE: The slave will not be generating Ack messages in these 
 653            circumstances.  The Master (if running) will therefore be aware
 654            that there is a problem.  
 655          
 656          -*------------------------------------------------------------------*/
 657          void SCU_B_MASTER_Watchdog_Init(void)   
 658             {
 659   1         // INIT NOT REQUIRED FOR 1232 EXTERNAL WATCHDOG
 660   1         // - May be required wwith different watchdog hardware
 661   1         //
 662   1         // Edit as required
 663   1         }
 664          
 665          
 666          /*------------------------------------------------------------------*-
 667          
 668            SCU_B_MASTER_Watchdog_Refresh()
 669          
 670            Feed the external (1232) watchdog.
 671          
 672            Timeout is between ~60 and 250 ms (hardware dependent)
 673          
 674            Assumes external 1232 watchdog
 675          
C51 COMPILER V6.10  SCU_BM                                                                 04/18/2001 17:23:01 PAGE 12  

 676          -*------------------------------------------------------------------*/
 677          void SCU_B_MASTER_Watchdog_Refresh(void) reentrant
 678             {
 679   1         // Change the state of the watchdog pin
 680   1         if (WATCHDOG_state_G == 1)
 681   1            {
 682   2            WATCHDOG_state_G = 0;
 683   2            WATCHDOG_pin = 0;
 684   2            }
 685   1         else
 686   1            {
 687   2            WATCHDOG_state_G = 1;
 688   2            WATCHDOG_pin = 1;
 689   2            } 
 690   1         }    
 691          
 692          
 693          /*------------------------------------------------------------------*-
 694            ---- END OF FILE -------------------------------------------------
 695          -*------------------------------------------------------------------*/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    779    ----
   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 + -