ARM Technical Support Knowledge Articles

OPERATING SYSTEM INITIALIZATION

Applies to: RTX166 Real-time Kernel

Answer


Information in this article applies to:


QUESTION

How do I start writing an RTX166 program? What files do I include and how do I initialize and start the OS?

ANSWER

There are only a few steps you must follow to create a working RTX166 program.

  1. Create a new, empty source file.
  2. Include the RTX header file:
    #include <rtx166.h>
    
  3. Declare the system and context heaps.
    /*-----------------------------------------------
    If the memory model is TINY or SMALL, create an
    8K system heap.
    
    If the memory model is larger, create a 4K system
    heap and a 4K context heap.
    -----------------------------------------------*/
    #if __MODEL__ <= 1
      static unsigned char near system_heap  [0x2000];
    #else
      static unsigned char huge system_heap  [0x1000];
      static unsigned char near context_heap [0x1000];
    #endif
    
  4. Declare the configuration structure that you pass to the os_start_system function. Note that the values you specify in this structure tell RTX166 the number of tasks, mailboxes, semaphores, and so on.
    /*-----------------------------------------------
    Configuration data for RTX166.
    -----------------------------------------------*/
    #define WSP 256  /* workspace (in bytes) for each task */
    
    static t_rtx_config rtx_cfg_data =
      {
      8,                      /* max tasks */
      8,                      /* max mailboxes */
      8,                      /* max semaphores */
      8,                      /* max memory pools */
      WSP,                    /* idle task workspace (in bytes) */
      WSP,                    /* clock task workspace (in bytes) */
      FALSE,                  /* round_robin */
      system_heap,            /* system_pool */
      sizeof (system_heap),   /* system_pool_size */
      FALSE,                  /* rtx51 */
    #if __MODEL__ > 1
      context_heap,           /* context_pool */
      sizeof (context_heap),  /* context_pool_size */
    #endif
      };
    
  5. Declare manifest constants for your task numbers as well as the task handles.
    /*-----------------------------------------------
    RTX166 manifest constants and handles for the
    blinker and flasher tasks.
    -----------------------------------------------*/
    #define FLASHER_TASK 1  /* Task number for the FLASHER task */
    #define BLINKER_TASK 2  /* Task number for the BLINKER task */
    
    t_rtx_handle blinker_task;
    t_rtx_handle flasher_task;
    
  6. Declare tasks.
    static void blinker (void) _task_ BLINKER_TASK
    {
    os_set_interval (blinker_task, 100);
    
    while (1)
      {
      P7 ^= 0x80;
      os_wait_interval ();
      }
    }
    
    static void flasher (void) _task_ FLASHER_TASK
    {
    os_set_interval (flasher_task, 10);
    
    while (1)
      {
      P7 ^= 0x01;
      os_wait_interval ();
      }
    }
    
  7. Declare the main C function that initializes your hardware, starts the OS, creates your tasks, and exits.
    void main (void)
    {
    DP7  = 0xFF;
    ODP7 = 0xFF;
    
    /*-----------------------------------------------
    Start the multitasker.
    -----------------------------------------------*/
    os_start_system (&rtx_cfg_data);
    
    /*-----------------------------------------------
    Create tasks.
    -----------------------------------------------*/
    os_create_task (&blinker_task, BLINKER_TASK, WSP);
    os_create_task (&flasher_task, FLASHER_TASK, WSP);
    
    /*-----------------------------------------------
    Begin looping.  Then, kill this task.  If it
    doesn't die, try again.
    -----------------------------------------------*/
    for (;;)
      {
      os_delete_task (os_running_task_id ());
      }
    }
    

SEE ALSO

Article last edited on: 2005-07-09 12:48:53

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential