aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2015-12-25 08:59:10 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2015-12-25 08:59:10 +0000
commit4b601a5d0fd06f8e238c17fb96633100ecc59503 (patch)
tree0ed28cfc2e87f0a346850c49a9343df30604f218 /os
parent6a20a7107a016a4cb43c3f98362b447f883db8c8 (diff)
downloadChibiOS-4b601a5d0fd06f8e238c17fb96633100ecc59503.tar.gz
ChibiOS-4b601a5d0fd06f8e238c17fb96633100ecc59503.tar.bz2
ChibiOS-4b601a5d0fd06f8e238c17fb96633100ecc59503.zip
USB upgrade.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8641 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/hal/include/usb.h4
-rw-r--r--os/hal/ports/STM32/LLD/OTGv1/usb_lld.c119
-rw-r--r--os/hal/ports/STM32/LLD/OTGv1/usb_lld.h44
-rw-r--r--os/hal/ports/STM32/LLD/USBv1/usb_lld.c133
-rw-r--r--os/hal/ports/STM32/LLD/USBv1/usb_lld.h45
-rw-r--r--os/hal/src/usb.c69
-rw-r--r--os/hal/templates/usb_lld.h43
7 files changed, 54 insertions, 403 deletions
diff --git a/os/hal/include/usb.h b/os/hal/include/usb.h
index 9f7cbf630..896aa31cd 100644
--- a/os/hal/include/usb.h
+++ b/os/hal/include/usb.h
@@ -575,10 +575,6 @@ extern "C" {
uint8_t *buf, size_t n);
void usbPrepareTransmit(USBDriver *usbp, usbep_t ep,
const uint8_t *buf, size_t n);
- void usbPrepareQueuedReceive(USBDriver *usbp, usbep_t ep,
- input_queue_t *iqp, size_t n);
- void usbPrepareQueuedTransmit(USBDriver *usbp, usbep_t ep,
- output_queue_t *oqp, size_t n);
bool usbStartReceiveI(USBDriver *usbp, usbep_t ep);
bool usbStartTransmitI(USBDriver *usbp, usbep_t ep);
bool usbStallReceiveI(USBDriver *usbp, usbep_t ep);
diff --git a/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c b/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c
index e20622424..4ec8fd976 100644
--- a/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c
+++ b/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c
@@ -234,50 +234,6 @@ static void otg_fifo_write_from_buffer(volatile uint32_t *fifop,
}
/**
- * @brief Writes to a TX FIFO fetching data from a queue.
- *
- * @param[in] fifop pointer to the FIFO register
- * @param[in] oqp pointer to an @p output_queue_t object
- * @param[in] n maximum number of bytes to copy
- *
- * @notapi
- */
-static void otg_fifo_write_from_queue(volatile uint32_t *fifop,
- output_queue_t *oqp,
- size_t n) {
- uint32_t w;
- size_t i;
-
- /* Pushing all complete words.*/
- i = 0;
- w = 0;
- while (i < n) {
- w |= (uint32_t)*oqp->q_rdptr << ((i & 3) * 8);
- oqp->q_rdptr++;
- if (oqp->q_rdptr >= oqp->q_top) {
- oqp->q_rdptr = oqp->q_buffer;
- }
- i++;
- if ((i & 3) == 0) {
- *fifop = w;
- w = 0;
- }
- }
-
- /* Remaining bytes.*/
- if ((i & 3) != 0) {
- *fifop = w;
- }
-
- /* Updating queue.*/
- osalSysLock();
- oqp->q_counter += n;
- osalThreadDequeueAllI(&oqp->q_waiting, Q_OK);
- osalOsRescheduleS();
- osalSysUnlock();
-}
-
-/**
* @brief Reads a packet from the RXFIFO.
*
* @param[in] fifop pointer to the FIFO register
@@ -307,43 +263,6 @@ static void otg_fifo_read_to_buffer(volatile uint32_t *fifop,
}
/**
- * @brief Reads a packet from the RXFIFO.
- *
- * @param[in] fifop pointer to the FIFO register
- * @param[in] iqp pointer to an @p input_queue_t object
- * @param[in] n number of bytes to pull from the FIFO
- *
- * @notapi
- */
-static void otg_fifo_read_to_queue(volatile uint32_t *fifop,
- input_queue_t *iqp,
- size_t n) {
- uint32_t w = 0;
- size_t i;
-
- i = 0;
- while (i < n) {
- if ((i & 3) == 0){
- w = *fifop;
- }
- *iqp->q_wrptr = (uint8_t)w;
- iqp->q_wrptr++;
- if (iqp->q_wrptr >= iqp->q_top) {
- iqp->q_wrptr = iqp->q_buffer;
- }
- w >>= 8;
- i++;
- }
-
- /* Updating queue.*/
- osalSysLock();
- iqp->q_counter += n;
- osalThreadDequeueAllI(&iqp->q_waiting, Q_OK);
- osalOsRescheduleS();
- osalSysUnlock();
-}
-
-/**
* @brief Incoming packets handler.
*
* @param[in] usbp pointer to the @p USBDriver object
@@ -366,20 +285,12 @@ static void otg_rxfifo_handler(USBDriver *usbp) {
case GRXSTSP_OUT_DATA:
cnt = (sts & GRXSTSP_BCNT_MASK) >> GRXSTSP_BCNT_OFF;
ep = (sts & GRXSTSP_EPNUM_MASK) >> GRXSTSP_EPNUM_OFF;
- if (usbp->epc[ep]->out_state->rxqueued) {
- /* Queue associated.*/
- otg_fifo_read_to_queue(usbp->otg->FIFO[0],
- usbp->epc[ep]->out_state->mode.queue.rxqueue,
- cnt);
- }
- else {
- otg_fifo_read_to_buffer(usbp->otg->FIFO[0],
- usbp->epc[ep]->out_state->mode.linear.rxbuf,
- cnt,
- usbp->epc[ep]->out_state->rxsize -
- usbp->epc[ep]->out_state->rxcnt);
- usbp->epc[ep]->out_state->mode.linear.rxbuf += cnt;
- }
+ otg_fifo_read_to_buffer(usbp->otg->FIFO[0],
+ usbp->epc[ep]->out_state->rxbuf,
+ cnt,
+ usbp->epc[ep]->out_state->rxsize -
+ usbp->epc[ep]->out_state->rxcnt);
+ usbp->epc[ep]->out_state->rxbuf += cnt;
usbp->epc[ep]->out_state->rxcnt += cnt;
break;
case GRXSTSP_OUT_GLOBAL_NAK:
@@ -420,20 +331,10 @@ static bool otg_txfifo_handler(USBDriver *usbp, usbep_t ep) {
#if STM32_USB_OTGFIFO_FILL_BASEPRI
__set_BASEPRI(CORTEX_PRIO_MASK(STM32_USB_OTGFIFO_FILL_BASEPRI));
#endif
- /* Handles the two cases: linear buffer or queue.*/
- if (usbp->epc[ep]->in_state->txqueued) {
- /* Queue associated.*/
- otg_fifo_write_from_queue(usbp->otg->FIFO[ep],
- usbp->epc[ep]->in_state->mode.queue.txqueue,
- n);
- }
- else {
- /* Linear buffer associated.*/
- otg_fifo_write_from_buffer(usbp->otg->FIFO[ep],
- usbp->epc[ep]->in_state->mode.linear.txbuf,
- n);
- usbp->epc[ep]->in_state->mode.linear.txbuf += n;
- }
+ otg_fifo_write_from_buffer(usbp->otg->FIFO[ep],
+ usbp->epc[ep]->in_state->txbuf,
+ n);
+ usbp->epc[ep]->in_state->txbuf += n;
#if STM32_USB_OTGFIFO_FILL_BASEPRI
__set_BASEPRI(0);
#endif
diff --git a/os/hal/ports/STM32/LLD/OTGv1/usb_lld.h b/os/hal/ports/STM32/LLD/OTGv1/usb_lld.h
index 78acf00c8..a8c3bd4d9 100644
--- a/os/hal/ports/STM32/LLD/OTGv1/usb_lld.h
+++ b/os/hal/ports/STM32/LLD/OTGv1/usb_lld.h
@@ -215,10 +215,6 @@ typedef struct {
*/
typedef struct {
/**
- * @brief Buffer mode, queue or linear.
- */
- bool txqueued;
- /**
* @brief Requested transmit transfer size.
*/
size_t txsize;
@@ -226,20 +222,10 @@ typedef struct {
* @brief Transmitted bytes so far.
*/
size_t txcnt;
- union {
- struct {
- /**
- * @brief Pointer to the transmission linear buffer.
- */
- const uint8_t *txbuf;
- } linear;
- struct {
- /**
- * @brief Pointer to the output queue.
- */
- output_queue_t *txqueue;
- } queue;
- } mode;
+ /**
+ * @brief Pointer to the transmission linear buffer.
+ */
+ const uint8_t *txbuf;
/**
* @brief Total transmit transfer size.
*/
@@ -251,10 +237,6 @@ typedef struct {
*/
typedef struct {
/**
- * @brief Buffer mode, queue or linear.
- */
- bool rxqueued;
- /**
* @brief Requested receive transfer size.
*/
size_t rxsize;
@@ -262,20 +244,10 @@ typedef struct {
* @brief Received bytes so far.
*/
size_t rxcnt;
- union {
- struct {
- /**
- * @brief Pointer to the receive linear buffer.
- */
- uint8_t *rxbuf;
- } linear;
- struct {
- /**
- * @brief Pointer to the input queue.
- */
- input_queue_t *rxqueue;
- } queue;
- } mode;
+ /**
+ * @brief Pointer to the receive linear buffer.
+ */
+ uint8_t *rxbuf;
/**
* @brief Total transmit transfer size.
*/
diff --git a/os/hal/ports/STM32/LLD/USBv1/usb_lld.c b/os/hal/ports/STM32/LLD/USBv1/usb_lld.c
index 45450b0bb..c06b317bb 100644
--- a/os/hal/ports/STM32/LLD/USBv1/usb_lld.c
+++ b/os/hal/ports/STM32/LLD/USBv1/usb_lld.c
@@ -152,50 +152,6 @@ static void usb_packet_read_to_buffer(stm32_usb_descriptor_t *udp,
}
/**
- * @brief Reads from a dedicated packet buffer.
- *
- * @param[in] udp pointer to a @p stm32_usb_descriptor_t
- * @param[in] iqp pointer to an @p input_queue_t object
- * @param[in] n maximum number of bytes to copy. This value must
- * not exceed the maximum packet size for this endpoint.
- *
- * @notapi
- */
-static void usb_packet_read_to_queue(stm32_usb_descriptor_t *udp,
- input_queue_t *iqp, size_t n) {
- size_t nhw;
- stm32_usb_pma_t *pmap= USB_ADDR2PTR(udp->RXADDR0);
-
- nhw = n / 2;
- while (nhw > 0) {
- stm32_usb_pma_t w;
-
- w = *pmap++;
- *iqp->q_wrptr++ = (uint8_t)w;
- if (iqp->q_wrptr >= iqp->q_top)
- iqp->q_wrptr = iqp->q_buffer;
- *iqp->q_wrptr++ = (uint8_t)(w >> 8);
- if (iqp->q_wrptr >= iqp->q_top)
- iqp->q_wrptr = iqp->q_buffer;
- nhw--;
- }
- /* Last byte for odd numbers.*/
- if ((n & 1) != 0) {
- *iqp->q_wrptr++ = (uint8_t)*pmap;
- if (iqp->q_wrptr >= iqp->q_top)
- iqp->q_wrptr = iqp->q_buffer;
- }
-
- /* Updating queue.*/
- osalSysLockFromISR();
-
- iqp->q_counter += n;
- osalThreadDequeueAllI(&iqp->q_waiting, Q_OK);
-
- osalSysUnlockFromISR();
-}
-
-/**
* @brief Writes to a dedicated packet buffer.
*
* @param[in] udp pointer to a @p stm32_usb_descriptor_t
@@ -237,52 +193,6 @@ static void usb_packet_write_from_buffer(stm32_usb_descriptor_t *udp,
}
/**
- * @brief Writes to a dedicated packet buffer.
- *
- * @param[in] udp pointer to a @p stm32_usb_descriptor_t
- * @param[in] buf buffer where to fetch the packet data
- * @param[in] n maximum number of bytes to copy. This value must
- * not exceed the maximum packet size for this endpoint.
- *
- * @notapi
- */
-static void usb_packet_write_from_queue(stm32_usb_descriptor_t *udp,
- output_queue_t *oqp, size_t n) {
- size_t nhw;
- syssts_t sts;
- stm32_usb_pma_t *pmap = USB_ADDR2PTR(udp->TXADDR0);
-
- nhw = n / 2;
- while (nhw > 0) {
- stm32_usb_pma_t w;
-
- w = (stm32_usb_pma_t)*oqp->q_rdptr++;
- if (oqp->q_rdptr >= oqp->q_top)
- oqp->q_rdptr = oqp->q_buffer;
- w |= (stm32_usb_pma_t)*oqp->q_rdptr++ << 8;
- if (oqp->q_rdptr >= oqp->q_top)
- oqp->q_rdptr = oqp->q_buffer;
- *pmap++ = w;
- nhw--;
- }
-
- /* Last byte for odd numbers.*/
- if ((n & 1) != 0) {
- *pmap = (stm32_usb_pma_t)*oqp->q_rdptr++;
- if (oqp->q_rdptr >= oqp->q_top)
- oqp->q_rdptr = oqp->q_buffer;
- }
-
- /* Updating queue.*/
- sts = osalSysGetStatusAndLockX();
-
- oqp->q_counter += n;
- osalThreadDequeueAllI(&oqp->q_waiting, Q_OK);
-
- osalSysRestoreStatusX(sts);
-}
-
-/**
* @brief Common ISR code, serves the EP-related interrupts.
*
* @param[in] usbp pointer to the @p USBDriver object
@@ -328,16 +238,11 @@ static void usb_serve_endpoints(USBDriver *usbp, uint32_t ep) {
if (EPR_EP_TYPE_IS_ISO(epr) && (epr & EPR_DTOG_TX))
USB_GET_DESCRIPTOR(ep)->TXCOUNT1 = (stm32_usb_pma_t)n;
- if (epcp->in_state->txqueued)
- usb_packet_write_from_queue(USB_GET_DESCRIPTOR(ep),
- epcp->in_state->mode.queue.txqueue,
- n);
- else {
- epcp->in_state->mode.linear.txbuf += transmitted;
- usb_packet_write_from_buffer(USB_GET_DESCRIPTOR(ep),
- epcp->in_state->mode.linear.txbuf,
- n);
- }
+ /* Writes the packet from the defined buffer.*/
+ epcp->in_state->txbuf += transmitted;
+ usb_packet_write_from_buffer(USB_GET_DESCRIPTOR(ep),
+ epcp->in_state->txbuf,
+ n);
osalSysLockFromISR();
usb_lld_start_in(usbp, ep);
osalSysUnlockFromISR();
@@ -370,21 +275,15 @@ static void usb_serve_endpoints(USBDriver *usbp, uint32_t ep) {
n = (size_t)udp->RXCOUNT1 & RXCOUNT_COUNT_MASK;
/* Reads the packet into the defined buffer.*/
- if (epcp->out_state->rxqueued)
- usb_packet_read_to_queue(udp,
- epcp->out_state->mode.queue.rxqueue,
- n);
- else {
- usb_packet_read_to_buffer(udp,
- epcp->out_state->mode.linear.rxbuf,
- n);
- epcp->out_state->mode.linear.rxbuf += n;
- }
+ usb_packet_read_to_buffer(udp,
+ epcp->out_state->rxbuf,
+ n);
+ epcp->out_state->rxbuf += n;
/* Transaction data updated.*/
- epcp->out_state->rxcnt += n;
- epcp->out_state->rxsize -= n;
- epcp->out_state->rxpkts -= 1;
+ epcp->out_state->rxcnt += n;
+ epcp->out_state->rxsize -= n;
+ epcp->out_state->rxpkts -= 1;
/* The transaction is completed if the specified number of packets
has been received or the current packet is a short packet.*/
@@ -828,12 +727,8 @@ void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep) {
if (EPR_EP_TYPE_IS_ISO(epr) && (epr & EPR_DTOG_TX))
USB_GET_DESCRIPTOR(ep)->TXCOUNT1 = (stm32_usb_pma_t)n;
- if (isp->txqueued)
- usb_packet_write_from_queue(USB_GET_DESCRIPTOR(ep),
- isp->mode.queue.txqueue, n);
- else
- usb_packet_write_from_buffer(USB_GET_DESCRIPTOR(ep),
- isp->mode.linear.txbuf, n);
+ usb_packet_write_from_buffer(USB_GET_DESCRIPTOR(ep),
+ isp->txbuf, n);
}
/**
diff --git a/os/hal/ports/STM32/LLD/USBv1/usb_lld.h b/os/hal/ports/STM32/LLD/USBv1/usb_lld.h
index 065350536..7464d52da 100644
--- a/os/hal/ports/STM32/LLD/USBv1/usb_lld.h
+++ b/os/hal/ports/STM32/LLD/USBv1/usb_lld.h
@@ -140,10 +140,6 @@
*/
typedef struct {
/**
- * @brief Buffer mode, queue or linear.
- */
- bool txqueued;
- /**
* @brief Requested transmit transfer size.
*/
size_t txsize;
@@ -151,21 +147,10 @@ typedef struct {
* @brief Transmitted bytes so far.
*/
size_t txcnt;
- union {
- struct {
- /**
- * @brief Pointer to the transmission linear buffer.
- */
- const uint8_t *txbuf;
- } linear;
- struct {
- /**
- * @brief Pointer to the output queue.
- */
- output_queue_t *txqueue;
- } queue;
- /* End of the mandatory fields.*/
- } mode;
+ /**
+ * @brief Pointer to the transmission linear buffer.
+ */
+ const uint8_t *txbuf;
} USBInEndpointState;
/**
@@ -173,10 +158,6 @@ typedef struct {
*/
typedef struct {
/**
- * @brief Buffer mode, queue or linear.
- */
- bool rxqueued;
- /**
* @brief Requested receive transfer size.
*/
size_t rxsize;
@@ -184,20 +165,10 @@ typedef struct {
* @brief Received bytes so far.
*/
size_t rxcnt;
- union {
- struct {
- /**
- * @brief Pointer to the receive linear buffer.
- */
- uint8_t *rxbuf;
- } linear;
- struct {
- /**
- * @brief Pointer to the input queue.
- */
- input_queue_t *rxqueue;
- } queue;
- } mode;
+ /**
+ * @brief Pointer to the receive linear buffer.
+ */
+ uint8_t *rxbuf;
/* End of the mandatory fields.*/
/**
* @brief Number of packets to receive.
diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c
index c4f612d0f..cea90b32e 100644
--- a/os/hal/src/usb.c
+++ b/os/hal/src/usb.c
@@ -401,10 +401,9 @@ void usbDisableEndpointsI(USBDriver *usbp) {
void usbPrepareReceive(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n) {
USBOutEndpointState *osp = usbp->epc[ep]->out_state;
- osp->rxqueued = false;
- osp->mode.linear.rxbuf = buf;
- osp->rxsize = n;
- osp->rxcnt = 0;
+ osp->rxbuf = buf;
+ osp->rxsize = n;
+ osp->rxcnt = 0;
usb_lld_prepare_receive(usbp, ep);
}
@@ -427,65 +426,9 @@ void usbPrepareTransmit(USBDriver *usbp, usbep_t ep,
const uint8_t *buf, size_t n) {
USBInEndpointState *isp = usbp->epc[ep]->in_state;
- isp->txqueued = false;
- isp->mode.linear.txbuf = buf;
- isp->txsize = n;
- isp->txcnt = 0;
-
- usb_lld_prepare_transmit(usbp, ep);
-}
-
-/**
- * @brief Prepares for a receive transaction on an OUT endpoint.
- * @post The endpoint is ready for @p usbStartReceiveI().
- * @note This function can be called both in ISR and thread context.
- * @note The queue must have enough free space to accommodate the
- * specified transaction size rounded to the next packet size
- * boundary. For example if the transaction size is 1 and the
- * packet size is 64 then the queue must have space for at least
- * 64 bytes.
- *
- * @param[in] usbp pointer to the @p USBDriver object
- * @param[in] ep endpoint number
- * @param[in] iqp input queue to be filled with incoming data
- * @param[in] n transaction size
- *
- * @special
- */
-void usbPrepareQueuedReceive(USBDriver *usbp, usbep_t ep,
- input_queue_t *iqp, size_t n) {
- USBOutEndpointState *osp = usbp->epc[ep]->out_state;
-
- osp->rxqueued = true;
- osp->mode.queue.rxqueue = iqp;
- osp->rxsize = n;
- osp->rxcnt = 0;
-
- usb_lld_prepare_receive(usbp, ep);
-}
-
-/**
- * @brief Prepares for a transmit transaction on an IN endpoint.
- * @post The endpoint is ready for @p usbStartTransmitI().
- * @note This function can be called both in ISR and thread context.
- * @note The transmit transaction size is equal to the data contained
- * in the queue.
- *
- * @param[in] usbp pointer to the @p USBDriver object
- * @param[in] ep endpoint number
- * @param[in] oqp output queue to be fetched for outgoing data
- * @param[in] n transaction size
- *
- * @special
- */
-void usbPrepareQueuedTransmit(USBDriver *usbp, usbep_t ep,
- output_queue_t *oqp, size_t n) {
- USBInEndpointState *isp = usbp->epc[ep]->in_state;
-
- isp->txqueued = true;
- isp->mode.queue.txqueue = oqp;
- isp->txsize = n;
- isp->txcnt = 0;
+ isp->txbuf = buf;
+ isp->txsize = n;
+ isp->txcnt = 0;
usb_lld_prepare_transmit(usbp, ep);
}
diff --git a/os/hal/templates/usb_lld.h b/os/hal/templates/usb_lld.h
index 8d0d4c860..3d6764bc6 100644
--- a/os/hal/templates/usb_lld.h
+++ b/os/hal/templates/usb_lld.h
@@ -82,10 +82,6 @@
*/
typedef struct {
/**
- * @brief Buffer mode, queue or linear.
- */
- bool txqueued;
- /**
* @brief Requested transmit transfer size.
*/
size_t txsize;
@@ -93,19 +89,10 @@ typedef struct {
* @brief Transmitted bytes so far.
*/
size_t txcnt;
- union {
- struct {
- /**
- * @brief Pointer to the transmission linear buffer.
- */
- const uint8_t *txbuf;
- } linear;
- struct {
- /**
- * @brief Pointer to the output queue.
- */
- output_queue_t *txqueue;
- } queue;
+ /**
+ * @brief Pointer to the transmission linear buffer.
+ */
+ const uint8_t *txbuf;
/* End of the mandatory fields.*/
} mode;
} USBInEndpointState;
@@ -115,10 +102,6 @@ typedef struct {
*/
typedef struct {
/**
- * @brief Buffer mode, queue or linear.
- */
- bool rxqueued;
- /**
* @brief Requested receive transfer size.
*/
size_t rxsize;
@@ -126,20 +109,10 @@ typedef struct {
* @brief Received bytes so far.
*/
size_t rxcnt;
- union {
- struct {
- /**
- * @brief Pointer to the receive linear buffer.
- */
- uint8_t *rxbuf;
- } linear;
- struct {
- /**
- * @brief Pointer to the input queue.
- */
- input_queue_t *rxqueue;
- } queue;
- } mode;
+ /**
+ * @brief Pointer to the receive linear buffer.
+ */
+ uint8_t *rxbuf;
/* End of the mandatory fields.*/
} USBOutEndpointState;