User manual

Tutorial: Handel-C code optimization
7.3.2 Flash memory client-server example
The operation of flash memory is more complicated than asynchronous RAM. It is organized into blocks
of data. An entire block must be erased before any locations within it can be programmed.
This example is based on the Intel flash memory part 28F640J3A, which has a capacity of 64 Mbits,
organized as 64 blocks. You can obtain the data sheet for this part from http://developer.intel.com.
The 28F640J3A has an internal state machine that you must program to perform device operations. The
device has the following connections:
23 bit address bus (input)
16 bit data bus (bi-directional)
chip enable pins (input)
reset pin (input)
output enable pin (input)
write enable pin (input)
status pin (output)
byte enable pin (input)
The device can operate in 16 bit data or 8 bit data mode. You select the mode using the byte enable
input. In 16 bit mode the Least Significant Bit (LSB) of the address bus is discarded. This example uses
the device in 16 bit mode so the byte enable is deactivated by wiring high (it is active low) and only the 22
most significant bits of the address bus are used. Each block inside the flash device contains 128 Kb. In
16 bit mode the blocks are 64 Kwords long. Of the total 23 address bits, the block address is given by the
most significant 6 bits and the address within a block is given by the least significant 17 bits.
The API requires functions for reading, writing and erasing data from the Flash device. Although the
device also features operations for querying device identity and locking blocks of data (to prevent them
from being erased) these are not essential for the operation of the device.
This example implements the interface translation code that converts API functions into device
operations using a server process that runs in parallel with an application. The API functions act as
clients to the server. The server is implemented using a non-terminating loop inside a macro procedure.
The API functions and the server use shared variables and a channel to communicate. These are
collected together inside a structure and passed as a parameter to the API functions and the server.
Here are the prototypes for the read, write and erase API functions:
/*
* Read datum from specified Address in flash into (*DataPtr)
* Parameters: FlashPtr : input of type (Flash)*
* Address : input of type (unsigned 22)
* DataPtr : input of type (unsigned 16)*
*/
extern macro proc FlashReadWord (FlashPtr, Address, DataPtr);
/*
* Write a datum from Data into Flash at specified Address
* Parameters: FlashPtr : input of type (Flash)*
* Address : input of type (unsigned 22)
* Data : input of type (unsigned 16)
*/
extern macro proc FlashWriteWord (FlashPtr, Address, Data);
www.celoxica.com
Page 82