亚洲欧美第一页_禁久久精品乱码_粉嫩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 = '2'; 

// ------ 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 0x32

#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一区二区三区免费野_久草精品视频
一区二区三区国产精华| 国产精品的网站| 亚洲成人精品一区| 久久久久国产成人精品亚洲午夜| 99久久精品费精品国产一区二区| 青青草视频一区| 最新国产成人在线观看| 精品国产一二三区| 欧美中文字幕亚洲一区二区va在线 | 精品一区二区三区免费视频| 五月婷婷欧美视频| 丝袜美腿一区二区三区| 性做久久久久久| 亚洲成av人片一区二区梦乃| 亚洲大型综合色站| 日韩中文字幕1| 美女视频第一区二区三区免费观看网站 | 亚洲午夜久久久久久久久电影院 | 亚洲午夜私人影院| 日韩黄色免费网站| 国产一区高清在线| 9人人澡人人爽人人精品| 色乱码一区二区三区88| 欧美老肥妇做.爰bbww视频| 日韩欧美一级二级三级久久久| 精品三级av在线| 久久久久9999亚洲精品| 中文字幕一区三区| 亚洲午夜激情网页| 五月婷婷综合激情| 成人中文字幕电影| 日本成人在线电影网| 亚洲老妇xxxxxx| 91麻豆文化传媒在线观看| 国产伦精品一区二区三区免费| 本田岬高潮一区二区三区| 91小视频在线免费看| 欧美手机在线视频| 欧美一级二级在线观看| 中文字幕成人网| 国产一区二区三区四区五区入口| 91精品欧美福利在线观看| 久久久精品中文字幕麻豆发布| 欧美精品一区二区三区久久久| 久久久久久久久久久久久女国产乱 | 香蕉成人伊视频在线观看| 日本欧美在线观看| 成人高清免费观看| 日韩视频一区二区三区在线播放| 国产欧美精品一区aⅴ影院| 亚洲一二三区在线观看| 国产毛片一区二区| 欧美人动与zoxxxx乱| 午夜精品久久久久久久蜜桃app| 欧美日韩免费一区二区三区视频| 久久精品欧美一区二区三区麻豆| 亚洲国产日韩精品| 99re这里只有精品视频首页| 成人精品视频.| 欧美日韩在线综合| 欧美精品一区二区久久婷婷| 国产精品久久久99| 日韩精品乱码av一区二区| 国产激情一区二区三区四区| 91福利精品视频| 久久女同精品一区二区| 亚洲综合色自拍一区| 欧美成人性福生活免费看| 99热精品一区二区| 2021国产精品久久精品| 亚洲精品视频免费看| 日韩电影在线一区二区| 99视频超级精品| 日韩视频一区二区三区 | 色综合久久综合网| 91精品在线一区二区| 亚洲美女淫视频| 狠狠色综合播放一区二区| 99久久久国产精品免费蜜臀| 欧美成人三级在线| 亚洲图片欧美综合| 成人av动漫在线| 久久影视一区二区| 91在线观看下载| 日韩免费观看高清完整版 | 欧美一区日韩一区| 91黄色免费观看| 美腿丝袜亚洲一区| 99久久亚洲一区二区三区青草| 精品国产一区二区三区久久影院| 一区二区三区高清在线| jizz一区二区| 国产农村妇女毛片精品久久麻豆| 久久99精品久久久久婷婷| 欧美剧在线免费观看网站 | 国产一区二三区| 欧美大白屁股肥臀xxxxxx| 日韩精品视频网站| 欧美日韩国产另类不卡| 亚洲综合一区二区| 97se亚洲国产综合自在线| 国产精品免费视频一区| 91精品婷婷国产综合久久竹菊| 欧美精品久久99| 久久久无码精品亚洲日韩按摩| 男人的天堂亚洲一区| 欧美嫩在线观看| 天涯成人国产亚洲精品一区av| 在线免费亚洲电影| 伊人色综合久久天天人手人婷| 国产欧美在线观看一区| 日韩欧美一区电影| 成人app网站| 久久综合久久综合九色| 国产在线一区观看| 国产偷国产偷精品高清尤物| 国产东北露脸精品视频| 中文字幕免费一区| 99视频在线观看一区三区| 亚洲人成网站影音先锋播放| aa级大片欧美| 亚洲午夜在线视频| 欧美性感一类影片在线播放| 五月婷婷激情综合| 欧美电影影音先锋| 激情欧美日韩一区二区| 久久久久国产精品厨房| 9色porny自拍视频一区二区| 玉米视频成人免费看| 欧美日韩国产成人在线免费| 久久国产麻豆精品| 国产欧美日韩另类一区| 97se亚洲国产综合自在线观| 亚洲成人免费影院| 精品国产乱码久久久久久牛牛| 国产成人精品1024| 亚洲免费在线播放| 911精品国产一区二区在线| 韩国精品久久久| 中文字幕在线不卡| 欧美亚洲综合网| 精品夜夜嗨av一区二区三区| 中文字幕一区二区三| 欧美三级电影网站| 国产一二精品视频| 136国产福利精品导航| 欧美日韩在线三区| 国产精品一区二区久激情瑜伽| 亚洲欧美经典视频| 欧美成人精精品一区二区频| 成年人网站91| 日本午夜一本久久久综合| 国产片一区二区| 欧美日韩三级一区| 国产91露脸合集magnet| 亚洲动漫第一页| 国产女人aaa级久久久级| 欧美性videosxxxxx| 国产精品综合二区| 亚洲成av人片在线| 国产精品国产三级国产普通话三级 | 亚洲欧美激情在线| 久久色.com| 欧美日韩国产美女| 99v久久综合狠狠综合久久| 日本成人中文字幕| 一区二区三区视频在线看| 欧美videos中文字幕| 91福利国产精品| 成人福利视频网站| 青娱乐精品视频| 亚洲免费av在线| 国产目拍亚洲精品99久久精品| 91.麻豆视频| 欧美性色aⅴ视频一区日韩精品| 国产精品小仙女| 蓝色福利精品导航| 亚洲成人免费视频| 亚洲人成影院在线观看| 国产色综合一区| 欧美一区三区四区| 欧美日韩一区二区在线观看 | 欧美v国产在线一区二区三区| 欧洲精品中文字幕| 成人性生交大片免费看视频在线| 奇米精品一区二区三区四区| 亚洲一区二区成人在线观看| 国产精品日产欧美久久久久| 精品第一国产综合精品aⅴ| 在线成人小视频| 在线亚洲一区观看| 91在线看国产| av网站一区二区三区| 国产成人自拍高清视频在线免费播放| 日本不卡一区二区| 婷婷久久综合九色综合绿巨人 | 色综合久久久久综合| 波多野结衣中文一区| 福利视频网站一区二区三区| 精品一区二区三区蜜桃|