📄 usb_task.lst
字号:
C51 COMPILER V6.20c USB_TASK 07/10/2002 15:17:42 PAGE 1
C51 COMPILER V6.20c, COMPILATION OF MODULE USB_TASK
OBJECT MODULE PLACED IN ..\obj\usb_task.obj
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE ..\src\mass\usb_task.c BROWSE INCDIR(..\src\system;..\..\..\lib) DEFINE(KEI
-L) DEBUG OBJECTEXTEND PRINT(.\usb_task.lst) OBJECT(..\obj\usb_task.obj)
stmt level source
1 /*C**************************************************************************
2 * $RCSfile: usb_task.c,v $
3 *----------------------------------------------------------------------------
4 * Copyright (c) 2002 Atmel.
5 *----------------------------------------------------------------------------
6 * RELEASE: $Name: DEMO_FAT_1_2_5 $
7 * REVISION: $Revision: 1.6 $
8 * FILE_CVSID: $Id: usb_task.c,v 1.6 2002/06/07 15:45:23 ffosse Exp $
9 *----------------------------------------------------------------------------
10 * PURPOSE:
11 * This file contains the USB task and attached routines
12 *****************************************************************************/
13
14 /*_____ I N C L U D E S ____________________________________________________*/
15
16 #include "config.h" /* system configuration */
17 #include "..\lib\usb\usb_drv.h" /* usb driver definition */
18 #include "..\clock\clock.h" /* clock definition */
19 #include "..\display\disp.h" /* display definition */
20 #include "..\mode\mode_task.h" /* mode task definition */
21 #include "..\mem\hard.h" /* low level function definition */
22 #include "sbc.h" /* SBC commands definition */
23 #include "usb_task.h" /* usb task definition */
24
25
26 /*_____ M A C R O S ________________________________________________________*/
27
28
29 /*_____ D E F I N I T I O N ________________________________________________*/
30
31 static bdata bit disconnected;
32 static idata Byte dCBWTag[4];
33
34 static bdata bit no_data_phase;
35
36 static bdata bit ms_multiple_drive; /* TRUE: multiple drive support */
37
38 static data Byte usb_resume_counter;
39
40 bdata bit bmCBWFlag7; /* Data OUT (0) or Data In (1) */
41 bdata bit status_ready;
42 data Byte status;
43 data Uint32 dCBWDataTransferLength; /* usb data message length */
44
45
46 /*_____ D E C L A R A T I O N ______________________________________________*/
47
48 static void usb_mass_storage_cbw (void);
49 static void usb_mass_storage_csw (void);
50
51
52 /*F**************************************************************************
53 * NAME: usb_task_init
54 *----------------------------------------------------------------------------
C51 COMPILER V6.20c USB_TASK 07/10/2002 15:17:42 PAGE 2
55 * PARAMS:
56 *
57 * return:
58 *----------------------------------------------------------------------------
59 * PURPOSE:
60 * USB task initialization
61 *----------------------------------------------------------------------------
62 * EXAMPLE:
63 *----------------------------------------------------------------------------
64 * NOTE:
65 *----------------------------------------------------------------------------
66 * REQUIREMENTS:
67 *****************************************************************************/
68 void usb_task_init (void)
69 {
70 1 disconnected = 0;
71 1 clock_usb_init(); /* for suspend detection */
72 1 usb_init();
73 1 }
74
75
76 /*F**************************************************************************
77 * NAME: usb_task
78 *----------------------------------------------------------------------------
79 * PARAMS:
80 *
81 * return:
82 *----------------------------------------------------------------------------
83 * PURPOSE:
84 * USB task
85 *----------------------------------------------------------------------------
86 * EXAMPLE:
87 *----------------------------------------------------------------------------
88 * NOTE:
89 * In order to avoid spurious connection, resume is done after the resume
90 * event has been detected at least #USB_WAIT_NB_RESUME times.
91 *----------------------------------------------------------------------------
92 * REQUIREMENTS:
93 *****************************************************************************/
94 void usb_task (void)
95 {
96 1 if (Usb_suspend()) /* -- if suspend flag -- */
97 1 {
98 2 if (disconnected == 0)
99 2 {
100 3 disconnected = 1;
101 3 clock_disable();
102 3 mode_exit_download();
103 3 usb_resume_counter = USB_WAIT_NB_RESUME;
104 3 }
105 2
106 2 if (Usb_resume()) /* check if resume */
107 2 {
108 3 if (usb_resume_counter == 0)
109 3 {
110 4 mode_set_download();
111 4 clock_usb_init();
112 4 print_mode_mass(); /* display mass storage icon */
113 4 print_screen(MASS_SCREEN); /* display storage screen */
114 4 disconnected = 0;
115 4 Usb_clear_SPINT();
116 4 Usb_clear_WUPCPU();
C51 COMPILER V6.20c USB_TASK 07/10/2002 15:17:42 PAGE 3
117 4 Usb_clear_SOFINT();
118 4 }
119 3 else
120 3 {
121 4 Usb_clear_WUPCPU();
122 4 Usb_clear_SOFINT();
123 4 usb_resume_counter--;
124 4 }
125 3 }
126 2 }
127 1 else
128 1 {
129 2 if (Usb_reset()) /* if end of reset */
130 2 {
131 3 disconnected = 0;
132 3 Usb_clear_WUPCPU();
133 3 Usb_clear_SPINT();
134 3 Usb_clear_EORINT();
135 3 ms_multiple_drive = FALSE; /* multiple disk support init */
136 3 sbc_mmc_init(); /* MMC SCSI driver init */
137 3 sbc_df_init(); /* DF SCSI driver init */
138 3 }
139 2
140 2 if (UEPINT != 0) /* new command */
141 2 {
142 3 Usb_select_ep(EP_CONTROL);
143 3 if (Usb_setup_received())
144 3 {
145 4 usb_enumeration_process();
146 4 }
147 3 Usb_select_ep(EP_OUT);
148 3 if (Usb_rx_complete())
149 3 {
150 4 usb_mass_storage_cbw();
151 4 usb_mass_storage_csw();
152 4 }
153 3 }
154 2 }
155 1 }
156
157
158 /*F**************************************************************************
159 * NAME: usb_mass_storage_cbw
160 *----------------------------------------------------------------------------
161 * PARAMS:
162 *
163 * return:
164 *----------------------------------------------------------------------------
165 * PURPOSE:
166 * Command Block Wrapper management
167 *----------------------------------------------------------------------------
168 * EXAMPLE:
169 *----------------------------------------------------------------------------
170 * NOTE:
171 *----------------------------------------------------------------------------
172 * REQUIREMENTS:
173 *****************************************************************************/
174 void usb_mass_storage_cbw (void)
175 {
176 1 bit cbw_error;
177 1
178 1 cbw_error = FALSE;
C51 COMPILER V6.20c USB_TASK 07/10/2002 15:17:42 PAGE 4
179 1 Usb_select_ep(EP_OUT);
180 1 if (0x55 != Usb_read_byte())
181 1 {
182 2 cbw_error = TRUE;
183 2 }
184 1 if (0x53 != Usb_read_byte())
185 1 {
186 2 cbw_error = TRUE;
187 2 }
188 1 if (0x42 != Usb_read_byte())
189 1 {
190 2 cbw_error = TRUE;
191 2 }
192 1 if (0x43 != Usb_read_byte()) /* check if dCBWSignature is correct */
193 1 {
194 2 cbw_error = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -