LIN总线程序实例

//****************************************************************************
// @Module LIN
// @Filename LIN_driver.c
// @Project LIN_Protocol
//----------------------------------------------------------------------------
// @Controller Infineon C161CI, Evaluation Kit
//
// @Compiler Keil uVision2 V2.03
//
// @Version 0.1
//
// @Description Includes general functions, that needed in the Master- and
// in the Slave-Tasks.
//
//----------------------------------------------------------------------------
// @Date 08/01/2000
//
//****************************************************************************

// USER CODE BEGIN
//----------------------------------------------------------------------------
// @Error
//
//
//----------------------------------------------------------------------------
// @AppNote
//
//
//----------------------------------------------------------------------------
//
//
//----------------------------------------------------------------------------
// @Copyright (C) 2000 INFINEON TECHNOLOGIES AG. All rights reserved.
//
// Systems Engineering Automotive AI SM SEA
// Juergen Ketterer
//****************************************************************************
// USER CODE END


//****************************************************************************
// @Project Includes
//****************************************************************************
// USER CODE BEGIN (main,)
#include // register definitions C161
//#include // headerfile with added register definitions
#include // LIN Initialization header
#include // headerfile for this file
// USER CODE END


//****************************************************************************
// @Macros
//****************************************************************************
// USER CODE BEGIN (main,)
//
// USER CODE END


//****************************************************************************
// @Defines
//****************************************************************************
// USER CODE BEGIN (,)
// USER CODE END


//****************************************************************************
// @Typedefs
//****************************************************************************
// USER CODE BEGIN (,)
// USER CODE END


//****************************************************************************
// @Imported Global Variables
//****************************************************************************
// USER CODE BEGIN (,

tion>)
//
// USER CODE END


//****************************************************************************
// @External Prototypes
//****************************************************************************
// USER CODE BEGIN (,)
// USER CODE END

//****************************************************************************
// @Global Variables
//****************************************************************************
// USER CODE BEGIN
// Status-words
TRANSCEIVER_STATUS nTRANSCEIVER_STATUS;
NODE_STATUS nNODE_STATUS;
PENDING_STATUS nPENDING_STATUS;
ERROR_STATUS nERROR_STATUS;

// is needed for checksum calculation
// it's impossible to define this in the checksum-calculation function
unsigned char bdata bucIdField;
sbit fb_id0 = bucIdField ^ 0;
sbit fb_id1 = bucIdField ^ 1;
sbit fb_id2 = bucIdField ^ 2;
sbit fb_id3 = bucIdField ^ 3;
sbit fb_id4 = bucIdField ^ 4;
sbit fb_id5 = bucIdField ^ 5;
sbit fb_p0 = bucIdField ^ 6;
sbit fb_p1 = bucIdField ^ 7;

// this varibale indicates a transmitted message by 1 otherwise a 0.
unsigned char ucMessageSent;

// uiBusIdleTimeOutBuffer
// with receiving a new message the timer-value will be saved in this buffer
// when the "fb_no_bus_activity_error"-bit is NOT set.
// if the message is NOT valid, the timer would be reloaded with this saved
// value and the timer go on.
// if the message is valid then this buffer will be set to 0 and the timer
// go on with the current value.
unsigned int uiBusIdleTimeOutBuffer;

// The stLinIdInfo[] buffer should save ID infos and ID-Types.
// size of Id Information-buffer depends on number of send- and receive IDs
// spezified in the node (LIN_hLinNode.h).
// in the LinIdInfo buffer are a number of MAX_LIN_ID ID-Infos
// to save
// the +1 is the ID for the Sleep-ID

// changed by HK
//stLIN_ID_INFO stLinIdInfo[MAX_LIN_ID+1];
stLIN_ID_INFO stLinIdInfo[MAX_LIN_ID];

// stLinTransceiveBuffer[] : The LIN-Transceive-Buffer, this buffer is
// used by the LIN-Functions to send and receive messages. If a message
// should be sent then all data and Id must be saved in this buffer first.
// And if a message has been received, the ID and the data will be saved
// in this buffer, too.
stLIN_MESSAGE stLinTransceiveBuffer[1];


//****************************************************************************
// @Declarations
//****************************************************************************
// global declaration of pointer at User-Call-Back-functions
// see Functions below in this file:
// LIN_vDefineUCBFunctionTxd(...)
// LIN_vDefineUCBFunctionRxd(...)
void (*pvfUcbTxdId)(unsigned char);
void (*pvfUcbRxdId)(unsigned char);


void LIN_vHandleCapCom(unsigned int uiLocalCCReg, \
unsigned int uiLocalCCTimerReg);


//*

