git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4599 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2012-08-21 08:50:11 +00:00
parent eee100dd44
commit c13206f3ee
5 changed files with 90 additions and 49 deletions

View File

@ -156,7 +156,7 @@ static FRESULT scan_files(BaseSequentialStream *chp, char *path) {
/*===========================================================================*/
/*
* USB Driver structure.
* Serial over USB Driver structure.
*/
static SerialUSBDriver SDU1;

View File

@ -81,6 +81,7 @@ static const USBEndpointConfig ep0config = {
0x40,
&ep0_state.in,
&ep0_state.out,
1,
ep0setup_buffer
};
@ -347,7 +348,6 @@ CH_IRQ_HANDLER(STM32_USB1_LP_HANDLER) {
EPR_CLEAR_CTR_TX(ep);
n = (size_t)USB_GET_DESCRIPTOR(ep)->TXCOUNT0;
epcp->in_state->mode.linear.txbuf += n;
epcp->in_state->txcnt += n;
epcp->in_state->txsize -= n;
if (epcp->in_state->txsize > 0) {
@ -361,10 +361,12 @@ CH_IRQ_HANDLER(STM32_USB1_LP_HANDLER) {
usb_packet_write_from_queue(USB_GET_DESCRIPTOR(ep),
epcp->in_state->mode.queue.txqueue,
n);
else
else {
epcp->in_state->mode.linear.txbuf += n;
usb_packet_write_from_buffer(USB_GET_DESCRIPTOR(ep),
epcp->in_state->mode.linear.txbuf,
n);
}
chSysLockFromIsr();
usb_lld_start_in(usbp, ep);
chSysUnlockFromIsr();
@ -391,13 +393,13 @@ CH_IRQ_HANDLER(STM32_USB1_LP_HANDLER) {
usb_packet_read_to_queue(udp,
epcp->out_state->mode.queue.rxqueue,
n);
else
else {
usb_packet_read_to_buffer(udp,
epcp->out_state->mode.linear.rxbuf,
n);
/* Transaction data updated.*/
epcp->out_state->mode.linear.rxbuf += n;
}
/* Transaction data updated.*/
epcp->out_state->rxcnt += n;
epcp->out_state->rxsize -= n;
epcp->out_state->rxpkts -= 1;

View File

@ -236,6 +236,11 @@ typedef struct {
*/
USBOutEndpointState *out_state;
/* End of the mandatory fields.*/
/**
* @brief Reserved field, not currently used.
* @note Initialize this field to 1 in order to be forward compatible.
*/
uint16_t ep_buffers;
/**
* @brief Pointer to a buffer for setup packets.
* @details Setup packets require a dedicated 8-bytes buffer, set this

View File

@ -34,7 +34,7 @@
/*===========================================================================*/
/*
* USB Driver structure.
* Serial over USB Driver structure.
*/
static SerialUSBDriver SDU1;
@ -231,24 +231,30 @@ static const USBDescriptor *get_descriptor(USBDriver *usbp,
static USBInEndpointState ep1instate;
/**
* @brief EP1 initialization structure (IN only).
* @brief OUT EP1 state.
*/
static USBOutEndpointState ep1outstate;
/**
* @brief EP1 initialization structure (both IN and OUT).
*/
static const USBEndpointConfig ep1config = {
USB_EP_MODE_TYPE_BULK,
NULL,
sduDataTransmitted,
NULL,
sduDataReceived,
0x0040,
0x0040,
0x0000,
&ep1instate,
NULL,
&ep1outstate,
1,
NULL
};
/**
* @brief OUT EP2 state.
* @brief IN EP2 state.
*/
USBOutEndpointState ep2outstate;
static USBInEndpointState ep2instate;
/**
* @brief EP2 initialization structure (IN only).
@ -260,28 +266,9 @@ static const USBEndpointConfig ep2config = {
NULL,
0x0010,
0x0000,
&ep2instate,
NULL,
&ep2outstate,
NULL
};
/**
* @brief OUT EP3 state.
*/
USBOutEndpointState ep3outstate;
/**
* @brief EP3 initialization structure (OUT only).
*/
static const USBEndpointConfig ep3config = {
USB_EP_MODE_TYPE_BULK,
NULL,
NULL,
sduDataReceived,
0x0000,
0x0040,
NULL,
&ep3outstate,
1,
NULL
};
@ -296,13 +283,17 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
chSysLockFromIsr();
/* Enables the endpoints specified into the configuration.
Note, this callback is invoked from an ISR so I-Class functions
must be used.*/
chSysLockFromIsr();
usbInitEndpointI(usbp, USB_CDC_DATA_REQUEST_EP, &ep1config);
usbInitEndpointI(usbp, USB_CDC_INTERRUPT_REQUEST_EP, &ep2config);
usbInitEndpointI(usbp, USB_CDC_DATA_AVAILABLE_EP, &ep3config);
/* Resetting the state of the CDC subsystem.*/
sduConfigureHookI(usbp);
chSysUnlockFromIsr();
return;
case USB_EVENT_SUSPEND:
@ -316,16 +307,20 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
}
/*
* Serial over USB driver configuration.
* USB driver configuration.
*/
static const SerialUSBConfig serusbcfg = {
&USBD1,
{
static const USBConfig usbcfg = {
usb_event,
get_descriptor,
sduRequestsHook,
NULL
}
};
/*
* Serial over USB driver configuration.
*/
static const SerialUSBConfig serusbcfg = {
&USBD1
};
/*===========================================================================*/
@ -386,10 +381,42 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
chThdWait(tp);
}
static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
static uint8_t buf[] =
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: write\r\n");
return;
}
while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
chSequentialStreamWrite(&SDU1, buf, sizeof buf - 1);
}
chprintf(chp, "\r\n\nstopped\r\n");
}
static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{"write", cmd_write},
{NULL, NULL}
};
@ -411,10 +438,11 @@ static msg_t Thread1(void *arg) {
(void)arg;
chRegSetThreadName("blinker");
while (TRUE) {
systime_t time = serusbcfg.usbp->state == USB_ACTIVE ? 250 : 500;
palClearPad(IOPORT3, GPIOC_LED);
chThdSleepMilliseconds(500);
chThdSleepMilliseconds(time);
palSetPad(IOPORT3, GPIOC_LED);
chThdSleepMilliseconds(500);
chThdSleepMilliseconds(time);
}
}
@ -434,15 +462,21 @@ int main(void) {
halInit();
chSysInit();
/*
* Initializes a serial-over-USB CDC driver.
*/
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);
/*
* Activates the USB driver and then the USB bus pull-up on D+.
* Note, a delay is inserted in order to not have to disconnect the cable
* after a reset.
*/
usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(1000);
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
palClearPad(GPIOC, GPIOC_USB_DISC);
/*
* Shell manager initialization.

View File

@ -34,7 +34,7 @@
/*===========================================================================*/
/*
* USB Driver structure.
* Serial over USB Driver structure.
*/
static SerialUSBDriver SDU1;