53 #include "cdc-acm/cdc-acm.h"
62 #define PRINTF(...) printf(__VA_ARGS__)
72 static const struct lang_id lang_id = {
sizeof(lang_id), 3, 0x0409 };
79 static struct serial_nr serial_nr = {
82 'A',
'A',
'A',
'A',
'A',
'A',
'A',
'A',
83 'A',
'A',
'A',
'A',
'A',
'A',
'A',
'A'
92 static const struct manufacturer manufacturer = {
96 'T',
'e',
'x',
'a',
's',
' ',
97 'I',
'n',
's',
't',
'r',
'u',
'm',
'e',
'n',
't',
's'
106 static const struct product product = {
110 'c',
'c',
'2',
'5',
'3',
'8',
' ',
111 'S',
'y',
's',
't',
'e',
'm',
'-',
'o',
'n',
'-',
'C',
'h',
'i',
'p'
118 #define RX_BUFFER_SIZE USB_EP3_SIZE
119 #define TX_BUFFER_SIZE (USB_EP2_SIZE - 1)
121 typedef struct _USBBuffer usb_buffer;
123 static usb_buffer data_rx_urb;
124 static usb_buffer data_tx_urb;
125 static uint8_t usb_rx_data[RX_BUFFER_SIZE];
126 static uint8_t enabled = 0;
128 #define SLIP_END 0300
129 static uint8_t usb_tx_data[TX_BUFFER_SIZE];
130 static uint8_t buffered_data = 0;
133 static int (* input_handler)(
unsigned char c);
136 usb_class_get_string_descriptor(uint16_t lang, uint8_t
string)
140 return (uint8_t *)&lang_id;
142 return (uint8_t *)&manufacturer;
144 return (uint8_t *)&product;
146 return (uint8_t *)&serial_nr;
153 set_serial_number(
void)
160 ieee_addr_cpy_to(ieee, 8);
162 for(i = 0; i < 8; i++) {
163 lown = ieee[i] & 0x0F;
164 highn = ieee[i] >> 4;
165 c = lown > 9 ?
'A' + lown - 0xA : lown +
'0';
166 serial_nr.string[i * 2 + 1] = c;
167 c = highn > 9 ?
'A' + highn - 0xA : highn +
'0';
168 serial_nr.string[i * 2] = c;
175 data_rx_urb.flags = USB_BUFFER_PACKET_END;
176 data_rx_urb.flags |= USB_BUFFER_NOTIFY;
177 data_rx_urb.data = usb_rx_data;
178 data_rx_urb.left = RX_BUFFER_SIZE;
179 data_rx_urb.next =
NULL;
180 usb_submit_recv_buffer(EPOUT, &data_rx_urb);
188 events = usb_get_global_events();
189 if(events & USB_EVENT_CONFIG) {
191 usb_setup_bulk_endpoint(EPIN);
192 usb_setup_bulk_endpoint(EPOUT);
196 if(events & USB_EVENT_RESET) {
200 events = usb_cdc_acm_get_events();
201 if(events & USB_CDC_ACM_LINE_STATE) {
202 uint8_t line_state = usb_cdc_acm_get_line_state();
203 PRINTF(
"CDC-ACM event 0x%04x, Line State = %u\n", events, line_state);
204 if(line_state & USB_CDC_ACM_DTE) {
215 events = usb_get_ep_events(EPOUT);
216 if((events & USB_EP_EVENT_NOTIFICATION)
217 && !(data_rx_urb.flags & USB_BUFFER_SUBMITTED)) {
218 if(!(data_rx_urb.flags & USB_BUFFER_FAILED)) {
223 len = RX_BUFFER_SIZE - data_rx_urb.left;
224 for(i = 0; i < len; i++) {
225 input_handler(usb_rx_data[i]);
236 if(buffered_data == 0) {
240 data_tx_urb.flags = USB_BUFFER_SHORT_END;
241 data_tx_urb.flags |= USB_BUFFER_NOTIFY;
242 data_tx_urb.next =
NULL;
243 data_tx_urb.data = usb_tx_data;
244 data_tx_urb.left = buffered_data;
246 usb_submit_xmit_buffer(EPIN, &data_tx_urb);
257 usb_tx_data[buffered_data] = b;
260 if(buffered_data == TX_BUFFER_SIZE) {
265 PROCESS(usb_serial_process,
"USB-Serial process");
276 usb_set_global_event_process(&usb_serial_process);
277 usb_cdc_acm_set_event_process(&usb_serial_process);
278 usb_set_ep_event_process(EPIN, &usb_serial_process);
279 usb_set_ep_event_process(EPOUT, &usb_serial_process);
283 if(ev == PROCESS_EVENT_EXIT) {
286 if(ev == PROCESS_EVENT_POLL) {
297 input_handler = input;
#define PROCESS_BEGIN()
Define the beginning of a process.
void usb_serial_set_input(int(*input)(unsigned char c))
Set an input hook for bytes received over USB.
#define NULL
The null pointer.
Header file with register and macro declarations for the cc2538 IEEE address driver.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
void usb_serial_init()
Initialise the Serial-over-USB process.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PROCESS(name, strname)
Declare a process.
void process_start(struct process *p, process_data_t data)
Start a process.
void usb_serial_flush()
Immediately transmit the content of Serial-over-USB TX buffers.
Header file for the Contiki process interface.
void usb_serial_writeb(uint8_t b)
Write a byte over USB.
Header file for the Rime address representation