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:
parent
f67eb2c108
commit
dd6a0b3ccd
|
@ -44,7 +44,6 @@
|
|||
USBDriver USBD1;
|
||||
#endif
|
||||
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables. */
|
||||
/*===========================================================================*/
|
||||
|
@ -62,15 +61,34 @@ static const USBEndpointConfig ep0config = {
|
|||
_usb_ep0in,
|
||||
_usb_ep0out,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x80
|
||||
0x40
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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.
|
||||
*
|
||||
|
@ -342,6 +360,9 @@ void usb_lld_reset(USBDriver *usbp) {
|
|||
cntr |= CNTR_SOFM;
|
||||
STM32_USB->CNTR = cntr;
|
||||
|
||||
/* Resets the packet memory allocator.*/
|
||||
pm_reset(usbp);
|
||||
|
||||
/* EP0 initialization.*/
|
||||
memset(&ep0state, 0, sizeof ep0state);
|
||||
ep0state.config = &ep0config;
|
||||
|
@ -417,8 +438,8 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
|
|||
dp = USB_GET_DESCRIPTOR(ep);
|
||||
dp->TXCOUNT = 0;
|
||||
dp->RXCOUNT = nblocks;
|
||||
dp->TXADDR = epcp->inaddr;
|
||||
dp->RXADDR = epcp->outaddr;
|
||||
dp->TXADDR = pm_alloc(usbp, epcp->in_maxsize);
|
||||
dp->RXADDR = pm_alloc(usbp, epcp->out_maxsize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -127,14 +127,6 @@ typedef struct {
|
|||
*/
|
||||
uint16_t out_maxsize;
|
||||
/* 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;
|
||||
|
||||
|
||||
|
@ -265,6 +257,10 @@ struct USBDriver {
|
|||
*/
|
||||
uint8_t configuration;
|
||||
/* End of the mandatory fields.*/
|
||||
/**
|
||||
* @brief Pointer to the next address in the packet memory.
|
||||
*/
|
||||
uint32_t pmnext;
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
|
|
|
@ -255,8 +255,6 @@ static const USBEndpointConfig ep1config = {
|
|||
sduDataTransmitted,
|
||||
NULL,
|
||||
0x0040,
|
||||
0x0000,
|
||||
0x00C0,
|
||||
0x0000
|
||||
};
|
||||
|
||||
|
@ -268,8 +266,6 @@ static const USBEndpointConfig ep2config = {
|
|||
sduInterruptTransmitted,
|
||||
NULL,
|
||||
0x0010,
|
||||
0x0000,
|
||||
0x0100,
|
||||
0x0000
|
||||
};
|
||||
|
||||
|
@ -281,9 +277,7 @@ static const USBEndpointConfig ep3config = {
|
|||
NULL,
|
||||
sduDataReceived,
|
||||
0x0000,
|
||||
0x0040,
|
||||
0x0000,
|
||||
0x0110
|
||||
0x0040
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue