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

📄 sci_dm.lst

📁 PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont This code is copyright (c) 200
💻 LST
📖 第 1 页 / 共 5 页
字号:
  25      =1  
  26      =1  // Possible system states
  27      =1  typedef 
  28      =1  enum {RED, RED_AMBER, GREEN, AMBER, BULB_BLOWN} eLight_State;
  29      =1  
  30      =1  
  31      =1  // ------ Public constants -----------------------------------------
  32      =1  
  33      =1  #define MASTER 1
  34      =1  #define SLAVE 0
  35      =1  
  36      =1  // ------ Public function prototypes -------------------------------
  37      =1  
  38      =1  void TRAFFIC_LIGHTS_Init(void);
  39      =1  void TRAFFIC_LIGHTS_Update(void);
  40      =1  
  41      =1  void TRAFFIC_LIGHTS_Display_Safe_Output(void);
C51 COMPILER V6.10  SCI_DM                                                                 04/18/2001 16:48:12 PAGE 15  

  42      =1  
  43      =1  /*------------------------------------------------------------------*-
  44      =1    ---- END OF FILE -------------------------------------------------
  45      =1  -*------------------------------------------------------------------*/
  39          
  40          // ------ Public variable definitions ------------------------------
  41          
  42          tByte Tick_message_data_G = RETURN_NORMAL;  
  43          tByte Ack_message_data_G = RETURN_NORMAL;
  44          
  45          // Used to detect slave activity
  46          bit First_call_G;
  47          bit Watchdog_input_previous_G;
  48          
  49          // ------ Public variable declarations -----------------------------
  50          
  51          // The array of tasks (see Sch51.c)
  52          extern sTask SCH_tasks_G[SCH_MAX_TASKS];
  53          
  54          // The error code variable (see Sch51.c)
  55          extern tByte Error_code_G;
  56          
  57          // Used to reset system in event of slave error (see Main.C)
  58          extern bit System_reset_G;
  59          
  60          // ------ Private function prototypes ------------------------------
  61          
  62          static void SCI_D_MASTER_Send_Tick_Message(void);
  63          static bit  SCI_D_MASTER_Process_Ack(void);
  64          
  65          /*------------------------------------------------------------------*-
  66          
  67            SCI_D_MASTER_Init_T2()
  68          
  69            Scheduler initialisation function.  Prepares scheduler data 
  70            structures and sets up timer interrupts at required rate.
  71            You must call this function before using the scheduler.  
  72          
  73          -*------------------------------------------------------------------*/
  74          void SCI_D_MASTER_Init_T2(void) 
  75             {
  76   1         tByte i;
  77   1      
  78   1         // No interrupts (yet)
  79   1         EA = 0;
  80   1      
  81   1         // ------ Set up the scheduler ----------------------------------
  82   1         // Sort out the tasks
  83   1         for (i = 0; i < SCH_MAX_TASKS; i++) 
  84   1            {
  85   2            SCH_Delete_Task(i);
  86   2            }
  87   1      
  88   1         // Reset the global error variable
  89   1         // - SCH_Delete_Task() will generate an error code, 
  90   1         //   (because the task array is empty)
  91   1         Error_code_G = 0;
  92   1      
  93   1         // ------ Set up Timer 2 (begin) --------------------------------
  94   1         // Now set up Timer 2
  95   1         // 16-bit timer function with automatic reload
  96   1      
C51 COMPILER V6.10  SCI_DM                                                                 04/18/2001 16:48:12 PAGE 16  

  97   1         // Crystal is assumed to be 12 MHz
  98   1         // The Timer 2 resolution is 0.000001 seconds (1 祍)
  99   1         // The required Timer 2 overflow is 0.001 seconds (1 ms)
 100   1         // - this takes 1000 timer ticks
 101   1         // Reload value is 65536 - 1000 = 64536 (dec) = 0xFC18
 102   1      
 103   1         T2CON = 0x04;   // load Timer 2 control register
 104   1         T2MOD = 0x00;   // load Timer 2 mode register
 105   1      
 106   1         TH2    = 0xFC;  // load timer 2 high byte
 107   1         RCAP2H = 0xFC;  // load timer 2 reload capture reg, high byte
 108   1         TL2    = 0x18;  // load timer 2 low byte
 109   1         RCAP2L = 0x18;  // load timer 2 reload capture reg, low byte
 110   1         
 111   1         ET2   = 1;  // Timer 2 interrupt is enabled
 112   1      
 113   1         TR2   = 1;  // Start Timer 2
 114   1         // ------ Set up Timer 2 (end) ----------------------------------
 115   1         }
 116          
 117          /*------------------------------------------------------------------*-
 118          
 119            SCI_D_MASTER_Start()
 120          
 121            Starts the scheduler, by enabling interrupts.
 122          
 123            NOTE: Usually called after all regular tasks are added,
 124            to keep the tasks synchronised.
 125          
 126            NOTE: ONLY THE SCHEDULER INTERRUPT SHOULD BE ENABLED!!! 
 127           
 128          -*------------------------------------------------------------------*/
 129          void SCI_D_MASTER_Start(void) 
 130             {
 131   1         // Try to place system in 'safe' state at start or after errors
 132   1         SCI_D_MASTER_Enter_Safe_State();
 133   1      
 134   1         // Delay here to cause the slave to time out and reset
 135   1         // Adjust this delay to match the timeout periods on the slaves
 136   1         Hardware_Delay_T0(500);
 137   1      
 138   1         // Now send first tick to start the slave
 139   1         // (starts on falling edge)
 140   1         Interrupt_output_pin = 1;
 141   1         Hardware_Delay_T0(5);
 142   1         Interrupt_output_pin = 0;
 143   1         Hardware_Delay_T0(5);
 144   1      
 145   1         Interrupt_output_pin = 1; // Ready for first tick
 146   1      
 147   1         // Start the scheduler
 148   1         EA = 1;
 149   1         }
 150          
 151          /*------------------------------------------------------------------*-
 152          
 153            SCI_D_MASTER_Update_T2
 154          
 155            This is the scheduler ISR.  It is called at a rate determined by 
 156            the timer settings in SCI_D_MASTER_Init_T2().  This version is 
 157            triggered by Timer 2 interrupts: timer is automatically reloaded.
 158          
C51 COMPILER V6.10  SCI_DM                                                                 04/18/2001 16:48:12 PAGE 17  

 159          -*------------------------------------------------------------------*/
 160          void SCI_D_MASTER_Update_T2(void) interrupt INTERRUPT_Timer_2_Overflow  
 161             {
 162   1         tByte Index;
 163   1      
 164   1         TF2 = 0; // Must manually clear this. 
 165   1      
 166   1         // Get the ack message from the slave
 167   1         if (SCI_D_MASTER_Process_Ack() == RETURN_ERROR)
 168   1            {
 169   2            // Did not receive ack!
 170   2            Error_code_G = ERROR_SCH_LOST_SLAVE;
 171   2      
 172   2            // Enter safe state and remain here until reset
 173   2            SCI_D_MASTER_Enter_Safe_State();
 174   2            while(1); 
 175   2            }
 176   1       
 177   1         // Send 'tick' message to the slave
 178   1         SCI_D_MASTER_Send_Tick_Message(); 
 179   1      
 180   1         // NOTE: calculations are in *TICKS* (not milliseconds)
 181   1         for (Index = 0; Index < SCH_MAX_TASKS; Index++)
 182   1            {
 183   2            // Check if there is a task at this location
 184   2            if (SCH_tasks_G[Index].pTask)
 185   2               {
 186   3               if (SCH_tasks_G[Index].Delay == 0)
 187   3                  {
 188   4                  // The task is due to run
 189   4                  SCH_tasks_G[Index].RunMe += 1;  // Increment the run flag
 190   4      
 191   4                  if (SCH_tasks_G[Index].Period)
 192   4                     {
 193   5                     // Schedule this periodic task to run again
 194   5                     SCH_tasks_G[Index].Delay = SCH_tasks_G[Index].Period;
 195   5                     }
 196   4                  }
 197   3               else
 198   3                  {
 199   4                  // Not yet ready to run: just decrement the delay 
 200   4                  SCH_tasks_G[Index].Delay -= 1;
 201   4                  }
 202   3               }         
 203   2            }
 204   1      
 205   1         // Prepare for next tick
 206   1         Interrupt_output_pin = 1;
 207   1         }   
 208          
 209          /*------------------------------------------------------------------*-
 210          
 211            SCI_D_MASTER_Send_Tick_Message()
 212          
 213            This function sends a tick message.
 214          
 215            The receipt of this message will cause an interrupt to be generated
 216            in the slave(s): this will, in turn, invoke the scheduler 'update' 
 217            function in the slave(s).
 218          
 219          -*------------------------------------------------------------------*/
 220          void SCI_D_MASTER_Send_Tick_Message(void) 