***************************************************************************
// @Function void LIN_vCreateIdInfo(void)
//
//----------------------------------------------------------------------------
// @Description
// this function creates an array which stores the ID definitions
// of this node. The informations are coming from the header-file
// LINhInitNode.h.
//----------------------------------------------------------------------------
// @Returnvalue
// void
//----------------------------------------------------------------------------
// @Parameters
// void
//----------------------------------------------------------------------------
// @Date 05/17/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// stLinIdInfo[] : is the LIN buffer which saves the defined IDs and Types
// of the messages
//----------------------------------------------------------------------------
// @AppNote
// size of message-buffer depends on number of send IDs spezified
// in the node-header (LIN_hLinNode.h).
//
// writes the defined IDs in the struct-variables
// also the Type of the ID: 3-Types are possible
// 1) SEND-TYPE: by receiving an ID defined as SEND-Type: this node
// should send the DATA to the bus
// 2) REC-TYPE: by receiving an ID defined as REC_Type: this node
// should receive the DATA comming on the bus
// 3) MON-TYPE: by receiving an ID defined as MON-Type: this node
// should only MONITOR the DATA (for Failer-Detection)
//
//****************************************************************************
void LIN_vCreateIdInfo(void)
{
volatile unsigned char ucLocalCounter = 0;

// set buffer to ZERO (0x00) == not defined
// changed by HK
//while(ucLocalCounter <= MAX_LIN_ID)

while(ucLocalCounter < MAX_LIN_ID)
{
stLinIdInfo[ucLocalCounter++].ucId = ZERO;
}

ucLocalCounter = 0;

// send-message-buffer.
#ifdef SEND_ID0
stLinIdInfo[ucLocalCounter].ucId = SEND_ID0;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID1
stLinIdInfo[ucLocalCounter].ucId = SEND_ID1;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID2
stLinIdInfo[ucLocalCounter].ucId = SEND_ID2;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID3
stLinIdInfo[ucLocalCounter].ucId = SEND_ID3;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID4
stLinIdInfo[ucLocalCounter].ucId = SEND_ID4;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID5
stLinIdInfo[ucLocalCounter].ucId = SEND_ID5;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID6
stLinIdInfo[ucLocalCounter].ucId = SEND_ID6;
st

LinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID7
stLinIdInfo[ucLocalCounter].ucId = SEND_ID7;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID8
stLinIdInfo[ucLocalCounter].ucId = SEND_ID8;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID9
stLinIdInfo[ucLocalCounter].ucId = SEND_ID9;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID10
stLinIdInfo[ucLocalCounter].ucId = SEND_ID10;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID11
stLinIdInfo[ucLocalCounter].ucId = SEND_ID11;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID12
stLinIdInfo[ucLocalCounter].ucId = SEND_ID12;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID13
stLinIdInfo[ucLocalCounter].ucId = SEND_ID13;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID14
stLinIdInfo[ucLocalCounter].ucId = SEND_ID14;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif
#ifdef SEND_ID15
stLinIdInfo[ucLocalCounter].ucId = SEND_ID15;
stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
#endif

// changed by HK
//#ifdef MASTER
// stLinIdInfo[ucLocalCounter].ucId = ZERO;
// stLinIdInfo[ucLocalCounter++].ucType = SEND_TYPE;
//#endif

// receive-message-buffer
#ifdef REC_ID0
stLinIdInfo[ucLocalCounter].ucId = REC_ID0;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID1
stLinIdInfo[ucLocalCounter].ucId = REC_ID1;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID2
stLinIdInfo[ucLocalCounter].ucId = REC_ID2;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID3
stLinIdInfo[ucLocalCounter].ucId = REC_ID3;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID4
stLinIdInfo[ucLocalCounter].ucId = REC_ID4;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID5
stLinIdInfo[ucLocalCounter].ucId = REC_ID5;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID6
stLinIdInfo[ucLocalCounter].ucId = REC_ID6;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID7
stLinIdInfo[ucLocalCounter].ucId = REC_ID7;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID8
stLinIdInfo[ucLocalCounter].ucId = REC_ID8;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID9
stLinIdInfo[ucLocalCounter].ucId = REC_ID9;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID10
stLinIdInfo[ucLocalCounter].ucId = REC_ID10;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID11
stLinIdInfo[ucLocalCounter].ucId = REC_ID11;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID12
stLinIdInfo[ucLocalCounter].ucId = REC_ID12;
stLin

IdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID13
stLinIdInfo[ucLocalCounter].ucId = REC_ID13;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID14
stLinIdInfo[ucLocalCounter].ucId = REC_ID14;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID15
stLinIdInfo[ucLocalCounter].ucId = REC_ID15;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif

#ifdef SLAVE
stLinIdInfo[ucLocalCounter].ucId = ZERO;
stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif


// monitor-message-buffer
#ifdef MON_ID0
stLinIdInfo[ucLocalCounter].ucId = MON_ID0;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID1
stLinIdInfo[ucLocalCounter].ucId = MON_ID1;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID2
stLinIdInfo[ucLocalCounter].ucId = MON_ID2;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID3
stLinIdInfo[ucLocalCounter].ucId = MON_ID3;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID4
stLinIdInfo[ucLocalCounter].ucId = MON_ID4;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID5
stLinIdInfo[ucLocalCounter].ucId = MON_ID5;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID6
stLinIdInfo[ucLocalCounter].ucId = MON_ID6;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID7
stLinIdInfo[ucLocalCounter].ucId = MON_ID7;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID8
stLinIdInfo[ucLocalCounter].ucId = MON_ID8;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID9
stLinIdInfo[ucLocalCounter].ucId = MON_ID9;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID10
stLinIdInfo[ucLocalCounter].ucId = MON_ID10;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID11
stLinIdInfo[ucLocalCounter].ucId = MON_ID11;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID12
stLinIdInfo[ucLocalCounter].ucId = MON_ID12;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID13
stLinIdInfo[ucLocalCounter].ucId = MON_ID13;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID14
stLinIdInfo[ucLocalCounter].ucId = MON_ID14;
stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID15
stLinIdInfo[ucLocalCounter].ucId = MON_ID15;
stLinIdInfo[ucLocalCounter].ucType = MON_TYPE;
#endif

}
//****************************************************************************
// USER CODE END: void LIN_vCreateIdInfo()





//****************************************************************************
// @Function unsigned char LIN_ucGetID(unsigned char ucLocalReceivedByte)
//
//--------------------------------------------------------------------------

--
// @Description
// this function separates the ID-number
// from the ID-field.
//----------------------------------------------------------------------------
// @Returnvalue unsigned char: the id-number and lenghtcontrol
// without parity bits
//
//----------------------------------------------------------------------------
// @Parameters unsigned char cLocalReceivedByte: the idfield
//
//----------------------------------------------------------------------------
// @Date 06/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// none
//----------------------------------------------------------------------------
// @AppNote
// Example:
//
// test = LIN_ucGetID(0x80)
//
// test == 0 rsp. test == 0x00
//
//****************************************************************************
unsigned char LIN_ucGetID(unsigned char ucLocalReceivedByte)
{
ucLocalReceivedByte &= 0x3F;
return(ucLocalReceivedByte);
}
//****************************************************************************
// USER CODE END: unsigned char LIN_ucGetID(unsigned char ucLocalReceivedByte)






//****************************************************************************
// @Function unsigned char LIN_ucGetNOD(unsigned char ucLocalReceivedByte)
//
//----------------------------------------------------------------------------
// @Description
// this function separates "Number of Data" from the ID-field.
//----------------------------------------------------------------------------
// @Returnvalue unsigned char: the lenghtcontrol without Id-bits and parity
// bits
// possible values: 2,4 or 8
//
//----------------------------------------------------------------------------
// @Parameters unsigned char ucLocalReceivedByte: the idfield
//
//----------------------------------------------------------------------------
// @Date 06/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// none
//----------------------------------------------------------------------------
// @AppNote
// Example:
//
// test = LIN_ucGetNOD(0x80)
//
// test == 2
//
//****************************************************************************
unsigned char LIN_ucGetNOD(unsigned char ucLocalReceivedByte)
{
ucLocalReceivedByte &= 0x30;
ucLocalReceivedByte >>= 4;
// if the result is 0, then NOD is 2 Databytes
switch(ucLocalReceivedByte)
{
case 0:
ucLocalReceivedByte = 2;
break;
case 1:
ucLocalReceivedByte = 2;
break;

case 2:
ucLocalReceivedByte = 4;
break;
case 3:
ucLocalReceivedByte = 8;
break;
default:
ucLocalReceivedByte = 2;
}
return(ucLocalReceivedByte);
}
//****************************************************************************
// USER CODE END: uchar LIN_ucGet(unsigned char ucLocalReceivedByte)




//****************************************************************************
// @Function unsigned char LIN_ucGetMode(unsigned char ucLocalId)
//
//----------------------------------------------------------------------------
// @Description
// this function returns the receive-mode of the node.
// 1) Transmit Data: return-value = 6
// 2) Receive Data : return-value = 7
// 3) Monitor Data : return-value = 8
// It's recommended to save the Return-Value in the nTRANSCEIVER_STATUS
// byte.
//----------------------------------------------------------------------------
// @Returnvalue unsigned char: the Node-Mode, see above
//----------------------------------------------------------------------------
// @Parameters uchar: the ID
//----------------------------------------------------------------------------
// @Date 06/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// none
//----------------------------------------------------------------------------
// @AppNote
// 1) For-loop: scan all array-elements from 0 to EOA (End of Array)
// 2) search the array-element with the desired Id
// 3) select between Send-Type an Receive-Type and write the result in
// the return varible
// else: the node has monitor-function
// 4) if the Id wasn't found then checksum_ok will be returned
//----------------------------------------------------------------------------
//****************************************************************************
unsigned char LIN_ucGetMode(unsigned char ucLocalId)
{
unsigned char ucLocalReturn;
unsigned char ucLocCoun;
ucLocalReturn = l_i_am_monitor;

for(ucLocCoun = 0;ucLocCoun <= MAX_LIN_ID;ucLocCoun++)
{
if(stLinIdInfo[ucLocCoun].ucId == ucLocalId)
{
if(stLinIdInfo[ucLocCoun].ucType == SEND_TYPE)
{
ucLocalReturn = l_i_am_transmitter;
}
else if(stLinIdInfo[ucLocCoun].ucType == REC_TYPE)
{
ucLocalReturn = l_i_am_receiver;
}
else
{
ucLocalReturn = l_i_am_monitor;
}
}
}
return(ucLocalReturn);
}
//****************************************************************************
// USER CODE END: unsigned char LIN_ucGetMode(unsigned char ucLocalId)





//****************************************************************************
// @

Function unsigned int LIN_uiCalcTFrameMax(volatile unsigned int uiLocNOD)
//
//----------------------------------------------------------------------------
// @Description
// this function gets the Time-FrameMax and loads the
// capture compare register
//
//----------------------------------------------------------------------------
// @Returnvalue the right maximum Time for the Frame (Time_frame_max)
//
//----------------------------------------------------------------------------
// @Parameters unsigned int: the Number of Data
//
//----------------------------------------------------------------------------
// @Date 08/02/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// none
//----------------------------------------------------------------------------
// @AppNote
//****************************************************************************
unsigned int LIN_uiCalcTFrameMax(volatile unsigned int uiLocNOD)
{

switch(uiLocNOD)
{
case 2:
uiLocNOD = TIME_FRAMEMAX2;
break;
case 4:
uiLocNOD = TIME_FRAMEMAX4;
break;
case 8:
uiLocNOD = TIME_FRAMEMAX8;
break;
default:
uiLocNOD = TIME_FRAMEMAX8;
}
return uiLocNOD;
}
//****************************************************************************
// USER CODE END: unsigned int LIN_uiCalcTFrameMax(volatile uint uiLocNOD)





