Cypress USB教程第5讲
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Diagnose the problem Add an ISR for USB Reset Demonstration (suspend2.c)
static void URES_ISR (void) interrupt 04 // '04' is USB bus reset interrupt number { EZUSB_IRQ_CLEAR(); // Always clear INT2 flag first USBIRQ = bmURES; // ...then clear SUSPEND IRQ by writing "1" to IRQ bit display_hex(0xB6); // 3 horiz segments only }
5-10
A solution
Re-arm IN2 whenever there‟s a USB reset
This preserves the data already loaded into the IN endpoint buffer Demonstration
static void URES_ISR (void) interrupt 04 // '04' is USB bus reset interrupt number { EZUSB_IRQ_CLEAR(); // Always clear INT2 flag first USBIRQ = bmURES; // ...then clear SUSPEND IRQ by writing "1" to IRQ bit display_hex(0xB6); // 3 horiz segments only IN2BC=1; // re-arm our IN endpoint }
Get_Descriptor: Device Get_Descriptor: Interface Get_Descriptor: String
5-1
Suspend/Resume
5-2
Suspend-Resume Mechanism (TRM Ch.11)
12 MHz
WAKEUP pin USB RESUME
5-9
What‟s Happening
USB bus reset un-arms all IN endpoints
TRM
page 10-6, Section 10.5:
“After a USB bus reset, the EZ-USB core „unarms‟ all Bulk IN endpoints. Data loaded by the 8051 into an IN endpoint buffer remains there, and the 8051 firmware can either re-send it by loading the endpoint byte count register to re-arm the transfer, or send new data by reloading the IN buffer before re-arming the endpoint.”
USB "SUSPEND" Interrupt
static void Suspend_ISR (void) interrupt 03 5-3
„SuEUP pin USB RESUME
ST ART ST OP
Oscillator
PLL 48 MHz div by 2 CLK24 PCON.0 "RESUME" INT 8051 Signal Resume (USBCS.0)
Set Report, Get Report
You need the spec, and the HID Usage Tables
5-18
Full Spec at
HID
The HID descriptor is in the Interface descriptor, not the Device descriptor
Help/Contents and Tutorial, and Help/Control Panel User Guide
5-16
HID Part 1
5-17
HID Class
Built into Windows 98 (or later) No need to write a driver! Mostly used by mice, keyboards Communicates with devices using reports
3bits5bitshidtools?hiddescriptortool?freeutilityonwwwusborg?helpscreatereportdescriptors?checksforerrors522?checksforerrors?hidview?partofusbcheck?alsoonwwwusborg?testsforusbcomplianceenumerationcode523enumerationlite?startwritingourownenumerationcode?projectssofarhaveusedthepreenumeratedchip?alldescriptorsforthepreenumeratedchiparehardwiredinthesieanddocumentedinthetrm?ezusbhasarenumbitusbcs07fd6bit1524?usbcs0x7fd6bit1?renum0whenthechipcomesoutofreset?intelligentsiehandlesallhostchapter9requests?8051codehandlesdatatransfers?weusedthisfeatureinbulkinandbulkoutassignments?the8051cansetrenum1tohandlecontrolrequestsincode
5-5
„Resume‟
12 MHz
WAKEUP pin USB RESUME
ST ART ST OP
Oscillator
PLL 48 MHz div by 2
Restart Delay
8051 Interrupt 6 (vector 0x33)
PCON.0 "RESUME" INT 8051
CLK24
This table is built from compile of your code (w. includes)
Set WatchPoints
5-14
Watch window updates when code execution stops
5-15
Where to find tools help
5-11
Final Suspend/Resume Note
No apparent consistency from PC to PC in handling suspend
Most variation seen in laptops How (and if) they suspend How (and if) they resume KILLER: Some turn off Vbus during suspend
Restart Delay
8051 does power-saving housekeeping, then sets PCON.0 to turn off oscillator.
No USB activity for 3 msec.
USB "SUSPEND" Interrupt
5-4
„Suspend‟ Code
C:\Cypress\USB\uV2_4k\keil\C51\HLP
A51.pdf is Assembler Reference Manual C51.pdf is C Compiler Reference Manual
C:\Cypress\USB\Doc\Keil Doc EZ-USB Control Panel
Lecture 5 Agenda
Suspend/Resume
How it works How to code it A Gotcha Keil Debug tip—the Watch window
HID Introduction Enumeration code
Start safely Use control panel to test:
suspend.c int2jmp.a51 wuisr.c
5-8
Suspend/Resume Issue
There is a problem with suspend.c
After „resume‟, the next IN-2 request hangs Demonstration
Allows different interfaces to use HID differently (e.g. for different controls)
Class code (in interface descriptor) bInterfaceClass = 3 for HID Report Descriptors
VERY hard to execute „resume‟ code if we are bus-powered and the power goes away…
5-12
Keil Debug Tip
5-13
Keil Debugging Tip
Using the Watch Window
Display all symbols
}
Note: this code MUST be placed in a different module than ‘suspend.c’ code, because ‘suspend.c’ overrides the normal 8051 interrupt vectors with it’s directive: #pragma intvector (0x17FD)
5-7
„Resume‟ Code
Complete example in „suspend.c‟ sofint.c with enhancements: Updates digit count rate from EP2OUT Adds suspend/resume code Three code modules
(Initialization in „main()‟: USBIEN = bmSOF | bmSUSP; EICON |= 0x20; // Enable SOF & --- Suspend interrupts // *** Enable Resume Interrupt // '03' is SUSPEND interrupt number
USB "SUSPEND" Interrupt
5-6
„Resume‟ Code
// wuisr.c sbit WAKEUP = 0xD8 ^ 4; // declare the SFR bit address for Wakeup (EICON.4) static void wakeup (void) interrupt 6 // vector addr 33h=51=(6*8)+3 { WAKEUP = 0; // just clear the interrupt request bit
ST ART ST OP
Oscillator
PLL 48 MHz div by 2 CLK24 PCON.0 "RESUME" INT 8051 Signal Resume (USBCS.0)
Restart Delay
8051 receives „suspend‟ interrupt
No USB activity for 3 msec.
Usage tells what a control is actually measuring
Also what should be done with the data
Example: x, y, z input
Report describes the data format
Example: three 8-bit fields
Signal Resume (USBCS.0)
Oscillator restarts, and 8051 receives interrupt 6, from one of two sources: USB bus activity or WAKEUP pin going LOW.
No USB activity for 3 msec.
static void Suspend_ISR (void) interrupt 03
{
EZUSB_IRQ_CLEAR(); USBIRQ = bmSUSP; display_hex(0x7F); PCON |= 1; } // Always clear INT2 flag first // ...then clear SUSPEND IRQ by writing "1" to IRQ bit // decimal point only // set bit zero only: zzzzzzzzzzzzzzzzz
static void URES_ISR (void) interrupt 04 // '04' is USB bus reset interrupt number { EZUSB_IRQ_CLEAR(); // Always clear INT2 flag first USBIRQ = bmURES; // ...then clear SUSPEND IRQ by writing "1" to IRQ bit display_hex(0xB6); // 3 horiz segments only }
5-10
A solution
Re-arm IN2 whenever there‟s a USB reset
This preserves the data already loaded into the IN endpoint buffer Demonstration
static void URES_ISR (void) interrupt 04 // '04' is USB bus reset interrupt number { EZUSB_IRQ_CLEAR(); // Always clear INT2 flag first USBIRQ = bmURES; // ...then clear SUSPEND IRQ by writing "1" to IRQ bit display_hex(0xB6); // 3 horiz segments only IN2BC=1; // re-arm our IN endpoint }
Get_Descriptor: Device Get_Descriptor: Interface Get_Descriptor: String
5-1
Suspend/Resume
5-2
Suspend-Resume Mechanism (TRM Ch.11)
12 MHz
WAKEUP pin USB RESUME
5-9
What‟s Happening
USB bus reset un-arms all IN endpoints
TRM
page 10-6, Section 10.5:
“After a USB bus reset, the EZ-USB core „unarms‟ all Bulk IN endpoints. Data loaded by the 8051 into an IN endpoint buffer remains there, and the 8051 firmware can either re-send it by loading the endpoint byte count register to re-arm the transfer, or send new data by reloading the IN buffer before re-arming the endpoint.”
USB "SUSPEND" Interrupt
static void Suspend_ISR (void) interrupt 03 5-3
„SuEUP pin USB RESUME
ST ART ST OP
Oscillator
PLL 48 MHz div by 2 CLK24 PCON.0 "RESUME" INT 8051 Signal Resume (USBCS.0)
Set Report, Get Report
You need the spec, and the HID Usage Tables
5-18
Full Spec at
HID
The HID descriptor is in the Interface descriptor, not the Device descriptor
Help/Contents and Tutorial, and Help/Control Panel User Guide
5-16
HID Part 1
5-17
HID Class
Built into Windows 98 (or later) No need to write a driver! Mostly used by mice, keyboards Communicates with devices using reports
3bits5bitshidtools?hiddescriptortool?freeutilityonwwwusborg?helpscreatereportdescriptors?checksforerrors522?checksforerrors?hidview?partofusbcheck?alsoonwwwusborg?testsforusbcomplianceenumerationcode523enumerationlite?startwritingourownenumerationcode?projectssofarhaveusedthepreenumeratedchip?alldescriptorsforthepreenumeratedchiparehardwiredinthesieanddocumentedinthetrm?ezusbhasarenumbitusbcs07fd6bit1524?usbcs0x7fd6bit1?renum0whenthechipcomesoutofreset?intelligentsiehandlesallhostchapter9requests?8051codehandlesdatatransfers?weusedthisfeatureinbulkinandbulkoutassignments?the8051cansetrenum1tohandlecontrolrequestsincode
5-5
„Resume‟
12 MHz
WAKEUP pin USB RESUME
ST ART ST OP
Oscillator
PLL 48 MHz div by 2
Restart Delay
8051 Interrupt 6 (vector 0x33)
PCON.0 "RESUME" INT 8051
CLK24
This table is built from compile of your code (w. includes)
Set WatchPoints
5-14
Watch window updates when code execution stops
5-15
Where to find tools help
5-11
Final Suspend/Resume Note
No apparent consistency from PC to PC in handling suspend
Most variation seen in laptops How (and if) they suspend How (and if) they resume KILLER: Some turn off Vbus during suspend
Restart Delay
8051 does power-saving housekeeping, then sets PCON.0 to turn off oscillator.
No USB activity for 3 msec.
USB "SUSPEND" Interrupt
5-4
„Suspend‟ Code
C:\Cypress\USB\uV2_4k\keil\C51\HLP
A51.pdf is Assembler Reference Manual C51.pdf is C Compiler Reference Manual
C:\Cypress\USB\Doc\Keil Doc EZ-USB Control Panel
Lecture 5 Agenda
Suspend/Resume
How it works How to code it A Gotcha Keil Debug tip—the Watch window
HID Introduction Enumeration code
Start safely Use control panel to test:
suspend.c int2jmp.a51 wuisr.c
5-8
Suspend/Resume Issue
There is a problem with suspend.c
After „resume‟, the next IN-2 request hangs Demonstration
Allows different interfaces to use HID differently (e.g. for different controls)
Class code (in interface descriptor) bInterfaceClass = 3 for HID Report Descriptors
VERY hard to execute „resume‟ code if we are bus-powered and the power goes away…
5-12
Keil Debug Tip
5-13
Keil Debugging Tip
Using the Watch Window
Display all symbols
}
Note: this code MUST be placed in a different module than ‘suspend.c’ code, because ‘suspend.c’ overrides the normal 8051 interrupt vectors with it’s directive: #pragma intvector (0x17FD)
5-7
„Resume‟ Code
Complete example in „suspend.c‟ sofint.c with enhancements: Updates digit count rate from EP2OUT Adds suspend/resume code Three code modules
(Initialization in „main()‟: USBIEN = bmSOF | bmSUSP; EICON |= 0x20; // Enable SOF & --- Suspend interrupts // *** Enable Resume Interrupt // '03' is SUSPEND interrupt number
USB "SUSPEND" Interrupt
5-6
„Resume‟ Code
// wuisr.c sbit WAKEUP = 0xD8 ^ 4; // declare the SFR bit address for Wakeup (EICON.4) static void wakeup (void) interrupt 6 // vector addr 33h=51=(6*8)+3 { WAKEUP = 0; // just clear the interrupt request bit
ST ART ST OP
Oscillator
PLL 48 MHz div by 2 CLK24 PCON.0 "RESUME" INT 8051 Signal Resume (USBCS.0)
Restart Delay
8051 receives „suspend‟ interrupt
No USB activity for 3 msec.
Usage tells what a control is actually measuring
Also what should be done with the data
Example: x, y, z input
Report describes the data format
Example: three 8-bit fields
Signal Resume (USBCS.0)
Oscillator restarts, and 8051 receives interrupt 6, from one of two sources: USB bus activity or WAKEUP pin going LOW.
No USB activity for 3 msec.
static void Suspend_ISR (void) interrupt 03
{
EZUSB_IRQ_CLEAR(); USBIRQ = bmSUSP; display_hex(0x7F); PCON |= 1; } // Always clear INT2 flag first // ...then clear SUSPEND IRQ by writing "1" to IRQ bit // decimal point only // set bit zero only: zzzzzzzzzzzzzzzzz