2012-03-26 13:45:36 +00:00
|
|
|
/*
|
2013-03-30 10:32:37 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
2012-03-26 13:45:36 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2012-03-26 13:45:36 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2012-03-26 13:45:36 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2012-03-26 13:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file STM32/OTGv1/usb_lld.h
|
|
|
|
* @brief STM32 USB subsystem low level driver header.
|
|
|
|
*
|
|
|
|
* @addtogroup USB
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _USB_LLD_H_
|
|
|
|
#define _USB_LLD_H_
|
|
|
|
|
|
|
|
#if HAL_USE_USB || defined(__DOXYGEN__)
|
|
|
|
|
2012-03-28 14:19:40 +00:00
|
|
|
#include "stm32_otg.h"
|
2012-03-26 13:45:36 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Maximum endpoint address.
|
|
|
|
*/
|
2012-08-18 13:17:03 +00:00
|
|
|
#if !STM32_USB_USE_OTG2 || defined(__DOXYGEN__)
|
2012-03-26 13:45:36 +00:00
|
|
|
#define USB_MAX_ENDPOINTS 3
|
2012-08-18 13:17:03 +00:00
|
|
|
#else
|
|
|
|
#define USB_MAX_ENDPOINTS 5
|
|
|
|
#endif
|
2012-03-26 13:45:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The address can be changed immediately upon packet reception.
|
|
|
|
*/
|
|
|
|
#define USB_SET_ADDRESS_MODE USB_EARLY_SET_ADDRESS
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief OTG1 driver enable switch.
|
2012-08-18 13:17:03 +00:00
|
|
|
* @details If set to @p TRUE the support for OTG_FS is included.
|
2012-03-26 13:45:36 +00:00
|
|
|
* @note The default is @p TRUE.
|
|
|
|
*/
|
|
|
|
#if !defined(STM32_USB_USE_OTG1) || defined(__DOXYGEN__)
|
2012-08-21 11:04:42 +00:00
|
|
|
#define STM32_USB_USE_OTG1 FALSE
|
2012-03-26 13:45:36 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-18 13:17:03 +00:00
|
|
|
/**
|
|
|
|
* @brief OTG2 driver enable switch.
|
|
|
|
* @details If set to @p TRUE the support for OTG_HS is included.
|
|
|
|
* @note The default is @p TRUE.
|
|
|
|
*/
|
|
|
|
#if !defined(STM32_USB_USE_OTG2) || defined(__DOXYGEN__)
|
2012-08-21 11:04:42 +00:00
|
|
|
#define STM32_USB_USE_OTG2 FALSE
|
2012-08-18 13:17:03 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-26 13:45:36 +00:00
|
|
|
/**
|
|
|
|
* @brief OTG1 interrupt priority level setting.
|
|
|
|
*/
|
|
|
|
#if !defined(STM32_USB_OTG1_IRQ_PRIORITY) || defined(__DOXYGEN__)
|
2012-06-16 06:22:39 +00:00
|
|
|
#define STM32_USB_OTG1_IRQ_PRIORITY 14
|
2012-03-26 13:45:36 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-18 13:17:03 +00:00
|
|
|
/**
|
|
|
|
* @brief OTG2 interrupt priority level setting.
|
|
|
|
*/
|
|
|
|
#if !defined(STM32_USB_OTG2_IRQ_PRIORITY) || defined(__DOXYGEN__)
|
|
|
|
#define STM32_USB_OTG2_IRQ_PRIORITY 14
|
|
|
|
#endif
|
|
|
|
|
2012-03-27 15:37:06 +00:00
|
|
|
/**
|
|
|
|
* @brief OTG1 RX shared FIFO size.
|
|
|
|
* @note Must be a multiple of 4.
|
|
|
|
*/
|
|
|
|
#if !defined(STM32_USB_OTG1_RX_FIFO_SIZE) || defined(__DOXYGEN__)
|
|
|
|
#define STM32_USB_OTG1_RX_FIFO_SIZE 512
|
|
|
|
#endif
|
|
|
|
|
2012-08-17 08:20:22 +00:00
|
|
|
/**
|
2012-08-18 13:17:03 +00:00
|
|
|
* @brief OTG2 RX shared FIFO size.
|
|
|
|
* @note Must be a multiple of 4.
|
|
|
|
*/
|
|
|
|
#if !defined(STM32_USB_OTG2_RX_FIFO_SIZE) || defined(__DOXYGEN__)
|
2012-08-21 11:04:42 +00:00
|
|
|
#define STM32_USB_OTG2_RX_FIFO_SIZE 1024
|
2012-08-18 13:17:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Dedicated data pump threads priority.
|
2012-08-17 08:20:22 +00:00
|
|
|
*/
|
2013-02-02 10:14:30 +00:00
|
|
|
#if !defined(STM32_USB_OTG_THREAD_PRIO) || defined(__DOXYGEN__)
|
2012-08-21 11:04:42 +00:00
|
|
|
#define STM32_USB_OTG_THREAD_PRIO LOWPRIO
|
2012-08-17 08:20:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2012-08-18 13:17:03 +00:00
|
|
|
* @brief Dedicated data pump threads stack size.
|
2012-08-17 08:20:22 +00:00
|
|
|
*/
|
2012-08-21 11:04:42 +00:00
|
|
|
#if !defined(STM32_USB_OTG_THREAD_STACK_SIZE) || defined(__DOXYGEN__)
|
|
|
|
#define STM32_USB_OTG_THREAD_STACK_SIZE 128
|
2012-08-17 08:20:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Exception priority level during TXFIFOs operations.
|
|
|
|
* @note Because an undocumented silicon behavior the operation of
|
|
|
|
* copying a packet into a TXFIFO must not be interrupted by
|
|
|
|
* any other operation on the OTG peripheral.
|
|
|
|
* This parameter represents the priority mask during copy
|
|
|
|
* operations. The default value only allows to call USB
|
|
|
|
* functions from callbacks invoked from USB ISR handlers.
|
|
|
|
* If you need to invoke USB functions from other handlers
|
|
|
|
* then raise this priority mast to the same level of the
|
|
|
|
* handler you need to use.
|
|
|
|
* @note The value zero means disabled, when disabled calling USB
|
|
|
|
* functions is only safe from thread level or from USB
|
|
|
|
* callbacks.
|
|
|
|
*/
|
2012-08-21 11:04:42 +00:00
|
|
|
#if !defined(STM32_USB_OTGFIFO_FILL_BASEPRI) || defined(__DOXYGEN__)
|
|
|
|
#define STM32_USB_OTGFIFO_FILL_BASEPRI 0
|
2012-08-17 08:20:22 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-26 13:45:36 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#if STM32_USB_USE_OTG1 && !STM32_HAS_OTG1
|
|
|
|
#error "OTG1 not present in the selected device"
|
|
|
|
#endif
|
|
|
|
|
2012-08-18 13:17:03 +00:00
|
|
|
#if STM32_USB_USE_OTG2 && !STM32_HAS_OTG2
|
|
|
|
#error "OTG2 not present in the selected device"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !STM32_USB_USE_OTG1 && !STM32_USB_USE_OTG2
|
2012-03-26 13:45:36 +00:00
|
|
|
#error "USB driver activated but no USB peripheral assigned"
|
|
|
|
#endif
|
|
|
|
|
2012-06-24 07:41:07 +00:00
|
|
|
#if STM32_USB_USE_OTG1 && \
|
|
|
|
!CORTEX_IS_VALID_KERNEL_PRIORITY(STM32_USB_OTG1_IRQ_PRIORITY)
|
|
|
|
#error "Invalid IRQ priority assigned to OTG1"
|
|
|
|
#endif
|
|
|
|
|
2012-08-18 13:17:03 +00:00
|
|
|
#if STM32_USB_USE_OTG2 && \
|
|
|
|
!CORTEX_IS_VALID_KERNEL_PRIORITY(STM32_USB_OTG2_IRQ_PRIORITY)
|
|
|
|
#error "Invalid IRQ priority assigned to OTG2"
|
|
|
|
#endif
|
|
|
|
|
2012-03-27 15:37:06 +00:00
|
|
|
#if (STM32_USB_OTG1_RX_FIFO_SIZE & 3) != 0
|
2012-08-18 13:17:03 +00:00
|
|
|
#error "OTG1 RX FIFO size must be a multiple of 4"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (STM32_USB_OTG2_RX_FIFO_SIZE & 3) != 0
|
|
|
|
#error "OTG2 RX FIFO size must be a multiple of 4"
|
2012-03-27 15:37:06 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(STM32F4XX) || defined(STM32F2XX)
|
|
|
|
#define STM32_USBCLK STM32_PLL48CLK
|
|
|
|
#elif defined(STM32F10X_CL)
|
|
|
|
#define STM32_USBCLK STM32_OTGFSCLK
|
|
|
|
#else
|
|
|
|
#error "unsupported STM32 platform for OTG functionality"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if STM32_USBCLK != 48000000
|
|
|
|
#error "the USB OTG driver requires a 48MHz clock"
|
|
|
|
#endif
|
2012-03-26 13:45:36 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2012-08-19 13:11:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Peripheral-specific parameters block.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
uint32_t rx_fifo_size;
|
|
|
|
uint32_t otg_ram_size;
|
|
|
|
uint32_t num_endpoints;
|
|
|
|
} stm32_otg_params_t;
|
|
|
|
|
2012-03-26 13:45:36 +00:00
|
|
|
/**
|
2012-06-11 16:54:35 +00:00
|
|
|
* @brief Type of an IN endpoint state structure.
|
2012-03-26 13:45:36 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/**
|
2012-06-11 16:54:35 +00:00
|
|
|
* @brief Buffer mode, queue or linear.
|
2012-03-26 13:45:36 +00:00
|
|
|
*/
|
2012-06-11 16:54:35 +00:00
|
|
|
bool_t txqueued;
|
2012-03-26 13:45:36 +00:00
|
|
|
/**
|
|
|
|
* @brief Requested transmit transfer size.
|
|
|
|
*/
|
|
|
|
size_t txsize;
|
|
|
|
/**
|
|
|
|
* @brief Transmitted bytes so far.
|
|
|
|
*/
|
|
|
|
size_t txcnt;
|
2012-06-11 16:54:35 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
/**
|
2012-06-13 16:13:00 +00:00
|
|
|
* @brief Pointer to the transmission linear buffer.
|
2012-06-11 16:54:35 +00:00
|
|
|
*/
|
|
|
|
const uint8_t *txbuf;
|
|
|
|
} linear;
|
|
|
|
struct {
|
|
|
|
/**
|
|
|
|
* @brief Pointer to the output queue.
|
|
|
|
*/
|
|
|
|
OutputQueue *txqueue;
|
|
|
|
} queue;
|
|
|
|
} mode;
|
2012-03-26 13:45:36 +00:00
|
|
|
} USBInEndpointState;
|
|
|
|
|
|
|
|
/**
|
2012-06-11 16:54:35 +00:00
|
|
|
* @brief Type of an OUT endpoint state structure.
|
2012-03-26 13:45:36 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/**
|
2012-06-11 16:54:35 +00:00
|
|
|
* @brief Buffer mode, queue or linear.
|
2012-03-26 13:45:36 +00:00
|
|
|
*/
|
2012-06-11 16:54:35 +00:00
|
|
|
bool_t rxqueued;
|
2012-03-26 13:45:36 +00:00
|
|
|
/**
|
|
|
|
* @brief Requested receive transfer size.
|
|
|
|
*/
|
|
|
|
size_t rxsize;
|
|
|
|
/**
|
|
|
|
* @brief Received bytes so far.
|
|
|
|
*/
|
|
|
|
size_t rxcnt;
|
2012-06-11 16:54:35 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
/**
|
2012-06-13 16:13:00 +00:00
|
|
|
* @brief Pointer to the receive linear buffer.
|
2012-06-11 16:54:35 +00:00
|
|
|
*/
|
|
|
|
uint8_t *rxbuf;
|
|
|
|
} linear;
|
|
|
|
struct {
|
|
|
|
/**
|
|
|
|
* @brief Pointer to the input queue.
|
|
|
|
*/
|
|
|
|
InputQueue *rxqueue;
|
|
|
|
} queue;
|
|
|
|
} mode;
|
2012-03-26 13:45:36 +00:00
|
|
|
} USBOutEndpointState;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Type of an USB endpoint configuration structure.
|
|
|
|
* @note Platform specific restrictions may apply to endpoints.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/**
|
|
|
|
* @brief Type and mode of the endpoint.
|
|
|
|
*/
|
|
|
|
uint32_t ep_mode;
|
|
|
|
/**
|
|
|
|
* @brief Setup packet notification callback.
|
|
|
|
* @details This callback is invoked when a setup packet has been
|
|
|
|
* received.
|
|
|
|
* @post The application must immediately call @p usbReadPacket() in
|
|
|
|
* order to access the received packet.
|
|
|
|
* @note This field is only valid for @p USB_EP_MODE_TYPE_CTRL
|
|
|
|
* endpoints, it should be set to @p NULL for other endpoint
|
|
|
|
* types.
|
|
|
|
*/
|
|
|
|
usbepcallback_t setup_cb;
|
|
|
|
/**
|
|
|
|
* @brief IN endpoint notification callback.
|
|
|
|
* @details This field must be set to @p NULL if the IN endpoint is not
|
|
|
|
* used.
|
|
|
|
*/
|
|
|
|
usbepcallback_t in_cb;
|
|
|
|
/**
|
|
|
|
* @brief OUT endpoint notification callback.
|
|
|
|
* @details This field must be set to @p NULL if the OUT endpoint is not
|
|
|
|
* used.
|
|
|
|
*/
|
|
|
|
usbepcallback_t out_cb;
|
|
|
|
/**
|
|
|
|
* @brief IN endpoint maximum packet size.
|
|
|
|
* @details This field must be set to zero if the IN endpoint is not
|
|
|
|
* used.
|
|
|
|
*/
|
|
|
|
uint16_t in_maxsize;
|
|
|
|
/**
|
|
|
|
* @brief OUT endpoint maximum packet size.
|
|
|
|
* @details This field must be set to zero if the OUT endpoint is not
|
|
|
|
* used.
|
|
|
|
*/
|
|
|
|
uint16_t out_maxsize;
|
|
|
|
/**
|
|
|
|
* @brief @p USBEndpointState associated to the IN endpoint.
|
2012-06-13 16:13:00 +00:00
|
|
|
* @details This structure maintains the state of the IN endpoint.
|
2012-03-26 13:45:36 +00:00
|
|
|
*/
|
|
|
|
USBInEndpointState *in_state;
|
|
|
|
/**
|
|
|
|
* @brief @p USBEndpointState associated to the OUT endpoint.
|
2012-06-13 16:13:00 +00:00
|
|
|
* @details This structure maintains the state of the OUT endpoint.
|
2012-03-26 13:45:36 +00:00
|
|
|
*/
|
|
|
|
USBOutEndpointState *out_state;
|
|
|
|
/* End of the mandatory fields.*/
|
2012-08-13 10:14:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Determines the space allocated for the TXFIFO as multiples of
|
|
|
|
* the packet size (@p in_maxsize). Note that zero is interpreted
|
|
|
|
* as one for simplicity and robustness.
|
|
|
|
*/
|
|
|
|
uint16_t in_multiplier;
|
2012-04-07 10:37:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Pointer to a buffer for setup packets.
|
|
|
|
* @details Setup packets require a dedicated 8-bytes buffer, set this
|
|
|
|
* field to @p NULL for non-control endpoints.
|
|
|
|
*/
|
|
|
|
uint8_t *setup_buf;
|
2012-03-26 13:45:36 +00:00
|
|
|
} USBEndpointConfig;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Type of an USB driver configuration structure.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/**
|
|
|
|
* @brief USB events callback.
|
|
|
|
* @details This callback is invoked when an USB driver event is registered.
|
|
|
|
*/
|
|
|
|
usbeventcb_t event_cb;
|
|
|
|
/**
|
|
|
|
* @brief Device GET_DESCRIPTOR request callback.
|
|
|
|
* @note This callback is mandatory and cannot be set to @p NULL.
|
|
|
|
*/
|
|
|
|
usbgetdescriptor_t get_descriptor_cb;
|
|
|
|
/**
|
|
|
|
* @brief Requests hook callback.
|
|
|
|
* @details This hook allows to be notified of standard requests or to
|
|
|
|
* handle non standard requests.
|
|
|
|
*/
|
|
|
|
usbreqhandler_t requests_hook_cb;
|
|
|
|
/**
|
|
|
|
* @brief Start Of Frame callback.
|
|
|
|
*/
|
|
|
|
usbcallback_t sof_cb;
|
|
|
|
/* End of the mandatory fields.*/
|
|
|
|
} USBConfig;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Structure representing an USB driver.
|
|
|
|
*/
|
|
|
|
struct USBDriver {
|
|
|
|
/**
|
|
|
|
* @brief Driver state.
|
|
|
|
*/
|
|
|
|
usbstate_t state;
|
|
|
|
/**
|
|
|
|
* @brief Current configuration data.
|
|
|
|
*/
|
|
|
|
const USBConfig *config;
|
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
const USBEndpointConfig *epc[USB_MAX_ENDPOINTS + 1];
|
2013-05-01 15:50:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Fields available to user, it can be used to associate an
|
|
|
|
* application-defined handler to an IN endpoint.
|
|
|
|
* @note The base index is one, the endpoint zero does not have a
|
|
|
|
* reserved element in this array.
|
|
|
|
*/
|
|
|
|
void *in_params[USB_MAX_ENDPOINTS];
|
|
|
|
/**
|
|
|
|
* @brief Fields available to user, it can be used to associate an
|
|
|
|
* application-defined handler to an OUT endpoint.
|
|
|
|
* @note The base index is one, the endpoint zero does not have a
|
|
|
|
* reserved element in this array.
|
|
|
|
*/
|
|
|
|
void *out_params[USB_MAX_ENDPOINTS];
|
2012-03-26 13:45:36 +00:00
|
|
|
/**
|
|
|
|
* @brief Endpoint 0 state.
|
|
|
|
*/
|
|
|
|
usbep0state_t ep0state;
|
|
|
|
/**
|
|
|
|
* @brief Next position in the buffer to be transferred through endpoint 0.
|
|
|
|
*/
|
|
|
|
uint8_t *ep0next;
|
|
|
|
/**
|
|
|
|
* @brief Number of bytes yet to be transferred through endpoint 0.
|
|
|
|
*/
|
|
|
|
size_t ep0n;
|
|
|
|
/**
|
|
|
|
* @brief Endpoint 0 end transaction callback.
|
|
|
|
*/
|
|
|
|
usbcallback_t ep0endcb;
|
|
|
|
/**
|
|
|
|
* @brief Setup packet buffer.
|
|
|
|
*/
|
|
|
|
uint8_t setup[8];
|
|
|
|
/**
|
|
|
|
* @brief Current USB device status.
|
|
|
|
*/
|
|
|
|
uint16_t status;
|
|
|
|
/**
|
|
|
|
* @brief Assigned USB address.
|
|
|
|
*/
|
|
|
|
uint8_t address;
|
|
|
|
/**
|
|
|
|
* @brief Current USB device configuration.
|
|
|
|
*/
|
|
|
|
uint8_t configuration;
|
|
|
|
#if defined(USB_DRIVER_EXT_FIELDS)
|
|
|
|
USB_DRIVER_EXT_FIELDS
|
|
|
|
#endif
|
|
|
|
/* End of the mandatory fields.*/
|
2012-08-18 13:17:03 +00:00
|
|
|
/**
|
|
|
|
* @brief Pointer to the OTG peripheral associated to this driver.
|
|
|
|
*/
|
|
|
|
stm32_otg_t *otg;
|
2012-08-19 13:11:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Peripheral-specific parameters.
|
|
|
|
*/
|
|
|
|
const stm32_otg_params_t *otgparams;
|
2012-04-10 17:15:46 +00:00
|
|
|
/**
|
|
|
|
* @brief Pointer to the next address in the packet memory.
|
|
|
|
*/
|
|
|
|
uint32_t pmnext;
|
2012-08-17 08:20:22 +00:00
|
|
|
/**
|
|
|
|
* @brief Mask of TXFIFOs to be filled by the pump thread.
|
|
|
|
*/
|
|
|
|
uint32_t txpending;
|
|
|
|
/**
|
|
|
|
* @brief Pointer to the thread.
|
|
|
|
*/
|
|
|
|
Thread *thd_ptr;
|
|
|
|
/**
|
|
|
|
* @brief Pointer to the thread when it is sleeping or @p NULL.
|
|
|
|
*/
|
|
|
|
Thread *thd_wait;
|
|
|
|
/**
|
|
|
|
* @brief Working area for the dedicated data pump thread;
|
|
|
|
*/
|
2012-08-21 11:04:42 +00:00
|
|
|
WORKING_AREA(wa_pump, STM32_USB_OTG_THREAD_STACK_SIZE);
|
2012-03-26 13:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the exact size of a receive transaction.
|
|
|
|
* @details The received size can be different from the size specified in
|
|
|
|
* @p usbStartReceiveI() because the last packet could have a size
|
|
|
|
* different from the expected one.
|
|
|
|
* @pre The OUT endpoint must have been configured in transaction mode
|
|
|
|
* in order to use this function.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
* @return Received data size.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
#define usb_lld_get_transaction_size(usbp, ep) \
|
|
|
|
((usbp)->epc[ep]->out_state->rxcnt)
|
|
|
|
|
2012-03-28 14:19:40 +00:00
|
|
|
/**
|
|
|
|
* @brief Connects the USB device.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2013-01-26 10:53:10 +00:00
|
|
|
#define usb_lld_connect_bus(usbp) ((usbp)->otg->GCCFG |= GCCFG_VBUSBSEN)
|
2012-03-28 14:19:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disconnect the USB device.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2013-01-26 10:53:10 +00:00
|
|
|
#define usb_lld_disconnect_bus(usbp) ((usbp)->otg->GCCFG &= ~GCCFG_VBUSBSEN)
|
2012-03-28 14:19:40 +00:00
|
|
|
|
2012-03-26 13:45:36 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#if STM32_USB_USE_OTG1 && !defined(__DOXYGEN__)
|
|
|
|
extern USBDriver USBD1;
|
|
|
|
#endif
|
|
|
|
|
2012-08-18 13:17:03 +00:00
|
|
|
#if STM32_USB_USE_OTG2 && !defined(__DOXYGEN__)
|
|
|
|
extern USBDriver USBD2;
|
|
|
|
#endif
|
|
|
|
|
2012-03-26 13:45:36 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void usb_lld_init(void);
|
|
|
|
void usb_lld_start(USBDriver *usbp);
|
|
|
|
void usb_lld_stop(USBDriver *usbp);
|
|
|
|
void usb_lld_reset(USBDriver *usbp);
|
|
|
|
void usb_lld_set_address(USBDriver *usbp);
|
|
|
|
void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep);
|
|
|
|
void usb_lld_disable_endpoints(USBDriver *usbp);
|
|
|
|
usbepstatus_t usb_lld_get_status_in(USBDriver *usbp, usbep_t ep);
|
|
|
|
usbepstatus_t usb_lld_get_status_out(USBDriver *usbp, usbep_t ep);
|
|
|
|
void usb_lld_read_setup(USBDriver *usbp, usbep_t ep, uint8_t *buf);
|
2012-06-17 07:49:08 +00:00
|
|
|
void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep);
|
|
|
|
void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep);
|
2012-03-26 13:45:36 +00:00
|
|
|
void usb_lld_start_out(USBDriver *usbp, usbep_t ep);
|
|
|
|
void usb_lld_start_in(USBDriver *usbp, usbep_t ep);
|
|
|
|
void usb_lld_stall_out(USBDriver *usbp, usbep_t ep);
|
|
|
|
void usb_lld_stall_in(USBDriver *usbp, usbep_t ep);
|
|
|
|
void usb_lld_clear_out(USBDriver *usbp, usbep_t ep);
|
|
|
|
void usb_lld_clear_in(USBDriver *usbp, usbep_t ep);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* HAL_USE_USB */
|
|
|
|
|
|
|
|
#endif /* _USB_LLD_H_ */
|
|
|
|
|
|
|
|
/** @} */
|