User manual
PAL tutorial
macro expr UsingButtons = PalSwitchCount () > 1;
macro expr UsingMouse = !UsingButtons && (PalPS2PortCount () > 0);
The first expression,
UsingButtons, is set to one if there are two or more buttons available on the
target board. If there are no buttons available, the code needs to check if there is a mouse available
instead: if the expression
UsingButtons evaluates to false and there is at least one PS2 port available,
then the macro expression
UsingMouse will evaluate to true.
Ensuring that at least one of the required devices is available
A compile-time assertion can be used to ensure that at least one of the supported devices is available on
the target platform.
For this application, either the buttons or a mouse needs to be available (one of
UsingButtons and
UsingMouse needs to be true). If they are not, then the compilation needs to fail gracefully with a clear
error message. This is done using an assert, as used for checking the availability of the video resource:
assert (UsingMouse || UsingButtons, 0, "Not enough buttons and no mouse");
Selecting the correct resource for the target platform
Handel-C offers compile-time selection of sections of code to compile, depending on evaluation of
constant expressions. This is done using the
ifselect keyword, which looks the same as the standard
if statement. The difference is that the condition in the brackets must be a compile-time constant and
the result is a choice of compilation rather than run-time execution.
ifselect (UsingButtons)
{
// run the button code
}
else
{
// run the mouse code
}
Note that the expression
UsingMouse() does not need to be tested here because the compilation will
have already failed due to the assert statement in Step 2 if there were neither buttons nor a mouse
available.
1.4.2 Run-time operations
Running PAL Cores
Part 2 of the tutorial uses a PAL Core resource. PAL Cores are utility cores that only use PAL resources,
and are therefore portable across PAL platforms.
PalMouse *MousePtr;
The core is connected to a PS/2 resource:
macro expr PS2Port = PalPS2PortCT (0);
PalMouseRun (&MousePtr, PS2Port, ClockRate);
The core now behaves in a similar way to a normal PAL resource, so it needs to be enabled to run in
parallel with the rest of the program before it can be used. For each PAL Core routine, a pointer to the
core needs to be passed in as the first argument.
www.celoxica.com
Page 11