Advertisement

Quick Links

Preface
Preface
This manual explains how to use the RTX51 Tiny Real-Time Operating System and gives
an overview of the functionality of RTX51 Full. The manual is not a detailed introduc-
tion to real-time applications and assumes that you are familiar with Keil C51, A51, the
related Utilities, the DOS operating system and the hardware and instruction set of the
8051 microcontrollers.
The following literature is recommended as an extensive introduction in the area of real-
time programming:
Deitel, H.M., Operating Systems, second edition,
Addison-Wesley Publishing Company, 1990
Ripps, David, A Guide to Real-Time Programming, Englewood Cliffs, N.J,
Prentice Hall, 1988/
Allworth, S.T., Introduction to Real-Time Software Design,
Springer-Verlag Inc., New York
This user's guide contains 6 parts:
Part 1:
Part 2:
Part 3:
Part 4:
Part 5:
Part 6:
Overview, describes the functionality of a the RTX51 real-time opeating
systems and discusses the basic features and differences of RTX51 Tiny and
RTX51 Full. Also included are the technical data of RTX51 Full and
RTX51 Tiny.
Requirements and Definitions, discusses the development tools and the
target system requirements of RTX51 Tiny, explains the terms used in the
the RTX51 Tiny manual and decribes the task definition.
Creating RTX51 Tiny Applicaitons, describes the steps necessary to cre-
ate RTX51 Tiny applications.
Library Functions, provides a reference for all RTX51 Tiny library rou-
tines.
System Debugging, describes the stack handling of RTX51 Tiny and con-
tains information about the system debugging.
Applications Examples, contains several examples using RTX51 Tiny and
describes the software development process. This information can be used
as a guideline for your real-time designs.
1

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the RTX51 and is the answer not in the manual?

Questions and answers

Summary of Contents for Keil RTX51

  • Page 1 This manual explains how to use the RTX51 Tiny Real-Time Operating System and gives an overview of the functionality of RTX51 Full. The manual is not a detailed introduc- tion to real-time applications and assumes that you are familiar with Keil C51, A51, the related Utilities, the DOS operating system and the hardware and instruction set of the 8051 microcontrollers.
  • Page 2: Table Of Contents

    Single Task Program....................8 Round-Robin Program....................8 Round-Robin Scheduling With RTX51..............8 RTX51 Events ......................9 Compiling and Linking with RTX51 ............... 11 REQUIREMENTS AND DEFINITIONS .............. 15 Development Tool Requirements......................15 Target System Requirements........................15 Interrupt Handling ....................15 Reentrant Functions ....................
  • Page 3 SYSTEM DEBUGGING ..................41 Stack Management...........................41 Debugging with dScope-51........................41 APPLICATION EXAMPLES ................45 RTX_EX1: Your First RTX51 Program....................45 RTX_EX2: A Simple RTX51 Application .....................47 TRAFFIC: A Traffic Light Controller ....................49 Traffic Light Controller Commands .................49 Software ........................49 Compiling and Linking TRAFFIC................62...
  • Page 5 RTX Tiny Notational Conventions This manual uses the following format conventions: Examples Description BL51 Bold capital texts used for the names of executable programs, data files, source files, environment variables, and other commands entered at the DOS command prompt. This text usually represents commands that you must type in literally.
  • Page 7: Overview

    No message routines are included. No memory pool allo- cation routines are available. The remainder of this chapter uses RTX51 to refer to both variants. Differences between the two are so stated in the text as their need becomes applicable.
  • Page 8: Single Task Program

    Each task is allowed to execute for a predetermined amount of time. Then, RTX51 switches to another task that is ready to run and allows that task to execute for a while. The time slices are very short, usually only a few milliseconds. For this reason, it...
  • Page 9: Rtx51 Events

    The simplest event you can wait for with the os_wait function is a time-out period in RTX51 clock ticks. This type of event can be used in a task where a delay is required. This could be used in code that polled a switch. In such a situation, the switch need only be checked every 50ms or so.
  • Page 10 RTX51 switches to the next task, which is job1. After job1 increments counter1, it too calls os_wait to pause for 5 clock ticks. Now, RTX51 has no other tasks to exe- cute, so it enters an idle loop waiting for 3 clock ticks to elapse before it can continue executing job0.
  • Page 11: Compiling And Linking With Rtx51

    In some circumstances, this is unacceptable for timing rea- sons. RTX51 allows you to assign priority levels to tasks. A task with a higher priority will interrupt or pre-empt a lower priority task whenever it becomes available. This is called preemptive multitasking or just preemption.
  • Page 12 RTX51 Full supports the exchange of messages between tasks with the functions: SEND & RECEIVE MESSAGE and WAIT for MESSAGE. A message is a 16-bit value, which can be interpreted as a number or as a pointer to a memory block. RTX51 Full supports variable sized messages with a memory pool system.
  • Page 13 RTX Tiny RTX51 Functions The following table shows all RTX51 functions; RTX51 Tiny supports only the functions marked with (*). (Timings are measured with RTX51 Full) Execution Time Function Description (cycles) os_create (*) move a task to execution queue os_delete (*)
  • Page 14 RTX51 Real-Time Operating System Technical Data Description RTX51 Full RTX51 Tiny Number of tasks 256; max. 19 tasks active RAM requirements 40 .. 46 bytes DATA 7 bytes DATA 20 .. 200 bytes IDATA (user stack) 3 * <task count> IDATA min.
  • Page 15: Requirements And Definitions

    The following chapter describes the software and hardware requiremens of RTX51 Tiny and defines the terms used within this manual. RTX51 Tiny uses a combination of system calls as well as the _task_ keyword for the task definition which is built in to the C51 compiler.
  • Page 16: Reentrant Functions

    Introduction to RTX51 Tiny RTX51 Tiny uses the 8051 timer 0 and the timer 0 interrupt of the 8051. Globally dis- abling all interrupts (EA bit) or the timer 0 interrupt stops therefore the operation of RTX51 Tiny. Except for a few 8051 instructions, the timer 0 interrupt should not be dis- abled.
  • Page 17: Registerbanks

    Task Management Each task that you define for RTX51 Tiny can be in one of a number of different states. The RTX51 Tiny Kernel maintains the proper state for each task. Following is a descrip- tion of the different states.
  • Page 18: Task Switching

    Each task is allowed to execute for a predetermined amount of time. Then, RTX51 Tiny switches to another task that is ready to run and allows that task to execute for a while. The duration of a time slice can be defined with the configurarion variable TIMESHARING.
  • Page 19 RTX Tiny Note: The event S can be combined with the events T and so that IGNAL IMEOUT RTX51 Tiny waits for both a signal and a time period.
  • Page 21: Creating Rtx51 Tiny Applications

    C program and that you declare your tasks \C51\INC\ using the _task_ function attribute. RTX51 Tiny programs do not require a main C function. The linking process will in- clude code that will cause execution to begin with task 0. RTX51 Tiny Configuration...
  • Page 22 These are described in the following table. Variable Description INT_REGBANK indicates which register bank is to be used by RTX51 Tiny for the system interrupt. INT_CLOCK defines the interval for the system clock. The system clock generates an interrupt using this interval.
  • Page 23: Compiling Rtx51 Tiny Programs

    Compiling RTX51 Tiny Programs RTX51 Tiny applications require no special compiler switches or settings. You should be able to compile your RTX51 Tiny source files just as you would ordinary C source files. Linking RTX51 Tiny Programs RTX51 Tiny applications must be linked using the BL51 code banking linker/locator.
  • Page 25: Rtx51 Tiny System Functions

    RTX Tiny RTX51 Tiny System Functions A number of routines are included in the RTX51 Tiny Library file that RTX51TNY.LIB can be found in the subdirectory. These routines allow you to create and de- \C51\LIB\ stroy tasks, send and receive signals from one task to another, and delay a task for a num- ber of timer ticks.
  • Page 26: Function Reference

    RTX51 Tiny Function Library Function Reference The following pages describe the RTX51 Tiny system functions. The system functions are described here in alphabetical order and each is divided into several sections: Summary: Briefly describes the routine’ s effect, lists include file(s) containing its declaration and prototype, illustrates the syntax, and describes any arguments.
  • Page 27: Isr_Send_Signal

    RTX Tiny isr_send_signal Summary: #include <rtx51tny.h> char isr_send_signal ( unsigned char task_id); /* ID of task to signal */ Description: The isr_send_signal function sends a signal to task task_id. If the specified task is already waiting for a signal, this function call will ready the task for execution.
  • Page 28: Os_Clear_Signal

    RTX51 Tiny Function Library os_clear_signal Summary: #include <rtx51tny.h> char os_clear_signal ( unsigned char task_id); /* task ID of signal to clear */ Description: The os_clear_signal function clears the signal flag for the task specified by task_id. Return Value: The os_clear_signal function returns a value of 0 if the signal flag was successfully cleared.
  • Page 29 The os_create_task function starts the defined task function using the task number specified by task_id. The task is marked as ready and is executed according to the rules specified for RTX51 Tiny. Return Value: The os_create_task function returns a value of 0 if the task was successfully started.
  • Page 30 RTX51 Tiny Function Library os_delete_task Summary: #include <rtx51tny.h> char os_delete_task ( unsigned char task_id); /* ID of task to stop and delete */ Description: The os_delete_task function stops the task specified by the task_id argument. The specified task is removed from the task list.
  • Page 31 RTX Tiny os_running_task_id Summary: #include <rtx51tny.h> char os_running_task_id (void); Description: The os_running_task_id function determines the task id of the currently executing task function. Return Value: The os_running_task_id function returns the task ID of the cur- rently executing task. This value is a number in the range 0 to 15. See Also: os_create_task, os_delete_task Example:...
  • Page 32 RTX51 Tiny Function Library os_send_signal Summary: #include <rtx51tny.h> char os_send_signal ( unsigned char task_id); /* ID of task to signal */ Description: The os_send_signal function sends a signal to task task_id. If the specified task is already waiting for a signal, this function call readies the task for execution.
  • Page 33 RTX Tiny Example: #include <rtx51tny.h> #include <stdio.h> /* for printf */ void signal_func (void) _task_ 2 os_send_signal (8); /* signal task #8 */ void tst_os_send_signal (void) _task_ 8 os_send_signal (2); /* signal task #2 */...
  • Page 34 The ticks argument specifies the number of timer ticks to wait for an interval event ( K_IVL ) or a time-out event ( K_TMO ). The dummy argument is provided for compatibility with RTX51 and is not used in RTX51 Tiny.
  • Page 35 RTX Tiny #include <stdio.h> /* for printf */ void tst_os_wait (void) _task_ 9 while (1) char event; event = os_wait (K_SIG + K_TMO, 50, 0); switch (event) default: /* this should never happen */ break; case TMO_EVENT: /* time-out */ /* 50 tick time-out occurred */ break;...
  • Page 36 RTX51 Tiny Function Library os_wait1 Summary: #include <rtx51tny.h> char os_wait1 ( unsigned char event_sel); /* events to wait for */ Description: The os_wait1 function halts the current task and waits for an event to occur. The os_wait1 function is a subset of the os_wait func- tion and does not allow all of the events that os_wait offers.
  • Page 37 RTX Tiny os_wait2 Summary: #include <rtx51tny.h> char os_wait2 ( unsigned char event_sel, /* events to wait for */ unsigned char ticks); /* timer ticks to wait */ Description: The os_wait2 function halts the current task and waits for one or several events such as a time interval, a time-out, or a signal from another task or interrupt.
  • Page 38 RTX51 Tiny Function Library Return Value Description SIG_EVENT A signal was received. TMO_EVENT A time out has completed or an interval has expired. NOT_OK The value of the event_sel argument is invalid. See Also: os_wait, os_wait1 Example: See os_wait.
  • Page 39 RTX Tiny...
  • Page 41 Stack Management RTX51 Tiny reserves an individual stack area for each task. Due to the design of RTX51 Tiny which uses only the on-chip memory resources of the 8051, the entire stack is man- age in the internal memory (IDATA) of the 8051. To allocate the largest available stack space to the current running task, the stack space used by other not running tasks is moved.
  • Page 42 The RTX51 Tiny application must be loaded prior to defining this debug function. The debug function is activated by pressing the F3-KEY and displays then the status of RTX51 Tiny. In addition every task switch is displayed with a message. Example: DS51 TRAFFIC >INCLUDE DBG_TINY.INC...
  • Page 43 EADY EADY After the currently running task has finished TATE processing, RTX51 Tiny starts the next task that is ready. Tasks which are waiting for an event are in the W AITING AITING . If the event occurs, the task is placed into the R...
  • Page 44 RTX51 Tiny Specifications...
  • Page 45 RTX TINY Application Examples RTX_EX1: Your First RTX51 Program The program RTX_EX1 demonstrates round-robin multitasking using RTX51 Tiny. This program is composed of only one source file located in the RTX_EX1.C directory. The \C51V4\RTX_TINY\RTX_EX1 \CDEMO\51\RTX_TINY\RTX_EX1 contents of is listed below.
  • Page 46 Application Examples DS51 RTX_EX1 INIT(RTX_EX1.INI) directive loads an initialization file that configures the DS51 INIT(RTX_EX1.INI) screen; loads the appropriate IOF driver file; initializes watchpoints for the variables , and ; and finally starts execution of RTX_EX1. counter0 counter1 counter2 As each task gets to execute, you will see the corresponding counter increase. The coun- ter variables are displayed in the watch window at the top of the screen.
  • Page 47 RTX TINY RTX_EX2: A Simple RTX51 Application The program RTX_EX2 demonstrates an RTX51 Tiny application that uses the os_wait function and signal passing. This program is composed of one source file RTX_EX2.C located in the \C51V4\RTX_TINY\RTX_EX2 \CDEMO\51\RTX_TINY\RTX_EX2 rectory. The contents of is listed below.
  • Page 48 WS counter2 WS counter3 This will set watchpoints for the four task counter variables and will begin execution of RTX_EX2. RTX_EX2 increments the four counters as follows: incremented every 5 RTX51 timer ticks counter0 incremented every 10 RTX51 timer ticks counter1...
  • Page 49 The preceding examples, RTX_EX1 and RTX_EX2, show only the basic features of RTX51 Tiny. These examples could just as easily have been implemented without using RTX51. This example, a pedestrian traffic light controller, is more complex and can not be easily implemented without a multitasking real-time operating system like RTX51.
  • Page 50 Application Examples • Task 4 Lights: controls the traffic light phases while the clock time is in the active time range (between the start and end times). • Task 5 Button: reads the pedestrian push button and sends signals to the lights task.
  • Page 51 RTX TINY extern getline (char idata *, char); /* external function: input line extern serial_init (); /* external function: init serial UART #define INIT /* task number of task: init #define COMMAND /* task number of task: command #define CLOCK /* task number of task: clock #define BLINKING...
  • Page 52 Application Examples init () _task_ INIT /* program execution starts here serial_init (); /* initialize the serial interface os_create_task (CLOCK); start clock task os_create_task (COMMAND); start command task os_create_task (LIGHTS); start lights task os_create_task (KEYREAD); start keyread task os_delete_task (INIT); /* stop init task (no longer needed) bit display_time = 0;...
  • Page 53 RTX TINY unsigned char args; /* number of arguments rtime.sec = 0; /* preset second args = sscanf (buffer, "%bd:%bd:%bd", /* scan input line for &rtime.hour, /* hour, minute and second &rtime.min, &rtime.sec); if (rtime.hour > 23 rtime.min > 59 /* check for valid inputs rtime.sec >...
  • Page 54 Application Examples getline (&inline, sizeof (inline)); /* get command line input for (i = 0; inline[i] != 0; i++) /* convert to uppercase inline[i] = toupper(inline[i]); inline[i] i++); skip blanks switch (inline[i]) /* proceed to command function case 'D': /* Display Time Command printf ("Start Time: %02bd:%02bd:%02bd "...
  • Page 55 RTX TINY end.min = rtime.min; end.sec = rtime.sec; break; case 'S': /* Set Start Time Command */ if (readtime (&inline[i+1])) /* read time input and start.hour = rtime.hour; /* store in 'start' start.min = rtime.min; start.sec = rtime.sec; break; default: /* Error Handling printf (menu);...
  • Page 56 Application Examples yellow = 1; /* yellow light on os_wait (K_TMO, 30, 0); /* wait for timeout: 30 ticks yellow = 0; /* yellow light off os_wait (K_TMO, 30, 0); /* wait for timeout: 30 ticks if (signalon ()) /* if blinking time over os_create_task (LIGHTS);...
  • Page 57 RTX TINY os_wait (K_TMO, 30, 0); /* wait for timeout: 30 ticks stop = 0; /* green light for walkers walk = 1; os_wait (K_TMO, 100, 0); /* wait for timeout: 100 ticks stop = 1; /* red light for walkers walk = 0;...
  • Page 58 Application Examples #define ILEN /* size of serial receiving buffer unsigned char istart; /* receiving buffer start index unsigned char iend; /* receiving buffer end index idata char inbuf[ILEN]; /* storage for receiving buffer unsigned char itask = 0xff; /* task number of output task #define CTRL_Q 0x11...
  • Page 59 RTX TINY otask os_running_task_id output task number os_wait (K_SIG, 0, 0); /* RTX-51 call: wait for signal otask = 0xff; /* clear output task number putbuf (0x0D); /* send CR before LF for <new line> while (sendfull) /* wait for transmission buffer empty otask os_running_task_id output...
  • Page 60 Application Examples switch process character case CTRL_S: sendstop = 1; /* if Control+S stop transmission break; case CTRL_Q: start_trans = sendstop; /* if Control+Q start transmission sendstop = 0; break; default: /* read all other characters into inbuf if (istart + ILEN != iend) inbuf[iend++ &...
  • Page 61 RTX TINY timer = 1; /* enable serial port interrupt GETLINE.C /***************************************************************************** GETLINE.C: Line Edited Character Input /***************************************************************************** #include <stdio.h> #define CNTLQ 0x11 #define CNTLS 0x13 #define DEL 0x7F #define BACKSPACE 0x08 #define CR 0x0D #define LF 0x0A /***************/ /* Line Editor */ /***************/ void getline (char idata *line, unsigned char n) unsigned char cnt = 0;...
  • Page 62 ), and start the TRAFFIC application. Following is the list- ing of DS51.INI load ..\..\ds51\8052.iof /* load 8052 CPU driver*/ include dbg_tiny.inc /* load debug function for RTX51 Tiny */ /* define watch variables */ ws red ws yellow ws green ws stop ws walk /* set P1.5 to zero:...
  • Page 63 RTX TINY When DS51 starts executing TRAFFIC, the serial window will display the command menu and waits for you to enter a command. Change to the serial window with Alt+S type d and press the key. This will display the current time and the start and ENTER end time range for the traffic light.
  • Page 64 34, 37 K_SIG 34, 37 K_TMO 34, 37 C51 Library Functions C51 memory model CAN Communication Linking CAN Functions Linking RTX51 Tiny Programs Compiling Compiling RTX51 Tiny Programs CONF_TNY.A51 Configuration Variables Message Passing FREE_STACK Multiple Data Pointer INT_CLOCK Multitasking Routines...
  • Page 65 Round-Robin Scheduling Task Switching RTX51 Technical Data Introduction Timer 0 RTX51 Full Interrupt RTX51 Tiny TIMESHARING 18, 22 RTX51 Tiny Configuration TMO_EVENT 34, 38 RTX51 Tiny System Functions RTX51TNY.H 15, 21 RTX51TNY.LIB Using Signals Using Time–outs SIG_EVENT 34, 36, 38...
  • Page 66 Keil Elektronik GmbH.
  • Page 67 Keil Software is market in the United States and Canada also under the Franklin Software, Inc. KEIL ELEKTRONIK GmbH has representatives in the following countries: Australia, Austria, Belgium, CFR, Denmark, Finland, France, Germany, India, Ireland, Israel, Italy, Netherlands, Norway, Poland, Spain, South Africa, Sweden, Switzerland, Taiwan, United Kingdom, United States and Canada.
  • Page 68 RTX51 TINY REAL– TIME OPERATING SYSTEM User’s Guide 2.95...

Table of Contents