Build-A-Burger
Full Member level 1
- Joined
- Oct 27, 2010
- Messages
- 95
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Wyoming
- Activity points
- 2,102
Idea for code generator for PIC16F877A
This app in C# (webform or winform) will generate code, in part if not all, for a multiprocessor network using the SPI sync serial port and each digital and analog io port to take readings from sensors, switches and control digital output. Each processor goes into a loop (after calling the appropriate init functions) which calls functions for reading io ports and updates a table with current readings or whatever. The commands to change vars or get info are sent thru the sync serial protocol from the master and/or the processor with the keypad. Which processor that has the keypad and lcd display is configurable. The app will let the user choose which processor has which features enabled with the exception of the SPI which is enabled on all.
Only one can be the master. One or more will use the RS232 serial port as a TTY for debugging.
Input:
# of processors
list of digital inputs and outputs (assigned to which processor)
list of analog inputs
which processor is the master
which processor has the keypad and lcd display
the priority of each io and how often it is updated
which processor(s) holds the table of values
what values are stored and for how long
The base class will generates the basic code file as follows:
the base class generates this basic template and the derived classes will make the modifications for each processor depending on the features chosen in the setup by inserting the calls the the ISRs the calls to the init functions in the init section and the calls to the update functions in the main loop.
the code is stored in an array of strings - each line is a string. The instruction set is in a SQL table (can be XML file) and there are text files that have the templates for each type of ISR (serial port, timer, etc) the init functions, and whatever functions are commonly used. The code generator will read these text files into arrays of strings and modify them for each processor according what features are enabled and which processor uses which IO port for what. Or I could store the templates in the db or as XML files.
I'm at the point where I have sample PIC programs that test each of the chip's features but its too much to cut and paste and modify without introducing bugs so I thought a code generator would be the way to go. I have been working with strictly the instruction set and have tried looking at the code generated by the compiler (I'm using MPLAB IDE) but the results are really hard to read or follow and they take up a lot more memory unless you buy the optimized compiler. Most of the code (like in the main loop) can be hand-crafted, but it would save a lot of time to have the program generate at least the ISRs and init functions and make the code relocatable.
I have some sample code that implements things like if/then, while and for-loops that I can use as templates too.
I'm not really up on design patterns but I've got some OO programming experience so could someone give me a boiler-plate or an example or suggest a design pattern that would work for this? (I'm thinking ICollection class?) Any ideas?
Dan
This app in C# (webform or winform) will generate code, in part if not all, for a multiprocessor network using the SPI sync serial port and each digital and analog io port to take readings from sensors, switches and control digital output. Each processor goes into a loop (after calling the appropriate init functions) which calls functions for reading io ports and updates a table with current readings or whatever. The commands to change vars or get info are sent thru the sync serial protocol from the master and/or the processor with the keypad. Which processor that has the keypad and lcd display is configurable. The app will let the user choose which processor has which features enabled with the exception of the SPI which is enabled on all.
Only one can be the master. One or more will use the RS232 serial port as a TTY for debugging.
Input:
# of processors
list of digital inputs and outputs (assigned to which processor)
list of analog inputs
which processor is the master
which processor has the keypad and lcd display
the priority of each io and how often it is updated
which processor(s) holds the table of values
what values are stored and for how long
The base class will generates the basic code file as follows:
Code:
list p=16f877a ; list directive to define processor
#include <p16f877a.inc> ; processor specific variable definitions
#include "xxx.inc" ; insert pertinent include file here
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
INT_VAR UDATA_SHR
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
pclath_temp RES 1 ; variable used for context saving
; insert pertinent vars here
; insert global and extern statements here
RESET_VECTOR CODE 0x0000 ; processor reset vector
nop
pagesel start
goto start ; go to beginning of program
INT_VECTOR CODE 0x0004 ; interrupt vector location
INTERRUPT
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register
; insert isrs here e.g. call Timer2ISR
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
MAIN_PROG CODE
start
; insert init functions here
mainLoop
; insert function calls here
goto mainLoop
END ; directive 'end of program'
the code is stored in an array of strings - each line is a string. The instruction set is in a SQL table (can be XML file) and there are text files that have the templates for each type of ISR (serial port, timer, etc) the init functions, and whatever functions are commonly used. The code generator will read these text files into arrays of strings and modify them for each processor according what features are enabled and which processor uses which IO port for what. Or I could store the templates in the db or as XML files.
I'm at the point where I have sample PIC programs that test each of the chip's features but its too much to cut and paste and modify without introducing bugs so I thought a code generator would be the way to go. I have been working with strictly the instruction set and have tried looking at the code generated by the compiler (I'm using MPLAB IDE) but the results are really hard to read or follow and they take up a lot more memory unless you buy the optimized compiler. Most of the code (like in the main loop) can be hand-crafted, but it would save a lot of time to have the program generate at least the ISRs and init functions and make the code relocatable.
I have some sample code that implements things like if/then, while and for-loops that I can use as templates too.
I'm not really up on design patterns but I've got some OO programming experience so could someone give me a boiler-plate or an example or suggest a design pattern that would work for this? (I'm thinking ICollection class?) Any ideas?
Dan