aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal')
-rw-r--r--os/hal/include/usb.h57
-rw-r--r--os/hal/platforms/STM32/OTGv1/usb_lld.c93
-rw-r--r--os/hal/platforms/STM32/OTGv1/usb_lld.h12
-rw-r--r--os/hal/src/serial_usb.c8
-rw-r--r--os/hal/src/usb.c4
5 files changed, 83 insertions, 91 deletions
diff --git a/os/hal/include/usb.h b/os/hal/include/usb.h
index 9e5eb1b62..89871ffe6 100644
--- a/os/hal/include/usb.h
+++ b/os/hal/include/usb.h
@@ -181,8 +181,8 @@
#define USB_EP_MODE_TYPE_ISOC 0x0001 /**< Isochronous endpoint. */
#define USB_EP_MODE_TYPE_BULK 0x0002 /**< Bulk endpoint. */
#define USB_EP_MODE_TYPE_INTR 0x0003 /**< Interrupt endpoint. */
-#define USB_EP_MODE_TRANSACTION 0x0000 /**< Transaction mode. */
-#define USB_EP_MODE_PACKET 0x0010 /**< Packet mode enabled. */
+#define USB_EP_MODE_LINEAR_BUFFER 0x0000 /**< Linear buffer mode. */
+#define USB_EP_MODE_QUEUE_BUFFER 0x0010 /**< Queue buffer mode. */
/** @} */
/*===========================================================================*/
@@ -372,73 +372,72 @@ typedef const USBDescriptor * (*usbgetdescriptor_t)(USBDriver *usbp,
#define usbGetReceiveStatusI(usbp, ep) ((usbp)->receiving & (1 << (ep)))
/**
- * @brief Reads from a dedicated packet buffer.
+ * @brief Prepares for a receive transaction on an OUT endpoint.
* @pre In order to use this function the endpoint must have been
- * initialized in packet mode.
- * @note This function can be invoked both in thread and IRQ context.
+ * initialized in transaction mode.
+ * @post The endpoint is ready for @p usbStartReceiveI().
*
* @param[in] usbp pointer to the @p USBDriver object
* @param[in] ep endpoint number
- * @param[out] buf buffer where to copy the packet data
- * @param[in] n maximum number of bytes to copy. This value must
- * not exceed the maximum packet size for this endpoint.
- * @return The received packet size regardless the specified
- * @p n parameter.
- * @retval 0 Zero size packet received.
+ * @param[out] buf buffer where to copy the received data
+ * @param[in] n maximum number of bytes to copy
*
* @special
*/
-#define usbReadPacketBuffer(usbp, ep, buf, n) \
- usb_lld_read_packet_buffer(usbp, ep, buf, n)
+#define usbPrepareReceive(usbp, ep, buf, n) \
+ usb_lld_prepare_receive(usbp, ep, buf, n)
/**
- * @brief Writes to a dedicated packet buffer.
+ * @brief Prepares for a transmit transaction on an IN endpoint.
* @pre In order to use this function the endpoint must have been
- * initialized in packet mode.
- * @note This function can be invoked both in thread and IRQ context.
+ * initialized in transaction mode.
+ * @post The endpoint is ready for @p usbStartTransmitI().
*
* @param[in] usbp pointer to the @p USBDriver object
* @param[in] ep endpoint number
- * @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.
+ * @param[in] buf buffer where to fetch the data to be transmitted
+ * @param[in] n maximum number of bytes to copy
*
* @special
*/
-#define usbWritePacketBuffer(usbp, ep, buf, n) \
- usb_lld_write_packet_buffer(usbp, ep, buf, n)
+#define usbPrepareTransmit(usbp, ep, buf, n) \
+ usb_lld_prepare_transmit(usbp, ep, buf, n)
/**
* @brief Prepares for a receive transaction on an OUT endpoint.
* @pre In order to use this function the endpoint must have been
* initialized in transaction mode.
* @post The endpoint is ready for @p usbStartReceiveI().
+ * @note The receive transaction size is equal to the space in the queue
+ * rounded to the lower multiple of a packet size. So make sure there
+ * is room for at least one packet in the queue before starting
+ * the receive operation.
*
* @param[in] usbp pointer to the @p USBDriver object
* @param[in] ep endpoint number
- * @param[out] buf buffer where to copy the received data
- * @param[in] n maximum number of bytes to copy
+ * @param[in] iq input queue to be filled with incoming data
*
* @special
*/
-#define usbPrepareReceive(usbp, ep, buf, n) \
- usb_lld_prepare_receive(usbp, ep, buf, n)
+#define usbPrepareQueuedReceive(usbp, ep, iq) \
+ usb_lld_prepare_queued_receive(usbp, ep, iq)
/**
* @brief Prepares for a transmit transaction on an IN endpoint.
* @pre In order to use this function the endpoint must have been
* initialized in transaction mode.
* @post The endpoint is ready for @p usbStartTransmitI().
+ * @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] buf buffer where to fetch the data to be transmitted
- * @param[in] n maximum number of bytes to copy
+ * @param[in] oq output queue to be fetched for outgoing data
*
* @special
*/
-#define usbPrepareTransmit(usbp, ep, buf, n) \
- usb_lld_prepare_transmit(usbp, ep, buf, n)
+#define usbPrepareQueuedTransmit(usbp, ep, oq) \
+ usb_lld_prepare_queued_transmit(usbp, ep, oq)
/**
* @brief Returns the exact size of a receive transaction.
diff --git a/os/hal/platforms/STM32/OTGv1/usb_lld.c b/os/hal/platforms/STM32/OTGv1/usb_lld.c
index 26a5975ee..44d292b8b 100644
--- a/os/hal/platforms/STM32/OTGv1/usb_lld.c
+++ b/os/hal/platforms/STM32/OTGv1/usb_lld.c
@@ -77,7 +77,7 @@ static uint8_t ep0setup_buffer[8];
* @brief EP0 initialization structure.
*/
static const USBEndpointConfig ep0config = {
- USB_EP_MODE_TYPE_CTRL | USB_EP_MODE_TRANSACTION,
+ USB_EP_MODE_TYPE_CTRL,
_usb_ep0setup,
_usb_ep0in,
_usb_ep0out,
@@ -716,57 +716,6 @@ void usb_lld_read_setup(USBDriver *usbp, usbep_t ep, uint8_t *buf) {
}
/**
- * @brief Reads from a dedicated packet buffer.
- * @pre In order to use this function he endpoint must have been
- * initialized in packet mode.
- * @note This function can be invoked both in thread and IRQ context.
- *
- * @param[in] usbp pointer to the @p USBDriver object
- * @param[in] ep endpoint number
- * @param[out] buf buffer where to copy the packet data
- * @param[in] n maximum number of bytes to copy. This value must
- * not exceed the maximum packet size for this endpoint.
- * @return The received packet size regardless the specified
- * @p n parameter.
- * @retval 0 Zero size packet received.
- *
- * @notapi
- */
-size_t usb_lld_read_packet_buffer(USBDriver *usbp, usbep_t ep,
- uint8_t *buf, size_t n) {
-
- (void)usbp;
- (void)ep;
- (void)buf;
- (void)n;
-
- return 0;
-}
-
-/**
- * @brief Writes to a dedicated packet buffer.
- * @pre In order to use this function he endpoint must have been
- * initialized in packet mode.
- * @note This function can be invoked both in thread and IRQ context.
- *
- * @param[in] usbp pointer to the @p USBDriver object
- * @param[in] ep endpoint number
- * @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
- */
-void usb_lld_write_packet_buffer(USBDriver *usbp, usbep_t ep,
- const uint8_t *buf, size_t n) {
-
- (void)usbp;
- (void)ep;
- (void)buf;
- (void)n;
-}
-
-/**
* @brief Prepares for a receive operation.
*
* @param[in] usbp pointer to the @p USBDriver object
@@ -821,6 +770,46 @@ void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep,
}
/**
+ * @brief Prepares for a receive transaction on an OUT endpoint.
+ * @pre In order to use this function the endpoint must have been
+ * initialized in transaction mode.
+ * @post The endpoint is ready for @p usbStartReceiveI().
+ * @note The receive transaction size is equal to the space in the queue
+ * rounded to the lower multiple of a packet size. So make sure there
+ * is room for at least one packet in the queue before starting
+ * the receive operation.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @param[in] ep endpoint number
+ * @param[in] iq input queue to be filled with incoming data
+ *
+ * @special
+ */
+void usb_lld_prepare_queued_receive(USBDriver *usbp, usbep_t ep,
+ InputQueue *iq) {
+
+}
+
+/**
+ * @brief Prepares for a transmit transaction on an IN endpoint.
+ * @pre In order to use this function the endpoint must have been
+ * initialized in transaction mode.
+ * @post The endpoint is ready for @p usbStartTransmitI().
+ * @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] oq output queue to be fetched for outgoing data
+ *
+ * @special
+ */
+void usb_lld_prepare_queued_transmit(USBDriver *usbp, usbep_t ep,
+ OutputQueue *oq) {
+
+}
+
+/**
* @brief Starts a receive operation on an OUT endpoint.
*
* @param[in] usbp pointer to the @p USBDriver object
diff --git a/os/hal/platforms/STM32/OTGv1/usb_lld.h b/os/hal/platforms/STM32/OTGv1/usb_lld.h
index 4cc18a05b..687d788ff 100644
--- a/os/hal/platforms/STM32/OTGv1/usb_lld.h
+++ b/os/hal/platforms/STM32/OTGv1/usb_lld.h
@@ -130,10 +130,6 @@ typedef struct {
*/
typedef struct {
/**
- * @brief Number of packets to receive.
- */
- uint16_t rxpkts;
- /**
* @brief Pointer to the receive buffer.
*/
uint8_t *rxbuf;
@@ -377,14 +373,14 @@ 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);
- size_t usb_lld_read_packet_buffer(USBDriver *usbp, usbep_t ep,
- uint8_t *buf, size_t n);
- void usb_lld_write_packet_buffer(USBDriver *usbp, usbep_t ep,
- const uint8_t *buf, size_t n);
void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep,
uint8_t *buf, size_t n);
void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep,
const uint8_t *buf, size_t n);
+ void usb_lld_prepare_queued_receive(USBDriver *usbp, usbep_t ep,
+ InputQueue *iq);
+ void usb_lld_prepare_queued_transmit(USBDriver *usbp, usbep_t ep,
+ OutputQueue *oq);
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/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c
index 2c7a37b4d..7f1658812 100644
--- a/os/hal/src/serial_usb.c
+++ b/os/hal/src/serial_usb.c
@@ -119,6 +119,7 @@ static const struct SerialUSBDriverVMT vmt = {
static void inotify(GenericQueue *qp) {
SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_wrptr;
+#if 0
/* Writes to the input queue can only happen when the queue has been
emptied, then a whole packet is loaded in the queue.*/
if (!usbGetReceiveStatusI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP) &&
@@ -139,6 +140,7 @@ static void inotify(GenericQueue *qp) {
while (notempty(&sdup->iqueue.q_waiting))
chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK;
}
+#endif
}
/**
@@ -148,6 +150,7 @@ static void onotify(GenericQueue *qp) {
SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_rdptr;
size_t n;
+#if 0
/* If there is any data in the output queue then it is sent within a
single packet and the queue is emptied.*/
n = chOQGetFullI(&sdup->oqueue);
@@ -166,6 +169,7 @@ static void onotify(GenericQueue *qp) {
while (notempty(&sdup->oqueue.q_waiting))
chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK;
}
+#endif
}
/*===========================================================================*/
@@ -298,6 +302,7 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) {
SerialUSBDriver *sdup = usbp->param;
size_t n;
+#if 0
chSysLockFromIsr();
/* If there is any data in the output queue then it is sent within a
single packet and the queue is emptied.*/
@@ -319,6 +324,7 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) {
chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK;
}
chSysUnlockFromIsr();
+#endif
}
/**
@@ -332,6 +338,7 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) {
void sduDataReceived(USBDriver *usbp, usbep_t ep) {
SerialUSBDriver *sdup = usbp->param;
+#if 0
chSysLockFromIsr();
/* Writes to the input queue can only happen when the queue has been
emptied, then a whole packet is loaded in the queue.*/
@@ -355,6 +362,7 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) {
chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK;
}
chSysUnlockFromIsr();
+#endif
}
/**
diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c
index 1927581f1..ceae24770 100644
--- a/os/hal/src/usb.c
+++ b/os/hal/src/usb.c
@@ -313,10 +313,10 @@ void usbInitEndpointI(USBDriver *usbp, usbep_t ep,
"usbEnableEndpointI(), #2", "already initialized");
/* Logically enabling the endpoint in the USBDriver structure.*/
- if (!(epcp->ep_mode & USB_EP_MODE_PACKET)) {
+// if (!(epcp->ep_mode & USB_EP_MODE_PACKET)) {
memset(epcp->in_state, 0, sizeof(USBInEndpointState));
memset(epcp->out_state, 0, sizeof(USBOutEndpointState));
- }
+// }
usbp->epc[ep] = epcp;
/* Low level endpoint activation.*/