|
Technical Support
Support Resources
Product Information
|
RTX166: Operating System Initialization
Information in this article applies to:
- C166 Version 3.12 and later
- RTX166 Version 3.10a and later
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.
- Create a new, empty source file.
-
Include the RTX header file:
#include </code>
-
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
-
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
};
-
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;
-
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 ();
}
}
-
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
Last Reviewed: Thursday, February 25, 2021
|
|