Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TivaDev.hxx
Go to the documentation of this file.
1
34#ifndef _FREERTOS_DRIVERS_TI_TIVADEV_HXX_
35#define _FREERTOS_DRIVERS_TI_TIVADEV_HXX_
36
37#ifndef gcc
38#define gcc
39#endif
40
41#include <cstdint>
42
43#include "driverlib/rom.h"
44#include "driverlib/rom_map.h"
45#include "driverlib/interrupt.h"
46#include "driverlib/timer.h"
47#include "driverlib/uart.h"
48#include "usblib/usblib.h"
49#include "usblib/usbcdc.h"
50#include "usblib/usb-ids.h"
51#include "usblib/device/usbdevice.h"
52#include "usblib/device/usbdcdc.h"
53
54#include "Serial.hxx"
55#include "Can.hxx"
56#include "I2C.hxx"
57
60class TivaCdc : public Serial
61{
62public:
67 TivaCdc(const char *name, uint32_t interrupt);
68
72 {
73 }
74
78 void interrupt_handler();
79
80private:
87 ssize_t write(File *file, const void *buf, size_t count) OVERRIDE;
88
95 bool select(File* file, int mode) OVERRIDE;
96
97 void enable() override;
98 void disable() override;
103
112 static uint32_t control_callback(void *data, unsigned long event,
113 unsigned long msg_param, void *msg_data);
114
123 static uint32_t rx_callback(void *data, unsigned long event,
124 unsigned long msg_param, void *msg_data);
125
134 static uint32_t tx_callback(void *data, unsigned long event,
135 unsigned long msg_param, void *msg_data);
136
137 tUSBDCDCDevice usbdcdcDevice;
138 uint32_t interrupt;
140 bool enabled;
141 int woken;
143 tLineCoding lineCoding;
149
151};
152
155class TivaUart : public Serial
156{
157public:
160 enum Mode
161 {
162 CS5 = UART_CONFIG_WLEN_5,
163 CS6 = UART_CONFIG_WLEN_6,
164 CS7 = UART_CONFIG_WLEN_7,
165 CS8 = UART_CONFIG_WLEN_8,
166 CSTOPB = UART_CONFIG_STOP_TWO,
167 };
168
170 typedef void (*TxEnableMethod)();
171
182 TivaUart(const char *name, unsigned long base, uint32_t interrupt,
183 uint32_t baud = 115200, uint32_t mode = CS8, bool hw_fifo = true,
184 TxEnableMethod tx_enable_assert = nullptr,
185 TxEnableMethod tx_enable_deassert = nullptr);
186
190 {
191 }
192
196 void interrupt_handler();
197
200 int ioctl(File *file, unsigned long int key, unsigned long data) override;
201
202private:
203 void enable() override;
204 void disable() override;
208 void tx_char() override;
209
212 void send();
213
215 void set_mode();
216
219
222
225
226 uint32_t base_;
227 uint32_t interrupt_ : 8;
228 uint32_t baud_ : 24;
229 uint8_t hwFIFO_;
230 uint8_t uartMode_;
231 uint8_t txPending_;
232 uint8_t nineBit_;
237
239};
240
243class TivaCan : public Can
244{
245public:
251 TivaCan(const char *name, unsigned long base, uint32_t interrupt);
252
256 {
257 }
258
262 void interrupt_handler();
263
269 int ioctl(File *file, unsigned long int key, unsigned long data) override;
270
271private:
272 void enable() override;
273 void disable() override;
274 void tx_msg() override;
276 unsigned long base;
277 unsigned long interrupt;
279 uint8_t canState;
283
285};
286
289class TivaI2C : public I2C
290{
291public:
298 TivaI2C(const char *name, unsigned long base, uint32_t interrupt,
299 bool fast_mode = false);
300
304 {
305 }
306
310 void interrupt_handler();
311
312private:
313 void enable() OVERRIDE {}
314 void disable() OVERRIDE {}
321 int transfer(struct i2c_msg *msg, bool stop) OVERRIDE;
322
323 unsigned long base;
324 unsigned long interrupt;
325 struct i2c_msg *msg_;
326 bool stop_;
327 int count_;
331
335
337};
338
339#endif /* _FREERTOS_DRIVERS_TI_TIVADEV_HXX_ */
Base class for a CAN device for the Arduino environment.
const char * name
device name
Definition Devtab.hxx:266
Private data for an I2C device.
Definition I2C.hxx:51
An object that can schedule itself on an executor to run.
This class provides a counting semaphore API.
Definition OS.hxx:243
Private data for a serial device.
Definition Serial.hxx:46
Specialization of CAN driver for Tiva CAN.
Definition TivaDev.hxx:244
int ioctl(File *file, unsigned long int key, unsigned long data) override
Request an ioctl transaction.
Definition TivaCan.cxx:121
unsigned long interrupt
interrupt of this device
Definition TivaDev.hxx:277
void interrupt_handler()
handle an interrupt.
Definition TivaCan.cxx:194
uint8_t canState
current state of the CAN-bus.
Definition TivaDev.hxx:279
unsigned long base
base address of this device
Definition TivaDev.hxx:276
void enable() override
function to enable device
Definition TivaCan.cxx:133
~TivaCan()
Destructor.
Definition TivaDev.hxx:255
bool txPending
transmission currently pending
Definition TivaDev.hxx:278
void tx_msg() override
function to try and transmit a message
Definition TivaCan.cxx:156
TivaCan()
Default constructor.
void disable() override
function to disable device
Definition TivaCan.cxx:147
Private data for this implementation of serial.
Definition TivaDev.hxx:61
void interrupt_handler()
handle an interrupt.
static uint32_t control_callback(void *data, unsigned long event, unsigned long msg_param, void *msg_data)
Handles CDC driver notifications related to control and setup of the device.
int woken
task woken metadata for ISR
Definition TivaDev.hxx:141
void tx_char() OVERRIDE
Function to try and transmit a character.
Definition TivaDev.hxx:102
bool txPending
true if a transmission is in progress or pending
Definition TivaDev.hxx:142
bool connected
connection status
Definition TivaDev.hxx:139
tUSBDCDCDevice usbdcdcDevice
CDC serial device instance.
Definition TivaDev.hxx:137
SelectInfo selInfoWr
Metadata for select() logic.
Definition TivaDev.hxx:144
uint32_t interrupt
interrupt number for device
Definition TivaDev.hxx:138
ssize_t write(File *file, const void *buf, size_t count) OVERRIDE
Write to a file or device.
bool select(File *file, int mode) OVERRIDE
Device select method.
static uint32_t tx_callback(void *data, unsigned long event, unsigned long msg_param, void *msg_data)
Handles CDC driver notifications related to transmission.
static uint32_t rx_callback(void *data, unsigned long event, unsigned long msg_param, void *msg_data)
Handles CDC driver notifications related to reception.
void disable() override
function to disable device
tLineCoding lineCoding
line encoding for the device
Definition TivaDev.hxx:143
~TivaCdc()
Destructor.
Definition TivaDev.hxx:71
void enable() override
function to enable device
TivaCdc()
Default constructor.
bool enabled
enabled status
Definition TivaDev.hxx:140
Specialization of Serial driver for Tiva UART.
Definition TivaDev.hxx:290
bool stop_
current transaction ends in a stop if true
Definition TivaDev.hxx:326
void disable() OVERRIDE
function to disable device
Definition TivaDev.hxx:314
struct i2c_msg * msg_
message for current transaction
Definition TivaDev.hxx:325
TivaI2C()
Default constructor.
int count_
current count index within transaction
Definition TivaDev.hxx:327
OSSem sem
Semaphore to wakeup task level from ISR.
Definition TivaDev.hxx:330
unsigned long interrupt
interrupt of this device
Definition TivaDev.hxx:324
~TivaI2C()
Destructor.
Definition TivaDev.hxx:303
int transfer(struct i2c_msg *msg, bool stop) OVERRIDE
Method to transmit/receive the data.
Definition TivaI2C.cxx:118
void interrupt_handler()
handle an interrupt.
Definition TivaI2C.cxx:177
unsigned long base
base address of this device
Definition TivaDev.hxx:323
void enable() OVERRIDE
function to enable device
Definition TivaDev.hxx:313
Specialization of Serial driver for Tiva UART.
Definition TivaDev.hxx:156
uint8_t nineBit_
true if using 9-bit reception
Definition TivaDev.hxx:232
void(* TxEnableMethod)()
Function point for the tx enable assert and deassert methods.
Definition TivaDev.hxx:170
uint8_t hwFIFO_
enable HW FIFO
Definition TivaDev.hxx:229
void tx_char() override
Try and transmit a message.
Definition TivaUart.cxx:189
void disable() override
function to disable device
Definition TivaUart.cxx:149
void interrupt_handler()
handle an interrupt.
Definition TivaUart.cxx:208
void send()
Send data until there is no more space left.
Definition TivaUart.cxx:157
Mode
These mode bits need to be OR-ed together for the mode argument and ioctl.
Definition TivaDev.hxx:161
@ CSTOPB
send two stop bits instead of 1
Definition TivaDev.hxx:166
@ CS7
7-bits word length
Definition TivaDev.hxx:164
@ CS5
5-bits word length
Definition TivaDev.hxx:162
@ CS6
6-bits word length
Definition TivaDev.hxx:163
@ CS8
8-bits word length
Definition TivaDev.hxx:165
~TivaUart()
Destructor.
Definition TivaDev.hxx:189
uint8_t uartMode_
uart config (mode) flags
Definition TivaDev.hxx:230
void set_mode()
Sets the port baud rate and mode from the class variables.
Definition TivaUart.cxx:283
void enable() override
function to enable device
Definition TivaUart.cxx:133
uint32_t baud_
desired baud rate
Definition TivaDev.hxx:228
TxEnableMethod txEnableAssert_
function pointer to a method that asserts the transmit enable.
Definition TivaDev.hxx:218
uint32_t interrupt_
interrupt of this device
Definition TivaDev.hxx:227
TxEnableMethod txEnableDeassert_
function pointer to a method that deasserts the transmit enable.
Definition TivaDev.hxx:221
uint32_t base_
base address of this device
Definition TivaDev.hxx:226
TivaUart()
Default constructor.
int ioctl(File *file, unsigned long int key, unsigned long data) override
Request an ioctl transaction.
Definition TivaUart.cxx:294
Notifiable * txComplete_
Notifiable to invoke when the transmit engine has finished operation.
Definition TivaDev.hxx:224
uint8_t txPending_
transmission currently pending
Definition TivaDev.hxx:231
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
Definition macros.h:180
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Definition macros.h:171
Select wakeup information.
Definition Devtab.hxx:491
File information.
Definition Devtab.hxx:52