亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? scu_bs.c

?? 時間觸發嵌入式系統設計模式源碼
?? C
字號:
/*------------------------------------------------------------------*-

   SCU_Bs.c (v1.00)

  ------------------------------------------------------------------

   This is an implementation of SCU SCHEDULER (RS-485) for 8051/52.

   --- See Chapter 27 ---

   *** SLAVE / BACKUP NODE ***
   *** MASTER CHECKS FOR SLAVE ACKNOWLEDEMENTS ***
   *** Includes support for tranceiver enables ***

   *** Uses 1232 watchdog timer ***

   *** Assumes 12 MHz osc (same as Master) ***

   *** Both Master and Slave share the same tick rate (5 ms) ***
   *** - See Master code for details ***


   COPYRIGHT
   ---------

   This code is from the book:

   PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont 
   [Pearson Education, 2001; ISBN: 0-201-33138-1].

   This code is copyright (c) 2001 by Michael J. Pont.
 
   See book for copyright details and other information.

-*------------------------------------------------------------------*/

#include "Main.h"
#include "Port.h"

#include "SCU_Bs.h"
#include "TLight_B.h"

// ------ Public variable definitions ------------------------------

// Data sent from the master to this slave
tByte Tick_message_data_G;

// Data sent from this slave to the master 
// - data may be sent on, by the master, to another slave  
tByte Ack_message_data_G = '1'; 

// ------ Public variable declarations -----------------------------

// The array of tasks (see Sch51.c)
extern sTask SCH_tasks_G[SCH_MAX_TASKS];

// The error code variable (see Sch51.c)
extern tByte Error_code_G;

// ------ Private function prototypes ------------------------------

static void  SCU_B_SLAVE_Enter_Safe_State(void);

static void  SCU_B_SLAVE_Send_Ack_Message_To_Master(void);
static tByte SCU_B_SLAVE_Process_Tick_Message(void);

static void  SCU_B_SLAVE_Watchdog_Init(void);
static void  SCU_B_SLAVE_Watchdog_Refresh(void) reentrant;


// ------ Private constants ----------------------------------------

// Each slave must have a unique non-zero ID 
#define SLAVE_ID 0x31

#define NO_NETWORK_ERROR (1) 
#define NETWORK_ERROR (0)

// ------ Private variables ----------------------------------------

static bit Message_byte_G;
static bit WATCHDOG_state_G = 0;
static tByte Message_ID_G = 0;


/*------------------------------------------------------------------*-
  SCU_B_SLAVE_Init_T1()

  Scheduler initialisation function.  Prepares scheduler
  data structures and sets up timer interrupts at required rate.
  Must call this function before using the scheduler.  
 
  BAUD_RATE - The required baud rate

-*------------------------------------------------------------------*/
void SCU_B_SLAVE_Init_T1(const tWord BAUD_RATE) 
   {
   tByte i;

   // Sort out the tasks
   for (i = 0; i < SCH_MAX_TASKS; i++) 
      {
      SCH_Delete_Task(i);
      }

   // Reset the global error variable
   // - SCH_Delete_Task() will generate an error code, 
   //   (because the task array is empty)
   Error_code_G = 0;

   // Set the network error pin (reset when tick message received)
   Network_error_pin = NETWORK_ERROR;

   // Set up RS-485 tranceiver
   RS485_Rx_NOT_Enable = 0;  // Receiver is (here) constantly enabled
                             // (NOTE - negative logic!)

   RS485_Tx_Enable = 0;      // Transmitter (in slave) is enabled 
                             // only when data are to be transmitted
                             // by this slave

   // Ready for first tick message
   Message_byte_G = 1;
 
   // ------ Set the baud rate (begin) -----------------------------
   PCON &= 0x7F;   // Set SMOD bit to 0 (don't double baud rates)

   //  receiver enabled
   //  9-bit data, 1 start bit, 1 stop bit, variable baud rate (asynchronous)
   SCON = 0xD2;

   TMOD |= 0x20;   // T1 in mode 2, 8-bit auto reload

   TH1 = (256 - (tByte)((((tLong)OSC_FREQ / 100) * 3125) 
            / ((tLong) BAUD_RATE * OSC_PER_INST * 1000)));

   TL1 = TH1;  
   TR1 = 1;  // Run the timer
   TI = 1;   // Send first character (dummy)

   // ------ Set the baud rate (end) -------------------------------

   // Interrupt enabled
   // (Both receiving and SENDING a byte will generate a serial interrupt)
   // Global interrupts not yet enabled.
   ES = 1;

   // Start the watchdog
   SCU_B_SLAVE_Watchdog_Init();  
   }

