git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4575 35acf78f-673a-0410-8e92-d51de3d6d3f4
parent
0969ab51e5
commit
e372aabda9
|
@ -92,10 +92,6 @@ typedef struct {
|
||||||
* @brief USB driver to use.
|
* @brief USB driver to use.
|
||||||
*/
|
*/
|
||||||
USBDriver *usbp;
|
USBDriver *usbp;
|
||||||
/**
|
|
||||||
* @brief USB driver configuration structure.
|
|
||||||
*/
|
|
||||||
USBConfig usb_config;
|
|
||||||
} SerialUSBConfig;
|
} SerialUSBConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -223,7 +223,6 @@ void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config) {
|
||||||
config->usbp->param = sdup;
|
config->usbp->param = sdup;
|
||||||
sdup->state = SDU_READY;
|
sdup->state = SDU_READY;
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
usbStart(config->usbp, &config->usb_config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -245,7 +244,6 @@ void sduStop(SerialUSBDriver *sdup) {
|
||||||
"invalid state");
|
"invalid state");
|
||||||
sdup->state = SDU_STOP;
|
sdup->state = SDU_STOP;
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
usbStop(sdup->config->usbp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -322,12 +320,23 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) {
|
||||||
so it is safe to transmit without a check.*/
|
so it is safe to transmit without a check.*/
|
||||||
chSysUnlockFromIsr();
|
chSysUnlockFromIsr();
|
||||||
|
|
||||||
usbPrepareQueuedTransmit(usbp,
|
usbPrepareQueuedTransmit(usbp, ep, &sdup->oqueue, n);
|
||||||
USB_CDC_DATA_REQUEST_EP,
|
|
||||||
&sdup->oqueue, n);
|
|
||||||
|
|
||||||
chSysLockFromIsr();
|
chSysLockFromIsr();
|
||||||
usbStartTransmitI(usbp, USB_CDC_DATA_REQUEST_EP);
|
usbStartTransmitI(usbp, ep);
|
||||||
|
}
|
||||||
|
else if (!(usbp->epc[ep]->in_state->txsize &
|
||||||
|
(usbp->epc[ep]->in_maxsize - 1))) {
|
||||||
|
/* Transmit zero sized packet in case the last one has maximum allowed
|
||||||
|
size. Otherwise the recipient may expect more data coming soon and
|
||||||
|
not return buffered data to app. See section 5.8.3 Bulk Transfer
|
||||||
|
Packet Size Constraints of the USB Specification document.*/
|
||||||
|
chSysUnlockFromIsr();
|
||||||
|
|
||||||
|
usbPrepareQueuedTransmit(usbp, ep, &sdup->oqueue, 0);
|
||||||
|
|
||||||
|
chSysLockFromIsr();
|
||||||
|
usbStartTransmitI(usbp, ep);
|
||||||
}
|
}
|
||||||
|
|
||||||
chSysUnlockFromIsr();
|
chSysUnlockFromIsr();
|
||||||
|
|
|
@ -324,16 +324,20 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Serial over USB driver configuration.
|
* USB driver configuration.
|
||||||
*/
|
*/
|
||||||
static const SerialUSBConfig serusbcfg = {
|
static const USBConfig usbcfg = {
|
||||||
&USBD1,
|
|
||||||
{
|
|
||||||
usb_event,
|
usb_event,
|
||||||
get_descriptor,
|
get_descriptor,
|
||||||
sduRequestsHook,
|
sduRequestsHook,
|
||||||
NULL
|
NULL
|
||||||
}
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Serial over USB driver configuration.
|
||||||
|
*/
|
||||||
|
static const SerialUSBConfig serusbcfg = {
|
||||||
|
&USBD1
|
||||||
};
|
};
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -479,13 +483,20 @@ int main(void) {
|
||||||
halInit();
|
halInit();
|
||||||
chSysInit();
|
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+.
|
* 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);
|
usbDisconnectBus(serusbcfg.usbp);
|
||||||
chThdSleepMilliseconds(1000);
|
chThdSleepMilliseconds(1000);
|
||||||
sduObjectInit(&SDU1);
|
usbStart(&USBD1, &usbcfg);
|
||||||
sduStart(&SDU1, &serusbcfg);
|
|
||||||
usbConnectBus(serusbcfg.usbp);
|
usbConnectBus(serusbcfg.usbp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue