source: rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/cores/arduino/USB/samd21_device.h@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 5.7 KB
Line 
1/* ----------------------------------------------------------------------------
2 * SAM Software Package License
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2011-2012, Atmel Corporation
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following condition is met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
13 *
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ----------------------------------------------------------------------------
28 */
29
30#ifndef SAMD21_DEVICE_H_INCLUDED
31#define SAMD21_DEVICE_H_INCLUDED
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37#define EP0 0
38#define EPX_SIZE 64// 64 for Full Speed, EPT size max is 1024
39
40// Force device low speed mode
41#define udd_force_low_speed() USB->DEVICE.CTRLB.reg &= ~USB_DEVICE_CTRLB_SPDCONF_Msk; USB->DEVICE.CTRLB.reg |= USB_DEVICE_CTRLB_SPDCONF_1_Val
42// Force full speed mode
43#define udd_force_full_speed() USB->DEVICE.CTRLB.reg &= ~USB_DEVICE_CTRLB_SPDCONF_Msk
44
45// Attaches to USB bus
46#define udd_attach_device() USB->DEVICE.CTRLB.reg &= ~USB_DEVICE_CTRLB_DETACH
47#define udd_detach_device() USB->DEVICE.CTRLB.reg |= USB_DEVICE_CTRLB_DETACH
48
49// Manage reset event
50// Set when a USB "End of Reset" has been detected
51#define udd_enable_reset_interrupt() USB->DEVICE.INTENSET.reg = USB_DEVICE_INTENSET_EORST
52#define udd_ack_reset() USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_EORST
53#define Is_udd_reset() (USB->DEVICE.INTFLAG.reg & USB_DEVICE_INTFLAG_EORST)
54
55// Manage start of frame (SOF) event
56#define udd_enable_sof_interrupt() USB->DEVICE.INTENSET.reg = USB_DEVICE_INTENSET_SOF
57#define udd_ack_sof() USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SOF
58#define Is_udd_sof() (USB->DEVICE.INTENSET.reg & USB_DEVICE_INTENSET_SOF)
59#define udd_frame_number() ((USB->DEVICE.FNUM.reg & USB_DEVICE_FNUM_FNUM_Msk) >> USB_DEVICE_FNUM_FNUM_Pos)
60
61// configures the USB device address and enable it.
62#define udd_configure_address(address) USB->DEVICE.DADD.reg = USB_DEVICE_DADD_ADDEN | address
63
64// Enables SETUP received interrupt
65#define udd_enable_setup_received_interrupt(ep) USB->DEVICE.DeviceEndpoint[ep].EPINTENSET.reg = USB_DEVICE_EPINTFLAG_RXSTP
66// ACKs OUT received
67#define udd_ack_out_received(ep) USB->DEVICE.DeviceEndpoint[ep].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK0RDY
68// ACKs OUT received
69#define udd_ack_in_received(ep) USB->DEVICE.DeviceEndpoint[ep].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY
70// Is transfert completed ?
71#define udd_is_transf_cplt(ep) (USB->DEVICE.DeviceEndpoint[ep].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT1)
72// Clear the transfer complete flag
73#define udd_clear_transf_cplt(ep) USB->DEVICE.DeviceEndpoint[ep].EPINTFLAG.bit.TRCPT1 = 1
74// Set the bank as ready
75#define udd_bk_rdy(ep) USB->DEVICE.DeviceEndpoint[ep].EPSTATUSSET.bit.BK1RDY = 1
76#define udd_read_endpoint_flag(ep) USB->DEVICE.DeviceEndpoint[ep].EPINTFLAG.reg
77// Enable interrupt transfer complete
78#define udd_ept_enable_it_transf_cplt_in(ep) USB->DEVICE.DeviceEndpoint[ep].EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRCPT1
79#define udd_ept_enable_it_transf_cplt_out(ep) USB->DEVICE.DeviceEndpoint[ep].EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRCPT0
80// Clear the stall flag
81#define udd_clear_stall_request(ep) USB->DEVICE.DeviceEndpoint[ep].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_STALL1
82// Remove stall
83#define udd_remove_stall_request(ep) USB->DEVICE.DeviceEndpoint[ep].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1
84
85// Endpoint Interrupt Summary
86#define udd_endpoint_interrupt() USB->DEVICE.EPINTSMRY.reg
87
88#define udd_clear_wakeup_interrupt() USB->DEVICE.INTENCLR.reg = USB_DEVICE_INTENCLR_WAKEUP
89#define udd_clear_eorsm_interrupt() USB->DEVICE.INTENCLR.reg = USB_DEVICE_INTENCLR_EORSM
90#define udd_clear_suspend_interrupt() USB->DEVICE.INTENCLR.reg = USB_DEVICE_INTENCLR_SUSPEND
91
92
93
94// Force device mode
95#define udd_force_device_mode() USB->DEVICE.CTRLA.reg &= ~USB_CTRLA_MODE
96// Run in Standby
97#define udd_device_run_in_standby() USB->DEVICE.CTRLA.reg |= USB_CTRLA_RUNSTDBY
98// Force host mode
99#define udd_force_host_mode() USB->DEVICE.CTRLA.reg |= USB_CTRLA_MODE
100
101
102// Enable USB macro
103#define udd_enable() USB->DEVICE.CTRLA.reg |= USB_CTRLA_ENABLE
104// Disable USB macro
105#define udd_disable() USB->DEVICE.CTRLA.reg &= ~USB_CTRLA_ENABLE
106
107#ifdef __cplusplus
108}
109#endif
110
111#endif /* SAMD21_DEVICE_H_INCLUDED */
112
Note: See TracBrowser for help on using the repository browser.