aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2015-12-30 11:47:19 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2015-12-30 11:47:19 +0000
commit32f4a2999d412aba93a6a252152ec8ca204c5b96 (patch)
treed25e0b223bf1e2089132c4d16f3bc95cd2df256f
parent73b405b13ff98171368c9b76aa37f07f189eb31f (diff)
downloadChibiOS-32f4a2999d412aba93a6a252152ec8ca204c5b96.tar.gz
ChibiOS-32f4a2999d412aba93a6a252152ec8ca204c5b96.tar.bz2
ChibiOS-32f4a2999d412aba93a6a252152ec8ca204c5b96.zip
USBv1 ported to the new model.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8655 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/hal/ports/STM32/LLD/USBv1/usb_lld.c56
-rw-r--r--os/hal/ports/STM32/LLD/USBv1/usb_lld.h33
-rw-r--r--testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c2
3 files changed, 37 insertions, 54 deletions
diff --git a/os/hal/ports/STM32/LLD/USBv1/usb_lld.c b/os/hal/ports/STM32/LLD/USBv1/usb_lld.c
index 05d03f524..5956e0db6 100644
--- a/os/hal/ports/STM32/LLD/USBv1/usb_lld.c
+++ b/os/hal/ports/STM32/LLD/USBv1/usb_lld.c
@@ -34,7 +34,7 @@
#define BTABLE_ADDR 0x0000
-#define EPR_EP_TYPE_IS_ISO(epr) ((epr & EPR_EP_TYPE_MASK) == EPR_EP_TYPE_ISO)
+#define EPR_EP_TYPE_IS_ISO(bits) ((bits & EPR_EP_TYPE_MASK) == EPR_EP_TYPE_ISO)
/*===========================================================================*/
/* Driver exported variables. */
@@ -219,9 +219,9 @@ static void usb_serve_endpoints(USBDriver *usbp, uint32_t ep) {
usb_packet_write_from_buffer(USB_GET_DESCRIPTOR(ep),
epcp->in_state->txbuf,
n);
- osalSysLockFromISR();
- usb_lld_start_in(usbp, ep);
- osalSysUnlockFromISR();
+
+ /* Starting IN operation.*/
+ EPR_SET_STAT_TX(ep, EPR_STAT_TX_VALID);
}
else {
/* Transfer completed, invokes the callback.*/
@@ -500,7 +500,7 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
receive descriptor fields are used for either direction.*/
switch (epcp->ep_mode & USB_EP_MODE_TYPE) {
case USB_EP_MODE_TYPE_ISOC:
- osalDbgAssert((epcp->in_cb == NULL) || (epcp->out_cb == NULL),
+ osalDbgAssert((epcp->in_state == NULL) || (epcp->out_state == NULL),
"isochronous EP cannot be IN and OUT");
epr = EPR_EP_TYPE_ISO;
break;
@@ -533,12 +533,12 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
but since we are not taking advantage of the double buffering, we set both
addresses to point to the same PMA.*/
if ((epcp->ep_mode & USB_EP_MODE_TYPE) == USB_EP_MODE_TYPE_ISOC) {
- if (epcp->in_cb != NULL) {
+ if (epcp->in_state != NULL) {
epr |= EPR_STAT_TX_VALID;
dp->TXCOUNT1 = dp->TXCOUNT0;
dp->TXADDR1 = dp->TXADDR0; /* Both buffers overlapped.*/
}
- if (epcp->out_cb != NULL) {
+ if (epcp->out_state != NULL) {
epr |= EPR_STAT_RX_VALID;
dp->RXCOUNT1 = dp->RXCOUNT0;
dp->RXADDR1 = dp->RXADDR0; /* Both buffers overlapped.*/
@@ -546,10 +546,10 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
}
else {
/* Initial status for other endpoint types is NAK.*/
- if (epcp->in_cb != NULL)
+ if (epcp->in_state != NULL)
epr |= EPR_STAT_TX_NAK;
- if (epcp->out_cb != NULL)
+ if (epcp->out_state != NULL)
epr |= EPR_STAT_RX_NAK;
}
@@ -657,14 +657,14 @@ void usb_lld_read_setup(USBDriver *usbp, usbep_t ep, uint8_t *buf) {
}
/**
- * @brief Prepares for a receive operation.
+ * @brief Starts a receive operation on an OUT endpoint.
*
* @param[in] usbp pointer to the @p USBDriver object
* @param[in] ep endpoint number
*
* @notapi
*/
-void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep) {
+void usb_lld_start_out(USBDriver *usbp, usbep_t ep) {
USBOutEndpointState *osp = usbp->epc[ep]->out_state;
/* Transfer initialization.*/
@@ -673,17 +673,19 @@ void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep) {
else
osp->rxpkts = (uint16_t)((osp->rxsize + usbp->epc[ep]->out_maxsize - 1) /
usbp->epc[ep]->out_maxsize);
+
+ EPR_SET_STAT_RX(ep, EPR_STAT_RX_VALID);
}
/**
- * @brief Prepares for a transmit operation.
+ * @brief Starts a transmit operation on an IN endpoint.
*
* @param[in] usbp pointer to the @p USBDriver object
* @param[in] ep endpoint number
*
* @notapi
*/
-void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep) {
+void usb_lld_start_in(USBDriver *usbp, usbep_t ep) {
size_t n;
USBInEndpointState *isp = usbp->epc[ep]->in_state;
uint32_t epr = STM32_USB->EPR[ep];
@@ -705,34 +707,6 @@ void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep) {
usb_packet_write_from_buffer(USB_GET_DESCRIPTOR(ep),
isp->txbuf, n);
-}
-
-/**
- * @brief Starts a receive operation on an OUT endpoint.
- *
- * @param[in] usbp pointer to the @p USBDriver object
- * @param[in] ep endpoint number
- *
- * @notapi
- */
-void usb_lld_start_out(USBDriver *usbp, usbep_t ep) {
-
- (void)usbp;
-
- EPR_SET_STAT_RX(ep, EPR_STAT_RX_VALID);
-}
-
-/**
- * @brief Starts a transmit operation on an IN endpoint.
- *
- * @param[in] usbp pointer to the @p USBDriver object
- * @param[in] ep endpoint number
- *
- * @notapi
- */
-void usb_lld_start_in(USBDriver *usbp, usbep_t ep) {
-
- (void)usbp;
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 7464d52da..3f4abc052 100644
--- a/os/hal/ports/STM32/LLD/USBv1/usb_lld.h
+++ b/os/hal/ports/STM32/LLD/USBv1/usb_lld.h
@@ -151,6 +151,13 @@ typedef struct {
* @brief Pointer to the transmission linear buffer.
*/
const uint8_t *txbuf;
+#if (USB_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Waiting thread.
+ */
+ thread_reference_t thread;
+#endif
+ /* End of the mandatory fields.*/
} USBInEndpointState;
/**
@@ -169,6 +176,12 @@ typedef struct {
* @brief Pointer to the receive linear buffer.
*/
uint8_t *rxbuf;
+#if (USB_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Waiting thread.
+ */
+ thread_reference_t thread;
+#endif
/* End of the mandatory fields.*/
/**
* @brief Number of packets to receive.
@@ -198,36 +211,34 @@ typedef struct {
usbepcallback_t setup_cb;
/**
* @brief IN endpoint notification callback.
- * @details This field must be set to @p NULL if the IN endpoint is not
- * used.
+ * @details This field must be set to @p NULL if callback is not required.
*/
usbepcallback_t in_cb;
/**
* @brief OUT endpoint notification callback.
- * @details This field must be set to @p NULL if the OUT endpoint is not
- * used.
+ * @details This field must be set to @p NULL if callback is not required.
*/
usbepcallback_t out_cb;
/**
* @brief IN endpoint maximum packet size.
- * @details This field must be set to zero if the IN endpoint is not
- * used.
+ * @details This field must be set to zero if the IN endpoint is not used.
*/
uint16_t in_maxsize;
/**
* @brief OUT endpoint maximum packet size.
- * @details This field must be set to zero if the OUT endpoint is not
- * used.
+ * @details This field must be set to zero if the OUT endpoint is not used.
*/
uint16_t out_maxsize;
/**
* @brief @p USBEndpointState associated to the IN endpoint.
- * @details This structure maintains the state of the IN endpoint.
+ * @details This field must be set to @p NULL if the IN endpoint is not
+ * used.
*/
USBInEndpointState *in_state;
/**
* @brief @p USBEndpointState associated to the OUT endpoint.
- * @details This structure maintains the state of the OUT endpoint.
+ * @details This field must be set to @p NULL if the OUT endpoint is not
+ * used.
*/
USBOutEndpointState *out_state;
/* End of the mandatory fields.*/
@@ -433,8 +444,6 @@ extern "C" {
usbepstatus_t usb_lld_get_status_in(USBDriver *usbp, usbep_t ep);
usbepstatus_t usb_lld_get_status_out(USBDriver *usbp, usbep_t ep);
void usb_lld_read_setup(USBDriver *usbp, usbep_t ep, uint8_t *buf);
- void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep);
- void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep);
void usb_lld_start_out(USBDriver *usbp, usbep_t ep);
void usb_lld_start_in(USBDriver *usbp, usbep_t ep);
void usb_lld_stall_out(USBDriver *usbp, usbep_t ep);
diff --git a/testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c b/testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c
index 07a492758..0b7b99767 100644
--- a/testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c
+++ b/testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c
@@ -235,7 +235,7 @@ static const USBEndpointConfig ep1config = {
0x0040,
&ep1instate,
&ep1outstate,
- 2,
+ 1,
NULL
};