RL-ARM User's Guide

RTX_ex1

The RTX_ex1 example program uses the RTX-RTOS to control and pass signals between two tasks. The tasks, task1 and task2, repeat after a delay of 50 ms and after both tasks finished. An additional delay of 20 ms exists between completion of task1 and start of task2.

Software

  1. Open the project \ARM\RL\RTX\Examples\RTX_ex1.uvproj.
  2. Select the RTX Operating System for the project under: Options for Target — Target — Operating System — RTX Kernel.
  3. The file RTX_ex1.c contains the source code including task1 and task2. Tasks can be declared as a special type of function using the keyword __task. From task1, call os_tsk_create() to start task2.
    __task void task1 (void)  {
      os_tsk_create (task2, 0);
    
      for (;;)  {
        .... code of task 1 placed here ....
      }
    }
    
    __task void task2 (void)  {
    
      for (;;)  {
        os_evt_wait_or (0x0004, 0xffff);
        os_dly_wait (2);
        os_evt_set (0x0004, id1);
      }
    }
    
  4. Place the task activities into endless loops.

    Use the system function os_dly_wait() to pauses a task for a number of system intervals. The RTX kernel starts a system timer by programming one of the on-chip hardware timers of the ARM processor. Timer 0 is used by default. Developers can change the settings.

    Use the system functions os_evt_wait_or() and os_evt_set() to wait for and set event flags. For this example, use the event flag at bit 2.

  5. Initialize the system with the function os_sys_init() in the C main function and pass the task name as an argument.
    void main (void)  {
      os_sys_init (task1);
    }
    
  6. The listing below contains all statements required to run the RTX example:
    #include "RTL.h"
    
    OS_TID id1, id2;                        // id1, id2 - task identifications numbers at run-time
    
    __task void task1 (void);               // Task forward reference
    __task void task2 (void);
    
    /*********************************************************************************************/
    __task void task1 (void)  {
    
      id1 = os_tsk_self ();                 // Obtain own system task identification number
      id2 = os_tsk_create (task2, 0);       // Assign system identification number of task2 to id2
    
      for (;;)  {                           // do-this
        os_evt_set (0x0004, id2);           // Indicate to task2 completion of do-this
        os_evt_wait_or (0x0004, 0xffff);    // Wait for do-that to complete (0xffff - no time-out)
        os_dly_wait (5);                    // Wait now for 50 ms
      }
    }
    
    /*********************************************************************************************/
    __task void task2 (void)  {
    
      for (;;)  {                           // do-that
        os_evt_wait_or (0x0004, 0xffff);    // Wait for do-this to complete (0xffff - no time-out)
        os_dly_wait (2);                    // Pause for 20 ms until signaling event to task1
        os_evt_set (0x0004, id1);           // Indicate to task1 completion of do-that
      }
    }
    
    /*********************************************************************************************/
    void main (void)  {
    
      os_sys_init (task1);                  // Initialize system and call task1
    }
    

Test the Application

  1. Build Build the application.
  2. Debug Button Start the µVision debugger in Simulation mode.
  3. run Run the application.