This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using RTX51 Tiny, no main () ?

Hi,

I'm trying to learn the MULTI-TASKING concept using RTX51 Tiny.

I noticed that you no longer use the main. You always start with TASK 0. But If I need to INIT my MCU, how do I proceed ?

Because if I put my init() in the TASK0, my MCU will be initialized several time, no ?

Help a newbie ;-)

Thx

  • I usually have several different sorts of initialization.

    - pre-kernel initialization.

    Relatively rare except for the C runtime and board support type stuff. But sometimes you need to do low-level initialization before anything else happens. This corresponds to Keil's STARTUP.A51, INIT.A51, and perhaps some other code.

    - pre-start initialization

    main() calls a bunch of init functions for various modules before any task starts running. These functions often create tasks, among other things.

    void main (void)
        {
        ModAInit();
        ModBInit();
        ModCInit();
    
        // start system running
        StartOs();
        }
    

    - per-task initialization

    Each task does some local initialization of its own when it first starts. Tasks thus have a structure that looks like:

    void TaskBody (void)
        {
        // startup init
        TaskInit();
    
        // never-ending task body
        for (;;)
            {
            // task activity
            e = WaitForEvent();
            HandleEvent (e);
            }
        } // TaskBody
    

    Often, embedded software needs to be able to re-initialize itself, so the "main task body" can often call the same init functions, reuse parts of the logic, or just do all of the initialization.

  • Task 0 is the entry for your program. It must contain a 'forever' loop such as a while(1){...}. Just put your init prior to the while(1) loop. It will init only one time.