LIN_master  0.1
Arduino LIN master emulation with preemptive background operation
LIN_Master Class Reference

LIN master node base class. More...

#include <LIN_master.h>

Inheritance diagram for LIN_Master:
LIN_Master_0 LIN_Master_1 LIN_Master_2 LIN_Master_3

Public Member Functions

void begin (uint16_t Baudrate, LIN_version_t Version, bool Background)
 setup UART and LIN framework More...
 
void end (void)
 end UART communication void end(void); //!< end UART communication More...
 
LIN_error_t sendMasterRequest (uint8_t id, uint8_t numData, uint8_t *data)
 send a master request frame More...
 
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 More...
 
LIN_error_t receiveSlaveResponse (uint8_t id, uint8_t numData, uint8_t *data)
 receive a slave response frame and copy to buffer More...
 
void handlerSend (void)
 LIN master receive handler for task scheduler. More...
 
void handlerReceive (void)
 send handler for task scheduler More...
 
void defaultCallback (uint8_t numData, uint8_t *data)
 receive callback function to copy data to buffer More...
 

Data Fields

bool flagTxComplete
 flag to indicate that data transmission is complete. Must be cleared manually
 
bool flagRxComplete
 flag to indicate that data reception is complete. Must be cleared manually
 
LIN_error_t error
 error state. Is latched until cleared
 

Protected Member Functions

uint8_t protectID (uint8_t id)
 calculate protected LIN ID More...
 
uint8_t checksum (uint8_t id, uint8_t numData, uint8_t *data)
 calculate frame checksum More...
 

Protected Attributes

HardwareSerial * pSerial
 pointer to used serial
 
void(* wrapperSend )(void)
 wrapper for transmission handler (for task scheduler)
 
void(* wrapperReceive )(void)
 wrapper for reception handler (for task scheduler)
 
void(* wrapperDefaultCallback )(uint8_t, uint8_t *)
 wrapper for default receive callback function
 
uint16_t baudrate
 communication baudrate [Baud]
 
LIN_version_t version
 LIN version for checksum calculation.
 
bool background
 background or blocking operation
 
uint8_t durationBreak
 duration of sync break [ms]
 
LIN_frame_t frameType
 LIN frame type.
 
uint8_t bufTx [12]
 send buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)
 
uint8_t lenTx
 send buffer length (max. 12)
 
uint8_t bufRx [12]
 receive buffer incl. SYNC, DATA and CHK (max. 11B)
 
uint8_t lenRx
 receive buffer length (max. 12)
 
uint8_t durationFrame
 duration of frame w/o BREAK [ms]
 
LIN_status_t state
 status of LIN state machine
 
void(* rx_handler )(uint8_t, uint8_t *)
 handler to decode slave response (for receiveFrame())
 
uint8_t * dataPtr
 pointer to data buffer in LIN_master3_copy()
 

Detailed Description

LIN master node base class.

LIN master node base class. From this class the actual LIN classes for a Serialx are derived.

Definition at line 104 of file LIN_master.h.

Member Function Documentation

◆ begin()

void LIN_Master::begin ( uint16_t  Baudrate = 19200,
LIN_version_t  Version = LIN_V2,
bool  Background = true 
)

setup UART and LIN framework

Setup library for LIN communication.

Create an instance of LIN master, configure UART and store bus parameters. For an explanation of the LIN bus and protocol e.g. see https://en.wikipedia.org/wiki/Local_Interconnect_Network

Parameters
[in]Baudratecommunication baudrate [Baud]. Default is 19200 Baud
[in]VersionLIN version for checksum calculation. Default is LIN_V2
[in]Backgroundbackground or blocking operation
Examples:
dual_LIN.ino, LIN_background.ino, LIN_blocking.ino, and LIN_callback.ino.

Definition at line 24 of file LIN_master.cpp.

◆ checksum()

uint8_t LIN_Master::checksum ( uint8_t  id,
uint8_t  numData,
uint8_t *  data 
)
protected

calculate frame checksum

Calculate LIN frame checksum.

Method to calculate the LIN frame checksum as described in LIN2.0 spec