C51 COMPILER V6.10  SCI_DM                                                                 04/18/2001 16:48:12 PAGE 18  

 221             {
 222   1         // Apply the tick data to the port
 223   1         SCI_transfer_port = Tick_message_data_G;
 224   1      
 225   1         // Send tick (falling edge) to the slave
 226   1         Interrupt_output_pin = 0;
 227   1         }
 228          
 229          
 230          /*------------------------------------------------------------------*-
 231          
 232            SCI_D_MASTER_Process_Ack()
 233          
 234            Checks that the slave is operating.
 235          
 236            Reads data from the slave.
 237          
 238          -*------------------------------------------------------------------*/
 239          
 240          bit SCI_D_MASTER_Process_Ack(void) 
 241             {
 242   1         if (First_call_G)
 243   1            {
 244   2            // This is the first time this function has been called
 245   2            First_call_G = 0;
 246   2      
 247   2            // Prepare for subsequent checking of the watchdog pin
 248   2            Watchdog_input_previous_G = Slave_watchdog_pin;
 249   2            }
 250   1         else
 251   1            {
 252   2            // Watchdog pin should change state every time
 253   2            // - if the slave is running correctly
 254   2            if (Watchdog_input_previous_G == Slave_watchdog_pin)
 255   2               {
 256   3               // Error!
 257   3               return RETURN_ERROR;
 258   3               }
 259   2      
 260   2            // Slave is OK
 261   2            Watchdog_input_previous_G = Slave_watchdog_pin;
 262   2            }
 263   1      
 264   1         // Set up port for reading
 265   1         SCI_transfer_port = 0xFF;
 266   1      
 267   1         // Read ack message
 268   1         Ack_message_data_G = SCI_transfer_port;
 269   1      
 270   1         return RETURN_NORMAL;
 271   1         }
 272          
 273          /*------------------------------------------------------------------*-
 274          
 275            SCI_D_MASTER_Enter_Safe_State()
 276          
 277            This is the state entered by the system when:
 278            (1) The node is powered up or reset
 279            (2) The slave node fails
 280            (3) The network has an error
 281            (4) Ack messages are delayed for any other reason
 282          
C51 COMPILER V6.10  SCI_DM                                                                 04/18/2001 16:48:12 PAGE 19  

 283            Try to ensure that the system is in a 'safe' state in these 
 284            circumstances.
 285          
 286          -*------------------------------------------------------------------*/
 287          void SCI_D_MASTER_Enter_Safe_State(void) reentrant
 288             {
 289   1         // USER DEFINED - Edit as required
 290   1      
 291   1         // Here we display a safe output
 292   1         TRAFFIC_LIGHTS_Display_Safe_Output();
 293   1         }  
 294          
 295          /*------------------------------------------------------------------*-
 296            ---- END OF FILE -------------------------------------------------
 297          -*------------------------------------------------------------------*/
C51 COMPILER V6.10  SCI_DM                                                                 04/18/2001 16:48:12 PAGE 20  

ASSEMBLY LISTING OF GENERATED OBJECT CODE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -