📄 bdlc.h
字号:
/*****************************************************************************/
/**
Copyright (c) 2006 Freescale Semiconductor
Freescale Confidential Proprietary
\file BDLC.h
\brief BDLC functions declarations and Constant Variables are located\n
in this file.
\author Freescale Semiconductor
\author R01160
\author Guadalajara Applications Laboratory RTAC Americas
\version v0.1
\date 06/June/2006
*/
/*****************************************************************************/
#ifndef BDLC_HEADER
#define BDLC_HEADER
#include "CommonHeaderFiles.h"
#define DATA_BUFFER_SIZE 12
#define TX_BUFFER_SIZE 12
#define BKTX_BUFF_SIZE DATA_BUFFER_SIZE
#define EMPTY 0
#define FULL 1
#define AVAILABLE 2
#define ON 1
#define OFF 0
#define DATA_READY 1
#define DATA_NOT_READY 0
/*******************************************************************************
* Structs *
*******************************************************************************/
struct retransmission_buffer
{
UINT8 FULL_BUFFER; /* Full buffer Flag */
UINT8 u8PendingCmds; /* Status of a pending msg in the Tx queue */
UINT8 u8CmdSize; /* Save Command Size */
UINT8 u8FreeBuffSpace; /* Available Buffer Space */
UINT8 u8LastCmdPrior; /* Saves the last buffer position */
UINT8 pu8CmdPtr; /* Buffer pointer */
UINT8 u8Command[TX_BUFFER_SIZE]; /* Retransmit Command Buffer */
};
/** This structure serves to handle all BDLC flags during any transmition or\n
reception procedures */
typedef struct {
UINT8 ReceivePacketFlag;
UINT8 ErrorDetectedFlag;
UINT8 TxFlag; /* Check if a transmition is in progress */
UINT8 TxFrameOut; /* Check if the complete frame has been sent */
UINT8 ReTransmit; /* Order the state machine to retransmit the package */
UINT8 IsAlive; /* BDLC connection is alive */
UINT8 RxFrameReady; /* Rx Frame has been completely received */
}_BDLCStateFlags;
typedef struct
{
UINT8 LoaErr; /* Lost of arbitration error */
UINT8 CrcErr; /* CRC error flag */
UINT8 InvSymErr; /* Invalid symbol error */
}_BDLCErrorFlags;
typedef struct
{
UINT8 u8CmdSize;
UINT8 u8BufferPayLoad;
UINT8 u8CmdType;
UINT8 u8BufferStatus;
UINT8 *pu8DataBuffer;
}transmit_buffer;
struct receive_buffer
{
UINT8 u8BufferPayLoad; /* Amount of bytes in the Rx Buffer */
UINT8 u8Bk_BuffPayLoad; /* Amount of bytes in the backup Buffer */
UINT8 u8BufferStatus; /* Buffer Status */
UINT8 u8DataReady; /* Data Ready flag */
UINT8 pu8RxData[DATA_BUFFER_SIZE]; /* Rx Buffer */
//UINT8 pu8RxBackBuffer[DATA_BUFFER_SIZE]; /* Backup Rx Buffer */
};
/*******************************************************************************
* Enums *
*******************************************************************************/
typedef enum
{
BDLC_IDLE_STATE,
RX_MSG_STATE,
TX_MSG_STATE,
ERR_STATE,
}_BDLCEnum;
/** BDLC Type of Errors */
typedef enum
{
NO_INT_PEND,
RX_EOF,
RX_IFR,
RX_FULL,
TX_EMPTY,
LOA,
CRC_ERROR,
INV_SYMBOL,
WAKEUP
}_BDLCStateValues;
/*******************************************************************************
* External Variables *
*******************************************************************************/
extern _BDLCStateFlags BDLCStatusFlags;
extern UINT8 u8ReceiveCmd;
extern transmit_buffer TransmitBuffer;
extern struct receive_buffer *RxBuffer;
extern struct receive_buffer *BackRxBuffer;
extern struct retransmission_buffer *RETRANSMIT_BUFF;
extern UINT8 u8RxPointer;
/*******************************************************************************/
/** This definition serves to configure the BDLC module */
#define MCUBusClock 8000000
/** Enable BDLC module */
#define EnableBDLCModule (DLCSCR = 0x10)
/** Ignore J1850 message. Discard frame until next Start of Frame */
#define IgnoreMessage (DLCBCR1_IMSG = 1)
/** J1850 Tx buffer */
#define TxBuffer DLCBDR
/** definition used to detect an invalid symbol while transmiting */
#define InvalidSymbolDetected (DLCBSVR == 0x1C)
/** Check if arbitration lost has been generated */
#define LossOfArbitration (DLCBSVR == 0x14)
/** Check if a CRC error has been generated */
#define CRCError (DLCBSVR == 0x18)
/** Check if TDRE interrupt is not serviced in a timely fashion */
#define TxRegEmpty 0x10
/** All bytes has been transmitted to the bus */
#define CompleteMessageTransmitted (DLCBCR2_TEOD = 1)
/** Check if a byte has been recieved in the BDLC module */
#define RxInterruptRequest (DLCBSVR == 0x3C)
/** Definition used to detect errors in the Received frames */
#define RxErrorDetected (DLCBSVR == 0x1C | DLCBSVR == 0x18)
/** Validates if the Rx buffer is ready to be read */
#define RxDataReady 0x0C
/** Check if an IFR reception has arrived */
#define IFRrx (DLCBSVR == 0x08)
/** Transmit flag used to detect if an error occurs during a TX */
#define TransmitError 1
/** Receive flag used to detect if an error occurs during a RX */
#define ReceiveError 0
/** Indicates that the external J1850 transciever sends true polarity data */
#define TransTruePolarity 0x40
/** Indicates that the external J1850 transciever sends inverted polarity data */
#define TransInvertedPolarity 0x00
/** Analog loopback mode bit */
#define aloop 0x07
/** Digital loopback mode bit */
#define dloop 0x06
/** Ignore Message is disabled (IMSG) */
#define IMSG_Disabled 0x80
/** Ignore Message is Enabled (IMSG) */
#define IMSG_Enabled 0x00
/******************************************************************************
* BDLC Configuration Variables
******************************************************************************/
/** Binary Frequency is selected (DLCBCR1_CLKS) */
#define BinaryFreq 0x40
/** Integer Frequency is selected (DLCBCR1_CLKS) */
#define IntegerFreq 0x00
/** BDLC Rate Selection. Value is calculated using the actual BUS Clock\n
of the system, so the rate selection is adjusted avery time the BUS\n
clock changes */
#define BDLCRateSelection CalculateRateSelection(MCUBusClock)
/** BDLC interrupt enabled */
#define BDLC_Int_Enabled 0x02
/** BDLC interrupt Disabled */
#define BDLC_Int_Disabled 0x00
/** Stop BDLC internal clock during CPU wait mode */
#define BDLC_Stop 0x01
/** Run BDLC internal clock during CPU wait mode */
#define BDLC_Run 0x00
/** Put registers in Reset State */
#define Reset 0x00
/** Tells the initialization function if a loopback test must be done */
#define MakeTest 0x01
/** Tells the initialization function to NOT make the loopback test */
#define MakeNoTest 0x00
/** Validates if an End of Frame has arrived */
#define EndOfFrame (0x04)
/*****************************************************************************
* Delay values (external transciever)
*****************************************************************************/
/** 9us delay value in external transciever */
#define _9us_delay 0x00
/** 10us delay value in external transciever */
#define _10us_delay 0x01
/** 11us delay value in external transciever */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -