lin_signal.c

来自「芯科原厂所有c8051fxx程序的例子。」· C语言 代码 · 共 1,024 行 · 第 1/3 页

C
1,024
字号
// Copyright (c) 2006 SILICON LABORATORIES, INC.
//
// FILE NAME   : LIN_Signal.c
// TARGET MCU  : C8051F52xA-53xA
// DESCRIPTION : Routines to access signals and flags in the Core LIN API.
//
// This file contains the signals and flags specific to the application, as
//    well as the routines to access them.
//


//-----------------------------------------------------------------------------
// Header Files
//-----------------------------------------------------------------------------
//
#include <c8051F520.h>
#include "LIN.h"


//-----------------------------------------------------------------------------
//  Signal Definitions
//-----------------------------------------------------------------------------
//
// These variables are the signals transmitted in LIN frames:
//
//    1. sw_slave_id_0  -   When 1, the switch connected to LIN_SLAVE_ID_0 has
//                          been pressed.
//
//    2. led_slave_id_0 -   The state (ON or OFF) of the LED controlled by
//                          LIN_SLAVE_ID_0.
//
//    3. sw_slave_id_1  -   When 1, the switch connected to LIN_SLAVE_ID_1 has
//                          been pressed.
//
//    4. led_slave_id_1 -   The state (ON or OFF) of the LED controlled by
//                          LIN_SLAVE_ID_1.
//
//    5. sw_slave_id_2  -   When 1, the switch connected to LIN_SLAVE_ID_2 has
//                          been pressed.
//
//    6. led_slave_id_2 -   The state (ON or OFF) of the LED controlled by
//                          LIN_SLAVE_ID_2.
//
#if ((LIN_MODE == LIN_MASTER) || (LIN_SLAVE_ID == LIN_SLAVE_ID_0))
l_bool   sw_slave_id_0 = 0;
l_bool   led_slave_id_0 = 0;
#endif

#if ((LIN_MODE == LIN_MASTER) || (LIN_SLAVE_ID == LIN_SLAVE_ID_1))
l_bool   sw_slave_id_1 = 0;
l_bool   led_slave_id_1 = 0;
#endif

#if ((LIN_MODE == LIN_MASTER) || (LIN_SLAVE_ID == LIN_SLAVE_ID_2))
l_bool   sw_slave_id_2 = 0;
l_bool   led_slave_id_2 = 0;
#endif

//-----------------------------------------------------------------------------
//  Flag Definitions
//-----------------------------------------------------------------------------
//
// These flags are set when the corresponding signals are recieved and
//    transmitted.
//
//    1. sw_slave_id_0_flag_rx  - This flag indicates that signal
//                                sw_slave_id_0 has been received.
//
//    2. sw_slave_id_0_flag_tx  - This flag indicates that signal
//                                sw_slave_id_0 has been transmitted.
//
//    3. led_slave_id_0_flag_rx - This flag indicates that signal
//                                led_slave_id_0 has been received.
//
//    4. led_slave_id_0_flag_tx - This flag indicates that signal
//                                led_slave_id_0 has been transmitted.
//
//    5. sw_slave_id_1_flag_rx  - This flag indicates that signal
//                                sw_slave_id_1 has been received.
//
//    6. sw_slave_id_1_flag_tx  - This flag indicates that signal
//                                sw_slave_id_1 has been transmitted.
//
//    7. led_slave_id_1_flag_rx - This flag indicates that signal
//                                led_slave_id_1 has been received.
//
//    8. led_slave_id_1_flag_tx - This flag indicates that signal
//                                led_slave_id_1 has been transmitted.
//
//    9. sw_slave_id_2_flag_rx  - This flag indicates that signal
//                                sw_slave_id_2 has been received.
//
//    10. sw_slave_id_2_flag_tx  - This flag indicates that signal
//                                 sw_slave_id_2 has been transmitted.
//
//    11. led_slave_id_2_flag_rx - This flag indicates that signal
//                                 led_slave_id_2 has been received.
//
//    12. led_slave_id_3_flag_tx - This flag indicates that signal
//                                 led_slave_id_2 has been transmitted.
//
#if ((LIN_MODE == LIN_MASTER) || (LIN_SLAVE_ID == LIN_SLAVE_ID_0))
l_bool   sw_slave_id_0_flag_rx = 0;
l_bool   sw_slave_id_0_flag_tx = 0;
l_bool   led_slave_id_0_flag_rx = 0;
l_bool   led_slave_id_0_flag_tx = 0;
#endif

