User manual

DSM tutorials
Step 4: Implement procedures for the device interface
Wrap communication with the Handel-C interfaces inside macro procedures. You should implement
macros that do simple device operations such as writing a value to an input to the device. If the device
uses some handshaking mechanism to input or output data you should also capture this inside the
macros.
Step 5: Implement the API to device interface translation
In cases where the API and the device interface are very similar this step may only require calling the
device interface macros directly from API. If the API functions require a complicated set of device
interface operations then your device driver may benefit from a client-server type design. In this you
capture all of your translation code in a server, and then implement your API as small clients to the
server. The benefit of this is that the amount of hardware you use for an instance of your device driver
does not increase each time you use API functions in an application.
To implement a device driver server use a non-terminating loop inside a macro procedure and then run
it in parallel with the application. The server can accept commands from its client API macros through a
shared variable or a Handel-C channel and then perform the corresponding device interface operations.
As well as reducing the hardware resources used by a device driver, this technique can be used to
provide arbitration between API functions, allowing only a single API function to run at one time. The
Flash memory device driver (see page 38) is an example of the client-server type device driver.
3.4.2 Example device drivers
The PSL Tutorial contains three example device drivers which can be used as a starting point for writing
your own drivers:
LED driver
Asynchronous RAM driver
Flash memory driver
The LED example gives an introduction to device Input/Output (I/O) from Handel-C. The Asynchronous
RAM example deals with timing issues and Handel-C. The Flash memory example shows how a device
driver can be implemented for use with more than one device.
Handel-C source code for the LED and RAM drivers is shown in the documentation. Source code for the
Flash memory driver is in the PSL Tutorial workspace. To open the workspace in DK select:
Start>Programs>Celoxica>Platform Developer's Kit>PSL>PSL Tutorial Workspace.
LED device driver
A device driver for an LED provides control of the LED state.
LED DEVICE DRIVER
First define a macro expression for the input to the LED.
static macro expr LedPin = {"P1"};
www.celoxica.com
Page 31