Copy a frame into the TX buffer and transmit This function copies a formatted TX frame into the TX buffer, and the transmit by setting the correct transmit command (e.g. normal, single shot, self RX) in the command register.
Check if certain HAL state flags are set The HAL will maintain a record of the controller's state via a set of flags. These flags are automatically maintained (i.e., set and reset) inside various HAL function calls. This function checks if certain flags are currently set.
Initialize TWAI peripheral and HAL context Sets HAL context, puts TWAI peripheral into reset mode, then sets some registers with default values.
Deinitialize the TWAI peripheral and HAL context Clears any unhandled interrupts and unsets HAL context
Start the TWAI peripheral Start the TWAI peripheral by configuring its operating mode, then exiting reset mode so that the TWAI peripheral can participate in bus activities.
Stop the TWAI peripheral Stop the TWAI peripheral by entering reset mode to stop any bus activity, then setting the operating mode to Listen Only so that REC is frozen.
Get a bit mask of the events that triggered that triggered an interrupt This function should be called at the beginning of an interrupt. This function will do the following: - Read and clear interrupt register - Calculate what events have triggered the interrupt - Respond to low latency interrupt events - Bus off: Change to LOM to freeze TEC/REC. Errata 1 Fix - Recovery complete: Enter reset mode - Clear ECC and ALC so that their interrupts are re-armed - Update HAL state flags based on interrupts that have occurred. - For the ESP32, check for errata conditions. If a HW reset is required, this function will set the TWAI_HAL_EVENT_NEED_PERIPH_RESET event.
Prepare the peripheral for a HW reset Some HW erratas will require the peripheral be reset. This function should be called if twai_hal_get_events() returns the TWAI_HAL_EVENT_NEED_PERIPH_RESET event. Preparing for a reset involves the following: - Checking if a reset will cancel a TX. If so, mark that we need to retry that message after the reset - Save how many RX messages were lost due to this reset - Enter reset mode to stop any the peripheral from receiving any bus activity - Store the regsiter state of the peripheral
Recover the peripheral after a HW reset This should be called after calling twai_hal_prepare_for_reset() and then executing the HW reset. Recovering the peripheral from a HW reset involves the following: - Restoring the previously saved register state - Exiting reset mode to allow receiving of bus activity - Retrying any TX message that was cancelled by the HW reset
Get the value of the TX Error Counter
Get the value of the RX Error Counter
Get the RX message count register
Check if the last transmitted frame was successful
Copy a frame from the RX buffer and release This function copies a frame from the RX buffer, then release the buffer (so that it loads the next frame in the RX FIFO). False is returned under the following conditions: - On the ESP32S2, false is returned if the RX buffer points to an overrun frame - On the ESP32, false is returned if the RX buffer points to the first overrun frame in the RX FIFO
Clear the RX FIFO of overrun frames This function will clear the RX FIFO of overrun frames. The RX message count will return to 0 after calling this function.
Get how many RX messages were lost due to HW reset
Helper functions that can decode what events have been triggered based on the values of the interrupt, status, TEC and REC registers. The HAL context's state flags are also updated based on the events that have triggered.