📄 scu_as.lst
字号:
C51 COMPILER V6.10 SCU_AS 04/19/2001 13:53:37 PAGE 5
242 3 }
243 2
244 2 // Check tick data - send ack if necessary
245 2 // NOTE: 'START' message will only be sent after a 'time out'
246 2 if (SCU_A_SLAVE_Process_Tick_Message() == SLAVE_ID)
247 2 {
248 3 SCU_A_SLAVE_Send_Ack_Message_To_Master();
249 3
250 3 // Feed the watchdog ONLY when a *relevant* message is received
251 3 // (noise on the bus, etc, will not stop the watchdog...)
252 3 //
253 3 // START messages will NOT refresh the slave
254 3 // - Must talk to every slave at regular intervals
255 3 SCU_A_SLAVE_Watchdog_Refresh();
256 3 }
257 2
258 2 // NOTE: calculations are in *TICKS* (not milliseconds)
259 2 for (Index = 0; Index < SCH_MAX_TASKS; Index++)
260 2 {
261 3 // Check if there is a task at this location
262 3 if (SCH_tasks_G[Index].pTask)
263 3 {
264 4 if (SCH_tasks_G[Index].Delay == 0)
265 4 {
266 5 // The task is due to run
267 5 SCH_tasks_G[Index].RunMe = 1; // Set the run flag
268 5
269 5 if (SCH_tasks_G[Index].Period)
270 5 {
271 6 // Schedule periodic tasks to run again
272 6 SCH_tasks_G[Index].Delay = SCH_tasks_G[Index].Period;
273 6 }
274 5 }
275 4 else
276 4 {
277 5 // Not yet ready to run: just decrement the delay
278 5 SCH_tasks_G[Index].Delay -= 1;
279 5 }
280 4 }
281 3 }
282 2 RI = 0; // Reset the RI flag
283 2 }
284 1 else
285 1 {
286 2 // ISR call was triggered by TI flag, after last character was sent
287 2 // Must clear the TI flag
288 2 TI = 0;
289 2 }
290 1 }
291
292 /*------------------------------------------------------------------*-
293
294 SCU_A_SLAVE_Send_Ack_Message_To_Master()
295
296 Slave must send and 'Acknowledge' message to the master, after
297 tick messages are received. NOTE: Only tick messages specifically
298 addressed to this slave should be acknowledged.
299
300 The acknowledge message serves two purposes:
301 [1] It confirms to the master that this slave is alive & well.
302 [2] It provides a means of sending data to the master and - hence
303 - to other slaves.
C51 COMPILER V6.10 SCU_AS 04/19/2001 13:53:37 PAGE 6
304
305 NOTE: Direct data transfer between slaves is NOT possible.
306
307 -*------------------------------------------------------------------*/
308 void SCU_A_SLAVE_Send_Ack_Message_To_Master(void)
309 {
310 1 // Sending one byte of data at a time, depending on index value
311 1 // If Message_byte_G is 0, send first byte (the slave ID)
312 1 if (Message_byte_G == 0)
313 1 {
314 2 TI = 0;
315 2 TB8 = 1; // Set 'Command' bit
316 2 SBUF = SLAVE_ID;
317 2 }
318 1 else
319 1 {
320 2 // Message_byte_G is 1, send the data byte
321 2 TI = 0;
322 2 TB8 = 0;
323 2 SBUF = Ack_message_data_G;
324 2 }
325 1
326 1 // Data sent - return
327 1 }
328
329 /*------------------------------------------------------------------*-
330
331 SCU_A_SLAVE_Process_Tick_Message()
332
333 The ticks messages are crucial to the operation of this shared-clock
334 scheduler: the arrival of a tick message (at regular intervals)
335 invokes the 'Update' ISR, that drives the scheduler.
336
337 The tick messages themselves may contain data. These data are
338 extracted in this function.
339
340 -*------------------------------------------------------------------*/
341 tByte SCU_A_SLAVE_Process_Tick_Message(void)
342 {
343 1 tByte Data;
344 1
345 1 // Try to get data byte
346 1 if (RI == 0)
347 1 {
348 2 // No data - something is wrong
349 2
350 2 // Set the error flag bit
351 2 Network_error_pin = NETWORK_ERROR;
352 2
353 2 // Return slave ID 0
354 2 return 0x00;
355 2 }
356 1
357 1 // There *ARE* data available
358 1 Data = (tByte) SBUF;
359 1 RI = 0; // Clear RI flag
360 1
361 1 // What we do with this message depends if it a first or second byte
362 1 if (Message_byte_G == 0)
363 1 {
364 2 // This is (should be) an ID byte
365 2 Message_ID_G = Data;
C51 COMPILER V6.10 SCU_AS 04/19/2001 13:53:37 PAGE 7
366 2
367 2 if (RB8 == 0)
368 2 {
369 3 Message_ID_G = 0; // Command bit should be set
370 3 }
371 2 }
372 1 else
373 1 {
374 2 // This is (should be) a data byte
375 2 // - Command bit should not be set
376 2 if ((Message_ID_G == SLAVE_ID) && (RB8 == 0))
377 2 {
378 3 Tick_message_data_G = Data;
379 3 }
380 2 else
381 2 {
382 3 // Something is wrong - set Message_ID to 0
383 3 Message_ID_G = 0;
384 3
385 3 // Set the error flag bit
386 3 Network_error_pin = NETWORK_ERROR;
387 3 }
388 2 }
389 1
390 1 return Message_ID_G;
391 1 }
392
393
394 /*------------------------------------------------------------------*-
395
396 SCU_A_SLAVE_Watchdog_Init()
397
398 This function sets up the watchdog timer.
399
400 If the Master fails (or other error develop),
401 no tick messages will arrive, and the scheduler
402 will stop.
403
404 To detect this situation, we have a (hardware) watchdog
405 running in the slave. This watchdog - which should be set to
406 overflow at around 100ms - is used to set the system into a
407 known (safe) state. The slave will then wait (indefinitely)
408 for the problem to be resolved.
409
410 NOTE: The slave will not be generating Ack messages in these
411 circumstances. The Master (if running) will therefore be aware
412 that there is a problem.
413
414 -*------------------------------------------------------------------*/
415 void SCU_A_SLAVE_Watchdog_Init(void)
416 {
417 1 // INIT NOT REQUIRED FOR 1232 EXTERNAL WATCHDOG
418 1 // - May be required wwith different watchdog hardware
419 1 //
420 1 // Edit as required
421 1 }
422
423
424 /*------------------------------------------------------------------*-
425
426 SCU_A_SLAVE_Watchdog_Refresh()
427
C51 COMPILER V6.10 SCU_AS 04/19/2001 13:53:37 PAGE 8
428 Feed the external (1232) watchdog.
429
430 Timeout is between ~60 and 250 ms (hardware dependent)
431
432 Assumes external 1232 watchdog
433
434 -*------------------------------------------------------------------*/
435 void SCU_A_SLAVE_Watchdog_Refresh(void) reentrant
436 {
437 1 // Change the state of the watchdog pin
438 1 if (WATCHDOG_state_G == 1)
439 1 {
440 2 WATCHDOG_state_G = 0;
441 2 WATCHDOG_pin = 0;
442 2 }
443 1 else
444 1 {
445 2 WATCHDOG_state_G = 1;
446 2 WATCHDOG_pin = 1;
447 2 }
448 1 }
449
450 /*------------------------------------------------------------------*-
451
452 SCU_A_SLAVE_Enter_Safe_State()
453
454 This is the state enterted by the system when:
455 (1) The node is powered up or reset
456 (2) The Master node fails, and no working backup is available
457 (3) The network has an error
458 (4) Tick messages are delayed for any other reason
459
460 Try to ensure that the system is in a 'safe' state in these
461 circumstances.
462
463 -*------------------------------------------------------------------*/
464 void SCU_A_SLAVE_Enter_Safe_State(void)
465 {
466 1 // USER DEFINED - Edit as required
467 1 TRAFFIC_LIGHTS_Display_Safe_Output();
468 1 }
469
470 /*------------------------------------------------------------------*-
471 ---- END OF FILE -------------------------------------------------
472 -*------------------------------------------------------------------*/
473
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 412 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 3 5
IDATA SIZE = ---- ----
BIT SIZE = 2 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -