diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-02-13 20:55:57 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-02-13 20:55:57 +0000 |
commit | dd6a0b3ccdd62873e1cb874969741e3fb683db4b (patch) | |
tree | 7cfc6331e32929b1930d20f828e1bb1d53ae25bb /os/hal/platforms | |
parent | f67eb2c108183bc6f037c0cabb95dbd5995207ca (diff) | |
download | ChibiOS-dd6a0b3ccdd62873e1cb874969741e3fb683db4b.tar.gz ChibiOS-dd6a0b3ccdd62873e1cb874969741e3fb683db4b.tar.bz2 ChibiOS-dd6a0b3ccdd62873e1cb874969741e3fb683db4b.zip |
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
Diffstat (limited to 'os/hal/platforms')
-rw-r--r-- | os/hal/platforms/STM32/usb_lld.c | 33 | ||||
-rw-r--r-- | os/hal/platforms/STM32/usb_lld.h | 12 |
2 files changed, 31 insertions, 14 deletions
diff --git a/os/hal/platforms/STM32/usb_lld.c b/os/hal/platforms/STM32/usb_lld.c index f09e6d0ea..cecbc9934 100644 --- a/os/hal/platforms/STM32/usb_lld.c +++ b/os/hal/platforms/STM32/usb_lld.c @@ -44,7 +44,6 @@ USBDriver USBD1;
#endif
-
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
@@ -62,9 +61,7 @@ static const USBEndpointConfig ep0config = { _usb_ep0in,
_usb_ep0out,
0x40,
- 0x40,
- 0x40,
- 0x80
+ 0x40
};
/*===========================================================================*/
@@ -72,6 +69,27 @@ static const USBEndpointConfig ep0config = { /*===========================================================================*/
/**
+ * @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.
*
* @param[in] ep endpoint number
@@ -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);
}
/**
diff --git a/os/hal/platforms/STM32/usb_lld.h b/os/hal/platforms/STM32/usb_lld.h index c1b00de06..d82fda644 100644 --- a/os/hal/platforms/STM32/usb_lld.h +++ b/os/hal/platforms/STM32/usb_lld.h @@ -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;
};
/*===========================================================================*/
|