//****************************************************************************
// @Function unsigned char LIN_ucChecksum(stLIN_MESSAGE *pstLocalHelp)
//
//----------------------------------------------------------------------------
// @Description
// this function creates the checksum-field. The checksum field
// will be calculated as a inverted sum over all data-bytes
// this is called inverted modulo-256. If the sum is over 0xFF
// the carry-bit will be set and must be added to LSB of the
// next addition.
//----------------------------------------------------------------------------
// @Returnvalue unsigned char; the checksum
//----------------------------------------------------------------------------
// @Parameters stLIN_MESSAGE *pstLocalHelp: pointer on struct, that's
// the address of the element
//
//----------------------------------------------------------------------------
// @Date 04/26/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// none
//----------------------------------------------------------------------------
// @AppNote
// If the addit

on of two bytes is over 0xFF, in assembler a carry-flag
// would be set but in C-language there is no permission on this flag so
// this must be calculated by an algorithm.
// Algorithm: If the addition is over 0xFF then a decrease in value of 0xFF
// must occur.
//
//----------------------------------------------------------------------------
// There must stay a ( unsigned char) in front of the data-bytes otherwise
// the translation from unsigned char to unsigned integer isn't able.
//****************************************************************************
unsigned char LIN_ucChecksum(stLIN_MESSAGE *pstLocalHelp)
{
unsigned int uiLocalHelp;
// two bytes must be added at least
uiLocalHelp = (unsigned char)pstLocalHelp->ucDataByte[0] +
(unsigned char)pstLocalHelp->ucDataByte[1];
if(uiLocalHelp > 0xFF) // if addition is over 0xFF then algorithm,
uiLocalHelp -= 0xFF; // see above

// if the Number of datas is more then 2
switch(LIN_ucGetNOD(pstLocalHelp->ucId))
{
case 2:
;
break;
case 4: // add two data-bytes more
uiLocalHelp += ( unsigned char)pstLocalHelp->ucDataByte[2];
if(uiLocalHelp > 0xFF)
uiLocalHelp -= 0xFF;
uiLocalHelp += ( unsigned char)pstLocalHelp->ucDataByte[3];
if(uiLocalHelp > 0xFF)
uiLocalHelp -= 0xFF;
break;
case 8: // add six data-bytes more
uiLocalHelp += ( unsigned char)pstLocalHelp->ucDataByte[2];
if(uiLocalHelp > 0xFF)
uiLocalHelp -= 0xFF;
uiLocalHelp += ( unsigned char)pstLocalHelp->ucDataByte[3];
if(uiLocalHelp > 0xFF)
uiLocalHelp -= 0xFF;
uiLocalHelp += ( unsigned char)pstLocalHelp->ucDataByte[4];
if(uiLocalHelp > 0xFF)
uiLocalHelp -= 0xFF;
uiLocalHelp += ( unsigned char)pstLocalHelp->ucDataByte[5];
if(uiLocalHelp > 0xFF)
uiLocalHelp -= 0xFF;
uiLocalHelp += ( unsigned char)pstLocalHelp->ucDataByte[6];
if(uiLocalHelp > 0xFF)
uiLocalHelp -= 0xFF;
uiLocalHelp += ( unsigned char)pstLocalHelp->ucDataByte[7];
if(uiLocalHelp > 0xFF)
uiLocalHelp -= 0xFF;
break;
default:
uiLocalHelp = 0;
}
// the result stays in an integer and is going to return an integer, but
// the recipient of this value expects an unsigned char.
return(uiLocalHelp); // return the inverted modulo-256 checksum
}
//****************************************************************************
// USER CODE END: unsigned char LIN_ucChecksum(stLIN_MESSAGE *pstLocalHelp)







//****************************************************************************
// @Function: void LIN_vCopy_SendData(unsigned char* pucLocalData)
//
//-------------------------------

---------------------------------------------
// @Description
// this function saves all requested data from the given start address
// to the LIN-Transceiver-Buffer and sends the first byte instantly
//
//----------------------------------------------------------------------------
// @Returnvalue void
//----------------------------------------------------------------------------
// @Parameters address of the first data byte to send
//----------------------------------------------------------------------------
// @Date 05/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// stLinTransceiveBuffer[] : The LIN-Transceive-Buffer, this buffer is
// used by the LIN-Functions to send and receive messages. If a message
// should be sent then all data and Id must be saved in this buffer first.
// And if a message has been received, the ID and the data will be saved
// in this buffer, too.
//----------------------------------------------------------------------------
// @AppNote
// This function should be called from within the User-Call-Back-Function:
// USER_vUCB_TxdId_Received(...)
// This function copies all data which should be sent in the LIN-Trans-
// ceiver Buffer.
// The ID is already standing in the stLinTransceiveBuffer[].ucId got by
// the message header before this function has been called,
//----------------------------------------------------------------------------
//****************************************************************************
void LIN_vCopy_SendData(unsigned char* pucLocalData)
{
unsigned char ucLocCoun = 0;
// get the Number Of Data
while(ucLocCoun < stLinTransceiveBuffer[BUFFER_1].ucNOD)
{
// save next byte in the transceiver-buffer
stLinTransceiveBuffer[BUFFER_1].ucDataByte[ucLocCoun] = \
*(pucLocalData + ucLocCoun);// here ucLocCoun is used as offset to
// the first data-byte given by address
ucLocCoun++;
}

// send first byte, the next byte will be transmitted after receiving this
// byte (in the Rxd-Interrupt function)
ASC_TRANSMIT_BUFFER_REGISTER = \
stLinTransceiveBuffer[BUFFER_1].ucDataByte[0];
}
//****************************************************************************
// USER CODE END: void LIN_vCopy_SendData(unsigned char* pucLocalData)





//****************************************************************************
// @Function: void LIN_vCopy_ReceiveData(unsigned char* ucLocalData)
//
//----------------------------------------------------------------------------
// @Description
// this function copies all received data from the LIN-Transceiver-Buffer
// to the USER-LIN-BUFFER. The user application has to provide the address
// of

