42#include <sys/select.h>
44#include "inc/hw_types.h"
45#include "inc/hw_memmap.h"
46#include "inc/hw_ints.h"
47#include "driverlib/rom.h"
48#include "driverlib/rom_map.h"
49#include "usblib/usblib.h"
50#include "usblib/usbcdc.h"
51#include "usblib/usb-ids.h"
52#include "usblib/device/usbdevice.h"
53#include "usblib/device/usbdcdc.h"
61#define TIVA_USB_PACKET_SIZE 64
66#define TIVA_USB_BUFFER_SIZE (TIVA_USB_PACKET_SIZE * 4)
74 USBShort(USB_LANG_EN_US)
83 'O', 0,
'p', 0,
'e', 0,
'n', 0,
'M', 0,
'R', 0,
'N', 0
92 'V', 0,
'i', 0,
'r', 0,
't', 0,
'u', 0,
'a', 0,
'l', 0,
' ', 0,
93 'C', 0,
'O', 0,
'M', 0,
' ', 0,
'P', 0,
'o', 0,
'r', 0,
't', 0
103 '2', 0,
'2', 0,
'3', 0,
'4', 0,
'5', 0,
'6', 0,
'7', 0,
'8', 0
112 'A', 0,
'C', 0,
'M', 0,
' ', 0,
'C', 0,
'o', 0,
'n', 0,
't', 0,
113 'r', 0,
'o', 0,
'l', 0,
' ', 0,
'I', 0,
'n', 0,
't', 0,
'e', 0,
114 'r', 0,
'f', 0,
'a', 0,
'c', 0,
'e', 0
123 'S', 0,
'e', 0,
'l', 0,
'f', 0,
' ', 0,
'P', 0,
'o', 0,
'w', 0,
124 'e', 0,
'r', 0,
'e', 0,
'd', 0,
' ', 0,
'C', 0,
'o', 0,
'n', 0,
125 'f', 0,
'i', 0,
'g', 0,
'u', 0,
'r', 0,
'a', 0,
't', 0,
'i', 0,
142#define NUM_STRING_DESCRIPTORS (sizeof(stringDescriptors) / sizeof(uint8_t *))
153 , usbdcdcDevice{USB_VID_TI_1CBE, USB_PID_SERIAL, 0, USB_CONF_ATTR_SELF_PWR,
154 control_callback, this, rx_callback, this, tx_callback,
156 , interrupt(interrupt)
161 , lineCoding{115200, USB_CDC_STOP_BITS_1, USB_CDC_PARITY_NONE, 8}
172 USBStackModeSet(0, eUSBModeForceDevice, 0);
198 unsigned char *data = (
unsigned char*)buf;
205 if (file->
flags & O_NONBLOCK)
214 ::select(fd + 1, NULL, &fds, NULL, NULL);
216 portENTER_CRITICAL();
227 if (file->
flags & O_NONBLOCK)
238 ::select(fd + 1, NULL, &fds, NULL, NULL);
264 portENTER_CRITICAL();
307 unsigned long msg_param,
void *msg_data)
313 case USB_EVENT_CONNECTED:
318 case USB_EVENT_DISCONNECTED:
321 case USBD_CDC_EVENT_GET_LINE_CODING:
323 tLineCoding *line_coding = (tLineCoding*)msg_data;
327 case USBD_CDC_EVENT_SET_LINE_CODING:
329 tLineCoding *line_coding = (tLineCoding*)msg_data;
333 case USBD_CDC_EVENT_SET_CONTROL_LINE_STATE:
335 case USBD_CDC_EVENT_SEND_BREAK:
337 case USBD_CDC_EVENT_CLEAR_BREAK:
339 case USB_EVENT_SUSPEND:
341 case USB_EVENT_RESUME:
358 unsigned long msg_param,
void *msg_data)
366 case USB_EVENT_RX_AVAILABLE:
381 case USB_EVENT_DATA_REMAINING:
383 case USB_EVENT_ERROR:
398 unsigned long msg_param,
void *msg_data)
406 case USB_EVENT_TX_COMPLETE:
419 USB0DeviceIntHandler();
420 os_isr_exit_yield_test(
woken);
static CC32xxUart * instances[2]
Instance pointers help us get context from the interrupt handler(s)
static TivaCdc * instances[1]
Instance pointers help us get context from the interrupt handler(s)
const uint8_t controlInterfaceString[]
The configuration interface description string.
#define TIVA_USB_BUFFER_SIZE
This is the size of the RX buffer in bytes.
const uint8_t *const stringDescriptors[]
The descriptor string table.
const uint8_t langDescriptor[]
The languages supported by this device.
const uint8_t manufacturerString[]
The manufacturur string.
const uint8_t productString[]
The product string.
#define TIVA_USB_PACKET_SIZE
This is fixed and equals the USB packet size that the CDC device will advertise to be able to receive...
const uint8_t configString[]
The configuration description string.
#define NUM_STRING_DESCRIPTORS
number of string descriptors
void usb0_interrupt_handler(void)
Handle interrupts for USB0.
const uint8_t serialNumberString[]
The serial number string.
size_t advance(size_t items)
Add a number of items to the buffer by advancing the writeIndex.
size_t pending()
Return the number of items in the queue.
void select_insert()
Add client to list of clients needing woken.
void signal_condition_from_isr()
Signal the wakeup condition from an ISR context.
size_t data_write_pointer(T **buf)
Get a reference to the current location in the buffer for write.
static int fd_lookup(File *file)
Looks up a file descriptor corresponding to a given File reference.
Private data for a serial device.
DeviceBuffer< uint8_t > * rxBuf
receive buffer
Private data for this implementation of serial.
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
bool txPending
true if a transmission is in progress or pending
bool connected
connection status
tUSBDCDCDevice usbdcdcDevice
CDC serial device instance.
SelectInfo selInfoWr
Metadata for select() logic.
uint32_t interrupt
interrupt number for device
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
void enable() override
function to enable device
TivaCdc()
Default constructor.
bool enabled
enabled status
#define FWRITE
Workaround for missing header defines on some newlib versions.
#define FREAD
Workaround for missing header defines on some newlib versions.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
static void select_wakeup_from_isr(SelectInfo *info, int *woken)
Wakeup the list of clients needing woken.
static void select_insert(SelectInfo *info)
Add client to list of clients needing woken.