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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? scu_as.c

?? 時(shí)間觸發(fā)嵌入式系統(tǒng)設(shè)計(jì)模式源碼
?? C
字號(hào):
/*------------------------------------------------------------------*-

   SCU_As.c (v1.00)

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

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

   --- See Chapter 27 ---

   *** MASTER NODE ***
   *** CHECKS FOR SLAVE ACKNOWLEDEMENTS ***
   *** Local / RS-232 version (no 'enable' support) ***

   *** 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_As.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_A_SLAVE_Enter_Safe_State(void);

static void  SCU_A_SLAVE_Send_Ack_Message_To_Master(void);
static tByte SCU_A_SLAVE_Process_Tick_Message(void);

static void  SCU_A_SLAVE_Watchdog_Init(void);
static void  SCU_A_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_A_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_A_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;

   // 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_A_SLAVE_Watchdog_Init();  
   }

/*------------------------------------------------------------------*-
  SCU_A_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_A_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_A_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_A_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
         TI = 0;                                            
         TB8 = 1; // Set command bit
         SBUF = (tByte) SLAVE_ID; 
         }
      else
         {
         Count = 0;
         }
      } while (Count < 2);

   // Start the scheduler
   EA = 1;
   }

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

  SCU_A_SLAVE_Update

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

  This Slave is triggered by USART interrupts.
 
-*------------------------------------------------------------------*/
void SCU_A_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_A_SLAVE_Process_Tick_Message() == SLAVE_ID)
         {
         SCU_A_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_A_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
      // Must clear the TI flag
      TI = 0;
      }
   }   

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

  SCU_A_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_A_SLAVE_Send_Ack_Message_To_Master(void)
   {
   // 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_A_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_A_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_A_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_A_SLAVE_Watchdog_Init(void)   
   {
   // INIT NOT REQUIRED FOR 1232 EXTERNAL WATCHDOG
   // - May be required wwith different watchdog hardware
   //
   // Edit as required
   }


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

  SCU_A_SLAVE_Watchdog_Refresh()

  Feed the external (1232) watchdog.

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

  Assumes external 1232 watchdog

-*------------------------------------------------------------------*/
void SCU_A_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_A_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_A_SLAVE_Enter_Safe_State(void)
   {
   // USER DEFINED - Edit as required
   TRAFFIC_LIGHTS_Display_Safe_Output();
   }  

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

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲成av人片观看| 亚洲日本乱码在线观看| 99re热视频精品| 日本亚洲一区二区| 亚洲日本va午夜在线电影| 日韩美女主播在线视频一区二区三区| 成人免费电影视频| 日本欧美一区二区三区乱码 | 3d动漫精品啪啪一区二区竹菊| 国产福利不卡视频| 免费精品视频在线| 亚洲在线观看免费视频| 国产免费成人在线视频| 91麻豆精品国产91久久久久| 91社区在线播放| 国产精品18久久久久| 日本sm残虐另类| 亚洲成人免费视| 一区二区三区四区在线免费观看| 久久精品欧美日韩精品 | 日韩一区在线看| 欧美不卡一二三| 91麻豆精品国产自产在线观看一区 | 欧美日韩1234| 91麻豆免费看| 成人小视频免费在线观看| 国产一区二区在线观看视频| 免费在线观看视频一区| 亚洲成人激情av| 亚洲成人一二三| 一区二区三区不卡在线观看| 日韩一区在线看| 亚洲欧洲日产国码二区| 国产精品麻豆久久久| 国产亚洲一本大道中文在线| 久久综合九色综合97_久久久| 日韩一区二区在线免费观看| 欧美一级二级三级蜜桃| 7777女厕盗摄久久久| 欧美乱熟臀69xxxxxx| 欧美视频在线观看一区二区| 91蜜桃在线观看| 91福利在线导航| 欧美在线一区二区| 欧美视频第二页| 欧美二区乱c少妇| 欧美一级免费观看| 91精品福利在线一区二区三区| 色成人在线视频| 欧美伊人久久久久久久久影院| 色老综合老女人久久久| 欧美亚洲综合色| 欧美久久一二区| 欧美一区二区三区视频| 欧美videofree性高清杂交| 日韩一区二区在线观看视频播放| 日韩欧美一区二区免费| 国产肉丝袜一区二区| 国产精品久久久久久久久晋中| 亚洲天堂中文字幕| 天堂蜜桃91精品| 久久99精品久久久久久| 成人禁用看黄a在线| 91传媒视频在线播放| 欧美一级一区二区| 久久日一线二线三线suv| 国产欧美精品一区二区三区四区| 亚洲欧洲综合另类| 日韩高清不卡一区二区三区| 国产精品一区二区在线观看网站| 97超碰欧美中文字幕| 欧美日韩你懂的| 精品精品国产高清一毛片一天堂| 国产色综合久久| 亚洲免费电影在线| 青青草国产精品97视觉盛宴 | 欧美日韩一区国产| 久久无码av三级| 一区二区在线免费| 国内欧美视频一区二区| 在线免费视频一区二区| 精品国产露脸精彩对白| 亚洲激情五月婷婷| 韩国中文字幕2020精品| 色婷婷精品大视频在线蜜桃视频| 日韩一级黄色片| 国产精品亚洲第一区在线暖暖韩国| 青青草原综合久久大伊人精品优势| 91精品午夜视频| 国产午夜精品在线观看| 亚洲成人先锋电影| 成人av网址在线| 91精品国产综合久久香蕉的特点| 国产欧美精品一区二区色综合朱莉| 亚洲va在线va天堂| 成人毛片视频在线观看| 日韩一二三四区| 亚洲精品精品亚洲| 国产一区二三区好的| 777亚洲妇女| 亚洲最大成人网4388xx| 国产激情一区二区三区四区| 91精品婷婷国产综合久久竹菊| 综合电影一区二区三区 | 国产毛片精品视频| 欧美日韩一二区| 亚洲乱码国产乱码精品精98午夜| 黑人巨大精品欧美一区| 91精品国产全国免费观看| 中文字幕在线视频一区| 久久电影网站中文字幕| 欧美丰满少妇xxxxx高潮对白| 中文字幕日韩精品一区| 国产一区91精品张津瑜| 欧美成人艳星乳罩| 视频一区中文字幕国产| 欧美在线高清视频| 亚洲天堂福利av| 成人福利电影精品一区二区在线观看 | 人妖欧美一区二区| 欧美日韩电影一区| 一区二区三区视频在线看| jlzzjlzz国产精品久久| 欧美极品美女视频| 91.麻豆视频| 亚洲图片有声小说| 欧美视频一区二区三区在线观看 | 欧美一级欧美三级| 丝袜美腿亚洲色图| 欧美精品亚洲一区二区在线播放| 亚洲自拍另类综合| 色狠狠av一区二区三区| 亚洲激情综合网| 欧美伊人久久大香线蕉综合69| 亚洲精品自拍动漫在线| 91黄色在线观看| 一区二区欧美视频| 欧美日韩中文另类| 亚洲成人黄色小说| 欧美精品日日鲁夜夜添| 奇米色一区二区| 日韩欧美综合在线| 久久99国产精品麻豆| 久久这里都是精品| 懂色av一区二区在线播放| 国产精品短视频| 欧美最新大片在线看| 偷拍一区二区三区四区| 91精品国产综合久久精品图片 | 日韩一区在线播放| 91免费版在线看| 亚洲国产综合色| 欧美一级日韩免费不卡| 久色婷婷小香蕉久久| 久久久久久免费毛片精品| 国产精品456露脸| 中文字幕五月欧美| 在线视频亚洲一区| 日本不卡高清视频| 久久久国产精品麻豆| 成人免费视频caoporn| 亚洲精品高清视频在线观看| 欧美日韩国产一级| 国产一区二区三区在线观看免费| 国产欧美日韩综合精品一区二区| 波多野结衣中文字幕一区| 亚洲一区成人在线| 日韩一二在线观看| av不卡在线播放| 婷婷中文字幕一区三区| 精品日韩一区二区三区免费视频| 成人一区在线看| 亚洲国产视频直播| 精品国产三级电影在线观看| av中文字幕亚洲| 丝袜亚洲另类丝袜在线| 国产欧美日韩视频一区二区| 精品视频色一区| 国产福利不卡视频| 亚洲高清三级视频| 国产天堂亚洲国产碰碰| 在线观看精品一区| 国产成人午夜高潮毛片| 亚洲国产精品嫩草影院| 久久久99免费| 欧美日本一区二区| 成人综合日日夜夜| 蜜臀av亚洲一区中文字幕| 国产精品久线在线观看| 欧美一区二区三区四区在线观看| 成人夜色视频网站在线观看| 全国精品久久少妇| 亚洲免费电影在线| 国产拍欧美日韩视频二区| 91精品国产欧美一区二区18| 97超碰欧美中文字幕| 国产精品99久久久久久久vr| 偷拍一区二区三区四区| 一区二区三区欧美日| 欧美国产一区在线|