lin_signal.c

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

C
1,024
字号

//-----------------------------------------------------------------------------
// l_flg_clr_led_slave_id_1_flag_rx ()
//-----------------------------------------------------------------------------
//
// Clears the flag led_slave_id_1_flag_rx.
//
void l_flg_clr_led_slave_id_1_flag_rx (void)
{
   led_slave_id_1_flag_rx = 0;
}

//-----------------------------------------------------------------------------
// l_flg_clr_led_slave_id_1_flag_tx ()
//-----------------------------------------------------------------------------
//
// Clears the flag led_slave_id_1_flag_tx.
//
void l_flg_clr_led_slave_id_1_flag_tx (void)
{
   led_slave_id_1_flag_tx = 0;
}

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

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

   // Write sw_slave_id_1.
   sw_slave_id_1 = v;
}

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

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

//-----------------------------------------------------------------------------
// l_flg_clr_sw_slave_id_1_flag_rx ()
//-----------------------------------------------------------------------------
//
// Clears the flag sw_slave_id_1_flag_rx.
//
void l_flg_clr_sw_slave_id_1_flag_rx (void)
{
   sw_slave_id_1_flag_rx = 0;
}

//-----------------------------------------------------------------------------
// l_flg_clr_sw_slave_id_1_flag_tx ()
//-----------------------------------------------------------------------------
//
// Clears the flag sw_slave_id_1_flag_tx.
//
void l_flg_clr_sw_slave_id_1_flag_tx (void)
{
   sw_slave_id_1_flag_tx = 0;
}

#endif

#if ((LIN_MODE == LIN_MASTER) || (LIN_SLAVE_ID == LIN_SLAVE_ID_2))
//-----------------------------------------------------------------------------
// l_bool_rd_led_slave_id_2 ()
//-----------------------------------------------------------------------------
//
// Returns the value of signal led_slave_id_2.
//
l_bool l_bool_rd_led_slave_id_2 (void)
{
   return (led_slave_id_2);
}

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

   // Write led_slave_id_2.
   led_slave_id_2 = v;
}

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

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

//-----------------------------------------------------------------------------
// l_flg_clr_led_slave_id_2_flag_rx ()
//-----------------------------------------------------------------------------
//
// Clears the flag led_slave_id_2_flag_rx.
//
void l_flg_clr_led_slave_id_2_flag_rx (void)
{
   led_slave_id_2_flag_rx = 0;
}

//-----------------------------------------------------------------------------
// l_flg_clr_led_slave_id_2_flag_tx ()
//-----------------------------------------------------------------------------
//
// Clears the flag led_slave_id_2_flag_tx.
//
void l_flg_clr_led_slave_id_2_flag_tx (void)
{
   led_slave_id_2_flag_tx = 0;
}

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

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

   // Write sw_slave_id_2.
   sw_slave_id_2 = v;
}

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

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

//-----------------------------------------------------------------------------
// l_flg_clr_sw_slave_id_2_flag_rx ()
//-----------------------------------------------------------------------------
//
// Clears the flag sw_slave_id_2_flag_rx.
//
void l_flg_clr_sw_slave_id_2_flag_rx (void)
{
   sw_slave_id_2_flag_rx = 0;
}

//-----------------------------------------------------------------------------
// l_flg_clr_sw_slave_id_2_flag_tx ()
//-----------------------------------------------------------------------------
//
// Clears the flag sw_slave_id_2_flag_tx.
//
void l_flg_clr_sw_slave_id_2_flag_tx (void)
{
   sw_slave_id_2_flag_tx = 0;
}

#endif


//-----------------------------------------------------------------------------
// Frame Processing Functions
//-----------------------------------------------------------------------------
//
// These functions process the data associated with a frame ID. This is where
//    signals are mapped to frames.
//
// The two processing functions are:
//
// 1. l_get_tx_frame_data - Returns the data to be transmitted with a
//                          particular frame.
//
// 2. l_get_sporadic_frame_id - When a sporadic frame slot is pending, this
//                              function returns the ID of the frame that
//                              will be sent in the frame slot.
//
// 3. l_tx_complete - This function is called after a frame is transmitted
//                    successfully. It performs any necessary post-transmit
//                    operations (such as setting flags related to the signals
//                    in the frame).
//
// 4. l_process_rx_frame_data - Takes data received in a frame and unloads it
//                              into signals based on the frame ID.
//

//----------------------------------------------------------------------------
// l_get_tx_frame_data ()
//-----------------------------------------------------------------------------
//
// Returns the data to be sent with a frame with the associated frame
//    identifier.
//
// Sets or clears any flags as necessary.
//
// Parameters:
//
//    1. frame_id - The identifier of the frame that will be sent.
//
//    2. frame_data - The data to send in the frame.
//
// Return value:
//
//    0 - The device should not send any data in the frame.
//
//    1 - The device will send the data in frame_data in the frame.
//
l_bool l_get_tx_frame_data (l_u8 frame_id, l_u8 * frame_data)
{
   l_bool retval = 1;

   switch (frame_id)
   {

#if (LIN_MODE == LIN_MASTER)

      case (LED_SLAVE_UNCONDITIONAL_ID):

         // Load the data to send into frame_data[0].
         // Bit 0 is led_slave_id_0.
         // Bit 1 is led_slave_id_1.
         // Bit 2 is led_slave_id_2.
         frame_data[0] = (l_u8) (((l_u8) led_slave_id_2 << 2) | ((l_u8) led_slave_id_1 << 1) | (l_u8) led_slave_id_0);
         break;

#elif (LIN_MODE == LIN_SLAVE)

      case (SW_SLAVE_EVENT_TRIGGERED_ID):

         // This is an event-triggered frame. If sw_slave_id_x has been updated
         // since the last time it was transmitted, send
         // SW_SLAVE_ID_X_UNCONDITIONAL_ID in byte 0 and the value of
         // sw_slave_id_x in bit 0 of byte 1.

#if (LIN_SLAVE_ID == LIN_SLAVE_ID_0)

         if (!sw_slave_id_0_flag_tx)
         {
            // Load the PID of the associated unconditional frame into the
            // first data byte to send.
            // NOTE: The hardware will not calculate the parity bits for this
            // frame ID because it is being loaded into LINDT0 instead of
            // LINID. Instead, the software gets the PID by calling
            // l_get_frame_pid().
            frame_data[0] = l_get_frame_pid (SW_SLAVE_ID_0_UNCONDITIONAL_ID);

            // Load sw_slave_id_0 into bit 1 of frame_data[1].
            frame_data[1] = (l_bool) sw_slave_id_0;
         }

⌨️ 快捷键说明

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