88 pid = (uint8_t) (pid & 0x3F);
89 tmp = (uint8_t) ((pid ^ (pid>>1) ^ (pid>>2) ^ (pid>>4)) & 0x01);
90 pid |= (uint8_t) (tmp << 6);
91 tmp = (uint8_t) (~((pid>>1) ^ (pid>>3) ^ (pid>>4) ^ (pid>>5)) & 0x01);
92 pid |= (uint8_t) (tmp << 7);
123 for (uint8_t i = 0; i < numData; i++)
125 chk += (uint16_t) (data[i]);
129 chk = (uint8_t)(0xFF - ((uint8_t) chk));
152 #if (LIN_DEBUG_LEVEL >= 1) 156 LIN_DEBUG_SERIAL.print(
".sendMasterRequest(): state != LIN_STATE_IDLE (is ");
176 memcpy(
bufTx+3, data, numData);
182 #if (LIN_DEBUG_LEVEL >= 2) 189 for (uint8_t i=0; i<
lenTx; i++)
203 *UCSRA &= ~(1<<U2X0);
259 #if (LIN_DEBUG_LEVEL >= 1) 263 LIN_DEBUG_SERIAL.print(
".receiveSlaveResponse(): state != LIN_STATE_IDLE (is ");
287 #if (LIN_DEBUG_LEVEL >= 2) 294 for (uint8_t i=0; i<
lenTx; i++)
308 *UCSRA &= ~(1<<U2X0);
341 uint32_t tStart = millis();
384 #if (LIN_DEBUG_LEVEL >= 1) 400 uint32_t tStart = micros();
401 while ((!(
pSerial->available())) && ((micros() - tStart) < 500));
408 #if (LIN_DEBUG_LEVEL >= 1) 422 if (
bufRx[0] != 0x00)
425 #if (LIN_DEBUG_LEVEL >= 1) 442 #if (LIN_DEBUG_LEVEL >= 2) 489 #if (LIN_DEBUG_LEVEL >= 1) 505 uint32_t tStart = micros();
506 while ((
pSerial->available() !=
lenRx-1) && ((micros() - tStart) < 500));
513 #if (LIN_DEBUG_LEVEL >= 1) 514 uint8_t num =
pSerial->available();
540 for (i=1; i<
lenRx; i++)
551 #if (LIN_DEBUG_LEVEL >= 1) 556 for (i=0; i<
lenRx; i++)
568 memset(
bufRx, 0, lenRx);
576 #if (LIN_DEBUG_LEVEL >= 2) 596 #if (LIN_DEBUG_LEVEL >= 1) 613 memset(
bufRx, 0, lenRx);
620 uint8_t
id =
bufRx[2];
621 uint8_t numData = lenRx-4;
622 uint8_t *data =
bufRx+3;
623 uint8_t chk =
bufRx[lenRx-1];
624 uint8_t chk_calc =
checksum(
id, numData, data);
628 #if (LIN_DEBUG_LEVEL >= 1) 638 memset(
bufRx, 0, lenRx);
667 memcpy(
dataPtr, data, numData);
void defaultCallback(uint8_t numData, uint8_t *data)
receive callback function to copy data to buffer
bool flagRxComplete
flag to indicate that data reception is complete. Must be cleared manually
#define LIN_DEBUG_SERIAL
Serial interface used for debug output.
uint8_t checksum(uint8_t id, uint8_t numData, uint8_t *data)
calculate frame checksum
uint8_t lenRx
receive buffer length (max. 12)
void begin(uint16_t Baudrate, LIN_version_t Version, bool Background)
setup UART and LIN framework
error in LIN state machine
LIN_error_t
LIN communication error codes.
LIN_version_t
LIN version of checksum.
uint8_t * dataPtr
pointer to data buffer in LIN_master3_copy()
LIN_error_t receiveSlaveResponse(uint8_t id, uint8_t numData, void(*Rx_handler)(uint8_t, uint8_t *))
receive a slave response frame with callback function
void(* wrapperDefaultCallback)(uint8_t, uint8_t *)
wrapper for default receive callback function
break is being transmitted
uint8_t bufRx[12]
receive buffer incl. SYNC, DATA and CHK (max. 11B)
uint8_t lenTx
send buffer length (max. 12)
Base class for LIN master emulation.
uint8_t durationFrame
duration of frame w/o BREAK [ms]
bool flagTxComplete
flag to indicate that data transmission is complete. Must be cleared manually
void handlerSend(void)
LIN master receive handler for task scheduler.
void end(void)
end UART communication void end(void); //!< end UART communication
no LIN transmission ongoing
void handlerReceive(void)
send handler for task scheduler
LIN_error_t error
error state. Is latched until cleared
uint16_t baudrate
communication baudrate [Baud]
LIN_status_t state
status of LIN state machine
bool background
background or blocking operation
LIN_frame_t frameType
LIN frame type.
uint8_t durationBreak
duration of sync break [ms]
uint8_t protectID(uint8_t id)
calculate protected LIN ID
LIN_version_t version
LIN version for checksum calculation.
void(* wrapperReceive)(void)
wrapper for reception handler (for task scheduler)
LIN_error_t sendMasterRequest(uint8_t id, uint8_t numData, uint8_t *data)
send a master request frame
void(* rx_handler)(uint8_t, uint8_t *)
handler to decode slave response (for receiveFrame())
frame is being transmitted
void(* wrapperSend)(void)
wrapper for transmission handler (for task scheduler)
HardwareSerial * pSerial
pointer to used serial
uint8_t bufTx[12]
send buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)