#if ((LIN_MODE == LIN_MASTER) || (LIN_SLAVE_ID == LIN_SLAVE_ID_1))
l_bool   sw_slave_id_1_flag_rx = 0;
l_bool   sw_slave_id_1_flag_tx = 0;
l_bool   led_slave_id_1_flag_rx = 0;
l_bool   led_slave_id_1_flag_tx = 0;
#endif

#if ((LIN_MODE == LIN_MASTER) || (LIN_SLAVE_ID == LIN_SLAVE_ID_2))
l_bool   sw_slave_id_2_flag_rx = 0;
l_bool   sw_slave_id_2_flag_tx = 0;
l_bool   led_slave_id_2_flag_rx = 0;
l_bool   led_slave_id_2_flag_tx = 0;
#endif

//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Signal Functions
//-----------------------------------------------------------------------------
//
// There should be functions to read and write the values of each signal.
//
// Additionally, there should be functions to read and clear all associated
//    flags.
//

#if ((LIN_MODE == LIN_MASTER) || (LIN_SLAVE_ID == LIN_SLAVE_ID_0))
//-----------------------------------------------------------------------------
// l_bool_rd_led_slave_id_0 ()
//-----------------------------------------------------------------------------
//
// Returns the value of signal led_slave_id_0.
//
l_bool l_bool_rd_led_slave_id_0 (void)
{
   return (led_slave_id_0);
}

//-----------------------------------------------------------------------------
// l_bool_wr_led_slave_id_0 ()
//-----------------------------------------------------------------------------
//
// Sets the value of signal led_slave_id_0.
//
// Parameters:
//    1. v - The value to write to signal led_slave_id_0.
//
void l_bool_wr_led_slave_id_0 (l_bool v)
{
   // If the current value of led_slave_id_0 is different from the value to
   // write, it is being updated, so clear led_slave_id_0_flag_tx.
   if (led_slave_id_0 != v)
      led_slave_id_0_flag_tx = 0;

   // Write led_slave_id_0.
   led_slave_id_0 = v;
}

//-----------------------------------------------------------------------------
// l_flg_tst_led_slave_id_0_flag_rx ()
//-----------------------------------------------------------------------------
//
// Returns the value of flag led_slave_id_0_flag_rx.
//
l_bool l_flg_tst_led_slave_id_0_flag_rx (void)
{
   return (led_slave_id_0_flag_rx);
}

//-----------------------------------------------------------------------------
// l_flg_tst_led_slave_id_0_flag_tx ()
//-----------------------------------------------------------------------------
//
// Returns the value of flag led_slave_id_0_flag_tx.
//
l_bool l_flg_tst_led_slave_id_0_flag_tx (void)
{
   return (led_slave_id_0_flag_tx);
}

//-----------------------------------------------------------------------------
// l_flg_clr_led_slave_id_0_flag_rx ()
//-----------------------------------------------------------------------------
//
// Clears the flag led_slave_id_0_flag_rx.
//
void l_flg_clr_led_slave_id_0_flag_rx (void)
{
   led_slave_id_0_flag_rx = 0;
}

//-----------------------------------------------------------------------------
// l_flg_clr_led_slave_id_0_flag_tx ()
//-----------------------------------------------------------------------------
//
// Clears the flag led_slave_id_0_flag_tx.
//
void l_flg_clr_led_slave_id_0_flag_tx (void)
{
   led_slave_id_0_flag_tx = 0;
}

//-----------------------------------------------------------------------------
// l_bool_rd_sw_slave_id_0 ()
//-----------------------------------------------------------------------------
//
// Returns the value of signal sw_slave_id_0.
//
l_bool l_bool_rd_sw_slave_id_0 (void)
{
   return (sw_slave_id_0);
}

