📄 2_cypress usb starter kit device driver complete with source code.htm
字号:
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>Status</FONT></P></TD></TR>
<TR>
<TD vAlign=top width="19%"><FONT face=Arial size=1>
<P>Read RAM</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>-</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>-</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>Address</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>0x16</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>-</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>-</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>Value</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>Status</FONT></P></TD></TR>
<TR>
<TD vAlign=top width="19%"><FONT face=Arial size=1>
<P>Read RAM</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>-</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>Value</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>Address</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>0x17</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>-</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>-</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>-</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>Status</FONT></P></TD></TR>
<TR>
<TD vAlign=top width="19%"><FONT face=Arial size=1>
<P>Read ROM</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>-</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>Index</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>NA</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>0x18</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>-</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>-</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>Value</FONT></P></TD>
<TD vAlign=top width="10%"><FONT face=Arial size=1>
<P align=center>Status</FONT></P></TD></TR></TBODY></TABLE></CENTER>
<P></P>
<P>At first glance, you would expect the Cypress USB MCU to send the
temperature using an Interrupt transfer periodically. After all, the
Cypress USB MCU returns an Endpoint Descriptor for EP1 as type equals
Interrupt, Maximum Packet Size of 8 Bytes and an Interrupt Interval of
10mS. The String Descriptor for this Endpoint returns "Endpoint1 10ms
Interrupt Pipe". </P>
<P>At this stage you jump straight to the vector table. The 128us timer is
not used, the 1024us timer is, and the endpoint1 interrupt is not used.
The Interrupt Service Routine for the 1024us interrupt, simply checks for
activity, sets the suspend accordantly, helps with the button de-bounce.
Maybe the 10mS Temperature Interrupt is done in the main loop? </P>
<P>Jumping to the code for the main loop shows we wait for enumeration,
Set the Enumeration LED, Read Temperature, Update Brightness, and Set new
Brightness. Maybe it's in the Read Temperature Routine? The Read
Temperature Routine firstly initialises the results, reads the temperature
from the DS1620 and stores it in the FIFO for Endpoint 1. </P>
<P>So where is the code for the Interrupt Transfer? Good question, you
tell me? (Have I overlooked something?) </P>
<P>Now what if we were to implement a couple of functions. Maybe ReadRAM,
WriteRAM? We could then check the status of the switch by reading a value
in RAM. We could read the temperature, provided the temperature was stored
in a RAM Location. Umm, life would be easy. We could change the LED
Brightness if we write the brightness to a location and set the Update
Brightness Semaphore! </P>
<P>This is what I believe has been done. Please correct me if I'm
mistaken! </P>
<CENTER><IMG alt="Flow Chart of Endpoint 0"
src="Cypress USB Starter Kit Device Driver complete with Source Code_files/endpoint0.gif">
<BR><FONT size=-1>Figure 1 : Flow Chart of Endpoint1</FONT>
<P></P></CENTER>
<P><B>IOCTL Codes.</B> </P>
<P>The documentation for the Cypress kit would suggest there is only one
valid IO Control Code, IOCTL 4. All driver functions are called within
this IOCTL Code. This is certainly not recommended practice. Microsoft has
a macro called CTL_CODE which is defined in DEVIOCTL.H which is included
in the Device Driver Kit. </P><PRE>// Macro definition for defining IOCTL and FSCTL function control codes. Note
// that function codes 0-2047 are reserved for Microsoft Corporation, and
// 2048-4095 are reserved for customers.
//
#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
)
The two least significant bits (Method) map the buffer transfer type which
determines how the buffer is passed in IOCTL calls. We need to use Method
Buffered, thus both bits must be zero.
#define METHOD_BUFFERED 0
#define METHOD_IN_DIRECT 1
#define METHOD_OUT_DIRECT 2
#define METHOD_NEITHER 3
</PRE>
<P>The function defines which function we wish to call. The Kits has used
Function 1, thus generating an IOCTL code of 4. The Access Type is
FILE_ANY_ACCESS (0x00), and the Device Type is Zero. This is not defined
in DEVIOCTL.H and Microsoft has reserved Device Types of 0-32767. We
should probably be using something like <TT>FILE_DEVICE_UNKNOWN
0x00000022.</TT> Likewise Function Codes codes 0-2047 are reserved for
Microsoft Corporation, and 2048-4095 are reserved for customers. </P>
<P>On top of the IOCTL4, I have added extra IOCTL Calls to all the
descriptors, Get the Status, and Send custom URB_FUNCTION_VENDOR_ENDPOINT
Commands, should you wish to later add more Vendor Commands to the
firmware. </P><BR><FONT size=5>Download Source Code & Driver</FONT>
<HR>
<UL><BR>
<LI><A href="http://www.beyondlogic.org/usb/cypressdrv.zip">Download
CypressDrv.zip </A><FONT face=ARIAL>Source Code and Driver for Cypress
USB Starter Kit. Includes IOCTL MAP and PDF Documentation of IOCTL Calls
(42KB)</FONT><BR><BR>
<P>A special thanks must go to Burkhard Kainka who has found some bugs
in the driver and have corrected them for us. The last compiliation has
in fact done by Burkhard. </P>
<P>This driver is still very much in development. The Cypress USB
Starter Kit was loaned to me for a duration of time and I have since
given it back. As a result, I cannot test any additional modifications
or support this driver in any way.</P></LI></UL><BR><FONT face=Impact
size=5>Links</FONT>
<HR>
<UL><FONT face=ARIAL size=3>
<UL>
<TABLE>
<TBODY>
<TR>
<TD vAlign=top><FONT face=ARIAL size=3><A
href="http://tilp.sourceforge.net/tpulink-thermo-en.html">Linux
device driver for the Cypress Thermometer</A></FONT></TD>
<TD><FONT face=ARIAL size=3>Romain Li関in has developed a Linux
Device Driver for the Cypress Thermometer Kit.<FONT
size=+0></FONT></FONT></TD></TR>
<TR>
<TD vAlign=top><FONT face=ARIAL size=3><A
href="http://www.beyondlogic.org/dddtools/dddtools.htm">Device
Driver Fiddler</A></FONT></TD>
<TD><FONT face=ARIAL size=3>Writing Device Drivers? Perhaps
playing with Cypress Semiconductor's USB Starter Kit? If so, the
Device Driver Fiddler allows you to test DeviceIOCommand() Calls
before you write your User Mode Application. . . </FONT></TD></TR>
<TR>
<TD vAlign=top><FONT face=ARIAL size=3><A
href="http://www.usb.org/forums/developers/webboard.html">USB
Webboard</A></FONT></TD>
<TD><FONT face=ARIAL size=3>Ask for Help, or have you say with
the USB Webboard.</FONT></TD></TR>
<TR>
<TD vAlign=top><FONT face=ARIAL size=3><A
href="http://www.ibhdoran.com/usb_link.html">USB Designer
Links</A></FONT></TD>
<TD><FONT face=ARIAL size=3>Quite a comprehensive page of links
to manufacturers and products. Great starting point to see what
is out there. <FONT
size=+0></FONT></FONT></TD></TR></TBODY></TABLE></UL></UL></FONT></TD></TR></TBODY></TABLE><BR><BR><FONT
size=2>Copyright 1999-2001 <A href="mailto:Craig.Peacock@beyondlogic.org">Craig
Peacock</A> 19th August 2001.</FONT> <BR><BR></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -