📄 binding3.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> Writing Socket Component Drivers and MTDs </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a></a><a href="binding.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="binding2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="binding4.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="97797">3.3 Writing a Socket Component Driver</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="91911"> </a>At start up, TrueFFS for Tornado creates a socket component driver for each flash device you want to support on your BSP. As shown in <a href="binding1.html#92117">Figure 3-1</a>, a call to <b class="routine"><i class="routine">tffsDrv</i></b><b>( )</b> eventually results in a call to <b class="routine"><i class="routine">sysTffsInit</i></b><b>( )</b>. This routine must do all that is necessary to register a socket component driver for each flash device attached to your embedded system. </p><dd><p class="Body"><a name="101476"> </a>For the most part, this means appropriating an <b class="symbol_lc">FLSocket</b> structure (previously allocated internally to TrueFFS for Tornado) and installing pointers to functions in your socket component driver. The details of how you handle this are up to you. Strictly speaking, there is no organization imposed on the internals of <b class="routine"><i class="routine">sysTffsInit</i></b><b>( )</b>. However, to allow for scalability, the details specific to each flash device are typically isolated to <i class="textVariable">xxx</i><b class="routine"><i class="routine">Register</i></b><b>( )</b> functions, one for each flash device on your system. </p><dd><p class="Body"><a name="101477"> </a>Finally, your socket component driver must provide two global functions: <b class="routine"><i class="routine">flFitInSocketWindow</i></b><b>( )</b> and <b class="routine"><i class="routine">flDelayLoop</i></b><b>( )</b>. These functions are global in the sense that they must be externally callable (and thus must not be declared as <b class="symbol_UC">LOCAL</b> or any other equivalent to <b class="symbol_lc">static</b>). </p><dd><p class="Body"><a name="101480"> </a>The <b class="routine"><i class="routine">flFitInSocketWindow</i></b><b>( )</b>routine returns the size (in bytes) of an individual chip in the flash array. TrueFFS uses this value to determine whether its socket window is big enough. The <b class="routine"><i class="routine">flDelayLoop</i></b><b>( )</b>routine gives TrueFFS a hardware-appropriate way to wait for a specific number of milliseconds. </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="87816">3.3.1 Writing a <b class="routine"><i class="routine">sysTffsInit</i></b><b>( )</b> Routine </a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="88278"> </a>The <b class="routine"><i class="routine">sysTffsInit</i></b><b>( )</b>function takes no arguments and returns void. Internally, it must, at a minimum, call the socket registration routine for each flash device you want registered. For an example of the simplest possible <b class="routine"><i class="routine">sysTffsInit</i></b><b>( )</b>, consider the <b class="routine"><i class="routine">sysTffsInit</i></b><b>( )</b>defined in the <b class="file">sysTffs.c</b> for the <b class="file">mv177</b> BSP: </p><dl class="margin"><dd><pre class="Code2"><b><a name="91561">LOCAL void sysTffsInit (void) { rfaRegister (); }</a></b></pre></dl><dd><p class="Body"><a name="91557"> </a>This BSP supports only one flash device. Thus, its <b class="routine"><i class="routine">sysTffsInit</i></b><b>( )</b> contains only a call to <b class="routine"><i class="routine">rfaRegister</i></b><b>( )</b>, a registration routine for a resident flash array, an on-board non-removable flash device. Other BSPs define slightly more complicated <b class="routine"><i class="routine">sysTffsInit</i></b><b>( )</b> routines. For example, the <b class="routine"><i class="routine">sysTffsInit</i></b><b>( )</b> routine in the pc486 BSP makes three <i class="textVariable">xxx</i><b class="routine"><i class="routine">Register</i></b><b>( )</b> calls:</p><dl class="margin"><dd><pre class="Code2"><b><a name="91682">#ifdef INCLUDE_SOCKET_DOC (void) docRegister (); /* Disk On Chip */ #endif /* INCLUDE_SOCKET_DOC */ #ifdef INCLUDE_SOCKET_PCIC0 (void) pcRegister (0, PC_BASE_ADRS_0); /* flash card on socket 0 */ #endif /* INCLUDE_SOCKET_PCIC0 */ #ifdef INCLUDE_SOCKET_PCIC1 (void) pcRegister (1, PC_BASE_ADRS_1); /* flash card on socket 1 */ #endif /* INCLUDE_SOCKET_PCIC1 */ </a></b></pre></dl><dd><p class="Body"><a name="91755"> </a>Note that each <i class="textVariable">xxx</i><b class="routine"><i class="routine">Register</i></b><b>( )</b> call is encapsulated in pre-processor conditional statements. The constants that control these statements are defined in the BSP's <b class="file">config.h</b>. Using these constants, you can selectively control which calls are included in <b class="routine"><i class="routine">sysTffsInit</i></b><b>( )</b> at compile time. </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="91758">3.3.2 Writing an <i class="textVariable">xxx</i><b class="routine"><i class="routine">Register</i></b><b>( )</b> Routine</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="92007"> </a>Internally, TrueFFS allocates an array of <b class="symbol_lc">FLSocket</b> structures. TrueFFS uses these structures to find the socket component driver functions (and other information) that it needs to interact with the flash hardware. Within your <i class="textVariable">xxx</i><b class="routine"><i class="routine">Register</i></b><b>( )</b>routine, you must appropriate one of these <b class="symbol_lc">FLSocket</b> structures and initialize its members appropriately. To appropriate an <b class="symbol_lc">FLSocket</b> structure from TrueFFS, call <b class="routine"><i class="routine">flSocketOf</i></b><b>( )</b>: </p><dl class="margin"><dd><pre class="Code2"><b><a name="95982">FLSocket *flSocketOf(unsigned volNo)</a></b></pre></dl><dd><p class="Body"><a name="95978"> </a>As input, this function expects a drive number (valid values range from 0 to 4, inclusive). Upon completion, this function returns a pointer to an <b class="symbol_lc">FLSocket</b> structure as its value. Consider the following code fragment: </p><dl class="margin"><dd><pre class="Code2"><b><a name="96016">FLSocket vol = flSocketOf (noOfDrives); if (noOfDrives >= DRIVES) return (flTooManyComponents); tffsSocket[noOfDrives] = "RFA"; noOfDrives++;</a></b></pre></dl><dd><p class="Body"><a name="96021"> </a>Both <b class="symbol_lc">noOfDrives</b> and <b class="symbol_lc">tffsSocket[ ] </b>are global. <b class="symbol_UC">DRIVES</b> is a symbolic constant set to the maximum number of drivers (currently 5, do not attempt to change this value). In your call to <b class="routine"><i class="routine">flSocketOf</i></b><b>( )</b>, you must use <b class="symbol_lc">noOfDrives</b> the global variable for the <b class="symbol_lc">volNo</b> parameter, and you must update it after successfully appropriating an <b class="symbol_lc">FLSocket</b> structure. This global variable is used internally by TrueFFS for Tornado to keep count of the flash memory logical devices it has created. </p><dd><p class="Body"><a name="101876"> </a>Likewise, you should update the <b class="symbol_lc">noOfDrives</b> element of the <b class="symbol_lc">tffsSocket[ ] </b>global array to contain a label for the drive you just created (this label is used in the output from the <b class="routine"><i class="routine">tffsShow</i></b><b>( )</b> and <b class="routine"><i class="routine">tffsShowAll</i></b><b>( )</b> routines). </p><dd><p class="Body"><a name="92009"> </a>After retrieving this <b class="symbol_lc">FLSocket</b> pointer, your <i class="textVariable">xxx</i><b class="routine"><i class="routine">Register</i></b><b>( )</b>routine must set the values of the following members:</p></dl><dl class="margin"><dd><div class="Item"><a name="93630"> </a><b class="symbol_lc">window.baseAddress <br></b></div><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent5"><a name="93786"> </a>See <a href="binding2.html#86717"><i class="title">window.baseAddress</i></a>. </div><br></dl></dl></dl></dl></dl><dd><div class="Item"><a name="93635"> </a><b class="symbol_lc">cardDetected</b></div><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent5"><a name="93636"> </a>See <a href="binding2.html#95066"><i class="title">cardDetected</i></a>. </div><br></dl></dl></dl></dl></dl><dd><div class="Item"><a name="94616"> </a><b class="symbol_lc">VccOn</b> </div><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent5"><a name="93808"> </a>See <a href="binding2.html#93652"><i class="title">VccOn</i></a>. </div><br></dl></dl></dl></dl></dl><dd><div class="Item"><a name="93681"> </a><b class="symbol_lc">VccOff</b> </div><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent5"><a name="93684"> </a>See <a href="binding2.html#93655"><i class="title">VccOff</i></a>. </div><br></dl></dl></dl></dl></dl><dd><div class="Item"><a name="93685"> </a><b class="symbol_lc">VppOn</b> </div><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent5"><a name="93686"> </a>See <a href="binding2.html#93659"><i class="title">VppOn</i></a>. </div><br></dl></dl></dl></dl></dl><dd><div class="Item"><a name="93687"> </a><b class="symbol_lc">VppOff</b> </div><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dl class="margin"><dd><div class="Indent5"><a name="93688"> </a>See <a href="binding2.html#94712"><i class="title">VppOff</i></a>. </div><br></dl></dl>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -