RAM optimization to the USB driver.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2732 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2011-02-12 11:54:15 +00:00
parent 2f003bd721
commit d749ecc10a
5 changed files with 36 additions and 31 deletions

View File

@ -242,7 +242,7 @@ typedef const USBDescriptor * (*usbgetdescriptor_t)(USBDriver *usbp,
* *
* @iclass * @iclass
*/ */
#define usbGetTransmitStatusI(usbp, ep) (usbp)->ep[ep]->transmitting #define usbGetTransmitStatusI(usbp, ep) ((usbp)->transmitting & (1 << (ep)))
/** /**
* @brief Returns the status of an OUT endpoint. * @brief Returns the status of an OUT endpoint.
@ -255,7 +255,7 @@ typedef const USBDescriptor * (*usbgetdescriptor_t)(USBDriver *usbp,
* *
* @iclass * @iclass
*/ */
#define usbGetReceiveStatusI(usbp, ep) (usbp)->ep[ep]->receiving #define usbGetReceiveStatusI(usbp, ep) ((usbp)->receiving & (1 << (ep)))
/** /**
* @brief Request transfer setup. * @brief Request transfer setup.

View File

@ -181,7 +181,7 @@ CH_IRQ_HANDLER(USB_LP_IRQHandler) {
EPR_CLEAR_CTR_TX(ep); EPR_CLEAR_CTR_TX(ep);
if (epcp->flags & USB_EP_FLAGS_IN_PACKET_MODE) { if (epcp->flags & USB_EP_FLAGS_IN_PACKET_MODE) {
/* Packet mode, just invokes the callback.*/ /* Packet mode, just invokes the callback.*/
(usbp)->ep[ep]->transmitting = FALSE; (usbp)->transmitting &= ~((uint16_t)(1 << ep));
epcp->in_cb(usbp, ep); epcp->in_cb(usbp, ep);
} }
else { else {
@ -200,7 +200,7 @@ CH_IRQ_HANDLER(USB_LP_IRQHandler) {
} }
else { else {
/* Transfer completed, invokes the callback.*/ /* Transfer completed, invokes the callback.*/
(usbp)->ep[ep]->transmitting = FALSE; (usbp)->transmitting &= ~((uint16_t)(1 << ep));
epcp->in_cb(usbp, ep); epcp->in_cb(usbp, ep);
} }
} }
@ -210,7 +210,7 @@ CH_IRQ_HANDLER(USB_LP_IRQHandler) {
/* OUT endpoint, receive.*/ /* OUT endpoint, receive.*/
if (epcp->flags & USB_EP_FLAGS_OUT_PACKET_MODE) { if (epcp->flags & USB_EP_FLAGS_OUT_PACKET_MODE) {
/* Packet mode, just invokes the callback.*/ /* Packet mode, just invokes the callback.*/
(usbp)->ep[ep]->receiving = FALSE; (usbp)->receiving &= ~((uint16_t)(1 << ep));
epcp->out_cb(usbp, ep); epcp->out_cb(usbp, ep);
} }
else { else {
@ -233,7 +233,7 @@ CH_IRQ_HANDLER(USB_LP_IRQHandler) {
} }
else { else {
/* Transfer completed, invokes the callback.*/ /* Transfer completed, invokes the callback.*/
(usbp)->ep[ep]->receiving = FALSE; (usbp)->receiving &= ~((uint16_t)(1 << ep));
epcp->out_cb(usbp, ep); epcp->out_cb(usbp, ep);
} }
} }
@ -398,7 +398,7 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
start ready to accept data else it must start in NAK mode.*/ start ready to accept data else it must start in NAK mode.*/
if (epcp->out_cb) { if (epcp->out_cb) {
if (epcp->flags & USB_EP_FLAGS_OUT_PACKET_MODE) { if (epcp->flags & USB_EP_FLAGS_OUT_PACKET_MODE) {
usbp->ep[ep]->receiving = TRUE; usbp->receiving |= ((uint16_t)(1 << ep));
epr |= EPR_STAT_RX_VALID; epr |= EPR_STAT_RX_VALID;
} }
else else

View File

@ -160,15 +160,6 @@ typedef struct {
* @brief Configuration associated to the endpoint. * @brief Configuration associated to the endpoint.
*/ */
const USBEndpointConfig *config; const USBEndpointConfig *config;
/**
* @brief @p TRUE if transmitting else @p FALSE.
*/
uint8_t transmitting;
/**
* @brief @p TRUE if receiving else @p FALSE.
*/
uint8_t receiving;
/* End of the mandatory fields.*/
/** /**
* @brief Number of packets to receive. * @brief Number of packets to receive.
*/ */
@ -243,6 +234,14 @@ struct USBDriver {
* application-defined handler to the USB driver. * application-defined handler to the USB driver.
*/ */
void *param; void *param;
/**
* @brief Bit map of the transmitting IN endpoints.
*/
uint16_t transmitting;
/**
* @brief Bit map of the receiving OUT endpoints.
*/
uint16_t receiving;
/** /**
* @brief Active endpoints configurations. * @brief Active endpoints configurations.
*/ */

View File

@ -124,7 +124,7 @@ static void inotify(GenericQueue *qp) {
if (n != USB_ENDPOINT_BUSY) { if (n != USB_ENDPOINT_BUSY) {
sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer; sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer;
chSemSetCounterI(&sdup->iqueue.q_sem, n); chSemSetCounterI(&sdup->iqueue.q_sem, n);
chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE); // chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE);
} }
} }
} }
@ -143,7 +143,7 @@ static void onotify(GenericQueue *qp) {
if (n != USB_ENDPOINT_BUSY) { if (n != USB_ENDPOINT_BUSY) {
sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer; sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer;
chSemSetCounterI(&sdup->oqueue.q_sem, SERIAL_USB_BUFFERS_SIZE); chSemSetCounterI(&sdup->oqueue.q_sem, SERIAL_USB_BUFFERS_SIZE);
chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY); // chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY);
} }
} }

