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
master
gdisirio 2011-02-06 13:51:08 +00:00
parent 18853dba22
commit 100573d2c3
4 changed files with 35 additions and 51 deletions

View File

@ -114,10 +114,14 @@ typedef struct {
InputQueue iqueue; \ InputQueue iqueue; \
/* Output queue.*/ \ /* Output queue.*/ \
OutputQueue oqueue; \ OutputQueue oqueue; \
/* Input circular buffer.*/ \ /* Input buffer 1.*/ \
uint8_t ib[SERIAL_USB_BUFFERS_SIZE]; \ uint8_t ib1[SERIAL_USB_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \ /* Input buffer 2.*/ \
uint8_t ob[SERIAL_USB_BUFFERS_SIZE]; \ 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.*/ \ /* End of the mandatory fields.*/ \
/* Current configuration data.*/ \ /* Current configuration data.*/ \
const SerialUSBConfig *config; const SerialUSBConfig *config;
@ -164,9 +168,9 @@ extern "C" {
void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config); void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config);
void sduStop(SerialUSBDriver *sdup); void sduStop(SerialUSBDriver *sdup);
bool_t sduRequestsHook(USBDriver *usbp); bool_t sduRequestsHook(USBDriver *usbp);
void sduDataRequest(USBDriver *usbp, usbep_t ep); void sduDataTransmitted(USBDriver *usbp, usbep_t ep);
void sduDataAvailable(USBDriver *usbp, usbep_t ep); void sduDataReceived(USBDriver *usbp, usbep_t ep);
void sduInterruptRequest(USBDriver *usbp, usbep_t ep); void sduInterruptTransmitted(USBDriver *usbp, usbep_t ep);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -206,7 +206,7 @@ void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config) {
"invalid state"); "invalid state");
sdup->config = config; sdup->config = config;
usbStart(config->usbp, &config->usb_config); usbStart(config->usbp, &config->usb_config);
config->usbp->usb_param = sdup; config->usbp->param = sdup;
sdup->state = SDU_READY; sdup->state = SDU_READY;
chSysUnlock(); chSysUnlock();
} }
@ -245,17 +245,17 @@ void sduStop(SerialUSBDriver *sdup) {
*/ */
bool_t sduRequestsHook(USBDriver *usbp) { bool_t sduRequestsHook(USBDriver *usbp) {
if ((usbp->usb_setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) { if ((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) {
switch (usbp->usb_setup[1]) { switch (usbp->setup[1]) {
case CDC_GET_LINE_CODING: case CDC_GET_LINE_CODING:
usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL); usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding));
return TRUE; return TRUE;
case CDC_SET_LINE_CODING: case CDC_SET_LINE_CODING:
usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding), NULL); usbSetupTransfer(usbp, (uint8_t *)&linecoding, sizeof(linecoding));
return TRUE; return TRUE;
case CDC_SET_CONTROL_LINE_STATE: case CDC_SET_CONTROL_LINE_STATE:
/* Nothing to do, there are no control lines.*/ /* Nothing to do, there are no control lines.*/
usbSetupTransfer(usbp, NULL, 0, NULL); usbSetupTransfer(usbp, NULL, 0);
return TRUE; return TRUE;
default: default:
return FALSE; 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 * @details The application must use this function as callback for the IN
* data endpoint. * data endpoint.
*/ */
void sduDataRequest(USBDriver *usbp, usbep_t ep) { void sduDataTransmitted(USBDriver *usbp, usbep_t ep) {
SerialUSBDriver *sdup = usbp->usb_param; SerialUSBDriver *sdup = usbp->param;
size_t n; size_t n;
chSysLockFromIsr(); 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 * @details The application must use this function as callback for the OUT
* data endpoint. * data endpoint.
*/ */
void sduDataAvailable(USBDriver *usbp, usbep_t ep) { void sduDataReceived(USBDriver *usbp, usbep_t ep) {
SerialUSBDriver *sdup = usbp->usb_param; SerialUSBDriver *sdup = usbp->param;
chSysLockFromIsr(); chSysLockFromIsr();
/* Writes to the input queue can only happen when the queue has been /* 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 * @details The application must use this function as callback for the IN
* interrupt endpoint. * interrupt endpoint.
*/ */
void sduInterruptRequest(USBDriver *usbp, usbep_t ep) { void sduInterruptTransmitted(USBDriver *usbp, usbep_t ep) {
(void)usbp; (void)usbp;
(void)ep; (void)ep;

View File

@ -93,7 +93,7 @@
* @brief Enables the SERIAL over USB subsystem. * @brief Enables the SERIAL over USB subsystem.
*/ */
#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__) #if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
#define HAL_USE_SERIAL_USB FALSE #define HAL_USE_SERIAL_USB TRUE
#endif #endif
/** /**

View File

@ -32,7 +32,7 @@
/* /*
* USB driver structure. * USB driver structure.
*/ */
//static SerialUSBDriver SDU1; static SerialUSBDriver SDU1;
/* /*
* USB Device Descriptor. * USB Device Descriptor.
@ -247,29 +247,11 @@ USBEndpointState ep2state;
*/ */
USBEndpointState ep3state; 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). * @brief EP1 initialization structure (IN only).
*/ */
static const USBEndpointConfig ep1config = { static const USBEndpointConfig ep1config = {
sduDataRequest, sduDataTransmitted,
NULL, NULL,
0x0040, 0x0040,
0x0000, 0x0000,
@ -282,7 +264,7 @@ static const USBEndpointConfig ep1config = {
* @brief EP2 initialization structure (IN only). * @brief EP2 initialization structure (IN only).
*/ */
static const USBEndpointConfig ep2config = { static const USBEndpointConfig ep2config = {
sduInterruptRequest, sduInterruptTransmitted,
NULL, NULL,
0x0010, 0x0010,
0x0000, 0x0000,
@ -296,7 +278,7 @@ static const USBEndpointConfig ep2config = {
*/ */
static const USBEndpointConfig ep3config = { static const USBEndpointConfig ep3config = {
NULL, NULL,
sduDataAvailable, sduDataReceived,
0x0000, 0x0000,
0x0040, 0x0040,
EPR_EP_TYPE_BULK | EPR_STAT_TX_DIS | EPR_STAT_RX_VALID, 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. * Serial over USB driver configuration.
*/ */
#if 0
static const SerialUSBConfig serusbcfg = { static const SerialUSBConfig serusbcfg = {
&USBD1, &USBD1,
{ {
@ -348,8 +329,8 @@ static const SerialUSBConfig serusbcfg = {
DATA_AVAILABLE_EP, DATA_AVAILABLE_EP,
INTERRUPT_REQUEST_EP INTERRUPT_REQUEST_EP
}; };
#endif
#if 0
#include "usb_cdc.h" #include "usb_cdc.h"
static cdc_linecoding_t linecoding = { static cdc_linecoding_t linecoding = {
{0x00, 0x96, 0x00, 0x00}, /* 38400. */ {0x00, 0x96, 0x00, 0x00}, /* 38400. */
@ -375,6 +356,7 @@ bool_t sduRequestsHook(USBDriver *usbp) {
} }
return FALSE; return FALSE;
} }
#endif
USBConfig usbconfig = { USBConfig usbconfig = {
usb_event, usb_event,
@ -405,7 +387,6 @@ static msg_t Thread1(void *arg) {
/* /*
* USB CDC loopback thread. * USB CDC loopback thread.
*/ */
#if 0
static WORKING_AREA(waThread2, 256); static WORKING_AREA(waThread2, 256);
static msg_t Thread2(void *arg) { static msg_t Thread2(void *arg) {
SerialUSBDriver *sdup = arg; SerialUSBDriver *sdup = arg;
@ -422,7 +403,6 @@ static msg_t Thread2(void *arg) {
} }
} }
} }
#endif
/* /*
* Application entry point. * Application entry point.
@ -442,10 +422,10 @@ int main(void) {
/* /*
* Activates the USB driver and then the USB bus pull-up on D+. * 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); palClearPad(GPIOC, GPIOC_USB_DISC);
// sduObjectInit(&SDU1);
// sduStart(&SDU1, &serusbcfg);
/* /*
* Activates the serial driver 2 using the driver default configuration. * Activates the serial driver 2 using the driver default configuration.
@ -460,7 +440,7 @@ int main(void) {
/* /*
* Creates the USB CDC loopback thread. * 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 * Normal main() thread activity, in this demo it does nothing except