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

📄 scc_s515.lst

📁 基于8051共享时钟调度器的can总线通讯
💻 LST
📖 第 1 页 / 共 2 页
字号:
 248   3      
 249   3               // Send ack
 250   3               CAN_messages[1].Data[0] = 0x00;     // Set data byte 0
 251   3               CAN_messages[1].Data[1] = SLAVE_ID; // Set data byte 1
 252   3               CAN_messages[1].MCR1 = 0xE7;  // Send it
 253   3               }
 254   2            else
 255   2               {
 256   3               // Not yet received correct message - wait
 257   3               Start_slave = 0;
 258   3               }
 259   2            } while (!Start_slave);
 260   1      
 261   1         // Start the scheduler
 262   1         IRCON = 0;
 263   1         EAL = 1;
 264   1         }
 265          
 266          /*------------------------------------------------------------------*-
 267          
 268            SCC_A_SLAVE_Update
 269          
 270            This is the scheduler ISR.  It is called at a rate 
 271            determined by the timer settings in SCC_A_SLAVE_Init().
 272          
 273            This Slave is triggered by USART interrupts.
 274          
 275          -*------------------------------------------------------------------*/
 276          void SCC_A_SLAVE_Update(void) interrupt INTERRUPT_CAN_c515c  
 277             {
 278   1         tByte Index;
 279   1      
 280   1         // Reset this when tick is received
 281   1         Network_error_pin = NO_NETWORK_ERROR;
 282   1      
 283   1         // Check tick data - send ack if necessary
 284   1         // NOTE: 'START' message will only be sent after a 'time out'
 285   1         if (SCC_A_SLAVE_Process_Tick_Message() == SLAVE_ID)
 286   1            {
 287   2            SCC_A_SLAVE_Send_Ack_Message_To_Master();
 288   2      
 289   2            // Feed the watchdog ONLY when a *relevant* message is received
 290   2            // (noise on the bus, etc, will not stop the watchdog...)
 291   2            //
 292   2            // START messages will NOT refresh the slave
 293   2            // - Must talk to every slave at regular intervals 
 294   2            SCC_A_SLAVE_Watchdog_Refresh();
 295   2            }
 296   1      
 297   1         // Check the last error codes on the CAN bus via the status register
 298   1         if ((CAN_sr & 0x07) != 0)
 299   1            {
 300   2            Error_code_G = ERROR_SCH_CAN_BUS_ERROR;
 301   2            Network_error_pin = NETWORK_ERROR;
 302   2         
 303   2            // See Infineon c515c manual for error code details
C51 COMPILER V6.10  SCC_S515                                                               04/19/2001 14:16:00 PAGE 6   

 304   2            CAN_error_pin0 = ((CAN_sr & 0x01) == 0);
 305   2            CAN_error_pin1 = ((CAN_sr & 0x02) == 0);
 306   2            CAN_error_pin2 = ((CAN_sr & 0x04) == 0);
 307   2            }
 308   1         else
 309   1            {
 310   2            CAN_error_pin0 = 1;
 311   2            CAN_error_pin1 = 1;
 312   2            CAN_error_pin2 = 1;
 313   2            }
 314   1      
 315   1         // NOTE: calculations are in *TICKS* (not milliseconds)
 316   1         for (Index = 0; Index < SCH_MAX_TASKS; Index++)
 317   1            {
 318   2            // Check if there is a task at this location
 319   2            if (SCH_tasks_G[Index].pTask)
 320   2               {
 321   3               if (SCH_tasks_G[Index].Delay == 0)
 322   3                  {
 323   4                  // The task is due to run
 324   4                  SCH_tasks_G[Index].RunMe = 1;  // Set the run flag
 325   4         
 326   4                  if (SCH_tasks_G[Index].Period)
 327   4                     {
 328   5                     // Schedule periodic tasks to run again
 329   5                     SCH_tasks_G[Index].Delay = SCH_tasks_G[Index].Period;
 330   5                     }
 331   4                  }
 332   3               else
 333   3                  {
 334   4                  // Not yet ready to run: just decrement the delay 
 335   4                  SCH_tasks_G[Index].Delay -= 1;
 336   4                  }
 337   3               }         
 338   2            }
 339   1         }   
 340          
 341          /*------------------------------------------------------------------*-
 342          
 343            SCC_A_SLAVE_Process_Tick_Message()
 344          
 345            The ticks messages are crucial to the operation of this shared-clock
 346            scheduler: the arrival of a tick message (at regular intervals) 
 347            invokes the 'Update' ISR, that drives the scheduler.
 348          
 349            The tick messages themselves may contain data.  These data are 
 350            extracted in this function. 
 351          
 352          -*------------------------------------------------------------------*/
 353          tByte SCC_A_SLAVE_Process_Tick_Message(void)
 354             {
 355   1         tByte Tick_ID;
 356   1      
 357   1         if ((CAN_messages[0].MCR1 & 0x0c) == 0x08)  // if MSGLST set
 358   1            {
 359   2            // Indicates that the CAN controller has stored a new 
 360   2            // message into this object, while NEWDAT was still set,
 361   2            // i.e. the previously stored message is lost.
 362   2      
 363   2            // We simply IGNORE this here and reset the flag
 364   2            CAN_messages[0].MCR1 = 0xf7;  // reset MSGLST
 365   2            }
C51 COMPILER V6.10  SCC_S515                                                               04/19/2001 14:16:00 PAGE 7   

 366   1      
 367   1         // The first byte is the ID of the slave for which the data are
 368   1         // intended
 369   1         Tick_ID = CAN_messages[0].Data[0];   // Get data byte 0 (Slave ID)
 370   1      
 371   1         if (Tick_ID == SLAVE_ID)
 372   1            {
 373   2            // Only if there is a match do we need to copy these fields
 374   2            Tick_message_data_G[0] = CAN_messages[0].Data[1];   
 375   2            Tick_message_data_G[1] = CAN_messages[0].Data[2];   
 376   2            Tick_message_data_G[2] = CAN_messages[0].Data[3];   
 377   2            Tick_message_data_G[3] = CAN_messages[0].Data[4];   
 378   2            }
 379   1      
 380   1         CAN_messages[0].MCR0 = 0xfd;  // reset NEWDAT, INTPND
 381   1         CAN_messages[0].MCR1 = 0xfd;  
 382   1      
 383   1         return Tick_ID;
 384   1         }
 385          
 386          
 387          /*------------------------------------------------------------------*-
 388          
 389            SCC_A_SLAVE_Send_Ack_Message_To_Master()
 390          
 391            Slave must send and 'Acknowledge' message to the master, after
 392            tick messages are received.  NOTE: Only tick messages specifically
 393            addressed to this slave should be acknowledged.
 394          
 395            The acknowledge message serves two purposes:
 396            [1] It confirms to the master that this slave is alive & well.
 397            [2] It provides a means of sending data to the master and - hence
 398                - to other slaves.
 399          
 400            NOTE: Data transfer between slaves is NOT permitted!
 401          
 402          -*------------------------------------------------------------------*/
 403          void SCC_A_SLAVE_Send_Ack_Message_To_Master(void)
 404             {
 405   1         // First byte of message must be slave ID
 406   1         CAN_messages[1].Data[0] = SLAVE_ID;   // data byte 0
 407   1      
 408   1         CAN_messages[1].Data[1] = Ack_message_data_G[0];   
 409   1         CAN_messages[1].Data[2] = Ack_message_data_G[1];   
 410   1         CAN_messages[1].Data[3] = Ack_message_data_G[2];   
 411   1         CAN_messages[1].Data[4] = Ack_message_data_G[3];   
 412   1      
 413   1         // Send the message on the CAN bus
 414   1         CAN_messages[1].MCR1 = 0xE7;  // TXRQ, reset CPUUPD
 415   1         }
 416          
 417          
 418          /*------------------------------------------------------------------*-
 419          
 420            SCC_A_SLAVE_Watchdog_Init()
 421          
 422            This function sets up the watchdog timer.
 423          
 424            If the Master fails (or other error develop), 
 425            no tick messages will arrive, and the scheduler
 426            will stop.  
 427          
C51 COMPILER V6.10  SCC_S515                                                               04/19/2001 14:16:00 PAGE 8   

 428            To detect this situation, we have a (hardware) watchdog
 429            running in the slave.  This watchdog - which should be set to
 430            overflow at around 100ms - is used to set the system into a
 431            known (safe) state.  The slave will then wait (indefinitely)
 432            for the problem to be resolved.
 433          
 434            NOTE: The slave will not be generating Ack messages in these 
 435            circumstances.  The Master (if running) will therefore be aware
 436            that there is a problem.  
 437          
 438          -*------------------------------------------------------------------*/
 439          void SCC_A_SLAVE_Watchdog_Init(void)   
 440             {
 441   1         // Watchdog timer prescaler (1/16) enabled 
 442   1         // Watchdog timer reload value is 0x6B
 443   1         // Watchdog period is 103.2 ms (10.0 MHz xtal, c515c)
 444   1         WDTREL = 0xEB;
 445   1        
 446   1         // Start watchdog timer
 447   1         WDT  = 1;
 448   1         SWDT = 1;     
 449   1         }
 450          
 451          
 452          /*------------------------------------------------------------------*-
 453          
 454            SCC_A_SLAVE_Watchdog_Refresh()
 455          
 456            Feed the watchdog.
 457          
 458          -*------------------------------------------------------------------*/
 459          void SCC_A_SLAVE_Watchdog_Refresh(void) reentrant
 460             {
 461   1         WDT  = 1;
 462   1         SWDT = 1;
 463   1         }    
 464          
 465          /*------------------------------------------------------------------*-
 466          
 467            SCC_A_SLAVE_Enter_Safe_State()
 468          
 469            This is the state enterted by the system when:
 470            (1) The node is powerec up or reset
 471            (2) The Master node fails, and no working backup is available
 472            (3) The network has an error
 473            (4) Tick messages are delayed for any other reason
 474          
 475            Try to ensure that the system is in a 'safe' state in these 
 476            circumstances.
 477          
 478          -*------------------------------------------------------------------*/
 479          void SCC_A_SLAVE_Enter_Safe_State(void)
 480             {
 481   1         // USER DEFINED 
 482   1         TRAFFIC_LIGHTS_Display_Safe_Output();
 483   1         }   
 484          
 485          /*------------------------------------------------------------------*-
 486            ---- END OF FILE -------------------------------------------------
 487          -*------------------------------------------------------------------*/
 488          

C51 COMPILER V6.10  SCC_S515                                                               04/19/2001 14:16:00 PAGE 9   


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    602    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      8       1
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       1
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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