aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2015-12-31 08:30:52 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2015-12-31 08:30:52 +0000
commit834cea0441464d57125e851d20182f0663392b2d (patch)
tree1e605b0d8e6d15d9f777c97db10742e1af814417
parentac528c28c72ed412c8c9d33dcf0967a723d6aede (diff)
downloadChibiOS-834cea0441464d57125e851d20182f0663392b2d.tar.gz
ChibiOS-834cea0441464d57125e851d20182f0663392b2d.tar.bz2
ChibiOS-834cea0441464d57125e851d20182f0663392b2d.zip
USBv1 code optimization.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8660 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/hal/ports/STM32/LLD/USBv1/usb_lld.c42
-rw-r--r--os/hal/ports/STM32/LLD/USBv1/usb_lld.h4
2 files changed, 23 insertions, 23 deletions
diff --git a/os/hal/ports/STM32/LLD/USBv1/usb_lld.c b/os/hal/ports/STM32/LLD/USBv1/usb_lld.c
index a4a8e4519..16c9bebd2 100644
--- a/os/hal/ports/STM32/LLD/USBv1/usb_lld.c
+++ b/os/hal/ports/STM32/LLD/USBv1/usb_lld.c
@@ -212,31 +212,22 @@ static void usb_serve_endpoints(USBDriver *usbp, uint32_t ep) {
const USBEndpointConfig *epcp = usbp->epc[ep];
if (epr & EPR_CTR_TX) {
- size_t transmitted;
/* IN endpoint, transmission.*/
+ USBInEndpointState *isp = epcp->in_state;
+
EPR_CLEAR_CTR_TX(ep);
- /* Double buffering is always enabled for isochronous endpoints, and
- although we overlap the two buffers for simplicity, we still need
- to read from the right counter. The DTOG_TX bit indicates the buffer
- that is currently in use by the USB peripheral, that is, the buffer
- from which the next packet will be sent, so we need to read the
- transmitted bytes from the counter of the OTHER buffer, which is
- where we stored the last transmitted packet.*/
- transmitted = (size_t)USB_GET_DESCRIPTOR(ep)->TXCOUNT0;
- if (EPR_EP_TYPE_IS_ISO(epr) && !(epr & EPR_DTOG_TX))
- transmitted = (size_t)USB_GET_DESCRIPTOR(ep)->TXCOUNT1;
-
- epcp->in_state->txcnt += transmitted;
- n = epcp->in_state->txsize - epcp->in_state->txcnt;
+ isp->txcnt += isp->txlast;
+ n = isp->txsize - isp->txcnt;
if (n > 0) {
/* Transfer not completed, there are more packets to send.*/
if (n > epcp->in_maxsize)
n = epcp->in_maxsize;
/* Writes the packet from the defined buffer.*/
- epcp->in_state->txbuf += transmitted;
- usb_packet_write_from_buffer(ep, epcp->in_state->txbuf, n);
+ isp->txbuf += isp->txlast;
+ isp->txlast = n;
+ usb_packet_write_from_buffer(ep, isp->txbuf, n);
/* Starting IN operation.*/
EPR_SET_STAT_TX(ep, EPR_STAT_TX_VALID);
@@ -247,26 +238,30 @@ static void usb_serve_endpoints(USBDriver *usbp, uint32_t ep) {
}
}
if (epr & EPR_CTR_RX) {
- EPR_CLEAR_CTR_RX(ep);
/* OUT endpoint, receive.*/
+
+ EPR_CLEAR_CTR_RX(ep);
+
if (epr & EPR_SETUP) {
/* Setup packets handling, setup packets are handled using a
specific callback.*/
_usb_isr_invoke_setup_cb(usbp, ep);
}
else {
+ USBOutEndpointState *osp = epcp->out_state;
+
/* Reads the packet into the defined buffer.*/
- n = usb_packet_read_to_buffer(ep, epcp->out_state->rxbuf);
- epcp->out_state->rxbuf += n;
+ n = usb_packet_read_to_buffer(ep, osp->rxbuf);
+ osp->rxbuf += n;
/* Transaction data updated.*/
- epcp->out_state->rxcnt += n;
- epcp->out_state->rxsize -= n;
- epcp->out_state->rxpkts -= 1;
+ osp->rxcnt += n;
+ osp->rxsize -= n;
+ osp->rxpkts -= 1;
/* The transaction is completed if the specified number of packets
has been received or the current packet is a short packet.*/
- if ((n < epcp->out_maxsize) || (epcp->out_state->rxpkts == 0)) {
+ if ((n < epcp->out_maxsize) || (osp->rxpkts == 0)) {
/* Transfer complete, invokes the callback.*/
_usb_isr_invoke_out_cb(usbp, ep);
}
@@ -707,6 +702,7 @@ void usb_lld_start_in(USBDriver *usbp, usbep_t ep) {
if (n > (size_t)usbp->epc[ep]->in_maxsize)
n = (size_t)usbp->epc[ep]->in_maxsize;
+ isp->txlast = n;
usb_packet_write_from_buffer(ep, isp->txbuf, n);
EPR_SET_STAT_TX(ep, EPR_STAT_TX_VALID);
diff --git a/os/hal/ports/STM32/LLD/USBv1/usb_lld.h b/os/hal/ports/STM32/LLD/USBv1/usb_lld.h
index 11cd924d0..c74888dac 100644
--- a/os/hal/ports/STM32/LLD/USBv1/usb_lld.h
+++ b/os/hal/ports/STM32/LLD/USBv1/usb_lld.h
@@ -182,6 +182,10 @@ typedef struct {
thread_reference_t thread;
#endif
/* End of the mandatory fields.*/
+ /**
+ * @brief Size of the last transmitted packet.
+ */
+ size_t txlast;
} USBInEndpointState;
/**