/*------------------------------------------------------------------*-
  SCU_B_SLAVE_Start()

  Starts the slave scheduler, by enabling interrupts.

  NOTE: Usually called after all regular tasks are added,
  to keep the tasks synchronised.

  NOTE: ONLY THE SCHEDULER INTERRUPT SHOULD BE ENABLED!!! 

-*------------------------------------------------------------------*/
void SCU_B_SLAVE_Start(void) 
   {
   tByte Command = 0;
   tByte Message_byte;
   tByte Count = 0;
   bit Slave_started = 0;

   // Disable interrupts 
   EA = 0;

   // We can be at this point because:
   // 1. The network has just been powered up
   // 2. An error has occurred in the Master, and it is not generating ticks
   // 3. The network has been damaged and no ticks are being received by this slave
   //
   // Try to make sure the system is in a safe state...
   SCU_B_SLAVE_Enter_Safe_State();

   // NOTE: Interrupts are disabled here
   Count = 0;

   Error_code_G = ERROR_SCH_WAITING_FOR_START_COMMAND_FROM_MASTER;
   SCH_Report_Status(); // Sch not yet running - do this manually

   // Now wait (indefinitely) for appropriate signals from the master
   do {
      // Wait for tick messages (byte 1), all bits set to 0, to be received 
      do {
         SCU_B_SLAVE_Watchdog_Refresh(); // Must keep feeding the watchdog
         } while (RI == 0);  

      Message_byte = (tByte) SBUF; 
      RI = 0;

      // Must get two ID messages in a row...
      // (with command bit)
      // Ack each one
      if ((Message_byte == (tByte) SLAVE_ID) && (RB8 == 1))
         {
         Count++;

         // Received message for this slave - send ack
         // Must enable the slave RS-485 (Max489) hardware (Tx)
         RS485_Tx_Enable = 1;

         TI = 0;                                            
         TB8 = 1; // Set command bit
         SBUF = (tByte) SLAVE_ID; 

         // Wait while data are sent
         // (watchdog will trap UART failure...)
         while (TI == 0);

         // Now clear Tx enable pin
         RS485_Tx_Enable = 0;
         }
      else
         {
         Count = 0;
         }
      } while (Count < 2);

   // Start the scheduler
   EA = 1;
   }

/*------------------------------------------------------------------*-

  SCU_B_SLAVE_Update

  This is the scheduler ISR.  It is called at a rate 
  determined by the timer settings in SCU_B_SLAVE_Init().

  This Slave is triggered by USART interrupts.
 
-*------------------------------------------------------------------*/
void SCU_B_SLAVE_Update(void) interrupt INTERRUPT_UART_Rx_Tx  
   {
   tByte Index;

   if (RI == 1) // Must check this. 
      {
      // Default
      Network_error_pin = NO_NETWORK_ERROR;

      // Two-byte messages are sent (Ack) and received (Tick)
      // - it takes two sched ticks to process each message
      //
      // Keep track of the current byte
      if (Message_byte_G == 0)
         {
         Message_byte_G = 1;
         }
      else
         {
         Message_byte_G = 0;
         }

      // Check tick data - send ack if necessary
      // NOTE: 'START' message will only be sent after a 'time out'
      if (SCU_B_SLAVE_Process_Tick_Message() == SLAVE_ID)
         {
         SCU_B_SLAVE_Send_Ack_Message_To_Master();

         // Feed the watchdog ONLY when a *relevant* message is received
         // (noise on the bus, etc, will not stop the watchdog...)
         //
         // START messages will NOT refresh the slave
         // - Must talk to every slave at regular intervals 
         SCU_B_SLAVE_Watchdog_Refresh();
         }

      // NOTE: calculations are in *TICKS* (not milliseconds)
      for (Index = 0; Index < SCH_MAX_TASKS; Index++)
         {
         // Check if there is a task at this location
         if (SCH_tasks_G[Index].pTask)
            {
            if (SCH_tasks_G[Index].Delay == 0)
               {
               // The task is due to run
               SCH_tasks_G[Index].RunMe = 1;  // Set the run flag
   
               if (SCH_tasks_G[Index].Period)
                  {
                  // Schedule periodic tasks to run again
                  SCH_tasks_G[Index].Delay = SCH_tasks_G[Index].Period;
                  }
               }
            else
               {
               // Not yet ready to run: just decrement the delay 
               SCH_tasks_G[Index].Delay -= 1;
               }
            }         
         }
      RI = 0;  // Reset the RI flag   
      }
   else
      {
      // ISR call was triggered by TI flag, after last character was sent

      // RS485_Tx_Enable flag is reset here 
      RS485_Tx_Enable = 0;

      // Must clear the TI flag
      TI = 0;
      }
   }   

/*------------------------------------------------------------------*-

  SCU_B_SLAVE_Send_Ack_Message_To_Master()

  Slave must send and 'Acknowledge' message to the master, after
  tick messages are received.  NOTE: Only tick messages specifically
  addressed to this slave should be acknowledged.

  The acknowledge message serves two purposes:
  [1] It confirms to the master that this slave is alive & well.
  [2] It provides a means of sending data to the master and - hence
      - to other slaves.

  NOTE: Direct data transfer between slaves is NOT possible.

-*------------------------------------------------------------------*/
void SCU_B_SLAVE_Send_Ack_Message_To_Master(void)
   {
   // Enable the slave RS-485 hardware (Tx)
   // NOTE: This flag will be reset in the 'Update' ISR
   RS485_Tx_Enable = 1;

   // Sending one byte of data at a time, depending on index value
   // If Message_byte_G is 0, send first byte (the slave ID)
   if (Message_byte_G == 0)
      {
      TI = 0;                                            
      TB8 = 1;  // Set 'Command' bit
      SBUF = SLAVE_ID;
      }
   else
      {
      // Message_byte_G is 1, send the data byte 
      TI = 0;
      TB8 = 0;
      SBUF = Ack_message_data_G;
      }
 
   // Data sent - return    
   }

/*------------------------------------------------------------------*-

  SCU_B_SLAVE_Process_Tick_Message()

  The ticks messages are crucial to the operation of this shared-clock
  scheduler: the arrival of a tick message (at regular intervals) 
  invokes the 'Update' ISR, that drives the scheduler.

  The tick messages themselves may contain data.  These data are 
  extracted in this function. 

-*------------------------------------------------------------------*/
tByte SCU_B_SLAVE_Process_Tick_Message(void)
   {
   tByte Data;

   // Try to get data byte
   if (RI == 0)
      {
      // No data - something is wrong

      // Set the error flag bit
      Network_error_pin = NETWORK_ERROR;

      // Return slave ID 0
      return 0x00;
      } 
 
   // There *ARE* data available
   Data = (tByte) SBUF;
   RI = 0;  // Clear RI flag

   // What we do with this message depends if it a first or second byte
   if (Message_byte_G == 0)
      {
      // This is (should be) an ID byte
      Message_ID_G = Data;   

      if (RB8 == 0)
         {
         Message_ID_G = 0;  // Command bit should be set
         }
      }
   else
      {
      // This is (should be) a data byte
      // - Command bit should not be set
      if ((Message_ID_G == SLAVE_ID) && (RB8 == 0))
         {
         Tick_message_data_G = Data;
         }
      else
         {
         // Something is wrong - set Message_ID to 0
         Message_ID_G = 0; 

         // Set the error flag bit
         Network_error_pin = NETWORK_ERROR;
         }
      }

   return Message_ID_G;
   }


/*------------------------------------------------------------------*-

  SCU_B_SLAVE_Watchdog_Init()

  This function sets up the watchdog timer.

  If the Master fails (or other error develop), 
  no tick messages will arrive, and the scheduler
  will stop.  

  To detect this situation, we have a (hardware) watchdog
  running in the slave.  This watchdog - which should be set to
  overflow at around 100ms - is used to set the system into a
  known (safe) state.  The slave will then wait (indefinitely)
  for the problem to be resolved.

  NOTE: The slave will not be generating Ack messages in these 
  circumstances.  The Master (if running) will therefore be aware
  that there is a problem.  

-*------------------------------------------------------------------*/
void SCU_B_SLAVE_Watchdog_Init(void)   
   {
   // INIT NOT REQUIRED FOR 1232 EXTERNAL WATCHDOG
   // - May be required wwith different watchdog hardware
   //
   // Edit as required
   }


