*Originally posted by Skabana159 *
**Okay, here is what our team decided about ifi_initialization does, and please anyone correct me if anything appears incorrect, because we were really just guessing.
We were under the impression that C will always start running at main(),
Is this correct?
It would be nice, however, to know what exact flow the program follows, rather than guessing like we did. **
If you look in ifi_startup.c, you will see a line:
#pragma code _entry_scn=RESET_VECTOR
This is defining the entry point for your code when the PIC resets. This is the start point for the code.
The code snippet which follows:
void _entry(void){_asm goto _startup _endasm}
calls the function _startup().
Next is the line:
#pragma code _startup_scn
which tells the compiler to put the next stuff in the “code” section at “_startup_scn”.
The following code:
void _startup(void){
_asm
…
_endasm
loop:
Clear_memory();
_do_cinit();
main();
goto loop:
}
starts your stuff executing.
In the file, main.c, you have your main() function, which calls IFI_Initialization() followed immediately by User_Initialization().
At this point, you can dump loop based routines into the while(1){…} loop, which is an infinite loop.
The functions Process_Data_From_Master_uP()
and
Process_Data_From_Local_IO()
run in a non-timed fashion in “the background”.
In user_fast_routines.c, there seems to be a timed loop. This would execute every “n” msec, regardless of what is going on in the while loop in main.
There also appears to be an interrupt service routine for the low priority interrupt and which can be executed using the 6 digital input pins on the front of the EDU-RC, labelled “Interrupt.”
This code would execute whenever a transition (low-to-high, I think) is initiated on one of those pins.
In embedded, interrupt driven code you have to give up the notion of step-by-step execution. Multiple programs can be running simultaneously and which interact with each other.