//-----------------------------------------------------------------------------
// l_bool_wr_sw_slave_id_0 ()
//-----------------------------------------------------------------------------
//
// Sets the value of signal sw_slave_id_0.
//
// Parameters:
//    1. v - The value to write to signal sw_slave_id_0.
//
void l_bool_wr_sw_slave_id_0 (l_bool v)
{
   // If the current value of sw_slave_id_0 is different from the value to
   // write, it is being updated, so clear sw_slave_id_0_flag_tx.
   if (sw_slave_id_0 != v)
      sw_slave_id_0_flag_tx = 0;

   // Write sw_slave_id_0.
   sw_slave_id_0 = v;
}

//-----------------------------------------------------------------------------
// l_flg_tst_sw_slave_id_0_flag_rx ()
//-----------------------------------------------------------------------------
//
// Returns the value of flag sw_slave_id_0_flag_rx.
//
l_bool l_flg_tst_sw_slave_id_0_flag_rx (void)
{
   return (sw_slave_id_0_flag_rx);
}

//-----------------------------------------------------------------------------
// l_flg_tst_sw_slave_id_0_flag_tx ()
//-----------------------------------------------------------------------------
//
// Returns the value of flag sw_slave_id_0_flag_tx.
//
l_bool l_flg_tst_sw_slave_id_0_flag_tx (void)
{
   return (sw_slave_id_0_flag_tx);
}

//-----------------------------------------------------------------------------
// l_flg_clr_sw_slave_id_0_flag_rx ()
//-----------------------------------------------------------------------------
//
// Clears the flag sw_slave_id_0_flag_rx.
//
void l_flg_clr_sw_slave_id_0_flag_rx (void)
{
   sw_slave_id_0_flag_rx = 0;
}

//-----------------------------------------------------------------------------
// l_flg_clr_sw_slave_id_0_flag_tx ()
//-----------------------------------------------------------------------------
//
// Clears the flag sw_slave_id_0_flag_tx.
//
void l_flg_clr_sw_slave_id_0_flag_tx (void)
{
   sw_slave_id_0_flag_tx = 0;
}

#endif

#if ((LIN_MODE == LIN_MASTER) || (LIN_SLAVE_ID == LIN_SLAVE_ID_1))
//-----------------------------------------------------------------------------
// l_bool_rd_led_slave_id_1 ()
//-----------------------------------------------------------------------------
//
// Returns the value of signal led_slave_id_1.
//
l_bool l_bool_rd_led_slave_id_1 (void)
{
   return (led_slave_id_1);
}

//-----------------------------------------------------------------------------
// l_bool_wr_led_slave_id_1 ()
//-----------------------------------------------------------------------------
//
// Sets the value of signal led_slave_id_1.
//
// Parameters:
//    1. v - The value to write to signal led_slave_id_1.
//
void l_bool_wr_led_slave_id_1 (l_bool v)
{
   // If the current value of led_slave_id_1 is different from the value to
   // write, it is being updated, so clear led_slave_id_1_flag_tx.
   if (led_slave_id_1 != v)
      led_slave_id_1_flag_tx = 0;

   // Write led_slave_id_1.
   led_slave_id_1 = v;
}

//-----------------------------------------------------------------------------
// l_flg_tst_led_slave_id_1_flag_rx ()
//-----------------------------------------------------------------------------
//
// Returns the value of flag led_slave_id_1_flag_rx.
//
l_bool l_flg_tst_led_slave_id_1_flag_rx (void)
{
   return (led_slave_id_1_flag_rx);
}

//-----------------------------------------------------------------------------
// l_flg_tst_led_slave_id_1_flag_tx ()
//-----------------------------------------------------------------------------
//
// Returns the value of flag led_slave_id_1_flag_tx.
//
l_bool l_flg_tst_led_slave_id_1_flag_tx (void)
{
   return (led_slave_id_1_flag_tx);
}

⌨️ 快捷键说明

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