![]() |
LIN_master
0.1
Arduino LIN master emulation with preemptive background operation
|
LIN master node base class. More...
#include <LIN_master.h>
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() | |
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.
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
[in] | Baudrate | communication baudrate [Baud]. Default is 19200 Baud |
[in] | Version | LIN version for checksum calculation. Default is LIN_V2 |
[in] | Background | background or blocking operation |
Definition at line 24 of file LIN_master.cpp.
|
protected |
calculate frame checksum
Calculate LIN frame checksum.
Method to calculate the LIN frame checksum as described in LIN2.0 spec
[in] | id | frame ID |
[in] | numData | number of data bytes in frame |
[in] | data | buffer containing data bytes |
Definition at line 109 of file LIN_master.cpp.
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.
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.
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.
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.
|
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"
[in] | id | frame ID (protection optional) |
Definition at line 79 of file LIN_master.cpp.
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.
[in] | id | frame ID (protection optional) |
[in] | numData | number of data bytes (0..8) |
[out] | Rx_handler | callback function to handle received data |
Definition at line 253 of file LIN_master.cpp.
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.
[in] | id | frame ID (protection optional) |
[in] | numData | number of data bytes (0..8) |
[out] | data | buffer to copy data to fater reception |
Definition at line 362 of file LIN_master.cpp.
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.
[in] | id | frame ID (protection optional) |
[in] | numData | number of data bytes (0..8) |
[in] | data | Tx data bytes |
Definition at line 146 of file LIN_master.cpp.