Parameters
[in]idframe ID
[in]numDatanumber of data bytes in frame
[in]databuffer containing data bytes
Returns
calculated frame checksum

Definition at line 109 of file LIN_master.cpp.

◆ defaultCallback()

void LIN_Master::defaultCallback ( uint8_t  numData,
uint8_t *  data 
)

receive callback function to copy data to buffer

Receive handler to copy data to buffer.

Dummy receive handler for receiveSlaveResponse() to copy data to a specified buffer. array pointer must be stored in dataPtr before calling

Definition at line 664 of file LIN_master.cpp.

◆ end()

void LIN_Master::end ( void  )

end UART communication void end(void); //!< end UART communication

Close serial communication.

Close serial communication, reset internal status

Definition at line 57 of file LIN_master.cpp.

◆ handlerReceive()

void LIN_Master::handlerReceive ( void  )

send handler for task scheduler

Handler for LIN_master3 transmission.

Handler for LIN_master3 transmission. This wrapper is required for task scheduler access to non-static member functions and class variables.

Definition at line 481 of file LIN_master.cpp.

◆ handlerSend()

void LIN_Master::handlerSend ( void  )

LIN master receive handler for task scheduler.

Handler for LIN master transmission.

send handler for task scheduler

Handler for LIN master transmission. Here the remainder of the frame after sync break is sent.

Definition at line 378 of file LIN_master.cpp.

◆ protectID()

uint8_t LIN_Master::protectID ( uint8_t  id)
protected

calculate protected LIN ID

Calculate protected LIN ID.

Method to calculate the protected LIN identifier as described in LIN2.0 spec "2.3.1.3 Protected identifier field"

Parameters
[in]idframe ID (protection optional)
Returns
protected LIN identifier

Definition at line 79 of file LIN_master.cpp.

◆ receiveSlaveResponse() [1/2]

LIN_error_t LIN_Master::receiveSlaveResponse ( uint8_t  id,
uint8_t  numData,
void(*)(uint8_t, uint8_t *)  Rx_handler 
)

receive a slave response frame with callback function

Receive slave response frame with callback function.

Receive a slave response and use callback function for handling received data. Actual transmission is handled by task scheduler for background operation. For an explanation of the LIN bus and protocoll e.g. see https://en.wikipedia.org/wiki/Local_Interconnect_Network.

Parameters
[in]idframe ID (protection optional)
[in]numDatanumber of data bytes (0..8)
[out]Rx_handlercallback function to handle received data
Examples:
LIN_background.ino, LIN_blocking.ino, and LIN_callback.ino.

Definition at line 253 of file LIN_master.cpp.

◆ receiveSlaveResponse() [2/2]

LIN_error_t LIN_Master::receiveSlaveResponse ( uint8_t  id,
uint8_t  numData,
uint8_t *  data 
)

receive a slave response frame and copy to buffer

Receive slave response frame and copy to buffer.

Receive a slave response and copy received data to specified buffer after reception. Actual transmission is handled by task scheduler for background operation. For an explanation of the LIN bus and protocoll e.g. see https://en.wikipedia.org/wiki/Local_Interconnect_Network.

Parameters
[in]idframe ID (protection optional)
[in]numDatanumber of data bytes (0..8)
[out]databuffer to copy data to fater reception

Definition at line 362 of file LIN_master.cpp.

◆ sendMasterRequest()

LIN_error_t LIN_Master::sendMasterRequest ( uint8_t  id,
uint8_t  numData,
uint8_t *  data 
)

send a master request frame

send a master request frame.

Send a master request frame. Actual transmission is handled by task scheduler for background operation. For an explanation of the LIN bus and protocoll e.g. see https://en.wikipedia.org/wiki/Local_Interconnect_Network.

Parameters
[in]idframe ID (protection optional)
[in]numDatanumber of data bytes (0..8)
[in]dataTx data bytes
Examples:
dual_LIN.ino, LIN_background.ino, LIN_blocking.ino, and LIN_callback.ino.

Definition at line 146 of file LIN_master.cpp.


The documentation for this class was generated from the following files: