Modifying Existing Application Code for Harnessing

General steps are:

Remove compiler specific code.

Try to compile all source code. Resolve all compiler errors by adding/removing needed source/header files.

In Visual Studio, you might need to add a path to each subfolder in 'Additional Include Directories' because it does not recursively look for include files in subfolders.

Resolve all linker errors by finding needed code, or by creating stubs when code is not essential.

Try to run the SUT with debugger. Find any places where it gets stuck in forever loops or tries to access hardware specific code which causes exceptions.

When harnessing the code, keep a copy of the 'pure' original source code in case you need to revert some changes or compare.

Never really remove code, use #ifndef MXVDEV and #ifdef MXVDEV to separate code for the target hardware and Windows. This will make the same code run on both.

When harnessing embedded code to run on windows remove any 'forever' loops, such as for(;;) or while(true) if they are expecting some input from the hardware.

All the actual hardware ports and registers should be mapped to a uint8 variable (or uint16 etc where appropriate), or just create an array uint8[] big enough to store all ports. Then you can use #defines of Port names with index whenever needed, for example:

#define PORT_A mxPorts[0]

#define PORT_B mxPorts[1]

Example

The C++ solution in the TurnDoorSample project is an example of harnessed code.

Related Topics:

MxV MicroController Emulation (µC Library)

Tips on Stubbing

Tips on Porting