aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src/hal_serial_usb.c
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2016-06-16 09:22:22 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2016-06-16 09:22:22 +0000
commitc3150eb13679314f8bfc02714ae0027dd1658002 (patch)
treeccb186462f6402db2fd8acded21d103519a58905 /os/hal/src/hal_serial_usb.c
parent77a63206e770cb4a73abf3063ce381fa8de4705b (diff)
downloadChibiOS-c3150eb13679314f8bfc02714ae0027dd1658002.tar.gz
ChibiOS-c3150eb13679314f8bfc02714ae0027dd1658002.tar.bz2
ChibiOS-c3150eb13679314f8bfc02714ae0027dd1658002.zip
USB fixes.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9628 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/src/hal_serial_usb.c')
-rw-r--r--os/hal/src/hal_serial_usb.c67
1 files changed, 32 insertions, 35 deletions
diff --git a/os/hal/src/hal_serial_usb.c b/os/hal/src/hal_serial_usb.c
index 7d4ed05a8..b97254fdd 100644
--- a/os/hal/src/hal_serial_usb.c
+++ b/os/hal/src/hal_serial_usb.c
@@ -50,6 +50,35 @@ static cdc_linecoding_t linecoding = {
/* Driver local functions. */
/*===========================================================================*/
+
+static bool sdu_start_receive(SerialUSBDriver *sdup) {
+ uint8_t *buf;
+
+ /* If the USB driver is not in the appropriate state then transactions
+ must not be started.*/
+ if ((usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) ||
+ (sdup->state != SDU_READY)) {
+ return true;
+ }
+
+ /* Checking if there is already a transaction ongoing on the endpoint.*/
+ if (usbGetReceiveStatusI(sdup->config->usbp, sdup->config->bulk_in)) {
+ return true;
+ }
+
+ /* Checking if there is a buffer ready for incoming data.*/
+ buf = ibqGetEmptyBufferI(&sdup->ibqueue);
+ if (buf == NULL) {
+ return true;
+ }
+
+ /* Buffer found, starting a new transaction.*/
+ usbStartReceiveI(sdup->config->usbp, sdup->config->bulk_out,
+ buf, SERIAL_USB_BUFFERS_SIZE);
+
+ return false;
+}
+
/*
* Interface implementation.
*/
@@ -140,24 +169,7 @@ static const struct SerialUSBDriverVMT vmt = {
*/
static void ibnotify(io_buffers_queue_t *bqp) {
SerialUSBDriver *sdup = bqGetLinkX(bqp);
-
- /* If the USB driver is not in the appropriate state then transactions
- must not be started.*/
- if ((usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) ||
- (sdup->state != SDU_READY)) {
- return;
- }
-
- /* Checking if there is already a transaction ongoing on the endpoint.*/
- if (!usbGetReceiveStatusI(sdup->config->usbp, sdup->config->bulk_out)) {
- /* Trying to get a free buffer.*/
- uint8_t *buf = ibqGetEmptyBufferI(&sdup->ibqueue);
- if (buf != NULL) {
- /* Buffer found, starting a new transaction.*/
- usbStartReceiveI(sdup->config->usbp, sdup->config->bulk_out,
- buf, SERIAL_USB_BUFFERS_SIZE);
- }
- }
+ (void) sdu_start_receive(sdup);
}
/**
@@ -309,19 +321,11 @@ void sduDisconnectI(SerialUSBDriver *sdup) {
* @iclass
*/
void sduConfigureHookI(SerialUSBDriver *sdup) {
- uint8_t *buf;
ibqResetI(&sdup->ibqueue);
obqResetI(&sdup->obqueue);
chnAddFlagsI(sdup, CHN_CONNECTED);
-
- /* Starts the first OUT transaction immediately.*/
- buf = ibqGetEmptyBufferI(&sdup->ibqueue);
-
- osalDbgAssert(buf != NULL, "no free buffer");
-
- usbStartReceiveI(sdup->config->usbp, sdup->config->bulk_out,
- buf, SERIAL_USB_BUFFERS_SIZE);
+ (void) sdu_start_receive(sdup);
}
/**
@@ -457,9 +461,7 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) {
* @param[in] ep OUT endpoint number
*/
void sduDataReceived(USBDriver *usbp, usbep_t ep) {
- uint8_t *buf;
SerialUSBDriver *sdup = usbp->out_params[ep - 1U];
-
if (sdup == NULL) {
return;
}
@@ -477,12 +479,7 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) {
/* The endpoint cannot be busy, we are in the context of the callback,
so a packet is in the buffer for sure. Trying to get a free buffer
for the next transaction.*/
- buf = ibqGetEmptyBufferI(&sdup->ibqueue);
- if (buf != NULL) {
- /* Buffer found, starting a new transaction.*/
- usbStartReceiveI(sdup->config->usbp, sdup->config->bulk_out,
- buf, SERIAL_USB_BUFFERS_SIZE);
- }
+ sdu_start_receive(sdup);
osalSysUnlockFromISR();
}