git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4265 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2012-06-10 16:31:03 +00:00
parent 1d023ea901
commit c762926b68
6 changed files with 96 additions and 104 deletions

View File

@ -181,8 +181,8 @@
#define USB_EP_MODE_TYPE_ISOC 0x0001 /**< Isochronous endpoint. */ #define USB_EP_MODE_TYPE_ISOC 0x0001 /**< Isochronous endpoint. */
#define USB_EP_MODE_TYPE_BULK 0x0002 /**< Bulk endpoint. */ #define USB_EP_MODE_TYPE_BULK 0x0002 /**< Bulk endpoint. */
#define USB_EP_MODE_TYPE_INTR 0x0003 /**< Interrupt endpoint. */ #define USB_EP_MODE_TYPE_INTR 0x0003 /**< Interrupt endpoint. */
#define USB_EP_MODE_TRANSACTION 0x0000 /**< Transaction mode. */ #define USB_EP_MODE_LINEAR_BUFFER 0x0000 /**< Linear buffer mode. */
#define USB_EP_MODE_PACKET 0x0010 /**< Packet mode enabled. */ #define USB_EP_MODE_QUEUE_BUFFER 0x0010 /**< Queue buffer mode. */
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/
@ -371,43 +371,6 @@ typedef const USBDescriptor * (*usbgetdescriptor_t)(USBDriver *usbp,
*/ */
#define usbGetReceiveStatusI(usbp, ep) ((usbp)->receiving & (1 << (ep))) #define usbGetReceiveStatusI(usbp, ep) ((usbp)->receiving & (1 << (ep)))
/**
* @brief Reads from a dedicated packet buffer.
* @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.
*
* @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.
*
* @special
*/
#define usbReadPacketBuffer(usbp, ep, buf, n) \
usb_lld_read_packet_buffer(usbp, ep, buf, n)
/**
* @brief Writes to a dedicated packet buffer.
* @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.
*
* @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.
*
* @special
*/
#define usbWritePacketBuffer(usbp, ep, buf, n) \
usb_lld_write_packet_buffer(usbp, ep, buf, n)
/** /**
* @brief Prepares for a receive transaction on an OUT endpoint. * @brief Prepares for a receive transaction on an OUT endpoint.
* @pre In order to use this function the endpoint must have been * @pre In order to use this function the endpoint must have been
@ -440,6 +403,42 @@ typedef const USBDescriptor * (*usbgetdescriptor_t)(USBDriver *usbp,
#define usbPrepareTransmit(usbp, ep, buf, n) \ #define usbPrepareTransmit(usbp, ep, buf, n) \
usb_lld_prepare_transmit(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[in] iq input queue to be filled with incoming data
*
* @special
*/
#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] oq output queue to be fetched for outgoing data
*
* @special
*/
#define usbPrepareQueuedTransmit(usbp, ep, oq) \
usb_lld_prepare_queued_transmit(usbp, ep, oq)
/** /**
* @brief Returns the exact size of a receive transaction. * @brief Returns the exact size of a receive transaction.
* @details The received size can be different from the size specified in * @details The received size can be different from the size specified in

View File

@ -77,7 +77,7 @@ static uint8_t ep0setup_buffer[8];
* @brief EP0 initialization structure. * @brief EP0 initialization structure.
*/ */
static const USBEndpointConfig ep0config = { static const USBEndpointConfig ep0config = {
USB_EP_MODE_TYPE_CTRL | USB_EP_MODE_TRANSACTION, USB_EP_MODE_TYPE_CTRL,
_usb_ep0setup, _usb_ep0setup,
_usb_ep0in, _usb_ep0in,
_usb_ep0out, _usb_ep0out,
@ -715,57 +715,6 @@ void usb_lld_read_setup(USBDriver *usbp, usbep_t ep, uint8_t *buf) {
memcpy(buf, usbp->epc[ep]->setup_buf, 8); memcpy(buf, usbp->epc[ep]->setup_buf, 8);
} }
/**
* @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. * @brief Prepares for a receive operation.
* *
@ -820,6 +769,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. * @brief Starts a receive operation on an OUT endpoint.
* *

View File

@ -129,10 +129,6 @@ typedef struct {
* @brief Type of an endpoint state structure. * @brief Type of an endpoint state structure.
*/ */
typedef struct { typedef struct {
/**
* @brief Number of packets to receive.
*/
uint16_t rxpkts;
/** /**
* @brief Pointer to the receive buffer. * @brief Pointer to the receive buffer.
*/ */
@ -377,14 +373,14 @@ extern "C" {
usbepstatus_t usb_lld_get_status_in(USBDriver *usbp, usbep_t ep); usbepstatus_t usb_lld_get_status_in(USBDriver *usbp, usbep_t ep);
usbepstatus_t usb_lld_get_status_out(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_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, void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep,
uint8_t *buf, size_t n); uint8_t *buf, size_t n);
void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep, void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep,
const uint8_t *buf, size_t n); 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_out(USBDriver *usbp, usbep_t ep);
void usb_lld_start_in(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); void usb_lld_stall_out(USBDriver *usbp, usbep_t ep);

View File

@ -119,6 +119,7 @@ static const struct SerialUSBDriverVMT vmt = {
static void inotify(GenericQueue *qp) { static void inotify(GenericQueue *qp) {
SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_wrptr; SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_wrptr;
#if 0
/* Writes to the input queue can only happen when the queue has been /* Writes to the input queue can only happen when the queue has been
emptied, then a whole packet is loaded in the queue.*/ emptied, then a whole packet is loaded in the queue.*/
if (!usbGetReceiveStatusI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP) && 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)) while (notempty(&sdup->iqueue.q_waiting))
chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK; 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; SerialUSBDriver *sdup = (SerialUSBDriver *)qp->q_rdptr;
size_t n; size_t n;
#if 0
/* If there is any data in the output queue then it is sent within a /* If there is any data in the output queue then it is sent within a
single packet and the queue is emptied.*/ single packet and the queue is emptied.*/
n = chOQGetFullI(&sdup->oqueue); n = chOQGetFullI(&sdup->oqueue);
@ -166,6 +169,7 @@ static void onotify(GenericQueue *qp) {
while (notempty(&sdup->oqueue.q_waiting)) while (notempty(&sdup->oqueue.q_waiting))
chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK; 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; SerialUSBDriver *sdup = usbp->param;
size_t n; size_t n;
#if 0
chSysLockFromIsr(); chSysLockFromIsr();
/* If there is any data in the output queue then it is sent within a /* If there is any data in the output queue then it is sent within a
single packet and the queue is emptied.*/ 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; chSchReadyI(fifo_remove(&sdup->oqueue.q_waiting))->p_u.rdymsg = Q_OK;
} }
chSysUnlockFromIsr(); chSysUnlockFromIsr();
#endif
} }
/** /**
@ -332,6 +338,7 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) {
void sduDataReceived(USBDriver *usbp, usbep_t ep) { void sduDataReceived(USBDriver *usbp, usbep_t ep) {
SerialUSBDriver *sdup = usbp->param; SerialUSBDriver *sdup = usbp->param;
#if 0
chSysLockFromIsr(); chSysLockFromIsr();
/* Writes to the input queue can only happen when the queue has been /* Writes to the input queue can only happen when the queue has been
emptied, then a whole packet is loaded in the queue.*/ 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; chSchReadyI(fifo_remove(&sdup->iqueue.q_waiting))->p_u.rdymsg = Q_OK;
} }
chSysUnlockFromIsr(); chSysUnlockFromIsr();
#endif
} }
/** /**

View File

@ -313,10 +313,10 @@ void usbInitEndpointI(USBDriver *usbp, usbep_t ep,
"usbEnableEndpointI(), #2", "already initialized"); "usbEnableEndpointI(), #2", "already initialized");
/* Logically enabling the endpoint in the USBDriver structure.*/ /* 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->in_state, 0, sizeof(USBInEndpointState));
memset(epcp->out_state, 0, sizeof(USBOutEndpointState)); memset(epcp->out_state, 0, sizeof(USBOutEndpointState));
} // }
usbp->epc[ep] = epcp; usbp->epc[ep] = epcp;
/* Low level endpoint activation.*/ /* Low level endpoint activation.*/