the first byte in the USER-LIN-BUFFER.
//
//----------------------------------------------------------------------------
// @Returnvalue
//----------------------------------------------------------------------------
// @Parameters address of the first data byte, where the data should be
// stored in the USER-LIN-BUFFER
//----------------------------------------------------------------------------
// @Date 05/22/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// stLinTransceiveBuffer[] : The LIN-Transceive-Buffer, this buffer is
// used by the LIN-Functions to send and receive messages. If a message
// should be sent then all data and Id must be saved in this buffer first.
// And if a message has been received, the ID and the data will be saved
// in this buffer, too.
//----------------------------------------------------------------------------
// @AppNote
// This function should be called from within the User-Call-Back-Function:
// USER_vUCB_RxdId_Received(...)
// The ID is already standing in the stLinTransceiveBuffer[].ucId got by
// the message header (ID-Field receiving) before this function has been
// called.
//----------------------------------------------------------------------------
//****************************************************************************
void LIN_vCopy_ReceiveData(unsigned char* pucLocalData)
{
// saves received byte in the LIN-receive-buffer
unsigned char ucLocCoun = 0;
// get the Number Of Data
while(ucLocCoun < stLinTransceiveBuffer[BUFFER_1].ucNOD)
{
// copy next data from LIN-Transceiverbuffer to the
// USER-LIN-BUFFER
*(pucLocalData + ucLocCoun) = \
stLinTransceiveBuffer[BUFFER_1].ucDataByte[ucLocCoun];
// next data-byte
ucLocCoun++ ;
}

//return (ucLocCoun);
}
//****************************************************************************
// USER CODE END: void LIN_vCopy_ReceiveData(unsigned char* ucLocalData)





//****************************************************************************
// @Function void LIN_vInitASC(void)
//
//----------------------------------------------------------------------------
// @Description This function initializes the ASC1 component. It effects all
// necessary configurations of the SFR, depending on the
// selected operating mode. The configuration determines
// whether the ASC interrupts are to be released, and the
// priority of the released interrupt.
//----------------------------------------------------------------------------
// @Returnvalue none
//
//----------------------------------------------------------------------------
// @Parameters none
//
//-----

-----------------------------------------------------------------------
// @Date 08/25/2000 13:01:22
//
//****************************************************************************
void LIN_vInitASC(void)
{
LIN_PORT_REGISTER |= LIN_TXD_BIT;
LIN_PORT_DIRECTION_REGISTER |= LIN_TXD_BIT;
// 8-bit data asynchronous operation
// one stop bit
// ignore framing error
// ignore overrun error
// receiver enabled
ASC_CONTROL_REGISTER = ASC_MODE_VALUE;

// ASC1 baudrate generator register
/// baudrate depends on selection LIN_hInitNode.H
ASC_BAUDRATE_REGISTER = BAUDRATE_ASC;

// receive interrupt Priority
ASC_RECEIVE_IRQ_CONTROL_REGISTER = ASC_RECEIVE_PRIORITY_VALUE;
// enable Receive Interrupt
ASC_RECEIVE_IRQ_CONTROL_REGISTER |= ASC_RECEIVE_IRQ_ENABLE;
}
//****************************************************************************
// USER CODE END: void LIN_vInitASC(void)



//****************************************************************************
// @Function void LIN_vInitTimer(void)
//
//----------------------------------------------------------------------------
// @Description
// this function initiate the timer
//----------------------------------------------------------------------------
// @Returnvalue void
//
//----------------------------------------------------------------------------
// @Parameters void
//
//----------------------------------------------------------------------------
// @Date 04/05/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//
//----------------------------------------------------------------------------
// @AppNote
// The timer has following settings by f_cpu=20MHz
// Timer-Period = 3,36sec
// Timer-Resolution = 51,2usec
// Timer-Prescaler = 1024
// The Values are written to the init-header-file LIN_hInitNode.H
//
//----------------------------------------------------------------------------
// The Baud-Rate of the LIN-Net should be 19,2 kbaud that means a bittime
// of 52,08usec.
// If the resolution would be 800nsec then a bittime of 52usec would be
// possible but in that way the timer couldn't reach the
// "bus-idle-time-out"-time = 25.000 bittime
//****************************************************************************
void LIN_vInitTimer(void)
{
CC_TIMER_CONTROL_REGISTER |= BITTIME_LIN; // Tx: resol.
CC_TIMER_REGISTER = TIMEBASE_LIN; // Time base = max
// Reload Value = max like base-time
CC_TIMER_RELOAD_REGISTER = TIMEBASE_LIN;
}
//****************************************************************************
// USER CODE END: LIN_vInitTimer(void)







//*********************************************************

*******************
// @Function void LIN_vInitCapCom(void)
//
//----------------------------------------------------------------------------
// @Description
// This function will be called to initialize the CapCom-Registers
//----------------------------------------------------------------------------
// @Returnvalue void
//
//----------------------------------------------------------------------------
// @Parameters void
//
//----------------------------------------------------------------------------
// @Date 5/30/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//
//----------------------------------------------------------------------------
// @AppNote
//
//----------------------------------------------------------------------------
//
//****************************************************************************
void LIN_vInitCapCom(void)
{
// Capture/Compare-functions
CC_MODE_REGISTER &= ~CC_MODE_DISABLE; // reset CapCom-Mode
CC_IRQ_CONTROL_REGISTER = CC_PRIORITY_VALUE;
// set compare mode 0
CC_MODE_REGISTER |= CC_COMPARE_MODE_0;
}
//****************************************************************************
// USER CODE END: void LIN_vInitCapCom(void)








