📄 usbd_udphs.lst
字号:
###############################################################################
# #
# 29/Jul/2008 15:06:16 #
# 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:\rock\atarm\at91sam7se\software\usb-device-core-projec #
# t-1.3-iar5-at91sam7se-ek\at91lib\usb\device\core\USBD_UD #
# PHS.c #
# Command line = D:\rock\atarm\at91sam7se\software\usb-device-core-projec #
# t-1.3-iar5-at91sam7se-ek\at91lib\usb\device\core\USBD_UD #
# PHS.c -D at91sam7se512 -lC D:\rock\atarm\at91sam7se\soft #
# ware\usb-device-core-project-1.3-iar5-at91sam7se-ek\at91 #
# sam7se-ek\usb-device-core-project\ewp\at91sam7se512_sdra #
# m\List\ --remarks -o D:\rock\atarm\at91sam7se\software\u #
# sb-device-core-project-1.3-iar5-at91sam7se-ek\at91sam7se #
# -ek\usb-device-core-project\ewp\at91sam7se512_sdram\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\IAR Systems\Embedded #
# Workbench 5.0 Evaluation\ARM\INC\DLib_Config_Full.h" -I #
# D:\rock\atarm\at91sam7se\software\usb-device-core-projec #
# t-1.3-iar5-at91sam7se-ek\at91sam7se-ek\usb-device-core-p #
# roject\ewp\..\..\..\at91lib\ -I #
# D:\rock\atarm\at91sam7se\software\usb-device-core-projec #
# t-1.3-iar5-at91sam7se-ek\at91sam7se-ek\usb-device-core-p #
# roject\ewp\..\..\..\at91lib\boards\at91sam7se-ek\ -I #
# D:\rock\atarm\at91sam7se\software\usb-device-core-projec #
# t-1.3-iar5-at91sam7se-ek\at91sam7se-ek\usb-device-core-p #
# roject\ewp\..\..\..\at91lib\peripherals\ -I #
# D:\rock\atarm\at91sam7se\software\usb-device-core-projec #
# t-1.3-iar5-at91sam7se-ek\at91sam7se-ek\usb-device-core-p #
# roject\ewp\..\..\..\at91lib\components\ -I #
# D:\rock\atarm\at91sam7se\software\usb-device-core-projec #
# t-1.3-iar5-at91sam7se-ek\at91sam7se-ek\usb-device-core-p #
# roject\ewp\..\..\..\at91lib\usb\ -I "D:\Program #
# Files\IAR Systems\Embedded Workbench 5.0 #
# Evaluation\ARM\INC\" --interwork --cpu_mode arm -On #
# List file = D:\rock\atarm\at91sam7se\software\usb-device-core-projec #
# t-1.3-iar5-at91sam7se-ek\at91sam7se-ek\usb-device-core-p #
# roject\ewp\at91sam7se512_sdram\List\USBD_UDPHS.lst #
# Object file = D:\rock\atarm\at91sam7se\software\usb-device-core-projec #
# t-1.3-iar5-at91sam7se-ek\at91sam7se-ek\usb-device-core-p #
# roject\ewp\at91sam7se512_sdram\Obj\USBD_UDPHS.o #
# #
# #
###############################################################################
D:\rock\atarm\at91sam7se\software\usb-device-core-project-1.3-iar5-at91sam7se-ek\at91lib\usb\device\core\USBD_UDPHS.c
1 /* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2007, 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 * - Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the disclaimer below in the documentation and/or
16 * other materials provided with the distribution.
17 *
18 * Atmel's name may not be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
24 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * ----------------------------------------------------------------------------
32 */
33
34 //------------------------------------------------------------------------------
35 // Headers
36 //------------------------------------------------------------------------------
37
38 #include "USBD.h"
39 #include "USBDCallbacks.h"
40 #include "USBDDriver.h"
41 #include <board.h>
42 #include <pio/pio.h>
43 #include <utility/trace.h>
44 #include <utility/led.h>
45 #include <usb/common/core/USBEndpointDescriptor.h>
46 #include <usb/common/core/USBGenericRequest.h>
47 #include <usb/common/core/USBFeatureRequest.h>
48
49 #include <stdio.h>
50
51 #ifdef BOARD_USB_UDPHS
52
53 //------------------------------------------------------------------------------
54 // Definitions
55 //------------------------------------------------------------------------------
56 #define NUM_IT_MAX (AT91C_BASE_UDPHS->UDPHS_IPFEATURES & AT91C_UDPHS_EPT_NBR_MAX)
57 #define NUM_IT_MAX_DMA ((AT91C_BASE_UDPHS->UDPHS_IPFEATURES & AT91C_UDPHS_DMA_CHANNEL_NBR)>>4)
58
59 #define SHIFT_DMA 24
60 #define SHIFT_INTERUPT 8
61
62
63 #define DMA
64
65 /// Max size of the FMA FIFO
66 #define DMA_MAX_FIFO_SIZE 65536
67
68 // Constants: Endpoint states
69 // UDP_ENDPOINT_DISABLED - Endpoint is disabled.
70 // UDP_ENDPOINT_HALTED - Endpoint is halted (i.e. STALLs every request).
71 // UDP_ENDPOINT_IDLE - Endpoint is idle (i.e. ready for transmission).
72 // UDP_ENDPOINT_SENDING - Endpoint is sending data.
73 // UDP_ENDPOINT_RECEIVING - Endpoint is receiving data.
74 #define UDP_ENDPOINT_DISABLED 0
75 #define UDP_ENDPOINT_HALTED 1
76 #define UDP_ENDPOINT_IDLE 2
77 #define UDP_ENDPOINT_SENDING 3
78 #define UDP_ENDPOINT_RECEIVING 4
79
80 //------------------------------------------------------------------------------
81 // Structures
82 //------------------------------------------------------------------------------
83
84 // Type: UDP transfer
85 // Describes an ongoing transfer on a UDP endpoint.
86 //
87 // Variables:
88 // data - Pointer to a data buffer used for emission/reception.
89 // buffered - Number of bytes which have been written into the UDP internal
90 // FIFO buffers.
91 // transferred - Number of bytes which have been sent/received.
92 // remaining - Number of bytes which have not been buffered/transferred yet.
93 // callback - Optional callback to invoke when the transfer completes.
94 // argument - Optional argument to the callback function.
95 typedef struct
96 {
97 char *pData;
98 volatile int buffered;
99 volatile int transferred;
100 volatile int remaining;
101 TransferCallback fCallback;
102 void *pArgument;
103 } Transfer;
104
105 // Type: UDP endpoint
106 // Describes the state of an endpoint of the UDP controller.
107 //
108 // Variables:
109 // state - Current endpoint state.
110 // bank - Current reception bank (0 or 1).
111 // size - Maximum packet size for the endpoint.
112 // transfer - Describes an ongoing transfer (if current state is either
113 // <UDP_ENDPOINT_SENDING> or <UDP_ENDPOINT_RECEIVING>).
114 typedef struct
115 {
116 unsigned char state;
117 unsigned char bank;
118 unsigned short size;
119 Transfer transfer;
120 } Endpoint;
121
122 //------------------------------------------------------------------------------
123 // Internal variables
124 //------------------------------------------------------------------------------
125
126 // Variables:
127 // endpoints - Holds the internal state for each endpoint of the UDP.
128 // deviceState - Device current state.
129 // suspended - Indicates if device is currently suspended.
130 static Endpoint endpoints[BOARD_USB_NUMENDPOINTS];
131 static unsigned char deviceState;
132 static unsigned char previousDeviceState;
133
134 // 7.1.20 Test Mode Support
135 static const char test_packet_buffer[] = {
136 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // JKJKJKJK * 9
137 0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA, // JJKKJJKK * 8
138 0xEE,0xEE,0xEE,0xEE,0xEE,0xEE,0xEE,0xEE, // JJJJKKKK * 8
139 0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, // JJJJJJJKKKKKKK * 8
140 0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD, // JJJJJJJK * 8
141 0xFC,0x7E,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0x7E // {JKKKKKKK * 10}, JK
142 };
143
144 //------------------------------------------------------------------------------
145 // Internal Functions
146 //------------------------------------------------------------------------------
147
148 //------------------------------------------------------------------------------
149 // Disables the BIAS of the USB controller
150 //------------------------------------------------------------------------------
151 static inline void UDPHS_DisableBIAS( void )
152 {
153 // For CAP9, SAM9RL, HS
154 #if !defined (BOARD_USB_NO_BIAS_COMMAND)
155 AT91C_BASE_PMC->PMC_UCKR &= ~AT91C_CKGR_BIASEN_ENABLED;
156 #endif
157 }
158
159 //------------------------------------------------------------------------------
160 // Enables the BIAS of the USB controller
161 //------------------------------------------------------------------------------
162 static inline void UDPHS_EnableBIAS( void )
163 {
164 // For CAP9, SAM9RL, HS
165 #if !defined (BOARD_USB_NO_BIAS_COMMAND)
166 UDPHS_DisableBIAS();
167 AT91C_BASE_PMC->PMC_UCKR |= AT91C_CKGR_BIASEN_ENABLED;
168 #endif
169 }
170
171 //------------------------------------------------------------------------------
172 // Enable UDPHS clock
173 // pUsb Pointer to a S_usb instance
174 //------------------------------------------------------------------------------
175 static inline void UDPHS_EnableUsbClock( void )
176 {
177 #if !defined (PMC_BY_HARD)
178 AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_UDPHS);
179 // Enable 480MHZ
180 AT91C_BASE_CKGR->CKGR_UCKR |= (AT91C_CKGR_PLLCOUNT & (3 << 20)) | AT91C_CKGR_UPLLEN;
181 // Wait until UTMI PLL is locked
182 while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCKU) == 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -