I have a working system loop in assembly that sets up basic communications, blinks a LED, and can reprogram memory outside of the system program area (usually starting at 800h). When the right combinations are sent by I2C to the PIC it will call address 800h which is a goto to the "application setup" routine. Once initialized the system loop will then call 808h which is a goto to the "application loop". Doing it this way makes it possible to reprogram the application program memory without having to update addresses in the system loop every time the program changes. Another right combination by I2C and the system loop will reprogram the application area.
An rough example of the system program. 0h - 7ffh
Then in application memory 800h - end of program memory space
I was wondering if there is a way to implement a similar program in XC8. I'm thinking it would need to limit the compiler's usage of ram for the C runtime stuff like stacks and what not for both the system program and the application program. I currently define all memory locations so that the system program and application program use the same data for everything. I would have to carry over that practice also.
More or less the main two questions I have are:
Is it possible to define where the functions are located in program memory with XC8?
Is there a way to limit XC8 to only using ram from 100h - 200h (or whatever works best) for the C runtime and have the rest of ram reserved for how the program itself uses it?
Although I'm rather fond of assembly this is one of those projects C would make so much easier in the end just to eliminate a whole lot of translating C to assembly to get USB up and running.
An rough example of the system program. 0h - 7ffh
Code:
setup oscilator, timers, I2C, and whatever else
_system_loop
handle i2c -- call ___application_start_ptr, ___application_stop_ptr, and whatever else as needed to reprogram, move data, etc.
if application initialized and running call ___application_loop_ptr
handle timer to blink led
goto _system_loop
Code:
___application_start_ptr
goto __application_start
___application_stop_ptr
goto __application_stop
___applcation_loop_ptr
goto __application_loop
__appllciation_start
change led blink rate
set system flag to show application started
do application related setup
return
__application_stop
change led blink rate
set system flag to show application stopped
do application related shutdown
return
__application_loop
do application related tasks
return
More or less the main two questions I have are:
Is it possible to define where the functions are located in program memory with XC8?
Is there a way to limit XC8 to only using ram from 100h - 200h (or whatever works best) for the C runtime and have the rest of ram reserved for how the program itself uses it?
Although I'm rather fond of assembly this is one of those projects C would make so much easier in the end just to eliminate a whole lot of translating C to assembly to get USB up and running.