//****************************************************************************
// @Function void LIN_vDefaultCondition(void)
//
//----------------------------------------------------------------------------
// @Description
// this function sets the node in the default condition
// after a send or receive action
//----------------------------------------------------------------------------
// @Returnvalue void
//
//----------------------------------------------------------------------------
// @Parameters void
//
//----------------------------------------------------------------------------
// @Date 08/25/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//
// uiBusIdleTimeOutBuffer:
// This variable stores the timer-value
// on start of receiving/transmitting- procedures if the LIN handles without
// an error then the timer can start by zero otherwise the timer will be
// loaded by the value stored in this variable. (Its for bus-Idle Time-Out
// detection)
//
// nTRANSCEIVER_STATUS:
// the transmission/receiving of a LIN message
// will be handled in a state-machine therefor
// this status byte is used to set the actually state
// of transmission or receiving a message.
//
// nNODE_STATUS
// the node can be in 3 different states
//----------------------------------------------------------------------------
// @AppNote
//------------------

----------------------------------------------------------
//
//****************************************************************************
void LIN_vDefaultCondition(void)
{
if(nPENDING_STATUS == l_wakeup_pending)
{
LIN_vHandleCapCom(T_T0BRK, 0x0000);// set and load timer
}
else
{
if(nTRANSCEIVER_STATUS != l_checksum_ok) // if TS==9
{
// the transmission wasn't ok, reload the timer-register with the timer
// value saved before. (for No_bus_activity_error)
CC_TIMER_REGISTER = uiBusIdleTimeOutBuffer;
}
else
{
CC_TIMER_REGISTER = ZERO;// start timer from the beginning
}
// CapCom-Register: Bus-Idle-Time
CC_REGISTER = TIME_OUT; // set compare_register time
nNODE_STATUS = l_ready_for_synchbreak; // set NS2
}
///////////////////////////////////////////////////////////////////////////
nTRANSCEIVER_STATUS = l_default_status; // set default-STATE =TS1
///////////////////////////////////////////////////////////////////////////

ASC_BAUDRATE_REGISTER = BAUDRATE_ASC;
}
//****************************************************************************
// USER CODE END: void LIN_vDefaultCondition(void)







//****************************************************************************
// @Function void LIN_vHandleCapCom(unsigned int uiLocalCCReg, \
// unsigned int uiLocalCCTimerReg)
//
//----------------------------------------------------------------------------
// @Description
// this function sets the CapCom Register, loads the
// CapCom Timer Register and activates the Interrupt
// and starts the timer
//----------------------------------------------------------------------------
// @Returnvalue void
//
//----------------------------------------------------------------------------
// @Parameters uiLocalCCReg: The CapCom Register Value
// uiLocalCCTimerReg: The CapCom Timer Register Value
//----------------------------------------------------------------------------
// @Date 06/07/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//
//----------------------------------------------------------------------------
// @AppNote
//----------------------------------------------------------------------------
//
//****************************************************************************
void LIN_vHandleCapCom(volatile unsigned int uiLocalCCReg, \
volatile unsigned int uiLocalCCTimerReg)
{
// CapCom-Register:
CC_REGISTER = uiLocalCCReg; // set compare_register
CC_IRQ_CONTROL_REGISTER |= CC_INTERRUPT_ENABLE_BIT;
CC_TIMER_REGISTER = uiLocalCCTimerReg; // timer value
CC_TIMER_CONTR

OL_REGISTER |= CC_TIMER_RUN_BIT; // start timer
}
//****************************************************************************
// USER CODE END: void LIN_vHandleCapCom(unsigned int uiLocalCCReg, \
// unsigned int uiLocalCCTimerReg)




//****************************************************************************
// @Function void LIN_vInitNode(void)
//
//----------------------------------------------------------------------------
// @Description
// this function initializes the node
//----------------------------------------------------------------------------
// @Returnvalue void
//
//----------------------------------------------------------------------------
// @Parameters void
//
//----------------------------------------------------------------------------
// @Date 04/05/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//
// uiBusIdleTimeOutBuffer:
// This variable stores the timer-value
// on start of receiving/transmitting- procedures if the LIN handles without
// an error then the timer can start by zero otherwise the timer will be
// loaded by the value stored in this variable. (Its for bus-Idle Time-Out
// detection)
//
// nTRANSCEIVER_STATUS:
// the transmission/receiving of a LIN message
// will be handled in a state-machine therefor
// this status byte is used to set the actually state
// of transmission or receiving a message.
//
// nNODE_STATUS
// the node can be in 3 different states
// 1) sleep-mode
// 2) ready_for_synchbreak-mode
// 3) not_ready_for_synchbreak-mode
// 4) disconnect
//
// nPENDING_STATUS
// 1) default_pending: no pending
// 2) wakeup-pending
// 3) sleep-pending
//
// nERROR_STATUS
// the LIN-Protocol Specification supports 6
// different kind of errors, which are flagged
// in this error status byte
//----------------------------------------------------------------------------
// @AppNote
//----------------------------------------------------------------------------
// Important: first initiate the timer and Capcom and later initiate ASC
//
//****************************************************************************
void LIN_vInitNode(void)
{
// init. the CapCom Registers
LIN_vInitCapCom();

// Timer 0
LIN_vInitTimer(); // init timer 0

// ASC1 init
LIN_vInitASC(); // init the UART

//Interrupt
//GLOBAL_INTERRUPT = ON;

//Create Buffer
LIN_vCreateIdInfo();

// Bytes and buffers
uiBusIdleTimeOutBuffer = ZERO;
LIN_vDefaultCondition();
// Status-Register
nERROR_STATUS = 0x0000; // set error-status-byte
nNODE_STATUS = l_disconnect; // set node-status-byte =NS1
nPENDING_STATUS = l_default_pending; // set pending-statu

s-byte =PS1
GLOBAL_INTERRUPT = ON;
// enable UART
ASC_CONTROL_REGISTER |= ASC_BAUDRATE_GENERATOR_RUN_BIT;
}
//****************************************************************************
// USER CODE END: void LIN_vInitNode(void)