View File

@ -229,7 +229,7 @@ static const USBDescriptor *get_descriptor(USBDriver *usbp,
* @brief EP1 initialization structure (IN only). * @brief EP1 initialization structure (IN only).
*/ */
static const USBEndpointConfig ep1config = { static const USBEndpointConfig ep1config = {
USB_EP_MODE_TYPE_BULK | USB_EP_MODE_PACKET, USB_EP_MODE_TYPE_BULK,
NULL, NULL,
sduDataTransmitted, sduDataTransmitted,
NULL, NULL,
@ -244,7 +244,7 @@ static const USBEndpointConfig ep1config = {
* @brief EP2 initialization structure (IN only). * @brief EP2 initialization structure (IN only).
*/ */
static const USBEndpointConfig ep2config = { static const USBEndpointConfig ep2config = {
USB_EP_MODE_TYPE_INTR | USB_EP_MODE_PACKET, USB_EP_MODE_TYPE_INTR,
NULL, NULL,
sduInterruptTransmitted, sduInterruptTransmitted,
NULL, NULL,
@ -259,7 +259,7 @@ static const USBEndpointConfig ep2config = {
* @brief EP3 initialization structure (OUT only). * @brief EP3 initialization structure (OUT only).
*/ */
static const USBEndpointConfig ep3config = { static const USBEndpointConfig ep3config = {
USB_EP_MODE_TYPE_BULK | USB_EP_MODE_PACKET, USB_EP_MODE_TYPE_BULK,
NULL, NULL,
NULL, NULL,
sduDataReceived, sduDataReceived,