Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Esp32HardwareTwai.hxx
Go to the documentation of this file.
1
37#ifndef _FREERTOS_DRIVERS_ESP32_ESP32HARDWARETWAI_HXX_
38#define _FREERTOS_DRIVERS_ESP32_ESP32HARDWARETWAI_HXX_
39
40#include <hal/gpio_types.h>
41#include <soc/soc.h>
42#include <soc/soc_caps.h>
43#include <stdint.h>
44#include <stdio.h>
45#include <unistd.h>
46
47#include "nmranet_config.h"
48#include "utils/Singleton.hxx"
49
50namespace openmrn_arduino
51{
52
54typedef struct
55{
58 uint32_t rx_processed;
59
61 uint32_t rx_missed;
62
64 uint32_t rx_discard;
65
67 uint32_t rx_lost;
68
70 uint32_t rx_overrun;
71
74 uint32_t tx_processed;
75
78 uint32_t tx_success;
79
82 uint32_t tx_failed;
83
85 uint32_t arb_loss;
86
88 uint32_t bus_error;
90
128class Esp32HardwareTwai : public Singleton<Esp32HardwareTwai>
129{
130public:
157 Esp32HardwareTwai(int rx, int tx
158 , bool report = true
159 , size_t rx_buffer_size = config_can_rx_buffer_size()
160 , size_t tx_buffer_size = config_can_tx_buffer_size()
161 , const char *path = "/dev/twai"
162 , int clock_out = GPIO_NUM_NC
163 , int bus_status = GPIO_NUM_NC
164 , uint32_t isr_preferred_core = DEFAULT_ISR_CORE);
165
168
173 void hw_init();
174
180
181private:
184
186 const int rxPin_;
187
189 const int txPin_;
190
192 const int extClockPin_;
193
195 const int busStatusPin_;
196
198 const uint32_t preferredIsrCore_;
199
200#if SOC_CPU_CORES_NUM > 1
202 static constexpr uint32_t DEFAULT_ISR_CORE = APP_CPU_NUM;
203#else
205 static constexpr uint32_t DEFAULT_ISR_CORE = PRO_CPU_NUM;
206#endif // SOC_CPU_CORES_NUM > 1
207
209 const char *vfsPath_;
210
212};
213
214} // namespace openmrn_arduino
215
218
219#endif // _FREERTOS_DRIVERS_ESP32_ESP32HARDWARETWAI_HXX_
Singleton class.
Definition Singleton.hxx:65
ESP32 Hardware TWAI (CAN) driver interface.
const int txPin_
GPIO pin connected to the external transceiver TX pin.
const int busStatusPin_
GPIO pin connected to an external bus status indicator.
const int extClockPin_
GPIO pin that generates an external clock signal.
const uint32_t preferredIsrCore_
Core which the TWAI ISR should be bound to.
Esp32HardwareTwai()
Default constructor.
static constexpr uint32_t DEFAULT_ISR_CORE
Default core for running the TWAI ISR.
const int rxPin_
GPIO pin connected to the external transceiver RX pin.
void get_driver_stats(esp32_twai_stats_t *stats)
Retrieves the current driver statistics.
const char * vfsPath_
VFS Mount point.
void hw_init()
Initializes the TWAI hardware and VFS adapter.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Definition macros.h:171
uint32_t tx_success
Number of frames that have been transmitted successfully by the low-level TWAI driver.
uint32_t rx_overrun
Number of frames that were lost due to RX FIFO overrun.
uint32_t rx_discard
Number of frames that were discarded that had too large of a DLC count.
uint32_t arb_loss
Number of arbitration losses that have been observed on the TWAI bus.
uint32_t rx_processed
Number of frames have been removed from rx_buf and sent to the OpenMRN stack.
uint32_t tx_processed
Number of frames that have been sent to the twai_tx_queue by the OpenMRN stack successfully.
uint32_t bus_error
Number of general bus errors that have been observed on the TWAI bus.
uint32_t rx_missed
Number of frames frames that could not be sent to rx_buf.
uint32_t tx_failed
Number of frames that have been could not be transmitted successfully by the low-level TWAI driver.
uint32_t rx_lost
Number of frames that were lost due to driver reset.