//****************************************************************************
// @Function unsigned char LIN_ucCreateID(unsigned char ucLocalId)
//
//----------------------------------------------------------------------------
// @Description
// this function creates the ID-field.
//----------------------------------------------------------------------------
// @Returnvalue unsigned char, the created idfield
//
//----------------------------------------------------------------------------
// @Parameters unsigned char ucLocalId:
// The ID (incl. the Number of Data) of the send-message
//
//----------------------------------------------------------------------------
// @Date 06/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// bucIdField Bitaddressable unsigned char MODULE: LIN_functions
//----------------------------------------------------------------------------
// @AppNote
//----------------------------------------------------------------------------
//****************************************************************************
unsigned char LIN_ucCreateID(unsigned char ucLocalId)
{
bucIdField=0; // set bitaddressable variable to 0

bucIdField |= ucLocalId ; // join the id together with the idfield

fb_p0 = fb_id0 ^ fb_id1 ^ fb_id2 ^ fb_id4; //create parity p0
fb_p1 = ~(fb_id1 ^ fb_id3 ^ fb_id4 ^ fb_id5); //create parity -p1

return(bucIdField); // return the idfield
}
//****************************************************************************
// USER CODE END: unsigned char LIN_ucCreateID(unsigned char ucLocalId)




//****************************************************************************
// @Function void LIN_vSetSleepMode(void)
//
//----------------------------------------------------------------------------
// @Description
// this function sets the controller in sleep-mode
//----------------------------------------------------------------------------
// @Returnvalue none
//----------------------------------------------------------------------------
// @Parameters none
//----------------------------------------------------------------------------
// @Date 05/29/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//
// nNODE_STATUS
// the node can be in

3 different states
//----------------------------------------------------------------------------
// @AppNote
//
//----------------------------------------------------------------------------
//****************************************************************************
void LIN_vSetSleepMode(void)
{
if(!LIN_ucReadFlag_Disconnect())
{
CC_IRQ_CONTROL_REGISTER &= ~CC_INTERRUPT_ENABLE_BIT; //disable Compare-IRQ
// go in sleep-mode
//SYSCON1 = 0x01;
nPENDING_STATUS = l_default_pending;
nNODE_STATUS = l_sleep;
SET_SLEEP_MODE;
}
}
//****************************************************************************
// USER CODE END: void LIN_vSetSleepMode(void)




//****************************************************************************
// @Function void LIN_vSendWakeUp(void)
//
//----------------------------------------------------------------------------
// @Description
// this function sends a wakeup signal on the bus
//----------------------------------------------------------------------------
// @Returnvalue none
//----------------------------------------------------------------------------
// @Parameters none
//----------------------------------------------------------------------------
// @Date 05/11/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//----------------------------------------------------------------------------
// @AppNote
//
// This sign can only be sent if the node is really in sleep-mode
//----------------------------------------------------------------------------
//****************************************************************************
void LIN_vSendWakeUp(void)
{
if(!LIN_ucReadFlag_Disconnect()) // if node is connected
{
if(LIN_ucReadFlag_Sleep())
{
// LIN_vEnableRXD(); // enable Rxd
nPENDING_STATUS = l_wakeup_pending; // set status for wakeup pending
ASC_TRANSMIT_BUFFER_REGISTER = LIN_WAKEUP_CHAR; //send wake-up-signal
CC_IRQ_CONTROL_REGISTER |= CC_INTERRUPT_ENABLE_BIT; //enable Compare-IRQ
LIN_vHandleCapCom(T_T0BRK, 0x0000); // set and load timer
}
}
}

//****************************************************************************
// USER CODE END: void LIN_vSendWakeUp(void)






//****************************************************************************
// @Function void LIN_vWakeUpProcedure(void)
//
//----------------------------------------------------------------------------
// @Description
// this function handles the wake up procedure
// !!! ONLY IN SLAVE MODE !!!
//----------------------------------------------------------------------------
// @Returnvalue none
//----------------------------------------------------------

------------------
// @Parameters none
//----------------------------------------------------------------------------
// @Date 05/31/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// none
//----------------------------------------------------------------------------
// @AppNote
//
//----------------------------------------------------------------------------
//****************************************************************************
void LIN_vWakeUpProcedure(void)
{
static unsigned char ucLocalCounter;
if(ucLocalCounter < 3)
{
ucLocalCounter++;
nNODE_STATUS = l_sleep;
LIN_vSendWakeUp();
}
else if(ucLocalCounter == 3)
{
ucLocalCounter = 0;
nNODE_STATUS = l_sleep;
// Loads CapCom and Timer Register and starts Timer and IRQ
LIN_vHandleCapCom(T_T3BRK, ZERO);
}
}
//****************************************************************************
// USER CODE END: void LIN_vWakeUpProcedure(void)



