User manual

DSM tutorials
macro proc FlashWriteWord (FlashPtr, Address, Data)
{
par
{
FlashPtr->APICommand ! FlashAPICommandWriteWord;
FlashPtr->APIAddress = Address;
FlashPtr->APIData = Data;
}
}
macro proc FlashEraseBlock (FlashPtr, BlockNumber)
{
par
{
FlashPtr->APICommand ! FlashAPICommandEraseBlock;
FlashPtr->APIBlockNumber = BlockNumber;
}
}
When the flash device driver is used, the application programmer must:
Declare a variable of type
(Flash *)
Call
FlashInit() with appropriate parameters to build interfaces to the correct pins and
to create and initialize a
Flash structure.
Run the
FlashRun() server process in parallel with the application
Alternatively, you can encapsulate drivers inside a PSL that is configured for a specific platform.
3.4.3 Encapsulating drivers in a PSL
A PSL is a collection of device drivers compiled into a Handel-C library. If you have written generic
device drivers, a PSL should encapsulate these and present an API for exactly the devices present on
the board.
In the following example PSL, a macro
PSLFlashRun()is defined which calls the FlashInit()
macro to construct interfaces for a particular platform, and then calls the
FlashRun() macro to run a
driver for that particular interface. This has the added benefit of creating the interfaces for the flash
device only when the device driver is actually used in an application. Putting the interfaces in the global
scope as shown in the earlier examples instructs the DK compiler to build those interfaces even if they
are not used in the application.
The macro
PSLFlashRun() exports an initialized interface to the driver via a global FlashPtr
variable. This is declared as
static so that it cannot be seen by the application programmer. The same
is done for platform specific pin definitions:
www.celoxica.com
Page 43