/*------------------------------------------------------------------*-

  SCU_B_SLAVE_Watchdog_Refresh()

  Feed the external (1232) watchdog.

  Timeout is between ~60 and 250 ms (hardware dependent)

  Assumes external 1232 watchdog

-*------------------------------------------------------------------*/
void SCU_B_SLAVE_Watchdog_Refresh(void) reentrant
   {
   // Change the state of the watchdog pin
   if (WATCHDOG_state_G == 1)
      {
      WATCHDOG_state_G = 0;
      WATCHDOG_pin = 0;
      }
   else
      {
      WATCHDOG_state_G = 1;
      WATCHDOG_pin = 1;
      } 
   }    

/*------------------------------------------------------------------*-

  SCU_B_SLAVE_Enter_Safe_State()

  This is the state enterted by the system when:
  (1) The node is powered up or reset
  (2) The Master node fails, and no working backup is available
  (3) The network has an error
  (4) Tick messages are delayed for any other reason

  Try to ensure that the system is in a 'safe' state in these 
  circumstances.

-*------------------------------------------------------------------*/
void SCU_B_SLAVE_Enter_Safe_State(void)
   {
   // USER DEFINED - Edit as required
   TRAFFIC_LIGHTS_Display_Safe_Output();
   }  

/*------------------------------------------------------------------*-
  ---- END OF FILE -------------------------------------------------
-*------------------------------------------------------------------*/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成年人午夜久久久| 北条麻妃国产九九精品视频| 亚洲第四色夜色| 久久国产精品露脸对白| 国产成人av电影在线播放| 91丨九色丨尤物| 精品视频一区二区三区免费| 日韩欧美123| 久久久国产精品午夜一区ai换脸| 亚洲视频每日更新| 国内精品伊人久久久久av影院| 国产91在线观看丝袜| 欧美日韩国产大片| 亚洲欧洲精品一区二区三区不卡| 日本亚洲免费观看| 在线国产电影不卡| 中文字幕一区av| 国产精品影视天天线| 91精品国产一区二区三区 | 国产精品天美传媒| 亚洲成国产人片在线观看| 国产福利一区在线| 制服丝袜中文字幕一区| 亚洲伦理在线免费看| 国产成人亚洲综合a∨猫咪| 69久久99精品久久久久婷婷 | 色综合久久久久久久| 久久久久久亚洲综合影院红桃| 日韩精品一级中文字幕精品视频免费观看 | 亚洲一区二区三区四区五区黄 | 中文字幕中文字幕在线一区 | 奇米影视一区二区三区小说| 在线观看国产精品网站| 亚洲一区二区视频在线| 91黄色小视频| 成人深夜福利app| 久久久久久免费网| 成人一区二区三区在线观看| 国产精品久久久久影院老司| 成人国产精品免费网站| 亚洲视频网在线直播| 色婷婷av一区二区三区gif| 一区二区三区精品视频在线| 欧美片网站yy| 国产在线观看免费一区| 国产精品色眯眯| 欧美色欧美亚洲另类二区| 午夜av一区二区| 久久久久久久久一| 一本色道久久综合亚洲91| 午夜精品123| 日本一区二区三区在线观看| 欧美在线视频日韩| 国产精品911| 青青草一区二区三区| 久久久精品免费免费| 欧美视频一区在线| 欧美四级电影网| 成人av网址在线观看| 极品少妇一区二区| 亚洲欧美另类久久久精品| 欧美成人福利视频| 欧美另类一区二区三区| 成人午夜av电影| 黑人精品欧美一区二区蜜桃| 久久成人久久爱| 中文字幕视频一区二区三区久| 欧美男女性生活在线直播观看| av资源站一区| 成人av网在线| 成人激情图片网| 国产成人av资源| 狠狠色综合播放一区二区| 久久精品国产亚洲aⅴ| 蜜桃av噜噜一区| 日本视频在线一区| 琪琪久久久久日韩精品| 亚洲国产精品天堂| 五月激情六月综合| 免费欧美在线视频| 欧美bbbbb| 激情六月婷婷久久| 国产激情一区二区三区| 国产成人亚洲综合a∨婷婷图片| 激情五月婷婷综合| 狠狠色丁香婷婷综合久久片| 国产精品香蕉一区二区三区| 国产电影一区二区三区| 91在线观看成人| 欧美日韩日本视频| 欧美大片一区二区| 国产精品美女久久久久av爽李琼| 中文字幕中文字幕一区| 亚洲成人先锋电影| 精品午夜久久福利影院| 色就色 综合激情| 日韩美女主播在线视频一区二区三区| 久久综合狠狠综合久久激情 | 日本韩国欧美在线| 欧美一级日韩一级| 亚洲日本在线看| 国内精品免费**视频| 色综合婷婷久久| 亚洲精品一区二区在线观看| 国产色产综合产在线视频| 亚洲免费视频成人| 国产精品亚洲一区二区三区在线| 91美女片黄在线观看91美女| 精品国产一二三| 亚洲福利一区二区三区| 丁香五精品蜜臀久久久久99网站 | 中文字幕亚洲欧美在线不卡| 另类人妖一区二区av| 欧美三级三级三级爽爽爽| 亚洲视频免费观看| 成人成人成人在线视频| 国产日韩欧美精品一区| 国产精品白丝jk黑袜喷水| 欧美日韩成人高清| 亚洲另类在线一区| av在线综合网| 亚洲麻豆国产自偷在线| 92精品国产成人观看免费 | 国产白丝精品91爽爽久久 | 午夜伊人狠狠久久| 色综合久久综合网97色综合| 亚洲欧美自拍偷拍色图| 99精品久久99久久久久| 亚洲一区二区三区四区不卡| 欧美日韩一本到| 久久成人久久鬼色| 国产精品国产三级国产aⅴ无密码| 成人精品国产一区二区4080| 国产精品毛片大码女人| 91精彩视频在线观看| 热久久免费视频| 久久综合网色—综合色88| 成人免费视频视频| 亚洲一区二区三区四区在线免费观看 | 日韩电影在线一区| 精品国产成人在线影院| 成人av资源在线观看| 一区二区三区精品久久久| 欧美一区二区国产| 91麻豆蜜桃一区二区三区| 视频一区二区三区入口| www成人在线观看| 99久久精品国产毛片| 日韩电影免费一区| 一色桃子久久精品亚洲| 日韩一区二区电影| 一本色道久久综合精品竹菊| 国产老妇另类xxxxx| 午夜视频在线观看一区二区 | av一区二区久久| 看片网站欧美日韩| 无码av中文一区二区三区桃花岛| 国产精品久久二区二区| 日韩欧美中文字幕制服| 欧美丝袜丝交足nylons| av电影一区二区| 国产成人综合精品三级| 日本中文在线一区| 亚洲3atv精品一区二区三区| 亚洲综合免费观看高清完整版在线| 久久久久国产成人精品亚洲午夜| 日韩欧美一二区| 日韩三级电影网址| 欧美变态凌虐bdsm| 精品国产1区2区3区| 久久久欧美精品sm网站| 精品国产凹凸成av人网站| 久久久久久综合| 国产精品无码永久免费888| 国产精品你懂的在线欣赏| 日本一二三四高清不卡| 综合在线观看色| 亚洲自拍另类综合| 日韩高清不卡一区二区三区| 黄色资源网久久资源365| 国产河南妇女毛片精品久久久| www.亚洲免费av| 色88888久久久久久影院按摩| 在线观看av一区| 久久久久久电影| 一区二区视频在线看| 日精品一区二区| 国产成人av自拍| 欧美日韩久久不卡| 国产视频一区二区在线| 一区二区三区在线视频免费观看 | 日韩午夜三级在线| 1000部国产精品成人观看| 午夜久久久久久久久久一区二区| 日本aⅴ精品一区二区三区| 成人动漫av在线| 久久一区二区视频| 视频一区欧美日韩| 色诱视频网站一区| 欧美高清在线一区|