📄 chap_9.lst
字号:
ARM COMPILER V2.53, Chap_9 28/06/07 09:54:11 PAGE 1
ARM COMPILER V2.53, COMPILATION OF MODULE Chap_9
OBJECT MODULE PLACED IN Chap_9.OBJ
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe Chap_9.c THUMB OPTIMIZE(0,SPEED) BROWSE DEBUG TABS(4)
stmt level source
1 /****************************************Copyright (c)**************************************************
2 ** Guangzou ZLG-MCU Development Co.,LTD.
3 ** graduate school
4 ** http://www.zlgmcu.com
5 **
6 **--------------File Info-------------------------------------------------------------------------------
7 ** File name: Chap_9.c
8 ** Last modified Date: 2005-8-6
9 ** Last Version: V1.0
10 ** Descriptions: chap_9.c, 实现USB1.1协议
11 ** chap_9.c, realize USB1.1 protocol
12 **------------------------------------------------------------------------------------------------------
13 ** Created by: 郑明远 MingYuan Zheng
14 ** Created date: 2005-8-6
15 ** Version: V1.0
16 ** Descriptions: 初始版本 The original version
17 **
18 **------------------------------------------------------------------------------------------------------
19 ** Modified by:
20 ** Modified date:
21 ** Version:
22 ** Descriptions:
23 **
24 **------------------------------------------------------------------------------------------------------
25 ** Modified by:
26 ** Modified date:
27 ** Version:
28 ** Descriptions:
29 **
30 ********************************************************************************************************/
31
32 //#include "config.h"
33 #include "USBConfig.h"
34
35 #include "USBCI.h"
36 #include "USBDriver.h"
37 #include "Chap_9.h"
38 #include "Descriptor.h"
39 #include "target.h"
40
41 /* define control transfer structure variable */
42 CONTROL_XFER ControlData; /* 定义传输控制结构变量 */
43
44 /*************************************************************************
45 ** 函数名称: USB 标准设备请求入口地址指针表
46 ** Function: Entry address of USB standard device request Function
47 **************************************************************************/
48 void (*StandardDeviceRequest[])(void) =
49 {
50 get_status,
51 clear_feature,
52 reserved,
53 set_feature,
54 reserved,
55 set_address,
56 get_descriptor,
57 reserved,
58 get_configuration,
59 set_configuration,
ARM COMPILER V2.53, Chap_9 28/06/07 09:54:11 PAGE 2
60 get_interface,
61 set_interface,
62 reserved,
63 reserved,
64 reserved,
65 reserved
66 };
67
68 //*************************************************************************
69 // USB 协议层函数 USB Protocal Function
70 //*************************************************************************
71
72 /*************************************************************************************************
73 ** 函数名称: stall_ep0() Name: stall_ep0()
74 ** 功能描述: 使控制端点处于停止状态 Function: stall logical endpoint 0
75 *************************************************************************************************/
76 void stall_ep0(void)
77 {
78 1 USB_SetEndpointStatus(0, 1);
79 1 USB_SetEndpointStatus(1, 1);
80 1 }
81
82 /*************************************************************************************************
83 ** 函数名称: reserved() Name: reserved()
84 ** 功能描述: 保留子程序 Function: reserved function
85 *************************************************************************************************/
86 void reserved(void)
87 {
88 1 stall_ep0();
89 1 }
90
91 /*************************************************************************************************
92 ** 函数名称: init_unconfig() Name: init_unconfig()
93 ** 功能描述: 进入地址状态,禁止 0 除外的所有端点 Function: disable all endpoints except for control endpo
-int 0
94 *************************************************************************************************/
95 void init_unconfig(void)
96 {
97 1 USB_SetEndpointEnable(0);
98 1 }
99
100 /*************************************************************************************************
101 ** 函数名称: init_config() Name: init_config()
102 ** 功能描述: 配置处理,允许端点收发 Function: enable all endpoints
103 *************************************************************************************************/
104 void init_config(void)
105 {
106 1 USB_SetEndpointEnable(1);
107 1 }
108
109 /*************************************************************************************************
110 ** 函数名称: single_transmit() Name: single_transmit()
111 ** 功能描述: 通过物理端点 1 发送数据 Function: send data by physical endpoint 1
112 ** 输 入: INT8U * buf: 发送数据指针 Input: INT8U * buf: send buffer
113 INT8U len: 发送数据长度 INT8U len: send data length
114 ** 输 出: 无 Output: NULL
115 *************************************************************************************************/
116 void single_transmit(INT8U * buf, INT8U len)
117 {
118 1 /* the len must below the maxpacket size of physical endpoint 1 */
119 1 if( len <= EP0_PACKET_SIZE)
120 1 { /* len 必须小于端点的最大包信息长度 */
121 2 USB_WriteEndpoint(1, len, buf);
122 2 }
123 1 }
124
ARM COMPILER V2.53, Chap_9 28/06/07 09:54:11 PAGE 3
125 /*************************************************************************************************
126 ** 函数名称: code_transmit() Name: code_transmit()
127 ** 功能描述: 通过物理端点 1 发送数据 Function: send data by physical endpoint 1
128 ** 输 入: INT8U *pRomData: 发送数据指针 Inptut: INT8U * buf: send buffer
129 INT16U len: 发送数据长度 INT8U len: send data length(the value can above
130 EP0_PACKET_SIZE)
131 ** 输 出: 无 Output: NULL
132 *************************************************************************************************/
133 void code_transmit(INT8U * pRomData, INT16U len)
134 {
135 1 ControlData.wCount = 0;
136 1
137 1 if(ControlData.wLength > len)
138 1 ControlData.wLength = len; /* 长度要小于len the wLength can't above len */
139 1
140 1 ControlData.pData = pRomData;
141 1 if( ControlData.wLength >= EP0_PACKET_SIZE)
142 1 { /* wLength above MaxPacketSize of physical endpoint 1 */
143 2 USB_WriteEndpoint(1, EP0_PACKET_SIZE, ControlData.pData);
144 2 ControlData.wCount += EP0_PACKET_SIZE; /* 计数器累加 count number have been sent */
145 2
146 2 DISABLE();
147 2 bEPPflags.bits.control_state = USB_TRANSMIT; /* 标识发送状态 flag transmit state */
148 2 ENABLE();
149 2 }
150 1 else
151 1 {
152 2 USB_WriteEndpoint(1, ControlData.wLength, pRomData); /* 将全部数据写入端点 write all data into endpoi
-nt */
153 2 ControlData.wCount += ControlData.wLength; /* 计数器累加 count number have been sent */
154 2 DISABLE();
155 2 bEPPflags.bits.control_state = USB_IDLE; /* 标识空闲状态 flag IDLE state */
156 2 ENABLE();
157 2 }
158 1 }
159
160
161
162 //*************************************************************************
163 // USB 标准设备请求服务程序 USB standard device request service program
164 //*************************************************************************
165
166
167 /********************************************************************************************************
-*******
168 ** 函数名称: get_status() Name: get_status()
169 ** 功能描述: 主机要求获取状态,设备返回16位的 Function: the USB host request get the status of USB device
-,
170 状态描述符给主机 USB device will response 16-bit descriptor
171 *********************************************************************************************************
-*******/
172 void get_status(void)
173 {
174 1 INT8U endp, txdat[2], c;
175 1 INT8U bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
176 1 /* 获取请求类型 get the Request type */
177 1 if (bRecipient == USB_RECIPIENT_DEVICE)
178 1 { /* request device */
179 2 if(bEPPflags.bits.remote_wakeup == 1)
180 2 txdat[0] = 3; /* 支持远程唤醒和自供电 support reamote wakeup and power itself */
181 2 else
182 2 txdat[0] = 1; /* 不支持以上两个功能 not support two function above */
183 2 txdat[1]=0; /* 高 8 位清 0 upper 8-bit clear */
184 2 single_transmit(txdat, 2); /* 发送16ibt到USB主机 transmit 16-bit to USB host */
185 2 }
186 1
ARM COMPILER V2.53, Chap_9 28/06/07 09:54:11 PAGE 4
187 1 else if (bRecipient == USB_RECIPIENT_INTERFACE)
188 1 { /* request interface */
189 2 txdat[0]=0;
190 2 txdat[1]=0;
191 2 single_transmit(txdat, 2); /* 发送16ibt到USB主机 transmit 16-bit to USB host */
192 2 }
193 1
194 1 else if (bRecipient == USB_RECIPIENT_ENDPOINT)
195 1 { /* request endpoint */
196 2 endp = (INT8U)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
197 2 if (ControlData.DeviceRequest.wIndex & (INT8U)USB_ENDPOINT_DIRECTION_MASK)
198 2 //判断接收到的get_status中的wIndex的Bit7(索引位7)
199 2 //Bit7标识了主机要求返回的端点的方向:
200 2 //为“1”时,返回输入(IN)端点的状态
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -