ESP32-SoftwareLIN
Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
SoftwareLin Class Reference
Inheritance diagram for SoftwareLin:

Public Member Functions

 SoftwareLin (int8_t rxPin, int8_t txPin)
 Construct a new Software Lin object. More...
 
 ~SoftwareLin ()
 Destroy the Software Lin object.
 
void sendBreak (int breakBits=13, int delimiterBits=1)
 Send Break Field and Break Delimiter to the bus. More...
 
bool checkBreak ()
 Check whether there is Break Field sent on the bus. This function blocks until the UART ISR is triggered. After the UART ISR is triggered, this function will check whether break field has been detected. If break field has been detected, this function will return true, otherwise this function will return false. More...
 
uint32_t setAutoBaud (const uint32_t commonBaud[], int commonBaudSize)
 setAutoBaud() is used for automatically detect and set baud rate after the break field has been detected. When setAutoBaud() is called, it's assumed that the Rx pin is receiving a SYNC byte (0x55). setAutoBaud() will detect the baud rate with SYNC byte and set the baud rate to the closest one in commonBaud[]. More...
 
void endFrame ()
 Notify SoftwareLin the LIN frame has ended. This is for SoftwareLin to reset the internal state registers and prepare for next frame.
 
int read (uint8_t *buffer, size_t size)
 Read bytes to buffer. More...
 
size_t write (const uint8_t *buffer, size_t size) override
 Write bytes to the bus. More...
 

Static Protected Member Functions

static void wakeCheckBreak (SoftwareLin *pThis)
 This function wake checkBreak() from blocking. When the UART ISR is triggered, m_isrSem is given so that checkBreak() can take it. Although this is a static function, it is actually std::bind to this. Therefore, this function can be regarded as a non-static member function of an instance. More...
 

Protected Attributes

bool m_inFrame
 Indicate whether SoftwareLin is still processing a frame. Initially, m_inFrame is false. After sendBreak() is executed or detectBreak() is true, m_inFrame is set to true. Only when m_inFrame is true, we can execute read()/write(), otherwise the assertion should failed. When the LIN frame has ended, endFrame() should be executed to reset m_inFrame to false, so that the next LIN frame can be processed.
 
SemaphoreHandle_t m_isrSem
 The semaphore for notifying checkBreak() that the ISR has been triggered.
 
StaticSemaphore_t m_isrSemBuf
 The buffer for static allocation of m_isrSem.
 

Constructor & Destructor Documentation

◆ SoftwareLin()

SoftwareLin::SoftwareLin ( int8_t  rxPin,
int8_t  txPin 
)

Construct a new Software Lin object.

Parameters
rxPinThe designated GPIO pin number of Rx pin
txPinThe designated GPIO pin number of Tx pin

Member Function Documentation

◆ checkBreak()

bool IRAM_ATTR SoftwareLin::checkBreak ( )

Check whether there is Break Field sent on the bus. This function blocks until the UART ISR is triggered. After the UART ISR is triggered, this function will check whether break field has been detected. If break field has been detected, this function will return true, otherwise this function will return false.

Returns
Whether the Break Field has been detected

◆ read()

int SoftwareLin::read ( uint8_t *  buffer,
size_t  size 
)

Read bytes to buffer.

Parameters
bufferThe buffer for the data read
sizeThe number of bytes to read
Returns
(int) The number of that has been successfully read

◆ sendBreak()

void IRAM_ATTR SoftwareLin::sendBreak ( int  breakBits = 13,
int  delimiterBits = 1 
)

Send Break Field and Break Delimiter to the bus.

Parameters
breakBitsNumber of dominant bits in the break field
delimiterBitsNumber of recessive bits in the break delimiter

◆ setAutoBaud()

uint32_t IRAM_ATTR SoftwareLin::setAutoBaud ( const uint32_t  commonBaud[],
int  commonBaudSize 
)

setAutoBaud() is used for automatically detect and set baud rate after the break field has been detected. When setAutoBaud() is called, it's assumed that the Rx pin is receiving a SYNC byte (0x55). setAutoBaud() will detect the baud rate with SYNC byte and set the baud rate to the closest one in commonBaud[].

Parameters
commonBaudcommonBaud The array of common baud rates. When baud rate is detected, setAutoBaud() will set the baud rate to the closest one in commandBaud[]
commonBaudSizecommonBaudSize The size of commonBaud[]
Returns
(uint32_t) The baud rate set by setAutoBaud(). Return 0 if setAutoBaud() failed, and the baud rate will not be changed.

◆ wakeCheckBreak()

void IRAM_ATTR SoftwareLin::wakeCheckBreak ( SoftwareLin pThis)
staticprotected

This function wake checkBreak() from blocking. When the UART ISR is triggered, m_isrSem is given so that checkBreak() can take it. Although this is a static function, it is actually std::bind to this. Therefore, this function can be regarded as a non-static member function of an instance.

Parameters
pThisThe pointer points to the instance of SoftwareLin.

◆ write()

size_t SoftwareLin::write ( const uint8_t *  buffer,
size_t  size 
)
override

Write bytes to the bus.

Parameters
bufferThe buffer for the data write
sizeThe number of bytes to write
Returns
(size_t) The number of that has been successfully write

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