From 100573d2c30750a50c3dfd9f3e7a051dcc987724 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 6 Feb 2011 13:51:08 +0000 Subject: [PATCH] Serial over USB changes, work in progress, the USB demo is not buildable. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2717 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/serial_usb.h | 18 +++++++++------ os/hal/src/serial_usb.c | 26 ++++++++++----------- testhal/STM32/USB_CDC/halconf.h | 2 +- testhal/STM32/USB_CDC/main.c | 40 +++++++++------------------------ 4 files changed, 35 insertions(+), 51 deletions(-) diff --git a/os/hal/include/serial_usb.h b/os/hal/include/serial_usb.h index b75f6fe59..9223c82a3 100644 --- a/os/hal/include/serial_usb.h +++ b/os/hal/include/serial_usb.h @@ -114,10 +114,14 @@ typedef struct { InputQueue iqueue; \ /* Output queue.*/ \ OutputQueue oqueue; \ - /* Input circular buffer.*/ \ - uint8_t ib[SERIAL_USB_BUFFERS_SIZE]; \ - /* Output circular buffer.*/ \ - uint8_t ob[SERIAL_USB_BUFFERS_SIZE]; \ + /* Input buffer 1.*/ \ + uint8_t ib1[SERIAL_USB_BUFFERS_SIZE]; \ + /* Input buffer 2.*/ \ + uint8_t ib2[SERIAL_USB_BUFFERS_SIZE]; \ + /* Output buffer 1.*/ \ + uint8_t ob1[SERIAL_USB_BUFFERS_SIZE]; \ + /* Output buffer 2.*/ \ + uint8_t ob2[SERIAL_USB_BUFFERS_SIZE]; \ /* End of the mandatory fields.*/ \ /* Current configuration data.*/ \ const SerialUSBConfig *config; @@ -164,9 +168,9 @@ extern "C" { void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config); void sduStop(SerialUSBDriver *sdup); bool_t sduRequestsHook(USBDriver *usbp); - void sduDataRequest(USBDriver *usbp, usbep_t ep); - void sduDataAvailable(USBDriver *usbp, usbep_t ep); - void sduInterruptRequest(USBDriver *usbp, usbep_t ep); + void sduDataTransmitted(USBDriver *usbp, usbep_t ep); + void sduDataReceived(USBDriver *usbp, usbep_t ep); + void sduInterruptTransmitted(USBDriver *usbp, usbep_t ep); #ifdef __cplusplus } #endif diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 62a901162..60976eca2 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -206,7 +206,7 @@ void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config) { "invalid state"); sdup->config = config; usbStart(config->usbp, &config->usb_config); - config->usbp->usb_param = sdup; + config->usbp->param = sdup; sdup->state = SDU_READY; chSysUnlock(); } @@ -245,17 +245,17 @@ void sduStop(SerialUSBDriver *sdup) { */ bool_t sduRequestsHook(USBDriver *usbp) { - if ((usbp->usb_setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) { - switch (usbp->usb_setup[1]) { + if ((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) { + switch (usbp->setup[1]) { case CDC_GET_LINE_CODING: - usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL); + usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding)); return TRUE; case CDC_SET_LINE_CODING: - usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL); + usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding)); return TRUE; case CDC_SET_CONTROL_LINE_STATE: /* Nothing to do, there are no control lines.*/ - usbSetupTransfer(usbp, NULL, 0, NULL); + usbSetupTransfer(usbp, NULL, 0); return TRUE; default: return FALSE; @@ -265,12 +265,12 @@ bool_t sduRequestsHook(USBDriver *usbp) { } /** - * @brief Default data request callback. + * @brief Default data transmitted callback. * @details The application must use this function as callback for the IN * data endpoint. */ -void sduDataRequest(USBDriver *usbp, usbep_t ep) { - SerialUSBDriver *sdup = usbp->usb_param; +void sduDataTransmitted(USBDriver *usbp, usbep_t ep) { + SerialUSBDriver *sdup = usbp->param; size_t n; chSysLockFromIsr(); @@ -289,12 +289,12 @@ void sduDataRequest(USBDriver *usbp, usbep_t ep) { } /** - * @brief Default data available callback. + * @brief Default data received callback. * @details The application must use this function as callback for the OUT * data endpoint. */ -void sduDataAvailable(USBDriver *usbp, usbep_t ep) { - SerialUSBDriver *sdup = usbp->usb_param; +void sduDataReceived(USBDriver *usbp, usbep_t ep) { + SerialUSBDriver *sdup = usbp->param; chSysLockFromIsr(); /* Writes to the input queue can only happen when the queue has been @@ -317,7 +317,7 @@ void sduDataAvailable(USBDriver *usbp, usbep_t ep) { * @details The application must use this function as callback for the IN * interrupt endpoint. */ -void sduInterruptRequest(USBDriver *usbp, usbep_t ep) { +void sduInterruptTransmitted(USBDriver *usbp, usbep_t ep) { (void)usbp; (void)ep; diff --git a/testhal/STM32/USB_CDC/halconf.h b/testhal/STM32/USB_CDC/halconf.h index 6700bcad5..0a957f0b9 100644 --- a/testhal/STM32/USB_CDC/halconf.h +++ b/testhal/STM32/USB_CDC/halconf.h @@ -93,7 +93,7 @@ * @brief Enables the SERIAL over USB subsystem. */ #if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__) -#define HAL_USE_SERIAL_USB FALSE +#define HAL_USE_SERIAL_USB TRUE #endif /** diff --git a/testhal/STM32/USB_CDC/main.c b/testhal/STM32/USB_CDC/main.c index 697740526..b55b24892 100644 --- a/testhal/STM32/USB_CDC/main.c +++ b/testhal/STM32/USB_CDC/main.c @@ -32,7 +32,7 @@ /* * USB driver structure. */ -//static SerialUSBDriver SDU1; +static SerialUSBDriver SDU1; /* * USB Device Descriptor. @@ -247,29 +247,11 @@ USBEndpointState ep2state; */ USBEndpointState ep3state; -void sduDataRequest(USBDriver *usbp, usbep_t ep) { - - (void)usbp; - (void)ep; -} - -void sduInterruptRequest(USBDriver *usbp, usbep_t ep) { - - (void)usbp; - (void)ep; -} - -void sduDataAvailable(USBDriver *usbp, usbep_t ep) { - - (void)usbp; - (void)ep; -} - /** * @brief EP1 initialization structure (IN only). */ static const USBEndpointConfig ep1config = { - sduDataRequest, + sduDataTransmitted, NULL, 0x0040, 0x0000, @@ -282,7 +264,7 @@ static const USBEndpointConfig ep1config = { * @brief EP2 initialization structure (IN only). */ static const USBEndpointConfig ep2config = { - sduInterruptRequest, + sduInterruptTransmitted, NULL, 0x0010, 0x0000, @@ -296,7 +278,7 @@ static const USBEndpointConfig ep2config = { */ static const USBEndpointConfig ep3config = { NULL, - sduDataAvailable, + sduDataReceived, 0x0000, 0x0040, EPR_EP_TYPE_BULK | EPR_STAT_TX_DIS | EPR_STAT_RX_VALID, @@ -335,7 +317,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) { /* * Serial over USB driver configuration. */ -#if 0 static const SerialUSBConfig serusbcfg = { &USBD1, { @@ -348,8 +329,8 @@ static const SerialUSBConfig serusbcfg = { DATA_AVAILABLE_EP, INTERRUPT_REQUEST_EP }; -#endif +#if 0 #include "usb_cdc.h" static cdc_linecoding_t linecoding = { {0x00, 0x96, 0x00, 0x00}, /* 38400. */ @@ -375,6 +356,7 @@ bool_t sduRequestsHook(USBDriver *usbp) { } return FALSE; } +#endif USBConfig usbconfig = { usb_event, @@ -405,7 +387,6 @@ static msg_t Thread1(void *arg) { /* * USB CDC loopback thread. */ -#if 0 static WORKING_AREA(waThread2, 256); static msg_t Thread2(void *arg) { SerialUSBDriver *sdup = arg; @@ -422,7 +403,6 @@ static msg_t Thread2(void *arg) { } } } -#endif /* * Application entry point. @@ -442,10 +422,10 @@ int main(void) { /* * Activates the USB driver and then the USB bus pull-up on D+. */ - usbStart(&USBD1, &usbconfig); +// usbStart(&USBD1, &usbconfig); + sduObjectInit(&SDU1); + sduStart(&SDU1, &serusbcfg); palClearPad(GPIOC, GPIOC_USB_DISC); -// sduObjectInit(&SDU1); -// sduStart(&SDU1, &serusbcfg); /* * Activates the serial driver 2 using the driver default configuration. @@ -460,7 +440,7 @@ int main(void) { /* * Creates the USB CDC loopback thread. */ -// chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, &SDU1); + chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, &SDU1); /* * Normal main() thread activity, in this demo it does nothing except