Code division
The source code of OPGUI and OP is divided in separate files according to function use; common files are:
progAVR.c (.h) | algorithms for ATMEL AVR |
progEEPROM.c (.h) | algorithms for serial memories |
progP12.c (.h) | algorithms for PIC12/16 with 12 bit memory |
progP16.c (.h) | algorithms for PIC12/16 with 14 bit memory |
progP18.c (.h) | algorithms for PIC18 |
progP24.c (.h) | algorithms for PIC24 and PIC33 |
I2CSPI.c (.h) | I2C and SPI communication functions |
fileIO.c (.h) | file management: loading and saving .hex and .bin |
coff.c (.h) | reading .coff files (for ICD debugging) |
icd.c (.h) | management of ICD debugging |
icons.c (.h) | icon source |
deviceRW.c (.h) | selection of the appropriate function and parameters.
Here is the list of supported devices |
strings.c (.h) | user interface strings |
common.h | global variables and functions |
instructions.h | low level programmer commands |
Makefile | needed to compile the project |
The main function with the user interface is contained in
opgui.c or
op.c according to the application.
OpenProg uses the same code, but all files have extension .cpp to be compatible with VC++.
Every function has indeed a double declaration like:
#ifdef _MSC_VER
void COpenProgDlg::DisplayCODE16F(int size){
#else
void DisplayCODE16F(int size){
#endif
General structure
In all three applications (
OPGUI, OP, OpenProg) the user interface first checks the selected options, then calls the same basic functions.
Loading a file |
fileIO.c -> Load(dev,loadfile) | fills the array memCODE_W (for PIC12-16) or memCODE, mem_EE, mem_CONFIG, mem_ID, with data to be written |
Write or read |
deviceRW.c -> Write(dev,ee)/Read(dev,ee,r) | find and call the correct function (defined in various progXX.c files); data stored in memXX |
Saving a file |
fileIO.c -> Save(dev,savefile) | write in a file the array memCODE_W (for PIC12-16) or memCODE, mem_EE, mem_CONFIG, mem_ID |
Selection of the read/write function
Selection of the right algorithm is performed in
deviceRW.c:
here is defined the array
DEVLIST[] in which every group of devices is associated with the corresponding read and write functions,
along with the correct parameters.
An example of array entry:
{"12F1822,16F1823,16F1826",PIC16,8.5,1,Read16F1xxx,{0x800,0x100,11,0},0x200,Write16F1xxx,{0x800,0x100,0},0}
Functions
Read(dev,ee,r) and
Write(dev,ee) parse the array until the device is found, then call the read or write function with
the parameters listed.
Communication with the programmer
The programmer communicates through data packets sent via USB; a packet can contain up to 64 bytes of instructions.
A detailed description of all instructions can be found in the
main page.
After elaborating a packet the programmer generates a response of the same size.
The instructions are defined in
instructions.c; their length is variable, as is the corresponding answer.
The array
bufferU of
DIMBUF bytes contains the data to be sent to the device;
bufferI contains the response.
DIMBUF is defined as 64 under Linux and 65 under Windows; in this case the first byte of the array has to be 0 to indicate
the HID report to use; it has been left to 0 also in the Linux version.
A typical communication looks like this:
bufferU[0]=0;
j=1;
bufferU[j++]=SET_PARAMETER;
....
bufferU[j++]=FLUSH;
for(;j<DIMBUF;j++) bufferU[j]=0x0;
write();
msDelay(2);
read();
Note the
FLUSH instruction, which terminates the execution immediately; without this the programmer would execute
a series of NOP (code 0) until the end of the packet, then it would send the response packet.
write() and
read() are non blocking calls under Linux, and blocking with timeout under Windows;
this means that if the delay in
msDelay() is not sufficient to get a response, read() will get the previous response under Linux.
PacketIO(delay) is used in places where timing is critical; it integrates read-delay-write and is blocking with timeout
on all systems; it's going to substitute the three functions in all the code.
Strings and messages
A series of functions that write messages are defined:
PrintMessage(msg), PrintMessage1(msg,par), etc.,
in order to share the code in all versions.
The array
strings[] contains all strings in the appropriate language; for example:
PrintMessage2(strings[S_ConfigWordX],1,memCODE_W[0x8007]);
Compiling the project
OPGUI uses the GTK libraries so under Windows it's necessary to install the
GTK Runtime Environment.
It's also necessary to have a GNU compatible environment with the GCC compiler; under Windows it's sufficient to install
the
MinGW suite.
OP only needs the GNU environment and GCC.
To compile execute:
> make
To install it under Linux(if you wish):
> make install
Regarding
OpenProg it's necessary to install the Visual C++ 6.
The development of this application is terminated; the new versions are only updated on algorithms and device support,
but the user interface is the same and has only the basic functions.
The only advantage is that it does not require any additional library.