The Compact-Flash Wildcard and CF Card Software Package User Guide
<< Previous | Next>>
Using the Driver Code with C
Move the library.c and library.h files into the same directory as your other C source code files. After loading the install.txt file as described above, use the following directive in your source code file:
#include "library.c"
This file contains calling primitives that implement the functions in the kernel extension package. The library.c file automatically includes the library.h header file. If you have a project with multiple source code files, you should only include library.c once, but use the directive
#include "library.h"
in every additional source file that references the CF Card software functions.
To load the optional demonstration program described above, use the "make" icon of the C compiler to compile the file named
FileDemo.c
that is provided on the Demos and Drivers media. Use the terminal to send the resulting FileDemo.txt file to the Mosaic controller, and type main to run the program. See the demo source code listing below for more details.
Note that all of the functions in the kernel extension are of the _forth type. While they are fully callable from C, there are two important restrictions. First, _forth functions may not be called as part of a parameter list of another _forth function. Second, _forth functions may not be called from within an interrupt service routine unless the instructions found in the file named
\fabius\qedcode\forthirq.c
are followed. Also, in most cases file manipulation functions should not be called from within interrupt service routines. Interrupt service routines should be kept short so that the processor can efficiently respond to events, and file operations take a relatively long time. More importantly, in multitasking environments any function that calls the Get or Release functions from within an interrupt service routine can halt the multitasker. All of the file I/O functions that access the CF Card Get and Release the CF resource variable, so it is not wise to call them from within an interrupt service routine.
NOTE: If your compiler was purchased before June 2002, you must update the files named qlink.bat and qmlink.bat in your /fabius/bin directory on your installation before using the kernel extension.
The two new files should be placed in c:\Fabius\bin. This upgrade only has to be done once for a given installation of the C compiler.
After loading the install.txt file and typing COLD, use the terminal to send the "library.4th" file to the Mosaic controller. Library.4th sets up a reasonable memory map and then defines the constants, structures, and name headers used by the CF Wildcard kernel extension. Library.4th leaves the memory map in the download map.
After library.4th has been loaded, the board is ready to receive your high level source code files. At this point you may want to load the FileDemo.4th file that is provided on the demo media.
Be sure that your software doesn't initialize the memory management variables DP, VP, or NP, as this could cause memory conflicts. If you wish to change the memory map, edit the memory map commands at the top of the library.4th file itself. The definitions in library.4th share memory with your Forth code, and are therefore vulnerable to corruption due to a crash while testing. If you have problems after reloading your code, try typing COLD, and reload everything starting with library.4th. It is very unlikely that the kernel extension runtime code itself (install.txt) can become corrupted since it is stored in flash on a page that is not typically accessed by code downloads.
We recommend that your source code file begin with the sequence:
WHICH.MAP 0=
IFTRUE 4 PAGE.TO.RAM \ if in standard.map...
5 PAGE.TO.RAM
6 PAGE.TO.RAM
DOWNLOAD.MAP
ENDIFTRUE
This moves all pre-loaded flash contents to RAM if your Mosaic controller is in the standard (flash-based) memory map, and then establishes the download (RAM-based) memory map. At the end of this sequence the Mosaic controller is in the download map, ready to receive additional code.
We recommend that your source code file end with the sequence:
4 PAGE.TO.FLASH
5 PAGE.TO.FLASH
6 PAGE.TO.FLASH
STANDARD.MAP
SAVE
This copies all loaded code from RAM to flash, and sets up the standard (flash-based) memory map with code located in pages 4, 5 and 6. The SAVE command means that you can often recover from a crash and continue working by typing RESTORE as long as flash pages 4, 5 and 6 haven't been rewritten with any bad data.
<< Previous | Next>>
|