PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/BmFW/AVR/ASF/Benchmark/Benchmark/src/asf/avr32/drivers/usbb/usbb_device.h

http://usb-travis.googlecode.com/
C Header | 571 lines | 241 code | 55 blank | 275 comment | 3 complexity | 09afa6aef97b06e6e0e615ee140574cc MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, LGPL-2.0
  1. /**
  2. * \file
  3. *
  4. * \brief USBB Device Driver header file.
  5. *
  6. * Copyright (C) 2009 Atmel Corporation. All rights reserved.
  7. *
  8. * \page License
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. *
  16. * 2. Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. *
  20. * 3. The name of Atmel may not be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * 4. This software may only be redistributed and used in connection with an
  24. * Atmel AVR product.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  27. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  29. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  30. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  36. * DAMAGE.
  37. */
  38. #ifndef _USBB_DEVICE_H_
  39. #define _USBB_DEVICE_H_
  40. #include "compiler.h"
  41. #include "preprocessor.h"
  42. //! \ingroup usb_device_group
  43. //! \defgroup udd_group USB Device Driver (UDD)
  44. //! USBB low-level driver for USB device mode
  45. //!
  46. //! @warning Bit-masks are used instead of bit-fields because PB registers
  47. //! require 32-bit write accesses while AVR32-GCC 4.0.2 builds 8-bit
  48. //! accesses even when volatile unsigned int bit-fields are specified.
  49. //! @{
  50. //! @name USBB Device IP properties
  51. //! These macros give access to IP properties
  52. //! @{
  53. //! Get maximal number of endpoints
  54. #define UDD_get_endpoint_max_nbr() (((Rd_bitfield(AVR32_USBB_ufeatures, AVR32_USBB_UFEATURES_EPT_NBR_MAX_MASK) - 1) & ((1 << AVR32_USBB_UFEATURES_EPT_NBR_MAX_SIZE) - 1)) + 1)
  55. //! @}
  56. //! @name USBB Device speeds management
  57. //! @{
  58. //! Enable/disable device low-speed mode
  59. #define udd_low_speed_enable() (Set_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_LS_MASK))
  60. #define udd_low_speed_disable() (Clr_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_LS_MASK))
  61. //! Test if device low-speed mode is forced
  62. #define Is_udd_low_speed_enable() (Tst_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_LS_MASK))
  63. #ifdef AVR32_USBB_UDCON_SPDCONF
  64. //! Enable high speed mode
  65. # define udd_high_speed_enable() (Wr_bitfield(AVR32_USBB.udcon, AVR32_USBB_UDCON_SPDCONF_MASK, 0))
  66. //! Disable high speed mode
  67. # define udd_high_speed_disable() (Wr_bitfield(AVR32_USBB.udcon, AVR32_USBB_UDCON_SPDCONF_MASK, 3))
  68. //! Test if controller is in full speed mode
  69. # define Is_udd_full_speed_mode() (Rd_bitfield(AVR32_USBB.usbsta, AVR32_USBB_USBSTA_SPEED_MASK) == AVR32_USBB_USBSTA_SPEED_FULL)
  70. #else
  71. # define udd_high_speed_enable() do { } while (0)
  72. # define udd_high_speed_disable() do { } while (0)
  73. # define Is_udd_full_speed_mode() true
  74. #endif
  75. //! @}
  76. //! @name USBB Device HS test mode management
  77. //! @{
  78. #ifdef AVR32_USBB_UDCON_SPDCONF
  79. //! Enable high speed test mode
  80. # define udd_enable_hs_test_mode() (Wr_bitfield(AVR32_USBB.udcon, AVR32_USBB_UDCON_SPDCONF_MASK, 2))
  81. # define udd_enable_hs_test_mode_j() (Set_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_TSTJ_MASK))
  82. # define udd_enable_hs_test_mode_k() (Set_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_TSTK_MASK))
  83. # define udd_enable_hs_test_mode_packet() (Set_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_TSTPCKT_MASK))
  84. #endif
  85. //! @}
  86. //! @name USBB Device vbus management
  87. //! @{
  88. #define udd_enable_vbus_interrupt() (Set_bits(AVR32_USBB.usbcon, AVR32_USBB_USBCON_VBUSTE_MASK))
  89. #define udd_disable_vbus_interrupt() (Clr_bits(AVR32_USBB.usbcon, AVR32_USBB_USBCON_VBUSTE_MASK))
  90. #define Is_udd_vbus_interrupt_enabled() (Tst_bits(AVR32_USBB.usbcon, AVR32_USBB_USBCON_VBUSTE_MASK))
  91. #define Is_udd_vbus_high() (Tst_bits(AVR32_USBB.usbsta, AVR32_USBB_USBSTA_VBUS_MASK))
  92. #define Is_udd_vbus_low() (!Is_udd_vbus_high())
  93. #define udd_ack_vbus_transition() (AVR32_USBB.usbstaclr = AVR32_USBB_USBSTACLR_VBUSTIC_MASK)
  94. #define udd_raise_vbus_transition() (AVR32_USBB.usbstaset = AVR32_USBB_USBSTASET_VBUSTIS_MASK)
  95. #define Is_udd_vbus_transition() (Tst_bits(AVR32_USBB.usbsta, AVR32_USBB_USBSTA_VBUSTI_MASK))
  96. //! @}
  97. //! @name USBB device attach control
  98. //! These macros manage the USBB Device attach.
  99. //! @{
  100. //! detaches from USB bus
  101. #define udd_detach_device() (Set_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_DETACH_MASK))
  102. //! attaches to USB bus
  103. #define udd_attach_device() (Clr_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_DETACH_MASK))
  104. //! test if the device is detached
  105. #define Is_udd_detached() (Tst_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_DETACH_MASK))
  106. //! @}
  107. //! @name USBB device bus events control
  108. //! These macros manage the USBB Device bus events.
  109. //! @{
  110. //! Initiates a remote wake-up event
  111. //! @{
  112. #define udd_initiate_remote_wake_up() (Set_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_RMWKUP_MASK))
  113. #define Is_udd_pending_remote_wake_up() (Tst_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_RMWKUP_MASK))
  114. //! @}
  115. //! Manage upstream resume event (=remote wakeup)
  116. //! The USB driver sends a resume signal called "Upstream Resume"
  117. //! @{
  118. #define udd_enable_remote_wake_up_interrupt() (AVR32_USBB.udinteset = AVR32_USBB_UDINTESET_UPRSMES_MASK)
  119. #define udd_disable_remote_wake_up_interrupt() (AVR32_USBB.udinteclr = AVR32_USBB_UDINTECLR_UPRSMEC_MASK)
  120. #define Is_udd_remote_wake_up_interrupt_enabled() (Tst_bits(AVR32_USBB.udinte, AVR32_USBB_UDINTE_UPRSME_MASK))
  121. #define udd_ack_remote_wake_up_start() (AVR32_USBB.udintclr = AVR32_USBB_UDINTCLR_UPRSMC_MASK)
  122. #define udd_raise_remote_wake_up_start() (AVR32_USBB.udintset = AVR32_USBB_UDINTSET_UPRSMS_MASK)
  123. #define Is_udd_remote_wake_up_start() (Tst_bits(AVR32_USBB.udint, AVR32_USBB_UDINT_UPRSM_MASK))
  124. //! @}
  125. //! Manage end of resume event (=remote wakeup)
  126. //! The USB controller detects a valid "End of Resume" signal initiated by the host
  127. //! @{
  128. #define udd_enable_resume_interrupt() (AVR32_USBB.udinteset = AVR32_USBB_UDINTESET_EORSMES_MASK)
  129. #define udd_disable_resume_interrupt() (AVR32_USBB.udinteclr = AVR32_USBB_UDINTECLR_EORSMEC_MASK)
  130. #define Is_udd_resume_interrupt_enabled() (Tst_bits(AVR32_USBB.udinte, AVR32_USBB_UDINTE_EORSME_MASK))
  131. #define udd_ack_resume() (AVR32_USBB.udintclr = AVR32_USBB_UDINTCLR_EORSMC_MASK)
  132. #define udd_raise_resume() (AVR32_USBB.udintset = AVR32_USBB_UDINTSET_EORSMS_MASK)
  133. #define Is_udd_resume() (Tst_bits(AVR32_USBB.udint, AVR32_USBB_UDINT_EORSM_MASK))
  134. //! @}
  135. //! Manage wake-up event (=usb line activity)
  136. //! The USB controller is reactivated by a filtered non-idle signal from the lines
  137. //! @{
  138. #define udd_enable_wake_up_interrupt() (AVR32_USBB.udinteset = AVR32_USBB_UDINTESET_WAKEUPES_MASK)
  139. #define udd_disable_wake_up_interrupt() (AVR32_USBB.udinteclr = AVR32_USBB_UDINTECLR_WAKEUPEC_MASK)
  140. #define Is_udd_wake_up_interrupt_enabled() (Tst_bits(AVR32_USBB.udinte, AVR32_USBB_UDINTE_WAKEUPE_MASK))
  141. #define udd_ack_wake_up() (AVR32_USBB.udintclr = AVR32_USBB_UDINTCLR_WAKEUPC_MASK)
  142. #define udd_raise_wake_up() (AVR32_USBB.udintset = AVR32_USBB_UDINTSET_WAKEUPS_MASK)
  143. #define Is_udd_wake_up() (Tst_bits(AVR32_USBB.udint, AVR32_USBB_UDINT_WAKEUP_MASK))
  144. //! @}
  145. //! Manage reset event
  146. //! Set when a USB "End of Reset" has been detected
  147. //! @{
  148. #define udd_enable_reset_interrupt() (AVR32_USBB.udinteset = AVR32_USBB_UDINTESET_EORSTES_MASK)
  149. #define udd_disable_reset_interrupt() (AVR32_USBB.udinteclr = AVR32_USBB_UDINTECLR_EORSTEC_MASK)
  150. #define Is_udd_reset_interrupt_enabled() (Tst_bits(AVR32_USBB.udinte, AVR32_USBB_UDINTE_EORSTE_MASK))
  151. #define udd_ack_reset() (AVR32_USBB.udintclr = AVR32_USBB_UDINTCLR_EORSTC_MASK)
  152. #define udd_raise_reset() (AVR32_USBB.udintset = AVR32_USBB_UDINTSET_EORSTS_MASK)
  153. #define Is_udd_reset() (Tst_bits(AVR32_USBB.udint, AVR32_USBB_UDINT_EORST_MASK))
  154. //! @}
  155. //! Manage start of frame event
  156. //! @{
  157. #define udd_enable_sof_interrupt() (AVR32_USBB.udinteset = AVR32_USBB_UDINTESET_SOFES_MASK)
  158. #define udd_disable_sof_interrupt() (AVR32_USBB.udinteclr = AVR32_USBB_UDINTECLR_SOFEC_MASK)
  159. #define Is_udd_sof_interrupt_enabled() (Tst_bits(AVR32_USBB.udinte, AVR32_USBB_UDINTE_SOFE_MASK))
  160. #define udd_ack_sof() (AVR32_USBB.udintclr = AVR32_USBB_UDINTCLR_SOFC_MASK)
  161. #define udd_raise_sof() (AVR32_USBB.udintset = AVR32_USBB_UDINTSET_SOFS_MASK)
  162. #define Is_udd_sof() (Tst_bits(AVR32_USBB.udint, AVR32_USBB_UDINT_SOF_MASK))
  163. #define udd_frame_number() (Rd_bitfield(AVR32_USBB.udfnum, AVR32_USBB_UDFNUM_FNUM_MASK))
  164. #define Is_udd_frame_number_crc_error() (Tst_bits(AVR32_USBB.udfnum, AVR32_USBB_UDFNUM_FNCERR_MASK))
  165. //! @}
  166. //! Manage Micro start of frame event (High Speed Only)
  167. //! @{
  168. #define udd_enable_msof_interrupt() (AVR32_USBB.udinteset = AVR32_USBB_UDINTESET_MSOFES_MASK)
  169. #define udd_disable_msof_interrupt() (AVR32_USBB.udinteclr = AVR32_USBB_UDINTECLR_MSOFEC_MASK)
  170. #define Is_udd_msof_interrupt_enabled() (Tst_bits(AVR32_USBB.udinte, AVR32_USBB_UDINTE_MSOFE_MASK))
  171. #define udd_ack_msof() (AVR32_USBB.udintclr = AVR32_USBB_UDINTCLR_MSOFC_MASK)
  172. #define udd_raise_msof() (AVR32_USBB.udintset = AVR32_USBB_UDINTSET_MSOFS_MASK)
  173. #define Is_udd_msof() (Tst_bits(AVR32_USBB.udint, AVR32_USBB_UDINT_MSOF_MASK))
  174. #define udd_micro_frame_number() (Rd_bitfield(AVR32_USBB.udfnum, (AVR32_USBB_UDFNUM_FNUM_MASK|AVR32_USBB_UDFNUM_MFNUM_MASK)))
  175. //! @}
  176. //! Manage suspend event
  177. //! @{
  178. #define udd_enable_suspend_interrupt() (AVR32_USBB.udinteset = AVR32_USBB_UDINTESET_SUSPES_MASK)
  179. #define udd_disable_suspend_interrupt() (AVR32_USBB.udinteclr = AVR32_USBB_UDINTECLR_SUSPEC_MASK)
  180. #define Is_udd_suspend_interrupt_enabled() (Tst_bits(AVR32_USBB.udinte, AVR32_USBB_UDINTE_SUSPE_MASK))
  181. #define udd_ack_suspend() (AVR32_USBB.udintclr = AVR32_USBB_UDINTCLR_SUSPC_MASK)
  182. #define udd_raise_suspend() (AVR32_USBB.udintset = AVR32_USBB_UDINTSET_SUSPS_MASK)
  183. #define Is_udd_suspend() (Tst_bits(AVR32_USBB.udint, AVR32_USBB_UDINT_SUSP_MASK))
  184. //! @}
  185. //! @}
  186. //! @name USBB device address control
  187. //! These macros manage the USBB Device address.
  188. //! @{
  189. //! enables USB device address
  190. #define udd_enable_address() (Set_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_ADDEN_MASK))
  191. //! disables USB device address
  192. #define udd_disable_address() (Clr_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_ADDEN_MASK))
  193. #define Is_udd_address_enabled() (Tst_bits(AVR32_USBB.udcon, AVR32_USBB_UDCON_ADDEN_MASK))
  194. //! configures the USB device address
  195. #define udd_configure_address(addr) (Wr_bitfield(AVR32_USBB.udcon, AVR32_USBB_UDCON_UADD_MASK, addr))
  196. //! gets the currently configured USB device address
  197. #define udd_get_configured_address() (Rd_bitfield(AVR32_USBB.udcon, AVR32_USBB_UDCON_UADD_MASK))
  198. //! @}
  199. //! @name USBB Device endpoint drivers
  200. //! These macros manage the common features of the endpoints.
  201. //! @{
  202. //! Generic macro for USBB registers that can be arrayed
  203. //! @{
  204. #define USBB_ARRAY(reg,index) ((&AVR32_USBB.reg)[(index)])
  205. //! @}
  206. //! @name USBB Device endpoint configguration
  207. //! @{
  208. //! enables the selected endpoint
  209. #define udd_enable_endpoint(ep) (Set_bits(AVR32_USBB.uerst, AVR32_USBB_UERST_EPEN0_MASK << (ep)))
  210. //! disables the selected endpoint
  211. #define udd_disable_endpoint(ep) (Clr_bits(AVR32_USBB.uerst, AVR32_USBB_UERST_EPEN0_MASK << (ep)))
  212. //! tests if the selected endpoint is enabled
  213. #define Is_udd_endpoint_enabled(ep) (Tst_bits(AVR32_USBB.uerst, AVR32_USBB_UERST_EPEN0_MASK << (ep)))
  214. //! resets the selected endpoint
  215. #define udd_reset_endpoint(ep) (Set_bits(AVR32_USBB.uerst, AVR32_USBB_UERST_EPRST0_MASK << (ep)),\
  216. Clr_bits(AVR32_USBB.uerst, AVR32_USBB_UERST_EPRST0_MASK << (ep)))
  217. //! tests if the selected endpoint is being reset
  218. #define Is_udd_resetting_endpoint(ep) (Tst_bits(AVR32_USBB.uerst, AVR32_USBB_UERST_EPRST0_MASK << (ep)))
  219. //! configures the selected endpoint type
  220. #define udd_configure_endpoint_type(ep, type) (Wr_bitfield(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_EPTYPE_MASK, type))
  221. //! gets the configured selected endpoint type
  222. #define udd_get_endpoint_type(ep) (Rd_bitfield(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_EPTYPE_MASK))
  223. //! enables the bank autoswitch for the selected endpoint
  224. #define udd_enable_endpoint_bank_autoswitch(ep) (Set_bits(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_AUTOSW_MASK))
  225. //! disables the bank autoswitch for the selected endpoint
  226. #define udd_disable_endpoint_bank_autoswitch(ep) (Clr_bits(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_AUTOSW_MASK))
  227. #define Is_udd_endpoint_bank_autoswitch_enabled(ep) (Tst_bits(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_AUTOSW_MASK))
  228. //! configures the selected endpoint direction
  229. #define udd_configure_endpoint_direction(ep, dir) (Wr_bitfield(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_EPDIR_MASK, dir))
  230. //! gets the configured selected endpoint direction
  231. #define udd_get_endpoint_direction(ep) (Rd_bitfield(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_EPDIR_MASK))
  232. #define Is_udd_endpoint_in(ep) (Tst_bits(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_EPDIR_MASK))
  233. //! Bounds given integer size to allowed range and rounds it up to the nearest
  234. //! available greater size, then applies register format of USBB controller
  235. //! for endpoint size bit-field.
  236. #define udd_format_endpoint_size(size) (32 - clz(((U32)min(max(size, 8), 1024) << 1) - 1) - 1 - 3)
  237. //! configures the selected endpoint size
  238. #define udd_configure_endpoint_size(ep, size) (Wr_bitfield(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_EPSIZE_MASK, udd_format_endpoint_size(size)))
  239. //! gets the configured selected endpoint size
  240. #define udd_get_endpoint_size(ep) (8 << Rd_bitfield(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_EPSIZE_MASK))
  241. //! configures the selected endpoint number of banks
  242. #define udd_configure_endpoint_bank(ep, bank) (Wr_bitfield(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_EPBK_MASK, bank))
  243. //! gets the configured selected endpoint number of banks
  244. #define udd_get_endpoint_bank(ep) (Rd_bitfield(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_EPBK_MASK))
  245. //! allocates the configuration selected endpoint in DPRAM memory
  246. #define udd_allocate_memory(ep) (Set_bits(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_ALLOC_MASK))
  247. //! un-allocates the configuration selected endpoint in DPRAM memory
  248. #define udd_unallocate_memory(ep) (Clr_bits(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_ALLOC_MASK))
  249. #define Is_udd_memory_allocated(ep) (Tst_bits(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_ALLOC_MASK))
  250. //! configures selected endpoint in one step
  251. #define udd_configure_endpoint(ep, type, dir, size, bank) \
  252. (\
  253. Wr_bits(USBB_ARRAY(uecfg0,ep), AVR32_USBB_UECFG0_EPTYPE_MASK |\
  254. AVR32_USBB_UECFG0_EPDIR_MASK |\
  255. AVR32_USBB_UECFG0_EPSIZE_MASK |\
  256. AVR32_USBB_UECFG0_EPBK_MASK, \
  257. (((U32)(type) << AVR32_USBB_UECFG0_EPTYPE_OFFSET) & AVR32_USBB_UECFG0_EPTYPE_MASK) |\
  258. (((U32)(dir ) << AVR32_USBB_UECFG0_EPDIR_OFFSET ) & AVR32_USBB_UECFG0_EPDIR_MASK ) |\
  259. ( (U32)udd_format_endpoint_size(size) << AVR32_USBB_UECFG0_EPSIZE_OFFSET ) |\
  260. (((U32)(bank) << AVR32_USBB_UECFG0_EPBK_OFFSET ) & AVR32_USBB_UECFG0_EPBK_MASK ))\
  261. )
  262. //! tests if current endpoint is configured
  263. #define Is_udd_endpoint_configured(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_CFGOK_MASK))
  264. //! returns the control direction
  265. #define udd_control_direction() (Rd_bitfield(USBB_ARRAY(uesta0(EP_CONTROL), AVR32_USBB_UESTA0_CTRLDIR_MASK))
  266. //! resets the data toggle sequence
  267. #define udd_reset_data_toggle(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_RSTDTS_MASK)
  268. //! tests if the data toggle sequence is being reset
  269. #define Is_udd_data_toggle_reset(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_RSTDT_MASK))
  270. //! returns data toggle
  271. #define udd_data_toggle(ep) (Rd_bitfield(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_DTSEQ_MASK))
  272. //! @}
  273. //! @name USBB Device control endpoint
  274. //! These macros contorl the endpoints.
  275. //! @{
  276. //! @name USBB Device control endpoint interrupts
  277. //! These macros control the endpoints interrupts.
  278. //! @{
  279. //! enables the selected endpoint interrupt
  280. #define udd_enable_endpoint_interrupt(ep) (AVR32_USBB.udinteset = AVR32_USBB_UDINTESET_EP0INTES_MASK << (ep))
  281. //! disables the selected endpoint interrupt
  282. #define udd_disable_endpoint_interrupt(ep) (AVR32_USBB.udinteclr = AVR32_USBB_UDINTECLR_EP0INTEC_MASK << (ep))
  283. //! tests if the selected endpoint interrupt is enabled
  284. #define Is_udd_endpoint_interrupt_enabled(ep) (Tst_bits(AVR32_USBB.udinte, AVR32_USBB_UDINTE_EP0INTE_MASK << (ep)))
  285. //! tests if an interrupt is triggered by the selected endpoint
  286. #define Is_udd_endpoint_interrupt(ep) (Tst_bits(AVR32_USBB.udint, AVR32_USBB_UDINT_EP0INT_MASK << (ep)))
  287. //! returns the lowest endpoint number generating an endpoint interrupt or MAX_PEP_NB if none
  288. #define udd_get_interrupt_endpoint_number() (ctz(((AVR32_USBB.udint >> AVR32_USBB_UDINT_EP0INT_OFFSET) &\
  289. (AVR32_USBB.udinte >> AVR32_USBB_UDINTE_EP0INTE_OFFSET)) |\
  290. (1 << MAX_PEP_NB)))
  291. //! @}
  292. //! @name USBB Device control endpoint errors
  293. //! These macros control the endpoint errors.
  294. //! @{
  295. //! enables the STALL handshake
  296. #define udd_enable_stall_handshake(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_STALLRQS_MASK)
  297. //! disables the STALL handshake
  298. #define udd_disable_stall_handshake(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_STALLRQC_MASK)
  299. //! tests if STALL handshake request is running
  300. #define Is_udd_endpoint_stall_requested(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_STALLRQ_MASK))
  301. //! tests if STALL sent
  302. #define Is_udd_stall(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_STALLEDI_MASK))
  303. //! acks STALL sent
  304. #define udd_ack_stall(ep) (USBB_ARRAY(uesta0clr,ep) = AVR32_USBB_UESTA0CLR_STALLEDIC_MASK)
  305. //! raises STALL sent
  306. #define udd_raise_stall(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_STALLEDIS_MASK)
  307. //! enables STALL sent interrupt
  308. #define udd_enable_stall_interrupt(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_STALLEDES_MASK)
  309. //! disables STALL sent interrupt
  310. #define udd_disable_stall_interrupt(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_STALLEDEC_MASK)
  311. //! tests if STALL sent interrupt is enabled
  312. #define Is_udd_stall_interrupt_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_STALLEDE_MASK))
  313. //! tests if NAK OUT received
  314. #define Is_udd_nak_out(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_NAKOUTI_MASK))
  315. //! acks NAK OUT received
  316. #define udd_ack_nak_out(ep) (USBB_ARRAY(uesta0clr,ep) = AVR32_USBB_UESTA0CLR_NAKOUTIC_MASK)
  317. //! raises NAK OUT received
  318. #define udd_raise_nak_out(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_NAKOUTIS_MASK)
  319. //! enables NAK OUT interrupt
  320. #define udd_enable_nak_out_interrupt(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_NAKOUTES_MASK)
  321. //! disables NAK OUT interrupt
  322. #define udd_disable_nak_out_interrupt(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_NAKOUTEC_MASK)
  323. //! tests if NAK OUT interrupt is enabled
  324. #define Is_udd_nak_out_interrupt_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_NAKOUTE_MASK))
  325. //! tests if NAK IN received
  326. #define Is_udd_nak_in(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_NAKINI_MASK))
  327. //! acks NAK IN received
  328. #define udd_ack_nak_in(ep) (USBB_ARRAY(uesta0clr,ep) = AVR32_USBB_UESTA0CLR_NAKINIC_MASK)
  329. //! raises NAK IN received
  330. #define udd_raise_nak_in(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_NAKINIS_MASK)
  331. //! enables NAK IN interrupt
  332. #define udd_enable_nak_in_interrupt(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_NAKINES_MASK)
  333. //! disables NAK IN interrupt
  334. #define udd_disable_nak_in_interrupt(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_NAKINEC_MASK)
  335. //! tests if NAK IN interrupt is enabled
  336. #define Is_udd_nak_in_interrupt_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_NAKINE_MASK))
  337. //! acks endpoint isochronous overflow interrupt
  338. #define udd_ack_overflow_interrupt(ep) (USBB_ARRAY(uesta0clr,ep) = AVR32_USBB_UESTA0CLR_OVERFIC_MASK)
  339. //! raises endpoint isochronous overflow interrupt
  340. #define udd_raise_overflow_interrupt(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_OVERFIS_MASK)
  341. //! tests if an overflow occurs
  342. #define Is_udd_overflow(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_OVERFI_MASK))
  343. //! enables overflow interrupt
  344. #define udd_enable_overflow_interrupt(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_OVERFES_MASK)
  345. //! disables overflow interrupt
  346. #define udd_disable_overflow_interrupt(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_OVERFEC_MASK)
  347. //! tests if overflow interrupt is enabled
  348. #define Is_udd_overflow_interrupt_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_OVERFE_MASK))
  349. //! acks endpoint isochronous underflow interrupt
  350. #define udd_ack_underflow_interrupt(ep) (USBB_ARRAY(uesta0clr,ep) = AVR32_USBB_UESTA0CLR_UNDERFIC_MASK)
  351. //! raises endpoint isochronous underflow interrupt
  352. #define udd_raise_underflow_interrupt(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_UNDERFIS_MASK)
  353. //! tests if an underflow occurs
  354. #define Is_udd_underflow(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_UNDERFI_MASK))
  355. //! enables underflow interrupt
  356. #define udd_enable_underflow_interrupt(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_RXSTPES_MASK)
  357. //! disables underflow interrupt
  358. #define udd_disable_underflow_interrupt(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_RXSTPEC_MASK)
  359. //! tests if underflow interrupt is enabled
  360. #define Is_udd_underflow_interrupt_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_RXSTPE_MASK))
  361. //! tests if CRC ERROR ISO OUT detected
  362. #define Is_udd_crc_error(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_STALLEDI_MASK))
  363. //! acks CRC ERROR ISO OUT detected
  364. #define udd_ack_crc_error(ep) (USBB_ARRAY(uesta0clr,ep) = AVR32_USBB_UESTA0CLR_STALLEDIC_MASK)
  365. //! raises CRC ERROR ISO OUT detected
  366. #define udd_raise_crc_error(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_STALLEDIS_MASK)
  367. //! enables CRC ERROR ISO OUT detected interrupt
  368. #define udd_enable_crc_error_interrupt(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_STALLEDES_MASK)
  369. //! disables CRC ERROR ISO OUT detected interrupt
  370. #define udd_disable_crc_error_interrupt(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_STALLEDEC_MASK)
  371. //! tests if CRC ERROR ISO OUT detected interrupt is enabled
  372. #define Is_udd_crc_error_interrupt_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_STALLEDE_MASK))
  373. //! @}
  374. //! @name USBB Device control endpoint transfer
  375. //! These macros control the endpoint transfer.
  376. //! @{
  377. //! tests if endpoint read allowed
  378. #define Is_udd_read_enabled(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_RWALL_MASK))
  379. //! tests if endpoint write allowed
  380. #define Is_udd_write_enabled(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_RWALL_MASK))
  381. //! returns the byte count
  382. #define udd_byte_count(ep) (Rd_bitfield(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_BYCT_MASK))
  383. //! clears FIFOCON bit
  384. #define udd_ack_fifocon(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_FIFOCONC_MASK)
  385. //! tests if FIFOCON bit set
  386. #define Is_udd_fifocon(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_FIFOCON_MASK))
  387. //! returns the number of busy banks
  388. #define udd_nb_busy_bank(ep) (Rd_bitfield(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_NBUSYBK_MASK))
  389. //! returns the number of the current bank
  390. #define udd_current_bank(ep) (Rd_bitfield(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_CURRBK_MASK))
  391. //! kills last bank
  392. #define udd_kill_last_in_bank(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_KILLBKS_MASK)
  393. //! tests if last bank killed
  394. #define Is_udd_last_in_bank_killed(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_KILLBK_MASK))
  395. //! forces all banks full (OUT) or free (IN) interrupt
  396. #define udd_force_bank_interrupt(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_NBUSYBKS_MASK)
  397. //! unforces all banks full (OUT) or free (IN) interrupt
  398. #define udd_unforce_bank_interrupt(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_NBUSYBKS_MASK)
  399. //! enables all banks full (OUT) or free (IN) interrupt
  400. #define udd_enable_bank_interrupt(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_NBUSYBKES_MASK)
  401. //! disables all banks full (OUT) or free (IN) interrupt
  402. #define udd_disable_bank_interrupt(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_NBUSYBKEC_MASK)
  403. //! tests if all banks full (OUT) or free (IN) interrupt enabled
  404. #define Is_udd_bank_interrupt_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_NBUSYBKE_MASK))
  405. //! tests if SHORT PACKET received
  406. #define Is_udd_short_packet(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_SHORTPACKETI_MASK))
  407. //! acks SHORT PACKET received
  408. #define udd_ack_short_packet(ep) (USBB_ARRAY(uesta0clr,ep) = AVR32_USBB_UESTA0CLR_SHORTPACKETIC_MASK)
  409. //! raises SHORT PACKET received
  410. #define udd_raise_short_packet(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_SHORTPACKETIS_MASK)
  411. //! enables SHORT PACKET received interrupt
  412. #define udd_enable_short_packet_interrupt(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_SHORTPACKETES_MASK)
  413. //! disables SHORT PACKET received interrupt
  414. #define udd_disable_short_packet_interrupt(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_SHORTPACKETEC_MASK)
  415. //! tests if SHORT PACKET received interrupt is enabled
  416. #define Is_udd_short_packet_interrupt_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_SHORTPACKETE_MASK))
  417. //! tests if SETUP received
  418. #define Is_udd_setup_received(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_RXSTPI_MASK))
  419. //! acks SETUP received
  420. #define udd_ack_setup_received(ep) (USBB_ARRAY(uesta0clr,ep) = AVR32_USBB_UESTA0CLR_RXSTPIC_MASK)
  421. //! raises SETUP received
  422. #define udd_raise_setup_received(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_RXSTPIS_MASK)
  423. //! enables SETUP received interrupt
  424. #define udd_enable_setup_received_interrupt(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_RXSTPES_MASK)
  425. //! disables SETUP received interrupt
  426. #define udd_disable_setup_received_interrupt() (USBB_ARRAY(uecon0clr(EP_CONTROL) = AVR32_USBB_UECON0CLR_RXSTPEC_MASK)
  427. //! tests if SETUP received interrupt is enabled
  428. #define Is_udd_setup_received_interrupt_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_RXSTPE_MASK))
  429. //! tests if OUT received
  430. #define Is_udd_out_received(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_RXOUTI_MASK))
  431. //! acks OUT received
  432. #define udd_ack_out_received(ep) (USBB_ARRAY(uesta0clr,ep) = AVR32_USBB_UESTA0CLR_RXOUTIC_MASK)
  433. //! raises OUT received
  434. #define udd_raise_out_received(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_RXOUTIS_MASK)
  435. //! enables OUT received interrupt
  436. #define udd_enable_out_received_interrupt(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_RXOUTES_MASK)
  437. //! disables OUT received interrupt
  438. #define udd_disable_out_received_interrupt(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_RXOUTEC_MASK)
  439. //! tests if OUT received interrupt is enabled
  440. #define Is_udd_out_received_interrupt_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_RXOUTE_MASK))
  441. //! tests if IN sending
  442. #define Is_udd_in_send(ep) (Tst_bits(USBB_ARRAY(uesta0,ep), AVR32_USBB_UESTA0_TXINI_MASK))
  443. //! acks IN sending
  444. #define udd_ack_in_send(ep) (USBB_ARRAY(uesta0clr,ep) = AVR32_USBB_UESTA0CLR_TXINIC_MASK)
  445. //! raises IN sending
  446. #define udd_raise_in_send(ep) (USBB_ARRAY(uesta0set,ep) = AVR32_USBB_UESTA0SET_TXINIS_MASK)
  447. //! enables IN sending interrupt
  448. #define udd_enable_in_send_interrupt(ep) (USBB_ARRAY(uecon0set,ep) = AVR32_USBB_UECON0SET_TXINES_MASK)
  449. //! disables IN sending interrupt
  450. #define udd_disable_in_send_interrupt(ep) (USBB_ARRAY(uecon0clr,ep) = AVR32_USBB_UECON0CLR_TXINEC_MASK)
  451. //! tests if IN sending interrupt is enabled
  452. #define Is_udd_in_send_interrupt_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0,ep), AVR32_USBB_UECON0_TXINE_MASK))
  453. //! Get 64-, 32-, 16- or 8-bit access to FIFO data register of selected endpoint.
  454. //! @param ep Endpoint of which to access FIFO data register
  455. //! @param scale Data scale in bits: 64, 32, 16 or 8
  456. //! @return Volatile 64-, 32-, 16- or 8-bit data pointer to FIFO data register
  457. //! @warning It is up to the user of this macro to make sure that all accesses
  458. //! are aligned with their natural boundaries except 64-bit accesses which
  459. //! require only 32-bit alignment.
  460. //! @warning It is up to the user of this macro to make sure that used HSB
  461. //! addresses are identical to the DPRAM internal pointer modulo 32 bits.
  462. #define udd_get_endpoint_fifo_access(ep, scale) \
  463. (((volatile TPASTE2(U, scale) (*)[0x10000 / ((scale) / 8)])AVR32_USBB_SLAVE)[(ep)])
  464. //! @name USBB endpoint DMA drivers
  465. //! These macros manage the common features of the endpoint DMA channels.
  466. //! @{
  467. //! enables the disabling of HDMA requests by endpoint interrupts
  468. #define udd_enable_endpoint_int_dis_hdma_req(ep) (USBB_ARRAY(uecon0set(ep) = AVR32_USBB_UECON0SET_EPDISHDMAS_MASK)
  469. //! disables the disabling of HDMA requests by endpoint interrupts
  470. #define udd_disable_endpoint_int_dis_hdma_req(ep) (USBB_ARRAY(uecon0clr(ep) = AVR32_USBB_UECON0CLR_EPDISHDMAC_MASK)
  471. //! tests if the disabling of HDMA requests by endpoint interrupts is enabled
  472. #define Is_udd_endpoint_int_dis_hdma_req_enabled(ep) (Tst_bits(USBB_ARRAY(uecon0(ep), AVR32_USBB_UECON0_EPDISHDMA_MASK))
  473. //! raises the selected endpoint DMA channel interrupt
  474. #define udd_raise_endpoint_dma_interrupt(ep) (AVR32_USBB.udintset = AVR32_USBB_UDINTSET_DMA1INTS_MASK << ((ep) - 1))
  475. //! raises the selected endpoint DMA channel interrupt
  476. #define udd_clear_endpoint_dma_interrupt(ep) (AVR32_USBB.udintclr = AVR32_USBB_UDINTSET_DMA1INTS_MASK << ((ep) - 1))
  477. //! tests if an interrupt is triggered by the selected endpoint DMA channel
  478. #define Is_udd_endpoint_dma_interrupt(ep) (Tst_bits(AVR32_USBB.udint, AVR32_USBB_UDINT_DMA1INT_MASK << ((ep) - 1)))
  479. //! enables the selected endpoint DMA channel interrupt
  480. #define udd_enable_endpoint_dma_interrupt(ep) (AVR32_USBB.udinteset = AVR32_USBB_UDINTESET_DMA1INTES_MASK << ((ep) - 1))
  481. //! disables the selected endpoint DMA channel interrupt
  482. #define udd_disable_endpoint_dma_interrupt(ep) (AVR32_USBB.udinteclr = AVR32_USBB_UDINTECLR_DMA1INTEC_MASK << ((ep) - 1))
  483. //! tests if the selected endpoint DMA channel interrupt is enabled
  484. #define Is_udd_endpoint_dma_interrupt_enabled(ep) (Tst_bits(AVR32_USBB.udinte, AVR32_USBB_UDINTE_DMA1INTE_MASK << ((ep) - 1)))
  485. //! Access points to the USBB device DMA memory map with arrayed registers
  486. //! @{
  487. //! Structure for DMA registers
  488. typedef struct {
  489. union {
  490. unsigned long nextdesc;
  491. avr32_usbb_uddma1_nextdesc_t NEXTDESC;
  492. };
  493. unsigned long addr;
  494. union {
  495. unsigned long control;
  496. avr32_usbb_uddma1_control_t CONTROL;
  497. };
  498. union {
  499. unsigned long status;
  500. avr32_usbb_uddma1_status_t STATUS;
  501. };
  502. } avr32_usbb_uxdmax_t;
  503. //! Structure for DMA registers
  504. #define USBB_UDDMA_ARRAY(ep) (((volatile avr32_usbb_uxdmax_t *)&AVR32_USBB.uddma1_nextdesc)[(ep) - 1])
  505. //! Set control desc to selected endpoint DMA channel
  506. #define udd_endpoint_dma_set_control(ep,desc) (USBB_UDDMA_ARRAY(ep).control=desc)
  507. //! Get control desc to selected endpoint DMA channel
  508. #define udd_endpoint_dma_get_control(ep) (USBB_UDDMA_ARRAY(ep).control)
  509. //! Set RAM address to selected endpoint DMA channel
  510. #define udd_endpoint_dma_set_addr(ep,add) (USBB_UDDMA_ARRAY(ep).addr=add)
  511. //! Get status to selected endpoint DMA channel
  512. #define udd_endpoint_dma_get_status(ep) (USBB_UDDMA_ARRAY(ep).status)
  513. //! @}
  514. //! @}
  515. //! @}
  516. #endif // _USBB_DEVICE_H_