User manual

PAL tutorial
1.5 PAL Tutorial Part 3
The Part3 project in the PAL tutorial describes how to use an external RAM.
The RAM is initialized and run from the
main() function. The GenerateData() macro no longer
displays the square directly to the screen but draws the square into RAM. Every clock cycle during the
visible period of the scan, the display process reads pixels out of the RAM and displays them on the
screen.
1.5.1 Compile-time configuration
Choosing the type of RAM to use
There are three different types of RAM access available in the PAL API: multi-cycle, single-cycle and
pipelined. For this application, single-cycle access is sufficient. This is perhaps the simplest way to use
the RAM on a platform as it means that all reads and writes take a single clock cycle. The name for
single-cycle access in PAL is
PalFastRAM.
Checking the required RAM resource is available
A compile-time assertion is needed to check that the platform for which the code is being compiled has
the required RAM resource. This is done in the same way as for the video output resource:
PalFastRAMRequire (1);
Selecting the RAM resource to use
Some boards have many banks of RAM, so one of the available FastRAM resources needs to be
chosen. This application only needs the one RAM bank for the frame buffer, so the first bank is used:
macro expr FastRAM = PalFastRAMCT (0);
Checking that the RAM is the correct size
For this application, the frame-buffer will store 640*480 pixels with eight pixels packed into one 32-bit
word, which means that the RAM needs to have 640*480/8 32-bit entries. In order that compilation fails
gracefully on inappropriate platforms, the application needs to assert that the number of entries in the
RAM (which can be inferred from the width of the address bus) is equal to or greater than the number
required (which means a minimum of a 16-bit address bus):
assert (PalFastRAMGetAddressWidthCT (FastRAM) > 15, 0,
"Not enough entries in FastRAM resource");
The RAM resource also needs to have a data width of at least 32 bits. This is checked as follows:
assert (PalFastRAMGetDataWidthCT (FastRAM) > 31, 0,
"Data width less than 32-bit in FastRAM resource");
Extending this method further, it is possible to write an application that will build different frame-buffers
that will be automatically selected depending on the attributes of the RAM resources available on the
target platform.
1.5.2 Run-time operations
Running the RAM resource
The RAM resource needs to be run in the standard way for PAL resources: in parallel with the main body
of the code and the running of any other PAL resources.
www.celoxica.com
Page 12