I have been programming teh VEX for a couple of months using both the robotc and MPLAB C18 compilers. I have been programming on and off for a number of years but working this close to the hardware is not something I have had experience with. As a result one of my goals for my robot activities is to gain a better understanding of low level programming.
One of the things that I want to do is reduce the programming framework on the VEX down to the absolute minimum and still be able to have a program that runs. Once I am at this point I want to experiment with coding interfaces to the sensors on my own.
Using the MPLAB C18 compiler I have gotten down to two c files, one asembler file and four header files.
I have looked at all of these files and have some idea what each of them does. However, I am perplexed at why the code in the main() functions loops executes continously.
Looking at ifi_startup.c I determined that main() is wrapped in a loop/goto loop set of statements. I thought I had found the answer until I remove the loop/goto loop statements. What I found was that main() no longer loops when it is downloaded using the ifi loader program but still loops when the code runs from a power on.
Looking into it further it would appear that the _entry() function in ifi_startup.c gets called after the _startup() function exits.
It is not a huge problem as I can think of a couple of ways to keep main from ever exiting. However, it bugs me that I cannot figure it out.
A noble goal, you will learn lots following this path…
First, A little known fact, is that any Microprocessor is always running an endless loop, unless the HALT Instruction has been executed or a Power Down has occurred.
You are familiar with Applications (Processes) like Internet Explorer, that you Launch (execute), and when Done, Exit (terminate). These types of Processes must allow for an exit from the Main Function, or the only way to Terminate them would be with the Task Manager.
Embedded Systems, like the Vex, have only One Process, and if you exit it, the Systems (i.e. Robot) does nothing, because its StartUp Code, only starts your Process, and does nothing else.
So it works, if you Power Cycle the Vex Controller after a Download of your Code??? I have seen that sometimes the Vex StarUp Code will Hang or Lock, and a Power Cycle is needed to correct things.
The code in [FONT=“Courier New”]ifi_startup.c[/FONT], sets up the environment for the main() of your Program. Windows does this for Processes like Internet Explorer, so you don’t typically see the Source Code. Embedded Systems like Vex are different.
Sure we have ideas… And we will Gladly share them with you…
Sorry, this was a Quick Response, so I might have “glossed over” some details.
In answer to your question, with the loop/goto loop removed main() executes only once just after it is downloaded. When the controller is power cycled main() executes repeatedly until the controller is turned off.
Based on what you have outlined I expect what is happening is that when main() exits and the _ifi_startup() exits the controller must reset which starts the process all over again. At least that is what it looks like.
When you download code and it is executed it must end up in a state where _ifi_startup is called once and when it exits the contoller must not reset.