lin_diagnostic.c

来自「芯科原厂所有c8051fxx程序的例子。」· C语言 代码 · 共 125 行

C
125
字号
// Copyright (c) 2006 SILICON LABORATORIES, INC.
//
// FILE NAME   : LIN_Diagnostic.c
// TARGET MCU  : C8051F52xA-53xA
// DESCRIPTION : Routines for diagnostic frames.
//
// This file contains routines that implement diagnostic LIN functionality.
//


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


//-----------------------------------------------------------------------------
//  Global Variables
//-----------------------------------------------------------------------------
//
// 1. NAD_tx_std_ifc - The NAD of the next diagnostic frame to be sent on
//                     interface std_ifc.
//
l_u8  NAD_tx_std_ifc = GO_TO_SLEEP_COMMAND;

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

//----------------------------------------------------------------------------
// l_get_diagnostic_tx_frame_data ()
//-----------------------------------------------------------------------------
//
// When the next frame in the schedule table is a master request frame or a
//    slave response frame, this function is called to return the data payload
//    of the frame.
//
// Parameters:
//
//    1. frame_data - The data to send in the frame.
//
void l_get_diagnostic_tx_frame_data (l_u8 * frame_data)
{

#if (LIN_MODE == LIN_MASTER)

   l_u8 i;

   // If the NAD of the pending master request frame is GO_TO_SLEEP_COMMAND,
   // send the go to sleep command.
   if (NAD_tx_std_ifc == GO_TO_SLEEP_COMMAND)
   {
      frame_data[0] = GO_TO_SLEEP_COMMAND;

      for (i = 0x01; i < 0x08; i++)
      {
         frame_data[i] = 0xFF;
      }
   }

#endif

}

//----------------------------------------------------------------------------
// l_diagnostic_tx_complete ()
//-----------------------------------------------------------------------------
//
// This routine is called when a master request frame or a slave response
//    frame has been transmitted successfully.
//
// Parameters:
//
//    1. frame_data - The data to send in the frame.
//
void l_diagnostic_tx_complete (l_u8 * frame_data)
{

#if (LIN_MODE == LIN_MASTER)

   if (frame_data[0] == GO_TO_SLEEP_COMMAND)
   {
      // set the schedule to L_NULL_SCHEDULE.
      // This ensures that the command is sent only once, and that no frames
      // will be schedule on the bus while the devices are in sleep mode.
      l_sch_set_std_ifc (L_NULL_SCHEDULE, 0);

      // Set GO_TO_SLEEP in status_std_ifc to indicate the go to sleep command
      // has been sent on interface std_ifc.
      status_std_ifc |= GO_TO_SLEEP;

      // Enable LIN interrupts to handle the wake up event..
      l_sys_irq_restore (INT_ENABLE_LEVEL);
   }
#endif

}

//----------------------------------------------------------------------------
// l_process_rx_diagnostic_data ()
//-----------------------------------------------------------------------------
//
// This routine is called when a master request frame or a slave response
//    frame has been received.
//
// Parameters:
//
//    1. frame_data - The data received in the frame.
//
void l_process_rx_diagnostic_data(l_u8 * frame_data)
{

#if (LIN_MODE == LIN_SLAVE)

   if (frame_data[0] == GO_TO_SLEEP_COMMAND)
   {
      // Set GO_TO_SLEEP in status_std_ifc if go to sleep was received.
      status_std_ifc |= GO_TO_SLEEP;
   }

#endif

}

⌨️ 快捷键说明

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