Keil Logo

RTX166: STARTING A NEW PROJECT


Information in this article applies to:

  • C166 Version 4.03
  • RTX166 Version 3.10a

QUESTION

How do I get started with RTX166 and C166 Version 4? I have installed µVision2 and the C166 compiler as well as RTX166. How do I create a simple example program?

ANSWER

Creating a new RTX166 program is fairly simple. However, there are a lot of steps you must follow. You must create a new project and set some project options, copy some configuration files from the RTX166 directory, and create a complete sample program.

Creating a Project

  1. Create a subdirectory for your RTX166 project.
  2. In µVision2, create a new project in that directory.
  3. Once the project is created, select Select Device... from the Project menu. This displays the device database dialog.
  4. Select one of the Infineon C166 derivatives or one of the STMicroelectronics ST10 derivatives. If you're unsure what to choose, select the Infineon C167CR-LM and click OK.
  5. Select Options for Target... from the Project menu. This displays the project options for the compiler, assembler, linker, and so on.
  6. Under the Target tab, select the RTX-166 Full Real-Time OS as the Operating System.
  7. Under the Target tab, in the External Memory section, for #1, select ROM starting at 0x000000 for a size of 0x8000. For #2, select RAM starting at 0x008000 for a size of 0x8000.

RTX166 Configuration Files

  1. Copy the following files from the \keil\c166\rtx166 directory to your new project directory: RTXCONF.C66 and RTXSETUP.H.
  2. Edit the RTXSETUP.H file to configure the OS as desired. You can leave this file alone for this example. As you become more familiar with the OS, the items in this config file will make more sense.
  3. Add the RTXCONF.C66 file to the project. You may wish to create a new file group for this file.
  4. When you add the RTXCONF.C66 file, µVision2 will prompt you to select the file type for this file. Select C Source File from the drop down menu and µVision2 adds this file to your project.
  5. The RTXCONF.C66 file is special. It must be compiled with the SRC option and then assembled with the A166 assembler to create an OBJ file.
  6. Right-click on the RTXCONF.C66 file. This opens the local menu. Select Options for File.... The option dialog displays.
  7. Under the Properties tab, check the Generate Assembler Source File and the Assemble SRC File checkboxes. Note that when you view the dialog, these options may have grey checks in the checkboxes. A grey check means that the options of the previous file group or target will be used. The checks must be black to be "checked".

At this point, you may wish to test what you have done. Right-click on RTXCONF.C66 and select Translate RTXCONF.C66 from the local menu. The Build Window (at the bottom of the screen) will show the following:

compiling Rtxconf.c66...
assembling Rtxconf.src...
Rtxconf.src - 0 Error(s), 0 Warning(s).

If the above information does not appear there is a problem. Check the steps above to make sure the files were added correctly and that the project was configured properly.

Example Program

Create a new, empty file and insert the following source code.

#include <rtx166.h>
#include <reg167.h>

/*-----------------------------------------------
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

/*-----------------------------------------------
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
  };

/*-----------------------------------------------
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;

/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
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 ();
  }
}

/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
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 ());
  }
}

Save this file as MAIN.C and add it to the project. Your project is now complete. You should be able to compile and link with no errors.

When you run this program in the simulator, be sure to watch port 7. You will see bit 0 toggling very quickly while bit 7 toggles very slowly.

SEE ALSO

Last Reviewed: Thursday, November 17, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.