//****************************************************************************
// @Function void LIN_vReceiveSynch0x00(unsigned char *pucLocalHelpS1RBUF)
//
//----------------------------------------------------------------------------
// @Description
// this function handles the receiveing of the synchbreakfield
// by detecting 0x00 in slower baudrate
//----------------------------------------------------------------------------
// @Returnvalue none
//----------------------------------------------------------------------------
// @Parameters pointer uchar: pointer at the received byte
//----------------------------------------------------------------------------
// @Date 07/21/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// nTRANSCEIVER_STATUS
// nERROR_STATUS
//----------------------------------------------------------------------------
// @AppNote
// STATE: TS2
// This function was separated from the Rxd-Interrupt-function to get
// a better overview there.
//----------------------------------------------------------------------------
//****************************************************************************
#ifdef MASTER
void LIN_vReceiveSynch0x00(unsigned char *pucLocalHelpS1RBUF)
{
if(*pucLocalHelpS1RBUF == LIN_SYNCHBREAK)
{
ASC_BAUDRATE_REGISTER = BAUDRATE_ASC;
// LIN_vEnableRXD(); // enable Rxd

if(nPENDING_STATUS == l_wakeup_pending)
{
nPENDING_STATUS = l_default_pending;
}

ucMessageSent = 0;
// next state
////////////////////////////////////////////////////////////////////////


nTRANSCEIVER_STATUS = l_synchbreak_done; // STATE: =TS3
////////////////////////////////////////////////////////////////////////
// send synchfield 0x55
ASC_TRANSMIT_BUFFER_REGISTER = LIN_SYNCHFIELD;
}
else
{
nERROR_STATUS |= l_bit_error; // error-handling:
LIN_vDefaultCondition(); // set default values

}
}
#endif
//****************************************************************************
// USER CODE END:void LIN_vReceiveSynch0x00(unsigned char *pucLocalHelpS1RBUF)





//****************************************************************************
// @Function void LIN_vReceiveSynchBreak(uchar *pucLocalHelpS1RBUF)
//
//----------------------------------------------------------------------------
// @Description
// this function handles the receiveing of the synchbreakfield
//----------------------------------------------------------------------------
// @Returnvalue none
//----------------------------------------------------------------------------
// @Parameters pointer uchar: pointer at the received byte
//----------------------------------------------------------------------------
// @Date 06/05/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// nNODE_STATUS
// nTRANSCEIVER_STATUS
// nERROR_STATUS
//----------------------------------------------------------------------------
// @AppNote
// STATE: TS1
// This function was separated from the Rxd-Interrupt-function to get
// a better overview there.
//----------------------------------------------------------------------------
//****************************************************************************
#ifdef SLAVE
void LIN_vReceiveSynchBreak(unsigned char *pucLocalHelpS1RBUF)
{
if(*pucLocalHelpS1RBUF == LIN_SYNCHBREAK)
{
// Loads CapCom and Timer Register and starts Timer and IRQ
// TIME_FRAMEMAX8 is default and will be corrected if the NOD is known
// for this the ID-field must be evaluated.
LIN_vHandleCapCom(TIME_FRAMEMAX8, ZERO);
nNODE_STATUS = l_not_ready_for_synchbreak;

////////////////////////////////////////////////////////////////////////
nTRANSCEIVER_STATUS = l_synchbreak_done; /// STATE: =TS4
////////////////////////////////////////////////////////////////////////

// reset flag, The user should have been read this flag before
ucMessageSent = 0;

// now the master-task has answered, reset the wake-up pending
if(nPENDING_STATUS == l_wakeup_pending)
{
nPENDING_STATUS = l_default_pending;
}
}
else
{
nERROR_STATUS |= l_bit_error; // error-handling:
LIN_vDefaultCondition(); // set default values
}
}
#endif
//****************

************************************************************
// USER CODE END: void LIN_vReceiveSynchBreak(uchar *pucLocalHelpS1RBUF)




//****************************************************************************
// @Function void LIN_vReceiveSynchField(*pucLocalHelpS1RBUF)
//
//----------------------------------------------------------------------------
// @Description
// this function handles the receiveing of the synchfield
//----------------------------------------------------------------------------
// @Returnvalue none
//----------------------------------------------------------------------------
// @Parameters uchar pointer at the received byte
//----------------------------------------------------------------------------
// @Date 06/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
// nTRANSCEIVER_STATUS
// nERROR_STATUS
// stLinTransceiveBuffer[] : The LIN-Transceive-Buffer, this buffer is
// used by the LIN-Functions to send and receive messages. If a message
// should be sent then all data and Id must be saved in this buffer first.
// And if a message has been received, the ID and the data will be saved
// in this buffer, too.
//----------------------------------------------------------------------------
// @AppNote
// STATE: TS4
// This function was separated from the Rxd-Interrupt-function to get
// a better overview there.
//----------------------------------------------------------------------------
//****************************************************************************
void LIN_vReceiveSynchField(unsigned char *pucLocalHelpS1RBUF)
{
// synchbreak done, next byte must be 0x55
// if received byte is the synch-field
if(*pucLocalHelpS1RBUF == LIN_SYNCHFIELD)
{
// set bit-flag that 0x55 has been received
////////////////////////////////////////////////////////////////////////
nTRANSCEIVER_STATUS = l_synchfield_received; // STATE: =TS5
////////////////////////////////////////////////////////////////////////

#ifdef MASTER
// the master-node set the wake-up pending
// now, the master-task has received the synchfield itself
// reset the wake-up pending, the bus should be awake
if(nPENDING_STATUS == l_wakeup_pending)
{
nPENDING_STATUS = l_default_pending;
}
// create the ID-field and send it to the bus
ASC_TRANSMIT_BUFFER_REGISTER = \
LIN_ucCreateID(stLinTransceiveBuffer[BUFFER_1].ucId);
#endif
}
else // if received byte is not the synchfield then
{
nERROR_STATUS |= l_inconsistent_synch_field_error; // set error flag
LIN_vDefaultCondition(); // set default-condition

相关文档
最新文档