View File

@ -234,9 +234,11 @@ void usbInit(void) {
*/ */
void usbObjectInit(USBDriver *usbp) { void usbObjectInit(USBDriver *usbp) {
usbp->state = USB_STOP; usbp->state = USB_STOP;
usbp->config = NULL; usbp->config = NULL;
usbp->param = NULL; usbp->param = NULL;
usbp->transmitting = 0;
usbp->receiving = 0;
} }
/** /**
@ -358,10 +360,10 @@ void usbDisableEndpointsI(USBDriver *usbp) {
size_t usbReadPacketI(USBDriver *usbp, usbep_t ep, size_t usbReadPacketI(USBDriver *usbp, usbep_t ep,
uint8_t *buf, size_t n) { uint8_t *buf, size_t n) {
if (usbp->ep[ep]->receiving) if (usbGetReceiveStatusI(usbp, ep))
return USB_ENDPOINT_BUSY; return USB_ENDPOINT_BUSY;
usbp->ep[ep]->receiving = TRUE; usbp->receiving |= (1 << ep);
return usb_lld_read_packet(usbp, ep, buf, n);; return usb_lld_read_packet(usbp, ep, buf, n);;
} }
@ -385,10 +387,10 @@ size_t usbReadPacketI(USBDriver *usbp, usbep_t ep,
size_t usbWritePacketI(USBDriver *usbp, usbep_t ep, size_t usbWritePacketI(USBDriver *usbp, usbep_t ep,
const uint8_t *buf, size_t n) { const uint8_t *buf, size_t n) {
if (usbp->ep[ep]->transmitting) if (usbGetTransmitStatusI(usbp, ep))
return USB_ENDPOINT_BUSY; return USB_ENDPOINT_BUSY;
usbp->ep[ep]->transmitting = TRUE; usbp->transmitting |= (1 << ep);
usb_lld_write_packet(usbp, ep, buf, n); usb_lld_write_packet(usbp, ep, buf, n);
return 0; return 0;
} }
@ -413,9 +415,10 @@ size_t usbWritePacketI(USBDriver *usbp, usbep_t ep,
bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep, bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep,
uint8_t *buf, size_t n) { uint8_t *buf, size_t n) {
if (usbp->ep[ep]->receiving) if (usbGetReceiveStatusI(usbp, ep))
return TRUE; return TRUE;
usbp->ep[ep]->receiving = TRUE;
usbp->receiving |= (1 << ep);
usb_lld_start_out(usbp, ep, buf, n); usb_lld_start_out(usbp, ep, buf, n);
return FALSE; return FALSE;
} }
@ -440,9 +443,10 @@ bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep,
bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep, bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep,
const uint8_t *buf, size_t n) { const uint8_t *buf, size_t n) {
if (usbp->ep[ep]->transmitting) if (usbGetTransmitStatusI(usbp, ep))
return TRUE; return TRUE;
usbp->ep[ep]->transmitting = TRUE;
usbp->transmitting |= (1 << ep);
usb_lld_start_in(usbp, ep, buf, n); usb_lld_start_in(usbp, ep, buf, n);
return FALSE; return FALSE;
} }
@ -460,8 +464,9 @@ bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep,
*/ */
bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) { bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) {
if (usbp->ep[ep]->receiving) if (usbGetReceiveStatusI(usbp, ep))
return TRUE; return TRUE;
usb_lld_stall_out(usbp, ep); usb_lld_stall_out(usbp, ep);
return FALSE; return FALSE;
} }
@ -479,8 +484,9 @@ bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) {
*/ */
bool_t usbStallTransmitI(USBDriver *usbp, usbep_t ep) { bool_t usbStallTransmitI(USBDriver *usbp, usbep_t ep) {
if (usbp->ep[ep]->transmitting) if (usbGetTransmitStatusI(usbp, ep))
return TRUE; return TRUE;
usb_lld_stall_in(usbp, ep); usb_lld_stall_in(usbp, ep);
return FALSE; return FALSE;
} }