📄 usbd_udphs.lst
字号:
###############################################################################
# #
# 24/Apr/2009 16:18:18 #
# IAR ARM ANSI C/C++ Compiler V5.11.0.20622/W32 EVALUATION #
# Copyright 1999-2007 IAR Systems. All rights reserved. #
# #
# Cpu mode = arm #
# Endian = little #
# Source file = D:\basic-dataflash-project-at91sam7se-ek\at91lib\usb\dev #
# ice\core\USBD_UDPHS.c #
# Command line = D:\basic-dataflash-project-at91sam7se-ek\at91lib\usb\dev #
# ice\core\USBD_UDPHS.c -D at91sam7se512 -D sram -D #
# TRACE_LEVEL=4 -lC D:\basic-dataflash-project-at91sam7se- #
# ek\at91sam7se-ek\basic-dataflash-project\ewp\at91sam7se5 #
# 12_sram\List\ --remarks --diag_suppress Pe826,Pe1375 -o #
# D:\basic-dataflash-project-at91sam7se-ek\at91sam7se-ek\b #
# asic-dataflash-project\ewp\at91sam7se512_sram\Obj\ #
# --no_cse --no_unroll --no_inline --no_code_motion #
# --no_tbaa --no_clustering --no_scheduling --debug #
# --endian little --cpu ARM7TDMI -e --fpu None #
# --dlib_config "D:\Program Files\arm\ARM\INC\DLib_Config_ #
# Full.h" -I D:\basic-dataflash-project-at91sam7se-ek\at91 #
# sam7se-ek\basic-dataflash-project\ewp\..\..\..\at91lib/p #
# eripherals\ -I D:\basic-dataflash-project-at91sam7se-ek\ #
# at91sam7se-ek\basic-dataflash-project\ewp\..\..\..\at91l #
# ib\ -I D:\basic-dataflash-project-at91sam7se-ek\at91sam7 #
# se-ek\basic-dataflash-project\ewp\..\..\..\at91lib/memor #
# ies\ -I D:\basic-dataflash-project-at91sam7se-ek\at91sam #
# 7se-ek\basic-dataflash-project\ewp\..\..\..\at91lib/boar #
# ds/at91sam7se-ek\ -I "D:\Program Files\arm\ARM\INC\" #
# --interwork --cpu_mode arm -Oh #
# List file = D:\basic-dataflash-project-at91sam7se-ek\at91sam7se-ek\b #
# asic-dataflash-project\ewp\at91sam7se512_sram\List\USBD_ #
# UDPHS.lst #
# Object file = D:\basic-dataflash-project-at91sam7se-ek\at91sam7se-ek\b #
# asic-dataflash-project\ewp\at91sam7se512_sram\Obj\USBD_U #
# DPHS.o #
# #
# #
###############################################################################
D:\basic-dataflash-project-at91sam7se-ek\at91lib\usb\device\core\USBD_UDPHS.c
1 /* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2008, 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 conditions are 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 //------------------------------------------------------------------------------
31 // Headers
32 //------------------------------------------------------------------------------
33
34 #include "USBD.h"
35 #include "USBDCallbacks.h"
36 #include "USBDDriver.h"
37 #include <board.h>
38 #include <pio/pio.h>
39 #include <utility/trace.h>
40 #include <utility/led.h>
41 #include <usb/common/core/USBEndpointDescriptor.h>
42 #include <usb/common/core/USBGenericRequest.h>
43 #include <usb/common/core/USBFeatureRequest.h>
44
45 #include <stdio.h>
46
47 #ifdef BOARD_USB_UDPHS
48
49 //------------------------------------------------------------------------------
50 // Definitions
51 //------------------------------------------------------------------------------
52
53 /// Maximum number of endpoints interrupts.
54 #define NUM_IT_MAX \
55 (AT91C_BASE_UDPHS->UDPHS_IPFEATURES & AT91C_UDPHS_EPT_NBR_MAX)
56 /// Maximum number of endpoint DMA interrupts
57 #define NUM_IT_MAX_DMA \
58 ((AT91C_BASE_UDPHS->UDPHS_IPFEATURES & AT91C_UDPHS_DMA_CHANNEL_NBR)>>4)
59 /// Bits that should be shifted to access DMA control bits.
60 #define SHIFT_DMA 24
61 /// Bits that should be shifted to access interrupt bits.
62 #define SHIFT_INTERUPT 8
63
64 /// Compile option, use DMA. Remove this define for not use DMA.
65 #define DMA
66
67 /// Max size of the FMA FIFO
68 #define DMA_MAX_FIFO_SIZE 65536
69
70 //------------------------------------------------------------------------------
71 /// \page "Endpoint states"
72 /// This page lists the endpoint states.
73 /// !States
74 // - UDP_ENDPOINT_DISABLED
75 // - UDP_ENDPOINT_HALTED
76 // - UDP_ENDPOINT_IDLE
77 // - UDP_ENDPOINT_SENDING
78 // - UDP_ENDPOINT_RECEIVING
79
80 /// Endpoint states: Endpoint is disabled
81 #define UDP_ENDPOINT_DISABLED 0
82 /// Endpoint states: Endpoint is halted (i.e. STALLs every request)
83 #define UDP_ENDPOINT_HALTED 1
84 /// Endpoint states: Endpoint is idle (i.e. ready for transmission)
85 #define UDP_ENDPOINT_IDLE 2
86 /// Endpoint states: Endpoint is sending data
87 #define UDP_ENDPOINT_SENDING 3
88 /// Endpoint states: Endpoint is receiving data
89 #define UDP_ENDPOINT_RECEIVING 4
90 //------------------------------------------------------------------------------
91
92 //------------------------------------------------------------------------------
93 // Structures
94 //------------------------------------------------------------------------------
95
96 /// Describes an ongoing transfer on a UDP endpoint.
97 typedef struct
98 {
99 /// Pointer to a data buffer used for emission/reception.
100 char *pData;
101 /// Number of bytes which have been written into the UDP internal FIFO
102 /// buffers.
103 volatile int buffered;
104 /// Number of bytes which have been sent/received.
105 volatile int transferred;
106 /// Number of bytes which have not been buffered/transferred yet.
107 volatile int remaining;
108 /// Optional callback to invoke when the transfer completes.
109 volatile TransferCallback fCallback;
110 /// Optional argument to the callback function.
111 void *pArgument;
112 } Transfer;
113
114 //------------------------------------------------------------------------------
115 /// Describes the state of an endpoint of the UDP controller.
116 //------------------------------------------------------------------------------
117 typedef struct
118 {
119 /// Current endpoint state.
120 volatile unsigned char state;
121 /// Current reception bank (0 or 1).
122 unsigned char bank;
123 /// Maximum packet size for the endpoint.
124 unsigned short size;
125 /// Describes an ongoing transfer (if current state is either
126 /// <UDP_ENDPOINT_SENDING> or <UDP_ENDPOINT_RECEIVING>)
127 Transfer transfer;
128 } Endpoint;
129
130 //------------------------------------------------------------------------------
131 // Internal variables
132 //------------------------------------------------------------------------------
133
134 /// Holds the internal state for each endpoint of the UDP.
135 static Endpoint endpoints[BOARD_USB_NUMENDPOINTS];
136 /// Device current state.
137 static unsigned char deviceState;
138 /// Indicates the previous device state
139 static unsigned char previousDeviceState;
140 /// Special case for send a ZLP
141 static unsigned char sendZLP = 0;
142
143 /// 7.1.20 Test Mode Support
144 /// Test codes for the USB HS test mode.
145 static const char test_packet_buffer[] = {
146 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // JKJKJKJK * 9
147 0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA, // JJKKJJKK * 8
148 0xEE,0xEE,0xEE,0xEE,0xEE,0xEE,0xEE,0xEE, // JJJJKKKK * 8
149 0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, // JJJJJJJKKKKKKK * 8
150 0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD, // JJJJJJJK * 8
151 0xFC,0x7E,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0x7E // {JKKKKKKK * 10}, JK
152 };
153
154 //------------------------------------------------------------------------------
155 // Internal Functions
156 //------------------------------------------------------------------------------
157
158 //------------------------------------------------------------------------------
159 /// Disables the BIAS of the USB controller
160 //------------------------------------------------------------------------------
161 static inline void UDPHS_DisableBIAS( void )
162 {
163 // For CAP9, SAM9RL, HS
164 #if !defined (BOARD_USB_NO_BIAS_COMMAND)
165 AT91C_BASE_PMC->PMC_UCKR &= ~AT91C_CKGR_BIASEN_ENABLED;
166 #endif
167 }
168
169 //------------------------------------------------------------------------------
170 /// Enables the BIAS of the USB controller
171 //------------------------------------------------------------------------------
172 static inline void UDPHS_EnableBIAS( void )
173 {
174 // For CAP9, SAM9RL, HS
175 #if !defined (BOARD_USB_NO_BIAS_COMMAND)
176 UDPHS_DisableBIAS();
177 AT91C_BASE_PMC->PMC_UCKR |= AT91C_CKGR_BIASEN_ENABLED;
178 #endif
179 }
180
181 //------------------------------------------------------------------------------
182 /// Enable UDPHS clock
183 //------------------------------------------------------------------------------
184 static inline void UDPHS_EnableUsbClock( void )
185 {
186 #if !defined (PMC_BY_HARD)
187 AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_UDPHS);
188 // Enable 480MHZ
189 AT91C_BASE_CKGR->CKGR_UCKR |= (AT91C_CKGR_PLLCOUNT & (3 << 20)) | AT91C_CKGR_UPLLEN;
190 // Wait until UTMI PLL is locked
191 while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCKU) == 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -