Implemented automatic allocation in the packet memory of the STM32 USB driver, no need to specify addresses anymore.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2737 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2011-02-13 20:55:57 +00:00
parent f67eb2c108
commit dd6a0b3ccd
3 changed files with 32 additions and 21 deletions

View File

@ -44,7 +44,6 @@
USBDriver USBD1; USBDriver USBD1;
#endif #endif
/*===========================================================================*/ /*===========================================================================*/
/* Driver local variables. */ /* Driver local variables. */
/*===========================================================================*/ /*===========================================================================*/
@ -62,15 +61,34 @@ static const USBEndpointConfig ep0config = {
_usb_ep0in, _usb_ep0in,
_usb_ep0out, _usb_ep0out,
0x40, 0x40,
0x40, 0x40
0x40,
0x80
}; };
/*===========================================================================*/ /*===========================================================================*/
/* Driver local functions. */ /* Driver local functions. */
/*===========================================================================*/ /*===========================================================================*/
/**
* @brief Resets the packet memory allocator.
*
* @param[in] usbp pointer to the @p USBDriver object
*/
static void pm_reset(USBDriver *usbp) {
usbp->pmnext = 64;
}
/**
* @brief Resets the packet memory allocator.
*
* @param[in] usbp pointer to the @p USBDriver object
* @param[in] size size of the packet buffer to allocate
*/
static uint32_t pm_alloc(USBDriver *usbp, size_t size) {
uint32_t next = usbp->pmnext;
usbp->pmnext += size;
return next;
}
/** /**
* @brief Copies a packet from memory into a packet buffer. * @brief Copies a packet from memory into a packet buffer.
* *
@ -342,6 +360,9 @@ void usb_lld_reset(USBDriver *usbp) {
cntr |= CNTR_SOFM; cntr |= CNTR_SOFM;
STM32_USB->CNTR = cntr; STM32_USB->CNTR = cntr;
/* Resets the packet memory allocator.*/
pm_reset(usbp);
/* EP0 initialization.*/ /* EP0 initialization.*/
memset(&ep0state, 0, sizeof ep0state); memset(&ep0state, 0, sizeof ep0state);
ep0state.config = &ep0config; ep0state.config = &ep0config;
@ -417,8 +438,8 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
dp = USB_GET_DESCRIPTOR(ep); dp = USB_GET_DESCRIPTOR(ep);
dp->TXCOUNT = 0; dp->TXCOUNT = 0;
dp->RXCOUNT = nblocks; dp->RXCOUNT = nblocks;
dp->TXADDR = epcp->inaddr; dp->TXADDR = pm_alloc(usbp, epcp->in_maxsize);
dp->RXADDR = epcp->outaddr; dp->RXADDR = pm_alloc(usbp, epcp->out_maxsize);
} }
/** /**

View File

@ -127,14 +127,6 @@ typedef struct {
*/ */
uint16_t out_maxsize; uint16_t out_maxsize;
/* End of the mandatory fields.*/ /* End of the mandatory fields.*/
/**
* @brief Endpoint IN buffer address as offset in the PMA.
*/
uint16_t inaddr;
/**
* @brief Endpoint OUT buffer address as offset in the PMA.
*/
uint16_t outaddr;
} USBEndpointConfig; } USBEndpointConfig;
@ -265,6 +257,10 @@ struct USBDriver {
*/ */
uint8_t configuration; uint8_t configuration;
/* End of the mandatory fields.*/ /* End of the mandatory fields.*/
/**
* @brief Pointer to the next address in the packet memory.
*/
uint32_t pmnext;
}; };
/*===========================================================================*/ /*===========================================================================*/

View File

@ -255,8 +255,6 @@ static const USBEndpointConfig ep1config = {
sduDataTransmitted, sduDataTransmitted,
NULL, NULL,
0x0040, 0x0040,
0x0000,
0x00C0,
0x0000 0x0000
}; };
@ -268,8 +266,6 @@ static const USBEndpointConfig ep2config = {
sduInterruptTransmitted, sduInterruptTransmitted,
NULL, NULL,
0x0010, 0x0010,
0x0000,
0x0100,
0x0000 0x0000
}; };
@ -281,9 +277,7 @@ static const USBEndpointConfig ep3config = {
NULL, NULL,
sduDataReceived, sduDataReceived,
0x0000, 0x0000,
0x0040, 0x0040
0x0000,
0x0110
}; };
/* /*