f53x_linsnooper_lin.h

来自「8051试验程序 基础教材」· C头文件 代码 · 共 405 行 · 第 1/2 页

H
405
字号
// definition:     Select the low 8 bits of the divider used in baud-rate
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_PointDiv() LINADDR=LINDIV      // Select LIN div address

//-----------------------------------------------------------------------------
// MACRO:          mLIN_PointMul
// Parameters:     NONE
// definition:     Select the multiplier register of the LIN interface
// Obs:            Prescaler[7:6], Multiplier[5:1], Divider[0] (MSb)
//-----------------------------------------------------------------------------
#define mLIN_PointMul() LINADDR=LINMUL      // Select LIN mul address

//-----------------------------------------------------------------------------
// MACRO:          mLIN_PointID
// Parameters:     NONE
// definition:     Select the ID of the LIN interface
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_PointID() LINADDR=LINID        // Select LIN ID address

//-----------------------------------------------------------------------------
// MACRO:          mLIN_StartTX
// Parameters:     NONE
// definition:     Start a LIN Transmission (master mode).
// Obs:            Used in Master Mode after writing ID, data length and the
//                 data itself.
//-----------------------------------------------------------------------------
#define mLIN_StartTX() mLIN_PointControl(); LINDATA |= STREQ

//-----------------------------------------------------------------------------
// MACRO:          mLIN_WakeUpRequest
// Parameters:     NONE
// definition:     Request Wake-Up signal, terminates sleep mode.
// Obs:            Must be issued to leave the sleep mode.
//-----------------------------------------------------------------------------
#define mLIN_WakeUpRequest() mLIN_PointControl(); LINDATA |= WUPREQ

//-----------------------------------------------------------------------------
// MACRO:          mLIN_ResetError
// Parameters:     NONE
// definition:     Request error flags to be reset.
// Obs:            Reset the error bits in status and error registers.
//-----------------------------------------------------------------------------
#define mLIN_ResetError() mLIN_PointControl(); LINDATA |= RSTERR

//-----------------------------------------------------------------------------
// MACRO:          mLIN_ResetInt
// Parameters:     NONE
// definition:     Request interrupt flag to be reset.
// Obs:            NONE
//-----------------------------------------------------------------------------
#define mLIN_ResetInt() mLIN_PointControl(); LINDATA |= RSTINT

//-----------------------------------------------------------------------------
// MACRO:          mLIN_DataACK
// Parameters:     NONE
// definition:     Issued after data request interrupt is processed
// Obs:            Must be used in slave mode after the ID is received
//                 and processed.
//-----------------------------------------------------------------------------
#define mLIN_DataACK() mLIN_PointControl(); LINDATA |= DTACK

//-----------------------------------------------------------------------------
// MACRO:          mLIN_Abort
// Parameters:     NONE
// definition:     Issued after data request interrupt is processed
// Obs:            Must be used in slave mode after the ID is received
//                 and processed and the ID refers to a message not intended
//                 for the slave. The peripheral will ignore the rest of the
//                 communication until another synch-break is issued.
//-----------------------------------------------------------------------------
#define mLIN_Abort() mLIN_PointControl(); LINDATA |= STOP

//-----------------------------------------------------------------------------
// MACRO:          mLIN_SetTxMode
// Parameters:     NONE
// definition:     Select the peripheral to transmit a frame
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_SetTxMode() mLIN_PointControl(); LINDATA |= TXRX

//-----------------------------------------------------------------------------
// MACRO:          mLIN_SetRxMode
// Parameters:     NONE
// definition:     Select the peripheral to receive a frame
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_SetRxMode() mLIN_PointControl(); LINDATA &= ~TXRX

//-----------------------------------------------------------------------------
// MACRO:          mLIN_SetSleepMode
// Parameters:     NONE
// definition:     Select the peripheral to go to sleep mode.
// Obs:            Used internally by the peripheral. The application must
//                 set it upon receiving a sleep mode frame or bus idle timeout
//                 interrupt.
//-----------------------------------------------------------------------------
#define mLIN_SetSleepMode() mLIN_PointControl(); LINDATA |= SLEEP

//-----------------------------------------------------------------------------
// MACRO:          mLIN_SetActiveMode
// Parameters:     NONE
// definition:     Select the peripheral to leave the sleep mode.
// Obs:            Used internally by the peripheral.
//-----------------------------------------------------------------------------
#define mSetActiveMode() mLIN_PointControl(); LINDATA &= ~SLEEP

//-----------------------------------------------------------------------------
// MACRO:          mLIN_SetEnhancedChecksum
// Parameters:     NONE
// definition:     Select the enhanced checksum (LIN V2.0)
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_SetEnhancedChecksum() mLIN_PointSize(); LINDATA |= ENHANCEDCHK

//-----------------------------------------------------------------------------
// MACRO:          mLIN_SetClassicChecksum
// Parameters:     NONE
// definition:     Select the classic checksum (LIN V1.3)
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_SetClassicChecksum() mLIN_PointSize(); LINDATA &= ~ENHANCEDCHK

//-----------------------------------------------------------------------------
// MACRO:          mLIN_SetMessageLength
// Parameters:     s - size of message in bytes (1...8)
// definition:     Select the message length
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_SetMessageLength(s) mLIN_PointSize(); LINDATA = ((LINDATA&0x80)|s)

//-----------------------------------------------------------------------------
// MACRO:          mLIN_SetDivider
// Parameters:     d - divider, from 200 to 511 (decimal)
// definition:     Select the divider
// Obs:            Must be between 200 and 511 !!
//-----------------------------------------------------------------------------
#define mLIN_SetDivider(d) mLIN_PointDiv(); LINDATA = ((unsigned char)(d)); mLIN_PointMul(); \
                       LINDATA = ((LINDATA&0xFE)|(d>>8))

//-----------------------------------------------------------------------------
// MACRO:          mLIN_SetSleepMode
// Parameters:     p - prescaler (0...3)
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_SetPrescaler(p) mLIN_PointMul(); LINDATA = (LINDATA&0xC0)|(p<<6)

//-----------------------------------------------------------------------------
// MACRO:          mLIN_SetMultiplier
// Parameters:     m - multiplier (0...31)
// definition:     Select the multiplier
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_SetMultiplier(m) mLIN_PointMul(); LINDATA = (LINDATA&0xC1)|(m<<1)

//-----------------------------------------------------------------------------
// MACRO:          mLIN_SetID
// Parameters:     i - LIN ID (0...63)
// definition:     Select the ID, subject to the protocol rules.
// Obs:
//-----------------------------------------------------------------------------
#define mLIN_SetID(i) mLIN_PointID(); LINDATA = (i)

#define ENABLE      _ENABLE
#define MASTER_MODE _MASTERMODE
#define SLAVEMODE   _SLAVEMODE
#define AUTOBAUD    _AUTOBAUD
#define MANUALBAUD  _MANUALBAUD


//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------
#ifdef   F53x_LIN_SOURCE

void LIN_Initialize(void);
void LIN_ISR(void);
void Inc_LIN_BUFFER_PUSH(void);
void Inc_LIN_BUFFER_GET(void);
#else
extern void LIN_Initialize(void);
extern __interrupt void LIN_ISR(void);
extern void Inc_LIN_BUFFER_PUSH(void);
extern void Inc_LIN_BUFFER_GET(void);
extern uchar LIN_BUFFER[LIN_BUFFER_SIZE];
extern uchar LIN_BUFFER_PUSH;
extern uchar LIN_BUFFER_GET;
#endif                                 // endif definition of F53x_LIN_SOURCE


//-----------------------------------------------------------------------------
// Include Files
//-----------------------------------------------------------------------------
#include "F53x_LINSnooper_Init.h"

#endif                                 // endif definition of __LIN_H__

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

⌨️ 快捷键说明

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