aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/STM32/LLD
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/ports/STM32/LLD')
-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
4 files changed, 40 insertions, 301 deletions
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.