usb_cdc: Rename interface functions to avoid the term "setup"

Use "ep0" when referring to endpoint0 - don't use "setup" as that can
be confused with the low-level usb setup token.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-09-30 14:09:55 -04:00
parent 50a8efe0a5
commit 6ab16d2407
4 changed files with 32 additions and 33 deletions

View File

@ -12,7 +12,7 @@
#include "generic/usbstd.h" // struct usb_device_descriptor #include "generic/usbstd.h" // struct usb_device_descriptor
#include "generic/usbstd_cdc.h" // struct usb_cdc_header_descriptor #include "generic/usbstd_cdc.h" // struct usb_cdc_header_descriptor
#include "sched.h" // sched_wake_task #include "sched.h" // sched_wake_task
#include "usb_cdc.h" // usb_notify_setup #include "usb_cdc.h" // usb_notify_ep0
// XXX - move to Kconfig // XXX - move to Kconfig
#define CONFIG_USB_VENDOR_ID 0x2341 #define CONFIG_USB_VENDOR_ID 0x2341
@ -300,7 +300,7 @@ static uint_fast8_t usb_xfer_size;
static void static void
usb_do_stall(void) usb_do_stall(void)
{ {
usb_set_stall(); usb_stall_ep0();
usb_state = US_READY; usb_state = US_READY;
} }
@ -314,9 +314,9 @@ usb_state_xfer(void)
xs = USB_CDC_EP0_SIZE; xs = USB_CDC_EP0_SIZE;
int_fast8_t ret; int_fast8_t ret;
if (usb_state == US_SEND) if (usb_state == US_SEND)
ret = usb_send_setup(usb_xfer, xs); ret = usb_send_ep0(usb_xfer, xs);
else else
ret = usb_read_setup(usb_xfer, xs); ret = usb_read_ep0(usb_xfer, xs);
if (ret == xs) { if (ret == xs) {
// Success // Success
usb_xfer += xs; usb_xfer += xs;
@ -324,7 +324,7 @@ usb_state_xfer(void)
if (!usb_xfer_size && xs < USB_CDC_EP0_SIZE) { if (!usb_xfer_size && xs < USB_CDC_EP0_SIZE) {
// Transfer completed successfully // Transfer completed successfully
if (usb_state == US_READ) if (usb_state == US_READ)
usb_send_setup(NULL, 0); usb_send_ep0(NULL, 0);
usb_state = US_READY; usb_state = US_READY;
return; return;
} }
@ -370,7 +370,7 @@ static void
usb_req_set_configuration(struct usb_ctrlrequest *req) usb_req_set_configuration(struct usb_ctrlrequest *req)
{ {
usb_set_configure(); usb_set_configure();
usb_send_setup(NULL, 0); usb_send_ep0(NULL, 0);
usb_notify_bulk_in(); usb_notify_bulk_in();
} }
@ -395,14 +395,14 @@ usb_req_get_line_coding(struct usb_ctrlrequest *req)
static void static void
usb_req_line_state(struct usb_ctrlrequest *req) usb_req_line_state(struct usb_ctrlrequest *req)
{ {
usb_send_setup(NULL, 0); usb_send_ep0(NULL, 0);
} }
static void static void
usb_state_ready(void) usb_state_ready(void)
{ {
struct usb_ctrlrequest req; struct usb_ctrlrequest req;
int_fast8_t ret = usb_read_setup(&req, sizeof(req)); int_fast8_t ret = usb_read_ep0(&req, sizeof(req));
if (ret != sizeof(req)) if (ret != sizeof(req))
// XXX - should verify that packet was sent with a setup token // XXX - should verify that packet was sent with a setup token
return; return;
@ -418,18 +418,18 @@ usb_state_ready(void)
} }
// State tracking dispatch // State tracking dispatch
static struct task_wake usb_setup_wake; static struct task_wake usb_ep0_wake;
void void
usb_notify_setup(void) usb_notify_ep0(void)
{ {
sched_wake_task(&usb_setup_wake); sched_wake_task(&usb_ep0_wake);
} }
void void
usb_setup_task(void) usb_ep0_task(void)
{ {
if (!sched_check_wake(&usb_setup_wake)) if (!sched_check_wake(&usb_ep0_wake))
return; return;
switch (usb_state) { switch (usb_state) {
case US_READY: usb_state_ready(); break; case US_READY: usb_state_ready(); break;
@ -437,12 +437,12 @@ usb_setup_task(void)
case US_READ: usb_state_xfer(); break; case US_READ: usb_state_xfer(); break;
} }
} }
DECL_TASK(usb_setup_task); DECL_TASK(usb_ep0_task);
void void
usb_shutdown(void) usb_shutdown(void)
{ {
usb_notify_bulk_in(); usb_notify_bulk_in();
usb_notify_setup(); usb_notify_ep0();
} }
DECL_SHUTDOWN(usb_shutdown); DECL_SHUTDOWN(usb_shutdown);

View File

@ -14,16 +14,15 @@ enum {
// callbacks provided by board specific code // callbacks provided by board specific code
int_fast8_t usb_read_bulk_out(void *data, uint_fast8_t max_len); int_fast8_t usb_read_bulk_out(void *data, uint_fast8_t max_len);
int_fast8_t usb_send_bulk_in(void *data, uint_fast8_t len); int_fast8_t usb_send_bulk_in(void *data, uint_fast8_t len);
int_fast8_t usb_read_setup(void *data, uint_fast8_t max_len); int_fast8_t usb_read_ep0(void *data, uint_fast8_t max_len);
int_fast8_t usb_send_setup(const void *data, uint_fast8_t len); int_fast8_t usb_send_ep0(const void *data, uint_fast8_t len);
void usb_send_pgm_setup(void *data, uint_fast8_t len); void usb_stall_ep0(void);
void usb_set_stall(void);
void usb_set_address(uint_fast8_t addr); void usb_set_address(uint_fast8_t addr);
void usb_set_configure(void); void usb_set_configure(void);
// usb_cdc.c // usb_cdc.c
void usb_notify_bulk_in(void); void usb_notify_bulk_in(void);
void usb_notify_bulk_out(void); void usb_notify_bulk_out(void);
void usb_notify_setup(void); void usb_notify_ep0(void);
#endif // usb_cdc.h #endif // usb_cdc.h

View File

@ -8,7 +8,7 @@
#include "LPC17xx.h" // LPC_SC #include "LPC17xx.h" // LPC_SC
#include "byteorder.h" // cpu_to_le32 #include "byteorder.h" // cpu_to_le32
#include "command.h" // output #include "command.h" // output
#include "generic/usb_cdc.h" // usb_notify_setup #include "generic/usb_cdc.h" // usb_notify_ep0
#include "internal.h" // gpio_peripheral #include "internal.h" // gpio_peripheral
#include "sched.h" // DECL_INIT #include "sched.h" // DECL_INIT
#include "usb_cdc_ep.h" // USB_CDC_EP_BULK_IN #include "usb_cdc_ep.h" // USB_CDC_EP_BULK_IN
@ -184,19 +184,19 @@ usb_send_bulk_in(void *data, uint_fast8_t len)
} }
int_fast8_t int_fast8_t
usb_read_setup(void *data, uint_fast8_t max_len) usb_read_ep0(void *data, uint_fast8_t max_len)
{ {
return usb_read_packet(EP0OUT, data, max_len); return usb_read_packet(EP0OUT, data, max_len);
} }
int_fast8_t int_fast8_t
usb_send_setup(const void *data, uint_fast8_t len) usb_send_ep0(const void *data, uint_fast8_t len)
{ {
return usb_write_packet(EP0IN, data, len); return usb_write_packet(EP0IN, data, len);
} }
void void
usb_set_stall(void) usb_stall_ep0(void)
{ {
usb_irq_disable(); usb_irq_disable();
sie_cmd_write(SIE_CMD_SET_ENDPOINT_STATUS | 0, (1<<7)); sie_cmd_write(SIE_CMD_SET_ENDPOINT_STATUS | 0, (1<<7));
@ -209,7 +209,7 @@ usb_set_address(uint_fast8_t addr)
usb_irq_disable(); usb_irq_disable();
sie_cmd_write(SIE_CMD_SET_ADDRESS, addr | (1<<7)); sie_cmd_write(SIE_CMD_SET_ADDRESS, addr | (1<<7));
usb_irq_enable(); usb_irq_enable();
usb_send_setup(NULL, 0); usb_send_ep0(NULL, 0);
} }
static void static void
@ -279,11 +279,11 @@ USB_IRQHandler(void)
uint32_t ueis = LPC_USB->USBEpIntSt; uint32_t ueis = LPC_USB->USBEpIntSt;
if (ueis & (1<<EP0OUT)) { if (ueis & (1<<EP0OUT)) {
sie_select_and_clear(EP0OUT); sie_select_and_clear(EP0OUT);
usb_notify_setup(); usb_notify_ep0();
} }
if (ueis & (1<<EP0IN)) { if (ueis & (1<<EP0IN)) {
sie_select_and_clear(EP0IN); sie_select_and_clear(EP0IN);
usb_notify_setup(); usb_notify_ep0();
} }
if (ueis & (1<<EP2OUT)) { if (ueis & (1<<EP2OUT)) {
sie_select_and_clear(EP2OUT); sie_select_and_clear(EP2OUT);

View File

@ -6,7 +6,7 @@
#include <string.h> // memcpy #include <string.h> // memcpy
#include "board/io.h" // readl #include "board/io.h" // readl
#include "board/usb_cdc.h" // usb_notify_setup #include "board/usb_cdc.h" // usb_notify_ep0
#include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN #include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN
#include "internal.h" // enable_pclock #include "internal.h" // enable_pclock
#include "samd21.h" // USB #include "samd21.h" // USB
@ -122,19 +122,19 @@ usb_send_bulk_in(void *data, uint_fast8_t len)
} }
int_fast8_t int_fast8_t
usb_read_setup(void *data, uint_fast8_t max_len) usb_read_ep0(void *data, uint_fast8_t max_len)
{ {
return usb_read_packet(0, 0, data, max_len); return usb_read_packet(0, 0, data, max_len);
} }
int_fast8_t int_fast8_t
usb_send_setup(const void *data, uint_fast8_t len) usb_send_ep0(const void *data, uint_fast8_t len)
{ {
return usb_write_packet(0, 1, data, len); return usb_write_packet(0, 1, data, len);
} }
void void
usb_set_stall(void) usb_stall_ep0(void)
{ {
EP0.EPSTATUSSET.reg = USB_DEVICE_EPSTATUS_STALLRQ(3); EP0.EPSTATUSSET.reg = USB_DEVICE_EPSTATUS_STALLRQ(3);
} }
@ -145,7 +145,7 @@ void
usb_set_address(uint_fast8_t addr) usb_set_address(uint_fast8_t addr)
{ {
writeb(&set_address, addr | USB_DEVICE_DADD_ADDEN); writeb(&set_address, addr | USB_DEVICE_DADD_ADDEN);
usb_send_setup(NULL, 0); usb_send_ep0(NULL, 0);
} }
void void
@ -212,7 +212,7 @@ USB_Handler(void)
USB->DEVICE.DADD.reg = set_address; USB->DEVICE.DADD.reg = set_address;
set_address = 0; set_address = 0;
} }
usb_notify_setup(); usb_notify_ep0();
} }
if (ep & (1<<USB_CDC_EP_BULK_OUT)) { if (ep & (1<<USB_CDC_EP_BULK_OUT)) {
uint8_t sts = EP_BULKOUT.EPINTFLAG.reg; uint8_t sts = EP_BULKOUT.EPINTFLAG.reg;