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

This commit is contained in:
gdisirio 2011-02-15 09:16:17 +00:00
parent 20a4b38126
commit 35ff732352
3 changed files with 29 additions and 12 deletions

View File

@ -108,10 +108,15 @@ typedef struct {
#define STM32_USB ((stm32_usb_t *)STM32_USB_BASE)
/**
* @brief Pointer to the USB RAM.
* @brief Pointer to the USB RAM.
*/
#define STM32_USBRAM ((uint32_t *)STM32_USBRAM_BASE)
/**
* @brief Size of the dedicated packet memory.
*/
#define USB_PMA_SIZE 512
/**
* @brief Mask of all the toggling bits in the EPR register.
*/

View File

@ -87,6 +87,9 @@ static const USBEndpointConfig ep0config = {
* @param[in] usbp pointer to the @p USBDriver object
*/
static void pm_reset(USBDriver *usbp) {
/* The first 64 bytes are reserved for the descriptors table. The effective
available RAM for endpoint buffers is just 448 bytes.*/
usbp->pmnext = 64;
}
@ -97,8 +100,11 @@ static void pm_reset(USBDriver *usbp) {
* @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;
uint32_t next;
next = usbp->pmnext;
usbp->pmnext += size;
chDbgAssert(usbp->pmnext > USB_PMA_SIZE, "pm_alloc(), #1", "PMA overflow");
return next;
}
@ -463,12 +469,14 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
void usb_lld_disable_endpoints(USBDriver *usbp) {
unsigned i;
(void)usbp;
/* Resets the packet memory allocator.*/
pm_reset(usbp);
/* Disabling all endpoints.*/
for (i = 1; i <= USB_ENDOPOINTS_NUMBER; i++) {
EPR_TOGGLE(i, 0);
EPR_SET(i, 0);
}
}
/**

View File

@ -335,6 +335,8 @@ void usbDisableEndpointsI(USBDriver *usbp) {
chDbgAssert(usbp->state == USB_SELECTED,
"usbDisableEndpointsI(), #1", "invalid state");
usbp->transmitting &= ~1;
usbp->receiving &= ~1;
for (i = 1; i <= USB_MAX_ENDPOINTS; i++)
usbp->epc[i] = NULL;
@ -399,7 +401,7 @@ size_t usbWritePacketI(USBDriver *usbp, usbep_t ep,
}
/**
* @brief Starts a receive operation on an OUT endpoint.
* @brief Starts a receive transaction on an OUT endpoint.
* @pre In order to use this function he endpoint must have been
* initialized in transaction mode.
* @post The endpoint callback is invoked when the transfer has been
@ -410,8 +412,8 @@ size_t usbWritePacketI(USBDriver *usbp, usbep_t ep,
* @param[out] buf buffer where to copy the received data
* @param[in] n maximum number of bytes to copy
* @return The operation status.
* @retval FALSE Operation complete.
* @retval TRUE Endpoint busy receiving.
* @retval FALSE Operation started successfully.
* @retval TRUE Endpoint busy, operation not started.
*
* @iclass
*/
@ -427,7 +429,7 @@ bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep,
}
/**
* @brief Starts a transmit operation on an IN endpoint.
* @brief Starts a transmit transaction on an IN endpoint.
* @pre In order to use this function he endpoint must have been
* initialized in transaction mode.
* @post The endpoint callback is invoked when the transfer has been
@ -438,8 +440,8 @@ bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep,
* @param[in] buf buffer where to fetch the data to be transmitted
* @param[in] n maximum number of bytes to copy
* @return The operation status.
* @retval FALSE Operation complete.
* @retval TRUE Endpoint busy transmitting.
* @retval FALSE Operation started successfully.
* @retval TRUE Endpoint busy, operation not started.
*
* @iclass
*/
@ -461,7 +463,7 @@ bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep,
* @param[in] ep endpoint number
* @return The operation status.
* @retval FALSE Endpoint stalled.
* @retval TRUE The endpoint was within a transaction, not stalled.
* @retval TRUE Endpoint busy, not stalled.
*
* @iclass
*/
@ -481,7 +483,7 @@ bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) {
* @param[in] ep endpoint number
* @return The operation status.
* @retval FALSE Endpoint stalled.
* @retval TRUE The endpoint was within a transaction, not stalled.
* @retval TRUE Endpoint busy, not stalled.
*
* @iclass
*/
@ -510,6 +512,8 @@ void _usb_reset(USBDriver *usbp) {
usbp->status = 0;
usbp->address = 0;
usbp->configuration = 0;
usbp->transmitting = 0;
usbp->receiving = 0;
/* Invalidates all endpoints into the USBDriver structure.*/
for (i = 0; i <= USB_MAX_ENDPOINTS; i++)