source: rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/cores/arduino/USB/samd21_host.h

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

1.7.10のファイルに更新

File size: 6.6 KB
Line 
1/*
2 Copyright (c) 2014 Arduino LLC. All right reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 See the GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18/*
19**Modified 04/04/2016 by Arduino.org development team
20*/
21
22#ifndef UOTGHS_HOST_H_INCLUDED
23#define UOTGHS_HOST_H_INCLUDED
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29extern __attribute__((__aligned__(4))) volatile UsbHostDescriptor usb_pipe_table[USB_EPT_NUM];
30
31#define USB_EP_DIR_IN 0x80 // USB_SETUP_DEVICE_TO_HOST
32#define USB_EP_DIR_OUT 0x00 // USB_SETUP_HOST_TO_DEVICE
33
34#define USB_HOST_PTYPE_DIS USB_HOST_PCFG_PTYPE(0x0) // Pipe is disabled
35#define USB_HOST_PTYPE_CTRL USB_HOST_PCFG_PTYPE(0x1) // Pipe is enabled and configured as CONTROL
36#define USB_HOST_PTYPE_ISO USB_HOST_PCFG_PTYPE(0x2) // Pipe is enabled and configured as ISO
37#define USB_HOST_PTYPE_BULK USB_HOST_PCFG_PTYPE(0x3) // Pipe is enabled and configured as BULK
38#define USB_HOST_PTYPE_INT USB_HOST_PCFG_PTYPE(0x4) // Pipe is enabled and configured as INTERRUPT
39#define USB_HOST_PTYPE_EXT USB_HOST_PCFG_PTYPE(0x5) // Pipe is enabled and configured as EXTENDED
40
41#define USB_HOST_NB_BK_1 1
42
43#define USB_HOST_PCFG_PTOKEN_SETUP USB_HOST_PCFG_PTOKEN(0x0)
44#define USB_HOST_PCFG_PTOKEN_IN USB_HOST_PCFG_PTOKEN(0x1)
45#define USB_HOST_PCFG_PTOKEN_OUT USB_HOST_PCFG_PTOKEN(0x2)
46
47#define USB_ERRORFLOW USB_HOST_STATUS_BK_ERRORFLOW
48#define USB_ERRORTIMEOUT USB_HOST_STATUS_PIPE_TOUTER
49#define USB_ERROR_DATATOGGLE USB_HOST_STATUS_PIPE_DTGLER
50
51#define USB_PCKSIZE_SIZE_8_BYTES 0
52#define USB_PCKSIZE_SIZE_16_BYTES 1
53#define USB_PCKSIZE_SIZE_32_BYTES 2
54#define USB_PCKSIZE_SIZE_64_BYTES 3
55#define USB_PCKSIZE_SIZE_128_BYTES 4
56#define USB_PCKSIZE_SIZE_256_BYTES 5
57#define USB_PCKSIZE_SIZE_512_BYTES 6
58#define USB_PCKSIZE_SIZE_1023_BYTES_FS 7
59#define USB_PCKSIZE_SIZE_1024_BYTES_HS 7
60
61#define USB_HOST_DTGL(p) (USB->HOST.HostPipe[p].PSTATUS.reg & USB_HOST_PSTATUS_DTGL)>>USB_HOST_PSTATUS_DTGL_Pos
62
63// USB host connection/disconnection monitoring
64#define uhd_enable_connection_int() USB->HOST.INTENSET.reg = USB_HOST_INTENSET_DCONN
65#define uhd_disable_connection_int() USB->HOST.INTENCLR.reg = USB_HOST_INTENCLR_DCONN
66#define uhd_ack_connection() USB->HOST.INTFLAG.reg = USB_HOST_INTFLAG_DCONN
67
68#define uhd_enable_disconnection_int() USB->HOST.INTENSET.reg = USB_HOST_INTENSET_DDISC
69#define uhd_disable_disconnection_int() USB->HOST.INTENCLR.reg = USB_HOST_INTENCLR_DDISC
70#define uhd_ack_disconnection() USB->HOST.INTFLAG.reg = USB_HOST_INTFLAG_DDISC
71
72// Initiates a USB register reset
73#define uhd_start_USB_reg_reset() USB->HOST.CTRLA.bit.SWRST = 1;
74
75// Bus Reset
76#define Is_uhd_starting_reset() (USB->HOST.CTRLB.bit.BUSRESET == 1)
77#define UHD_BusReset() USB->HOST.CTRLB.bit.BUSRESET = 1
78#define uhd_stop_reset() // nothing to do
79
80#define uhd_ack_reset_sent() USB->HOST.INTFLAG.reg = USB_HOST_INTFLAG_RST
81#define Is_uhd_reset_sent() (USB->HOST.INTFLAG.reg & USB_HOST_INTFLAG_RST)
82
83// Initiates a SOF events
84#define uhd_enable_sof() USB->HOST.CTRLB.bit.SOFE = 1
85#define uhd_disable_sof() USB->HOST.CTRLB.bit.SOFE = 0
86#define Is_uhd_sof_enabled() (USB->HOST.CTRLB & USB_HOST_CTRLB_SOFE)
87#define Is_uhd_sof() (USB->HOST.INTFLAG.reg & USB_HOST_INTFLAG_HSOF)
88
89// USB address of pipes
90#define uhd_configure_address(pipe_num, addr) usb_pipe_table[pipe_num].HostDescBank[0].CTRL_PIPE.bit.PDADDR = addr
91#define uhd_get_configured_address(pipe_num) usb_pipe_table[pipe_num].HostDescBank[0].CTRL_PIPE.bit.PDADDR
92
93// Pipes
94#define uhd_freeze_pipe(p) USB->HOST.HostPipe[p].PSTATUSSET.reg = USB_HOST_PSTATUSSET_PFREEZE
95#define uhd_unfreeze_pipe(p) USB->HOST.HostPipe[p].PSTATUSCLR.reg = USB_HOST_PSTATUSCLR_PFREEZE
96#define Is_uhd_pipe_frozen(p) ((USB->HOST.HostPipe[p].PSTATUS.reg&USB_HOST_PSTATUS_PFREEZE)==USB_HOST_PSTATUS_PFREEZE)
97
98// Pipe configuration
99#define uhd_configure_pipe_token(p, token) USB->HOST.HostPipe[p].PCFG.bit.PTOKEN = token
100
101// Pipe data management
102#define uhd_byte_count(p) usb_pipe_table[p].HostDescBank[0].PCKSIZE.bit.BYTE_COUNT
103#define uhd_ack_setup_ready(p) USB->HOST.HostPipe[p].PINTFLAG.reg = USB_HOST_PINTFLAG_TXSTP
104#define Is_uhd_setup_ready(p) ((USB->HOST.HostPipe[p].PINTFLAG.reg&USB_HOST_PINTFLAG_TXSTP) == USB_HOST_PINTFLAG_TXSTP)
105#define uhd_ack_in_received(p) USB->HOST.HostPipe[p].PINTFLAG.reg = USB_HOST_PINTFLAG_TRCPT(1)
106#define Is_uhd_in_received(p) ((USB->HOST.HostPipe[p].PINTFLAG.reg&USB_HOST_PINTFLAG_TRCPT(1)) == USB_HOST_PINTFLAG_TRCPT(1))
107#define uhd_ack_out_ready(p) USB->HOST.HostPipe[p].PINTFLAG.reg = USB_HOST_PINTFLAG_TRCPT(1)
108#define Is_uhd_out_ready(p) ((USB->HOST.HostPipe[p].PINTFLAG.reg&USB_HOST_PINTFLAG_TRCPT(1)) == USB_HOST_PINTFLAG_TRCPT(1))
109#define uhd_ack_nak_received(p) usb_pipe_table[p].HostDescBank[1].STATUS_BK.reg &= ~USB_HOST_STATUS_BK_ERRORFLOW
110#define Is_uhd_nak_received(p) (usb_pipe_table[p].HostDescBank[1].STATUS_BK.reg & USB_HOST_STATUS_BK_ERRORFLOW)
111
112// Endpoint Interrupt Summary
113#define uhd_endpoint_interrupt() USB->HOST.PINTSMRY.reg
114
115// Run in Standby
116#define uhd_run_in_standby() USB->HOST.CTRLA.reg |= USB_CTRLA_RUNSTDBY
117// Force host mode
118#define uhd_force_host_mode() USB->HOST.CTRLA.reg |= USB_CTRLA_MODE
119
120// Enable USB macro
121#define uhd_enable() USB->HOST.CTRLA.reg |= USB_CTRLA_ENABLE
122// Disable USB macro
123#define uhd_disable() USB->HOST.CTRLA.reg &= ~USB_CTRLA_ENABLE
124
125// Force full speed mode
126#define uhd_force_full_speed() USB->HOST.CTRLB.reg &= ~USB_HOST_CTRLB_SPDCONF_Msk
127
128#ifdef __cplusplus
129}
130#endif
131
132#endif /* UOTGHS_HOST_H_INCLUDED */
Note: See TracBrowser for help on using the repository browser.