When working with IOTester® it is convenient to be able to swap the same C source modules between
use on the PC platform and use on the target processor platform.
The I/O driver code for external I/O peripheral devices are assumed to be written so they are fully portable
across platforms by use of the syntax for I/O register access defined in <iohw.h>.
For such C modules there is no problem.
It is simply assumed that for each target platform there exist an <iohw.h> header, and a
header with definition of I/O registers and addresses (ex. <ioregisters.h>).
Typically these header files will be located in separate directories.
Selection of which header set to include (i.e. which platform to compile for) may therefore be
done (automatically) via the compilers include file path settings.
No machine code is generated when IOTester specific functions iot_xxx(..) are compiled with a target compiler.
This further facilitates swapping between PC mode compilation and target mode compilation.
What remains, in order to make swapping between platforms as easy as possible, is a way to handle
those cases were (part of) the target system functionality, for instance,
is emulated by use of internal IOTester devices and functionality.
Such cases are often most easily handled by use of conditional compilation.
Conditional compilation
When IOTester is used with PC compilers the switch IOTESTER_USB is globally defined.
This switch can be used for globally activate and deactivate PC platform specific code
fragments using conditional compilation like this:
#ifdef IOTESTER_USB
// PC mode part. Only compiled for PC mode execution
#else
// Default mode. Only compiled for the final target system.
#endif
Example
The I/O driver function below can be compiled both for use with the internal IOTester SPI device,
and for use of a target processor specific SPI bus device. (Internal IOTester registers are predefined)
#include <iohw.h> // The standardized I/O register access functions
#include <ioregisters.h> // I/O register definitions (for target hardware)
// Transmit buffer over SPI bus, 8 bit data units.
void send_data(unsigned char *buf, unsigned long buf_length)
{
if (buf != NULL)
{
while( buf_length-- > 0)
{
#ifdef IOTESTER_USB
// PC mode compilation
// Using IOTester SPI device
iowr( IOT_SPI_BUS8, *buf);
#else
// Target processor compilation
// Insert use of target system SPI registers
#endif
buf++;
}
}
}
The prevoius examples illustrates how most "embedded" application and I/O driver source modules can
easily be developed tested on a PC platform by use of high-productivity PC tools.
Best of all by using the methods described it does not require much effort to write C (C++) source modules for which
are fully portable to any standard C (C++) conforming compiler for the target processor. Including I/O driver source code for I/O hardware periherals.
Links to:
IOTester tool description
Example 1: Start using IOTester I/O port pins - "Single chip mode"
Example 2: Enabling the External bus
Example 3: Using Internal Devices and External bus.
Example 4: Using Target Interrupt.
Example 5: Writing portable I/O driver source code with <iohw.h>
Example 6: <iohw.h> implementation methods and definition of I/O registers
Example 7: Swapping source code between PC and target platforms