Home
RTX Tiny
Contents
1. PORT1 0x20 set Port1 5 twatch 50000 wait 50 ms PORTI amp 0x20 reset Port1 5 define F4 key as call to button set F4 button You can start the execution of the application TRAFFIC with the GO command g RTX TINY When 0551 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 ENTER key This will display the current time and the start and end time range for the traffic light For example Start Time 07 30 00 End Time 18 30 00 Clock Time 12 00 11 type ESC to abort As the program runs you can watch the red yellow and green lamps of the traffic light change The pedestrian button is simulated using F4 Press F4 to see the traffic light switch to red and the walk light switch to on You can display the task status using F3 much as before The following task information will be displayed 4 Task ID Start State Wait for Event i Signal Timer Stack 1 4 4 4 4 4 4 0 0026H DELETED i 0 i 1244221 84H 1 OOD1H WAITING SIGNAL 1 0 3 2231 4 84H 2 0043H WAITING 0 5 86H 3 0278H DELETED 1 0 2021771 88H 4 O2ACH WAITING SIGNAL amp TIMEOUT 0 220 88H
2. esses nren rennen enne 49 Traffic Light Controller 49 esee eie edu e eerie 49 Compiling and Linking TRAFFIC esent 62 Testing and Debugging TRAFFIC anon ae aneve e enes eee e eee eneve oren 62 RTX Tiny Notational Conventions This manual uses the following format conventions Examples Courier KEYS ALT lt x gt CTRL lt x gt Description 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 For example CLS DIR DS51 INI C51 A51 SET Note that you are not actually required to enter these commands using all capital letters Text in this typeface is used to represent the appearance of information that would be displayed on the screen or printed on the printer This typeface is also used within the text when discussing or describing items which appear on the command line Text in this typeface represents actual keys on the keyboard For example Press Enter to Continue Indicates an Alt key combination the Alt and the x key must be simultaneously pressed Indicates an control key combination the ct x1 and the x key must be simultaneously pressed RTX Tiny 7 Overview RTXSI is a multitasking real time operating system for the 80
3. You can communicate with the traffic light controller via the serial port interface of the 8051 You can use the serial window of DS51 to test the traffic light controller com mands The serial commands that are available are listed in the following table These commands are composed of ASCII text characters All commands must be terminated with a car riage return Command Serial Text Description Display clock start and ending times Set the current time in 24 hour format Set the starting time in 24 hour format The traffic light controller operates normally between the start and end times Outside these times the yellow light flashes Set the ending time in 24 hour format Software The TRAFFIC application is composed of three files that can be found in the C51V4 RTX_TINY TRAFFIC or CDEMO 5SI RTX_TINY TRAFFIC directory TRAFFIC C contains the traffic light controller program which is divided into the fol lowing tasks Task 0 Initialize initializes the serial interface and starts all other tasks Task 0 deletes itself since initialization is only needed once e Task 1 Command is the command processor for the traffic light controller This task controls and processes serial commands received e Task 2 Clock controls the time clock e Task 3 Blinking flashes the yellow light when the clock time is out side the active time range 50 Application Examples e Task 4 Lights controls the traffic light ph
4. int counterl counter for task 1 int counter2 counter for task 2 int counter3 counter for task 2 JAKAKAKKKKKKKKKKKKKKKKK KOK KO K k k K K K K K K K K K R OR R R R K R KOK KOR OR KOR KOK KOK o o e e K R R R Task 0 job0 RTX51 tiny starts execution with task 0 VE k k k k k k k k k k k k k k k k k k K KOK KKK KA K K K k k k K K K K K K K K OR R R R R RO KOR RK KOR KOR KOK KO o o o e R R R R R R R R jobo task 0 os create task 1 start task 1 os create task 2 start task 2 os create task 3 start task 3 while 1 endless loop counter0 increment counter 0 os wait K TMO 5 0 wait for timeout 5 ticks k dsl k k k k k k k k k k k k k k k k KKK k k k k K k k k K K K K K R K K K R K KOR 7 Task 1 jobl RTX51 tiny starts this task with os create task 1 JAKAKAKKKKKKKKKKKKKKKKK KKK k k k K k k k k k k K K K K K K K K R K R R R KKK KOR KOR KOK KO O 7 jobl task 1 while 1 1 endless loop counteritt increment counter 1 os wait K TMO 10 0 wait for timeout 10 ticks BRR k k k k k k k k k k k k k k KKK k k k k HK k k k k k k K K K K K K R R R R R R KKK KOR KOR OK K KO o 7 Task 2 job2 RTX51 tiny starts this task with os create task 2 KK RRR KR RIKKI KK RIK HK k k k k k k k k k k K K K K K K K K K R R R R KOR R KOR KOR KOK KO o 7 job2 task 2 1
5. RTX51 Tiny Function Library include lt rtx51tny h gt char os_wait unsigned char event_sel events to wait for unsigned char ticks timer ticks to wait unsigned int dummy unused argument The os wait 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 The event sel argument specifies the event or events to wait for and can be any combination of the fol lowing manifest constants Event constant Description Wait for a timer tick interval Wait for a signal Wait for a time out The above events can be logically ORed using the vertical bar character 1 For example K TMO K SIG specifies that the task wait for a time out or for a signal 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 When one of the specified events occurs the task is enabled for execution Execution is restored and a manifest constant that iden tifies the event that restarted the task is returned by the os wait function Possible return values are 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 os waitl os vvait2 include l
6. tions can use the remaining registerbanks However RTX51 Tiny requires 6 permanent bytes in the registerbank area The registerbank used by RTX51 Tiny for these bytes can be defined with the configurarion variable INT REGBANK Refer to chapter 3 RTX51 Tiny configuration for more information Task Definition Real Time or multitasking applications are composed of one or more tasks that perform specific operations RTX51 Tiny allows for up to 16 tasks Tasks are simply C functions that have a void return type and a void argument list and are declared using the task function attribute using the following format void func void task num where num is a task ID number from 0 to 15 Example void jobO void task 0 while 1 counter0 increment counter defines the function jobO to be task number 0 All that this task does is increment a counter and repeat You should note that all tasks are implemented as endless loops in this fashion 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 Description RUNNING The task currently being executed is in the RUNNING State Only one task can be running at a time READY Tasks which are waiting to be executed are in the READY STATE After the currently running task has finished processing RTX51 Tiny starts t
7. 18 30 storage for end time values 20 sbit P1 2 I O Pin red lamp output MM yellow 171 I O Pin yellow lamp output green 1 0 I O Pin green lamp output aot stop P 123 I O Pin stop lamp output oe walk 1 4 I O Pin walk lamp output ae key P1 5 I O Pin self service key input idata char inline 16 storage for command input line Vlde k k k k k k k k k k k k k k k k k k k k k k k k k k K k K K K K K k k k k K K KOK K R K RO R R R R R o o o O R OOO RO R KKK e Task 0 init Initialize x7 BR RRR RRR k k k k k k k k k k k k k k k k k k k k k k k k k k k k K K K K K k k k k K K K K K K R R R R KR K k o o o O K R OR RO R R R R e e eA 51 52 Application Examples init task INIT program execution starts here x serial init initialize the serial interface i os create task CLOCK start clock task e os create task COMMAND start command task 0 os create task LIGHTS start lights task 0 os create task KEYREAD start keyread task i os delete task INIT stop init task no longer needed bit display time 0 flag signal cmd state display time n Vlde k k k k k k k k k k k k k k k k k k k k k k k k k k k k K K K K K k k k k k K KOK KOK KOR K R R K K o o oK KO K O ORO RO R R R EE i Task 2 clock x RRR KKK HK RIK ELE k k k k k k k k k k k k k k k K K K K K k k k k k k KOK R K R R R K R K K
8. be executed in synchronous intervals a simple example is a clock RTX Tiny 19 Note The event SIGNAL can be combined with the events TIMEOUT and so that RTX51 Tiny waits for both a signal and a time period 21 RTX Tiny Creating RTX51 Tiny Applications Writing RTX51 Tiny programs requires that you include the RTXSITNY H header file found in the C51 INC subdirectory in your C program and that you declare your tasks 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 You can modify the RTXSI Tiny configuration file CONF 51 found in the C51 LIB subdirectory You can change the following parameters in this configuration Register bank used for the system timer tick interrupt Interval for the system timer Round robin time out value Internal data memory size Free stack size after RTX51 Tiny is started portion of this file is listed below This file is part of the RTX51 tiny Real Time Operating System Package CONF TNY A51 This code allows configuration of the RTX51 tiny Real Time Operating System To translate this file use A51 with the following invocation A51 CONF TNY A51 To link the modified CONF TNY OBJ file to your application use the following BL51 invocation BL51 your object file list CONF TNY OBJ controls With the followin
9. while 1 1 endless loop counter2 increment counter 2 if counter2 0 signal overflow of counter 2 os send signal 3 to task 3 VE k k k k k k k k k k k k k k k k k k K K k KOK K K K k k k k K K k K K e K R R R R R R RO He He KOR R KOR KOK KO 7 Task 3 job3 RTX51 tiny starts this task with os create task 3 k k k k k k k k k e K KOK KOK OK k K K K k k k k K K K K K K K R K R R R RK KK KOR KOK KOK KO K k o e K O R R R R R R R k job3 task 3 1 while 1 1 endless loop os wait K SIG 0 0 wait for signal counter3 process overflow from counter 2 48 Application Examples Enter the following commands at the DOS prompt to compile and link RTX_EX2 C51 RTX EX2 C DEBUG OBJECTEXTEND BL51 RTX 2 RTX51TINY When RTX_EX2 is compiled and linked you can test it using DS51 Type DS51 RTX EX2 to run DS51 and load RTX EX2 When DS51 is loaded type the following commands at the DS51 command prompt WS counterO WS counteri WS counter2 WS counter3 G 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 countero counteri counter2 counter3 incremented every 5 RTX51 timer ticks incremented every 10 RTX51 timer ticks incremented as fast as possible this task gets most of the available CPUS time increment
10. 5 032BH WAITING TIMEOUT 0 Te 8AH I 6 OOOEH WAITING SIGNAL 0 If the Exe window is not large enough to show the entire status text you can press ALTAR to remove the register window You can also increase the vertical size of the Exe window Press ALT E to select the Exe window then enter ALT U several times to in crease the size of the window When you are through using DS51 type EXIT atthe DS51 command prompt 63 64 A Application Example RTX Example TRAFFIC Arithmetic Unit bank switching BITBUS Communication C C51 Library Functions C51 memory model CAN Communication CAN Functions Compiling Compiling RTX51 Tiny Programs 51 Configuration Variables FREE STACK INT CLOCK INT REGBANK RAMTOP STACK ERROR TIMESHARING D DBG TINY INC Debugging with dScope 51 Development Tool Requirements E Event Interval Signal Timeout F FREE STACK 45 47 49 16 15 12 16 15 12 13 11 23 21 22 22 22 22 22 22 42 41 15 9 12 18 18 18 18 22 Application Examples INT CLOCK INT REGBANK Interrupt Handling Interrupts isr send signal K K IVL K SIG K TMO L Linking Linking RTX51 Tiny Programs Message Passing Multiple Data Pointer Multitasking Routines isr send signal os clear signal Os create task os delete task os running tas
11. K K KOK KOR R RO KR R R R o o oK K K R OR R R R R R e e e n serial init initialize serial interface 0 RRR KR KK RIK KKK KKK KI HK e e e KR IH KI KKK HK RIK KKK KI x serial init SCON 0x50 mode 1 8 bit UART enable receiver e TMOD 0x20 timer 1 mode 2 8 Bit reload 0 TH1 Oxf3 reload value 2400 baud ei RTX TINY 61 TR1 2 1 timer 1 run enable serial port interrupt GETLINE C olde k k k k k k k k k k k k K k k k k k k k k k k k k k k k K K K K k K k k k k K KI HK R K K R R R K K R o o K K K K O OR R RO R e e ke e x SH GETLINE C eu SH BR RRR KKK RIK KKK KKK KI KKK k k KKK KKK KKK KKK K K K k k k K K KKK KKK KKK KKK KKK KKK K ORO RO RO RO R R R ke K e Line Edited Character Input include stdio h define CNTLQ 0 11 define CNTLS 0 13 define DEL Ox7F define BACKSPACE 0x08 define CR OxOD define LF 0 0 fk dee eee eee gt Line Editor JAKKAKKKKKKKKKKKJ void getline char idata line unsigned char n unsigned char cnt 0 char c do if c _getkey CR c read character e if c BACKSPACE c DEL process backspace p if cnt 0 cnt decrement count X line and line pointer 7 putchar 0x08 echo backspace d putchar putchar 0x08 else if c CNTLO 86 CNTLS ignore Control S Q 7 putchar line c echo and store character
12. You write and compile RTX51 programs using standard C constructs and compiling them with C51 Only a few deviations from standard C are required in order to specify the task ID and priority RTX51 programs also require that you include the real time executive header file and link using the BL51 Linker Locator and the appropriate RTX51 library file 8 RTX51 Real Time Operating System Single Task Program A standard C program starts execution with the main function In an embedded applica tion main is usually coded as an endless loop and can be thought of as a single task which is executed continuously For example int counter void main void counter 0 while 1 repeat forever counter tt increment counter Round Robin Program A more sophisticated C program may implement what is called a round robin pseudo multitasking scheme without using a RTOS In this scheme tasks or functions are called iteratively from within an endless loop For example int counter void main void counter 0 while 1 repeat forever check serial io process serial cmds process serial input check kbd io process kbd cmds process keyboard input adjust ctrlr parms adjust the controller counter tt increment counter Round Robin Scheduling With RTX51 RTXSI also performs round robin multitasking which allows quasi parallel execution of several endless loops o
13. a aa ee 18 CREATING RTX51 TINY APPLICATIONS 21 RTX51 Tiny Contig ration ene etr ee re leer tende e eed Hae rer 21 Cornipiling RTX51 Tiny Prograt s ass eene diiit ce tei de pee en ee 23 Linking RTX51 Tiny Programs 22422010 00 0 un trennen nest ne enne ente enne enne enne 23 Optimizing Tiny Programs ee d tee Deren into twee UE 23 RTX51 TINY SYSTEM FUNCTIONS 25 Function Reference ger eR eU RD aen Qn UI Ore Uie p EE 26 isr send sionale en dt REP ee IUBE 27 et Sos 28 Preface 3 OS create Laska Eundem gne 29 OS delete TASK tdi 30 os runtiiig 6 Dede n s shkro 31 OSS SON renal n D E EE 32 OS WAL bose Su an Du e ERS 34 cd D T 36 n ht dd O 37 SYSTEM DEBUGGING PRES ERES anna nans REPER REP ESE tee 41 Stack Management sis uertit te DB EE UE De dost 41 Debugging with dScope 51 u me gen RU REO ee oun cee seis e e EE 41 APPLICATION EXAMNPLES PESE EP SS REP aaa Q J 45 RTX EXIT Your First REX JI Program 35 eet ert tre Sas UE RE PH RE Eee eee au 45 RTX EX2 A Simple RTX51 Application vr ee ore enes nennen 47 TRAFFIC A Traffic Light Controller
14. area The layout of the RTX 51 tasks is described under Stack Management earlier in this chapter 44 RTX51 Tiny Specifications RTX TINY 45 Application Examples RTX EX1 Your First RTX51 Program The program RTX EXI demonstrates round robin multitasking using RTX51 Tiny This program is composed of only one source RTX EXI C located in the C51V4 RTX_TINY RTX_EX1 CDEMO 51 RTX_TINY RTX_EX1 directory The contents of RTX EXI C is listed below RRR k k k k k k k k k k k k k k k k k k k k k k k k K k k k k k k K k k K K K K K R K K R HK R KOR 5 RTX EX1 C The first RTX51 Program 52 JAKAKAKKKKKKKKKKKKKKKKK k k k k k k k k k k k k k k K K K K K K K K K K R R KOR RO R KOR KOR KO o 7 pragma CODE DEBUG OBJECTEXTEND include lt rtx5ltny h gt RTX51 tiny functions amp defines int countero counter for task 0 Ea int counterl counter for task 1 int counter2 counter for task 2 VE k k k k k k k k k k k k k k k k k k k k HK k k k k k k k k k k k k K K K 7 Task 0 jobo RTX51 tiny starts execution with task 0 JAKAKAKKKKKKKKKKKKKKKKK k k k k k k k k k k k k K k K K K K K K K R R R R K R KOR He He R KOR KOK KO o 7 jobO task 0 os_create_task 1 start task 1 os_create_task 2 start task 2 while 1 1 endless loop counter0 increment counter 0 JAKAKAKKKKKKKKKKKKK k k k k k k k k k k k k k k k K K k K K K K R K K K R R
15. dScope 51 Stack Management RTXSI 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 The following figure illustrates the stack assignment of the individual tasks RAMTOP RAMTOP RAMTOP OFFH OFFH Stack Area Stack Area for Task 2 for Task 2 OF8H Stack Area Stack Area for Task 1 for Task 2 OFOH Stack Area for Task 1 60H Stack Area Stack Area for Task 0 for Task 1 58H Stack Area Stack Area PSTACK for Task 0 for Task 0 PSTACK 50H 50H Stack Assignment for Stack Assignment for Stack Assignment for Tasko z Running Task Task1 Running Task Task2 Running Task The figure illustrates that RTX51 Tiny always allocates the entiere free memory as a stacka area for thye currently running task The memory used for the stack starts at the symbol STACK which denotes the start address of the STACK segment The 2STACK symbol reserves the first unassigned byte in the internal memory Debugging with dScope 51 A RTXSI Tiny application can be tested using the dScope 51 Source Level Debugger The RTXSI system status is displayed using a debug function The use of this debug function is explained in the following 42 RTX51 Tiny Specifications T
16. events to wait for unsigned char ficks P timer ticks to wait 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 The event sel argument specifies the event or events to wait for and can be any combination of the fol lowing manifest constants Event constant Description Wait for a timer tick interval Wait for a signal Wait for a time out The above events can be logically ORed using the vertical bar character 1 For example K TMO K SIG specifies that the task wait for a time out or for a signal The ticks argument specifies the number of timer ticks to wait for an interval event K IVL or a time out event K TMO When one of the specified events occurs the task is enabled for execution Execution is restored and the manifest constant that identifies the event that restarted the task is returned by the os wait2 function Possible return values are 37 38 See Also Example Return Value SIG EVENT TMO EVENT NOT OK os wait os waitl See os wait RTX51 Tiny Function Library Description A signal was received A time out has completed or an interval has expired The value of the event sel argument is invalid RTX Tiny 39 RTX Tiny 41 System Debugging This chapter contains additonal information about the stack handling and the system de bugging with
17. order to trig ger for an interrupt RTX51 Tiny does not contain any management for interrupts for this reason the interrupt enable is sufficient to process interrupts 15 16 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 RTXSI Tiny Except for a few 8051 instructions the timer 0 interrupt should not be dis abled Reentrant Functions It is not allowed to call non reentrant C functions from several tasks or interrupt proce dures Non reentrant C51 functions store their parameters and automatic variables local data in static memory segments for this reason this data is overwritten when multiple function calls occur simultaneously Therefore non reentrant C functions can only be call for several tasks if the user can ensure that they are not called recursive Usally this means that the Round Robin task scheduling must be disabled and that such functions do not call any RTX51 Tiny system functions C functions which are only using registers for parameter and automatic variables are in herently reentrant and can be called without any restrictions from different RTX51 Tiny tasks The C51 Compiler provides also reentrant functions Refer to the C51 User s Manual for more information Reentrant functions store their parameters and local data variables on a reentrant stack and th
18. 1 programming language This makes generation of RTXSI applications very easy to master The previous examples are executable RTX51 programs You do not need to write any 8051 assembly routines or functions You only have to compile your RTX51 programs with C51 and link them with the BLSI Linker Locator For example you should use the following command lines if you are using RTX51 Tiny C51 EXAMPLE C BL51 EXAMPLE OBJ RTX51TINY Use the following command lines to compile and link using RTX51 11 12 RTX51 Real Time Operating System C51 EXAMPLE C BL51 EXAMPLE OBJ RTX51 Interrupts RTXSI works in parallel with interrupt functions Interrupt functions can communicate with RTX51 and can send signals or messages to RTX51 tasks RTX51 Full allows the assignment of interrupts to a task Message Passing RTX51 Full supports the exchange of messages between tasks with the functions SEND amp 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 CAN Communication Controller Area Networks are easily implemented with RTX51 CAN RTXSI CAN 15 a CAN task integrated into RTX51 Full A RTX51 CAN task implements message passing via the CAN network Other CAN stations can be configured either with or without 51 BITBUS Communication RTX51 Full covers Master and Slave BITBUS task
19. 51 family of processors RTX51 simplifies software design of complex time critical projects There are two distinct versions of RTX51 available RTX51 Full Performs both round robin and preemptive task switching using up to four task priorities RTX51 works in parallel with interrupt functions Signals and messages may be passed between tasks us ing a mailbox system You can allocate and free memory from a memory pool You can force a task to wait for an interrupt time out or signal or message from another task or interrupt RTX51 Tiny Is a subset of RTXSI that will easily run on single chip 8051 sys tems without any external data memory RTXSI Tiny supports many of the features found in RTX51 with the following excep tions RTXSI Tiny only supports round robin and the use of sig nals for task switching Preemptive task switching is not sup ported 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 Introduction Many microcontroller applications require simultaneous execution of multiple jobs or tasks For such applications a real time operating system RTOS allows flexible sched uling of system resources CPU memory etc to several tasks RTX51 implements a powerful RTOS which is easy to use RTX51 works with all 8051 derivatives
20. 7 line increment line pointer x cnttt and count 7 while cnt lt n 1 amp amp c LF check limit and line feed SH 62 Application Examples line 0 mark end of string Compiling and Linking TRAFFIC Enter the following commands at the DOS prompt to compile and link TRAFFIC C51 TRAFFIC C DEBUG OBJECTEXTEND RF TRAFFIC REG C51 SERIAL C DEBUG OBJECTEXTEND RF TRAFFIC REG C51 GETLINE C DEBUG OBJECTEXTEND RF TRAFFIC REG BL51 QTRAFFIC LIN Alternatively there is a batch file called TRAFFIC BAT that you can use to compile link and automatically run DS51 Testing and Debugging TRAFFIC Once you have compiled and linked TRAFFIC you can test it using DS51 Type DS51 TRAFFIC to run DS51 and load including DS51 INI initialization file This file will automati cally load the IOF driver load the traffic program load an include file for displaying task status active watchpoints for the traffic lights define a function for the pedestrian button which is activated using F4 and start the TRAFFIC application Following is the list ing of DSSLINI load N Nds51N8052 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 Key Input PORTI amp 0x20 define a debug function for the pedestrian push button signal void button void
21. ELETED TIME OUT Description The task currently being executed is in the RUNNING State Only one task can be running at a time Tasks which are waiting to be executed are in the READY STATE After the currently running task has finished processing RTX51 Tiny starts the next task that is ready Tasks which are waiting for an event are in the WAITING STATE If the event occurs the task is placed into the READY STATE Tasks which are not started are in the DELETED STATE Tasks which were interrupted by a round robin time out are placed in the TIME OUT STATE This state is equivalent to the READY STATE Indicates which events the task is currently waiting for The events can be a combination of the following TIMEOUT SIGNAL Description The task is in the state VVAITING until the Timer reaches the value 0 This event is displayed when the os wait function is called with the K TMO or K IVL event selector The task is in the state VVAITING until the signal flag goes to one This event is displayed when the os wait function is called with the K SIG event selector Indicates the state of the signal flag 1 for signal set O for signal reset Indicates the number of timer ticks which are required for a timeout It should be noted that the Timer is free running and only set to the timeout value when the os wait function is called with a K TMO ar gument Indicates the start address of the local task stack in the IDATA
22. K k k k k K KOK HK K R K R R KR KR K K o o o KO R OOO R R R R R K signalon check if clock time is between start and end RRR KKK k k k k k k k k k k k k k k k k k k k k k k k KKK HK K K K K K k k k k K K KOK KKK KOR R KR K R o o o O R R OR RO R R KKK KE bit signalon if memcmp amp start amp end sizeof struct time lt 0 if memcmp amp start amp ctime sizeof struct time lt 0 amp amp memcmp amp ctime amp end sizeof struct time 0 return 1 else if memcmp tend amp ctime sizeof start gt 0 amp amp memcmp amp ctime amp start sizeof start 0 return 1 return 0 signal off blinking on JAKKAKKKKKKKAKKKKKK k k k k k k k k k k k k k k k k k K K K K K K k k k k K KKK K K R KOR R KR K R o o o o OR ORO RO R R R R R e x Task 3 blinking runs if current time is outside start amp end time x BRR RRR RK KI HK KKK KKK RIK k k k k k k k k k k k he k k K K K k k k k k k k ke ke K K KO KOR R R K K ooo o O K OOO R RO R R R e blinking _task_ BLINKING blink yellow light x red 0 all lights off x yellow green stop walk H H while 1 endless loop 20 56 Application Examples yellow 1 yellow light on os wait K TMO 30 0 wait for timeout 30 ticks 0 yellow 0 yellow light off ei os wait K TMO 30 0 wait for timeout 30 ticks 0 if signalon if blinking time over x o
23. KK IK KIKI He He He He He He He He He He e e e e e i char putchar char c if c n expand new line character i while sendfull wait for transmission buffer empty E RTX TINY otask os running task id 0 set output task number x os wait K SIG 0 0 RTX 51 call wait for signal x otask Oxff clear output task number x putbuf 0 0 send CR before LF for new line while sendfull wait for transmission buffer empty x otask os running task id 0 set output task number os_wait K_SIG 0 0 RTX 51 call wait for signal otask Oxff clear output task number x putbuf c send character return c return character ANSI requirement Vlde k k k k k k k k k k k k k k k k k k k k k k k k k k k k K K K K K k k k k K k K K K K R KOR R R RIK KKK KI O O ORO RO R R R R R KE x _getkey x Vlde k k k k k k k k k k k k k k k k k k k k k k k k k k k k K K K k K k k k k k k kO K K K KOR R KR K R o o o K o O ORO R R KKK KE char _getkey void interrupt controlled _getkey while iend istart itask os_running_task_id set input task number x os wait K SIG 0 0 RTX 51 call wait for signal x itask Oxff clear input task number x return inbuf istart amp ILEN 1 RRR KKK k k k k k k k k k k k k k k k k k k k k k k k k k k k k K K K K K k k k k K ee ke e R R KOR R R K K o o o KOR R R OR R
24. NC at the DS51 command prompt This will load an include file that allows you to display status information of the tasks You may need to increase the size of the exe window us ing ALT U so all of the task information is displayed Once the include file is loaded press F3 to display status information for the three tasks defined in this program Task ID Start State Wait for Event i Signal Timer Stack 1 4 4 4 4 4 4 0 0 OOOEH TIMEOUT 4 0 1 ZI 4 20H 1 0023H RUNNING 1 0 2173 1 2FH 1 2 002EH TIMEOUT 1 0 ZUR FOH RTX TINY 47 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 or CDEMO 51I RTX_TINY RTX_EX2 di rectory The contents of RTX EX2 C is listed below JAKAKAKKKKKKKKKKKKKKKKKKKKK K K k K k K K K K K K K K K R R R K KKK KOR KOR KOK KO 7 RTX_EX2 C A RTX51 Application RRR k k k k k k k k k k k k k k K k k K k k k K K K HK K K k K K K K K K K K K K He R KOR HK He He He K KOR KOR KOK KOK o 7 pragma CODE DEBUG OBJECTEXTEND include lt rtx5ltny h gt RTX51 tiny functions amp defines int counter0 counter for task 0
25. 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 RTXSI 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 RTXSI Tiny Applicaitons describes the steps necessary to cre ate RTX51 Tiny applications Library Functions provides a reference for all RTX51 Tiny
26. R KOR 7 Task 1 jobl RTX51 tiny starts this task with os create task 1 RRR k k k k k k k k k k k k k k k k k k k k k HK k k k k k k k k K K K K K K K K R K R K KOR KOR KOR KOR KO KO o 7 jobl task 1 1 while 1 1 endless loop counteritt increment counter 1 JAKAKAKKKKKKKKKKKKKKKKKKKKK e e k k k k k k k k K K K K K K K R e R R ke KOR KOR KOR KOR ke e o 7 Task 2 job2 RTX51 tiny starts this task with os create task 2 BRR k k k k k k k k k k k k k k k k K k k k k k k k k k k k k k k k k k k K K K K K K K K R R KOR KOR KOR KOR KOK KOK o 7 job2 task 2 1 while 1 1 endless loop counter2 increment counter 2 To compile and link RTX_EX1 type the following commands at the DOS command prompt C51 RTX_EX1 C DEBUG OBJECTEXTEND BL51 RTX_EX1 OBJ RTX51TINY Once RTX_EX1 is compiled and linked you can test it using DS51 Type 46 Application Examples DS51 RTX EX1 INIT RTX_EX1 INI The INIT RTX EX1 INI directive loads an initialization file that configures the DS51 screen loads the appropriate IOF driver file initializes watchpoints for the variables counter0 counterl and counter2 and finally starts execution of RTX 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 Enter CTRL C to halt execution of RTX EXI then type INCLUDE DBG TINY I
27. R R R R R e serial RRR KKK HRI KKK KKK KK IK k k k k k k k k k k k k k K K K K K K k k k k K K KOK K K K R KOR R K e o o oK KOR K K K OR R e e e e e serial receiver transmitter interrupt serial interrupt 4 using 2 use registerbank 2 for interrupt unsigned char c bit start_trans 0 if RI if receiver interrupt SBUF read character 4 0 clear interrupt request flag nA 59 60 Application Examples switch c 1 process character 0 case S sendstop 1 if Control S stop transmission x break case CTRL OQ start trans sendstop if Controlto start transmission eu sendstop 0 break default read all other characters into inbuf 7 if istart ILEN iend inbuf iend ILEN 1 c if task waiting signal ready t if itask OxFF isr send signal itask break if TI start trans if transmitter interrupt gt 0 clear interrupt request flag i if ostart oend if characters in buffer and 0 if sendstop if not Control S received 0 SBUF outbuf ostart amp OLEN 1 transmit character x sendfull 0 clear sendfull flag i if task waiting signal ready 2 if otask OxFF isr send signal otask else sendactive 0 if all transmitted clear sendactive i boi k k k k k k k k k k k k k k k k k k k k k k k k k k K K K K K K k k k k k k
28. ases while the clock time is in the active time range between the start and end times e Task 5 Button reads the pedestrian push button and sends signals to the lights task Task 6 Quit checks for an ESC character in the serial stream If one is encountered this task terminates a previously specified display command SERIAL C implements an interrupt driven serial interface This file contains the functions putchar and getkey The high level I O functions printf and getline call these basic I O routines The traffic light application will also operate without using interrupt driven serial I O but will not perform as well GETLINE C is the command line editor for characters received from the serial port This source file is also used by the MEASURE application TRAFFIC C e x TRAFFIC C Traffic Light Controller using the C51 Compiler e CK hehe hee kk ke k eek k k k k k e Kk k K K K e ke ek ke KK K dee KK KK KKK KA KAKAKAKKKKKKAKKKAKAKKK ui code char menu An TRAFFIC LIGHT CONTROLLER using C51 and RTX 51 tiny n This program is a simple Traffic Light Controller Between start time and end time the system controls a traffic light n with pedestrian self service Outside
29. cter entered x RRR KKK RIKKI KK RIKKI KKK k k k k k k k k k k k k K K K K K k k k k K K KOK K K KOR R KR KR R K ok o o O K K CLE e e e e e x Task 6 get escape check if ESC escape character was entered E olde k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k K K K K K k k k k K K K K K R R R R R KR K K o o o K OR OOO RO R R R R R e x7 get escape task GET ESC while 1 endless loop x if getkey ESC escape 1 set flag if ESC entered x if escape if escape flag send signal x os send signal COMMAND to task command x RRR KKK KR IK RIK KKK k k k k k k k k k k k k k k k K K K K K k K k k k k K K KOK K R K R R R KR K K o o oK OO K CLE R R EE Task 1 command command processor loi k k k k k k k k k k k k k k k k k k k k k k k k k k k k k K K K K k K k k k k K K KOK K K R R R R R R R o o oK K K K RO OR R R R e e e x command task COMMAND unsigned char i printf menu display command menu while 1 endless loop printf nCommand display prompt x 54 Application Examples getline amp inline sizeof inline get command line input x for i 0 inline i 0 i convert to uppercase i inline i toupper inline i for i 0 inline i skip blanks e switch inline i proceed to command function i case D Display Time Command gt printf Start Time 02bd 02b
30. d 02bd End Time 02bd 02bd 02bd n start hour start min start sec end hour end min end sec printf type ESC to abort Nr os create task GET ESC ESC check in display loop x escape 0 clear escape flag e display time 1 set display time flag x os clear signal COMMAND clear pending signals i while escape while no ESC entered i printf Clock Time 02bd 02bd 02bd r display time eu ctime hour ctime min ctime sec os wait K SIG O 0 wait for time change or ESC 0 os delete task GET ESC ESC check not longer needed x display time 0 clear display time flag x printf n n break case T Set Time Command x if readtime amp inline i 1 read time input and e ctime hour rtime hour store ctime t ctime min rtime min ctime sec rtime sec break case E Set End Time Command 0 if readtime amp 1 1 1 read time input and 2 end hour rtime hour store in end RTX TINY 55 end min rtime min end sec rtime sec break case S Set Start Time Command if readtime amp inline i 1 read time input and x start hour rtime hour store in start x start min rtime min start sec rtime sec break default Error Handling printf menu display command menu break JAKKAKKKKKKKAKKKKKKKKKK k k k k k k k k k k k k k k K K K K
31. dance with the terms of the agreement It is against the law to copy the software on any medium except as specifically allowed in the license or nondisclosure agreement The purchaser may make one copy of the software for backup purposes No part of this manual and or databases may be reproduced or transmitted in any form or by any means electronic or mechanical including photocopy ing recording or information storage and retrieval systems for any purpose other than for the purchasers personal use without the express written permission of Keil Elektronik GmbH Copyright 1995 Keil Elektronik GmbH All rights reserved Printed in the Germany ISHELL Keil C166 Keil C51 dScope and Professional Developers Kit are trademarks of Keil Elektronik GmbH Microsoft MSDOSG Windows and MASMQ are registered trademarks of Microsoft Corporation IBM and PCO are registered trademarks of International Business Machines Corporation Intel MCS AEDIT ASMSI and PL M31 are registered trademarks of Intel Corporation Germany and Europe KEIL ELEKTRONIK GmbH Bretonischer Ring 15 D 85630 Grasbrunn b M nchen Tel 49 089 46 50 57 FAX 49 089 46 81 62 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 P
32. determines the task id of the currently executing task function 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 os_create_task os_delete_task include lt rtx5ltny h gt include lt stdio h gt for printf void tst os running task void task 3 unsigned char tid tid os running task id tid 3 32 RTX51 Tiny Function Library os send signal Summary Description Return Value See Also include lt rtx51tny h gt char os_send_signal unsigned char task_id ID of task to signal 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 Otherwise the signal is stored in the signal flag of the task The os send signal function may be called only from task func tions The os send signal function returns a value of 0 if successful and if the specified task does not exist isr send signal os clear signal os wait RTX Tiny Example 33 include lt rtx5ltny h gt include lt stdio h gt 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 34 os wait Summary Description Return Value See Also Example
33. e data are protected in this way against multiple calls However RTX51 Tiny does not contain any management for the C51 reentrant stack If you are using reentrant functions in your application you must ensure that these functions do not call any RTX51 Tiny system functions and that reentrant functions are not interrupted by the Round Robin task scheduling of RTX51 Tiny The full version RTX51 Full contains a stack management for reentrant functions C51 Library Functions All C51 library functions which are reentrant can be used in all tasks without any restric tions For C51 library functions which are non reentrant the same restrictions apply as for non reentrant C functions Refer to Reentrant Functions for more information Usage of Multiple Data Pointers and Arithmetic Units The C51 compiler allows you to use Multiple Data Pointers and Arithmetic Units of vari ous 8051 derivatives Since RTX51 Tiny does not contain any management for these hardware components it is recommended that you are not using these components to gether with RTX51 Tiny However you can use Multiple Data Pointers and Arithmetic Units if you can ensure that there is no round robin task during the execution of program parts using such additional hardware components RTX Tiny Registerbanks 51 Tiny assigns all tasks to registerbank 0 For this reason all task functions must be compiled with the default setting of C51 REGISTERBANK 0 The interrupt func
34. e task for execution Otherwise the signal is stored in the signal flag of the task The isr_send_signal function may be called only from interrupt functions The isr_send_signal function returns a value of 0 if successful and if the specified task does not exist os clear signal os send signal os wait include lt rtx5ltny h gt void tst_isr_send_signal void interrupt 2 isr_send_signal 8 signal task 8 28 RTX51 Tiny Function Library os clear signal Summary Description Return Value See Also Example include lt rtx51tny h gt char os_clear_signal unsigned char task_id task ID of signal to clear The os_clear_signal function clears the signal flag for the task specified by task_id The os_clear_signal function returns a value of 0 if the signal flag was successfully cleared A value of 1 is returned if the specified task does not exist isr send signal os send signal include lt rtx5ltny h gt include lt stdio h gt for printf void tst_os_clear_signal void _task_ 8 os_clear_signal 5 clear signal flag in task 5 RTX Tiny 29 os create task Summary Description Return Value See Also Example include lt rtx51tny h gt char os_create_task unsigned char task_id ID of task to start The os_create_task function starts the defined task function using the task number specified by task_id The task i
35. eady while 1 loop forever counter0 update the counter void jobl void task 1 while 1 loop forever counter1 update the counter RTX51 Events Rather than waiting for a tasks time slice to be up you can use the os wait function to signal RTX51 that it can let another task begin execution This function suspends execu tion of the current task and waits for a specified event to occur During this time any number of other tasks may be executing Using Time outs with RTX51 The simplest event you can wait for with the os wait function is a time out period in RTXSI 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 The next example shows how you can use the os wait function to delay execution while allowing other tasks to execute 10 RTX51 Real Time Operating System include rtx5ltny h int counter0 int counterl void jobO void task 0 os create 1 mark task 1 as ready while 1 loop forever counter0 update the counter os wait 3 pause for 3 clock ticks void jobl void task 11 while 1 loop forever counter1 update the counter os_wait K_TMO 5 pause for 5 clock ticks In the above example jobO enables job1 as before But now af
36. ed for every overflow of counter2 Enter CTRL C to halt execution of RTX and enter F3 to display status informa tion for the four tasks defined in this program Task ID ee MMMM MMM MMM MMM MMM MMMM MMM MMM MMMM Start State Wait for Event i Signal Timer Stack 4 4 000 WAITING 0 5 28H 0032H WAITING TIMEOUT 0 10 2AH 0047H RUNNING I 0 I 196 2CH 005DH WAITING SIGNAL I 0 196 FDH a a MMM MMM MMM MMM MMM MMM MMMM MiM MiMi iii RTX_EX2 uses the os_wait function to wait for events The event that each task is wait ing for is shown in the displayed task list shown above RTX TINY 49 TRAFFIC A Traffic Light Controller The preceding examples RTX EXI and RTX_EX2 show only the basic features of RTX51 Tiny These examples could just as easily have been implemented without using RTXSI 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 TRAFFIC is a time controlled traffic light controller During a user defined clock time interval the traffic light is operating Outside this time interval the yellow light flashes If a pedestrian presses the request button the traffic light goes immediately into a Walk state Otherwise the traffic light works continuously Traffic Light Controller Commands
37. efines which task is running according to the following rules The currently running task is interrupted if 1 The task calls the 05 wait function and the specified event has not occurred 2 The task has executed for longer than the defined round robin time out Another task is started if 1 No other task is running 2 Thetask which is to be started is in the READY or TIME OUT State Events The os wait function of RTX51 Tiny supports the following event types SIGNAL Bit for task communication A signal can be set or cleared using RTX51 Tiny system functions A task can wait for a signal to be set before con tinuing If a task calls the os wait function to wait for a signal and if the signal is not set the task is suspended until the signal gets set Then the task is returned to the READY State and can begin execution TIMEOUT time delay which is started by the os wait function The duration of the time delay is specified in timer ticks The task who is calling the os wait funciton with a TIMEOUT value is suspended until the time delay is over Then the task is returned to the READY State and can begin execution INTERVAL A interval delay which is started by the os wait function The interval delay is also specified in in timer ticks The difference to a timeout delay is that the RTX51 timer is not reset Therefore the event INTERVAL works with a timer which is running permantly An interval can be used if the task is to
38. g EQU statements the initialization of the RTX51 tiny Hardware Timer can be defined RTX51 tiny uses the 8051 Timer 0 for controlling RTX51 software timers define the register bank used for the timer interrupt INT REGBANK EQU default is Registerbank 1 define Hardware Timer Overflow in 8051 machine cycles INT_CLOCK EQU 10000 default is 10000 cycles F TIMESHARING EQU 5 define Round Robin Timeout in Hardware Timer Ticks default is 5 ticks note Round Robin can be disabled by using value 0 22 Creating RTX51 Tiny Applications Note Round Robin Task Switching can be disabled by using 0 as p value for the TIMESHARING equate The following EQU statements defines the size of the internal RAM used for stack area and the minimum free space on the stack A macro defines the code executed when the stack space is exhausted define the highest RAM address used for CPU stack RAMTOP EQU OFFH default is address 256 1 FREE STACK EQU 20 default is 20 bytes free space on stack STACK ERROR MACRO CLR EA disable interrupts SJMP endless loop if stack space is exhausted ENDM This configuration file defines a number of constants that may be modified to suit the re quirements of your particular application These are described in the following table Variable Description INT REGBANK indicates which register bank is to be used by RTX51 Tiny for the sy
39. ge or set a semaphore call from task send a message call from interrupt receive a message call from interrupt define a memory pool get a block from a memory pool return a block to a memory pool define RTX51 system clock value Execution Time cycles 302 172 408 with task switch 316 with fast task switch 71 without task switch 57 46 68 for pending signal 160 for pending mes 119 96 81 80 443 with task switch 343 with fast task switch 94 without task switch 53 71 with message 644 size 20 10 bytes 148 160 67 13 Additional DEBUG and SUPPORT functions check mailboxes check tasks check mail check pool set int mask reset int mask check task CAN Functions only available with RTX51 Full CAN controllers supported Philips 82C200 80C592 and Intel 82526 more CAN con trollers in preparation CAN Function Description mN can_task_create create the CAN communication task can_hw_init CAN controller hardware initialization can_def_obj define the communication objects can start can stop start and stop the CAN communication can send send an object over the CAN bus can write write new data to an object without sending it can read read an objects data direct can receive receive all not bound objects can bind obj bind an object to a task task is started when object is received can unbind obj untie the binding between task and object can wait wait for receiving of a b
40. he debug function is defined in the file DBG_TINY INC for Windows dScope the file name is TINY DSW and is loaded within dScope 51 by entering the following commands The RTXSI 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 gt INCLUDE DBG TINY INC gt G lt gt i Task ID Start State Wait for Event i Signal Timer Stack 1 4 4 4 4 4 4 0 0026H DELETED T 0 l Lali 84H 1 1 OODIH WAITING SIGNAL 0 23197 84H 2 0043H WAITING 0 5 86H 1 3 0278H DELETED 0 1 131 1 88H 4 O2ACH WAITING SIGNAL amp TIMEOUT 0 220 88H 5 032BH WAITING TIMEOUT 0 al 6 1 WAITING SIGNAL 0 T3171 FBH RTX Tiny Interpretation of the debug output Task ID Start State Wait for Event Signal Timer Stack Indicates the task number which is used in the task definition within the task keyword of the C51 Compiler Indicates the start address of the task function Indicates the state of the task State can be one of the following RUNNING READY WAITING D
41. he next task that is ready WAITING Tasks which are waiting for an event are in the WAITING STATE If the event occurs the task is placed into the READY STATE DELETED Tasks which are not started are in the DELETED STATE TIME OUT Tasks which were interrupted by a round robin time out are placed in the TIME OUT STATE This state is equivalent to the READY STATE 17 18 Introduction to RTX51 Tiny Task Switching RTXSI Tiny performs round robin multitasking which allows quasi parallel execution of several endless loops or tasks Tasks are not executed concurrently but are time sliced The available CPU time is divided into time slices and RTX51 Tiny assigns a time slice to every task 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 Refer to chapter 3 RTX51 Tiny configuration for more information Rather then wait for a task time slice to expire you can use the os wait system function to signal RTX51 Tiny that it can let another task begin execution os wait suspends the execution of the current task and waits for a specified event to occur During this time any number of other tasks may be executing The section of RTX51 Tiny which assigns the processor to a task is called the scheduler The RTX51 Tiny scheduler d
42. ignal OS create task os delete task os running task id os send signal os wait os 1 os wait2 Description Sends a signal to a task from an interrupt Deletes a signal that was sent Moves a task to the execution queue Removes a task from the execution queue Returns the task ID of the task that is currently running Sends a signal to a task from another task Waits for an event Waits for an event Waits for an event 26 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 routines effect lists include file s containing its declaration and prototype illustrates the syntax and describes any arguments Description Provides a detailed description of the routine and how it is used Return Value Describes the value returned by the routine See Also Names related routines Example Gives a function or program fragment demonstrating proper use of the function RTX Tiny 27 isr send signal Summary Description Return Value See Also Example include lt rtx51tny h gt char isr_send_signal unsigned char task_id ID of task to signal 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 th
43. ize of serial receiving buffer x unsigned char istart receiving buffer start index gt unsigned char iend receiving buffer end index x idata char inbuf ILEN storage for receiving buffer x unsigned char itask Oxff task number of output task define CTRL Q 0x11 Control Q character code x define CTRL_S 0x13 Control S character code bit sendfull flag marks transmit buffer full i bit sendactive flag marks transmitter active x bit sendstop flag marks XOFF character gt RRR RRR k k k k k k k k k k k k k k k k k k k k k k k k k k k k K K K K K K k k k k K K ORO K R R K R R K K o o oK O K R ORO RO RO R R R e K i putbuf write a character to SBUF or transmission buffer x RRR KR KK RIK KKK KKK k k k k k k k k k k k k k k he he e K K K K K k k k k k ehe ke e He He R R R R K K o o e ee ee RO OR R R R R e e eu putbuf char c if sendfull transmit only if buffer not full i if sendactive amp amp sendstop 1 if transmitter not active 0 sendactive 1 transfer the first character direct i SBUF c to SBUF to start transmission gt else otherwize a outbufloendtt amp OLEN 1 c transfer char to transmission buffer i if oend ostart amp OLEN 1 0 sendfull 1 set flag if buffer is full x putchar interrupt controlled putchar function 0 RRR KKK KR IK KKK KKK RIK KKK KI HK RIK KKK RIK KKK KIKI KKK
44. k id os send signal os wait os waitl os wait2 N NOT OK Notational Conventions O Optimizing RTX51 Tiny Programs os_clear_signal os_create_task os_delete_task os running task id 22 17 22 15 12 25 27 34 37 34 37 34 37 11 23 12 16 25 25 25 25 25 25 25 25 25 34 36 38 3 23 25 28 25 29 25 30 25 31 RTX TINY os send signal os wait os waitl os wait2 P Preemption Priorities R RAMTOP Reentrant Functions Registerbanks Round Robin Program Round Robin Scheduling 51 Introduction RTX51 Full RTX51 Tiny RTX51 Tiny Configuration RTX51 Tiny System Functions RTXSITNY H RTXSITNY LIB S SIG EVENT 25 32 25 34 25 36 225594 11 11 34 36 38 Single Task Program Stack Management STACK ERROR System Debugging System Functions T Target System Requirements Task Definition Task Management Task State Deleted Ready Running Time out Waiting Task Switching Technical Data Timer 0 Interrupt TIMESHARING TMO EVENT U Using Signals Using Time outs 65 41 22 41 13 15 17 17 17 17 17 17 17 18 14 16 16 18 22 34 38 Information in this document is subject to change without notice and does not represent a commitment on the part of Keil Elektronik GmbH The software and or databases de scribed in this document are furnished under license agreement or nondisclosure agree ment and may be used or copied only in accor
45. 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 2 Contents OVERVIEW uides ies eter REED kt ad 7 Introduction u a ect eee dee eee e eie ie ene eie 7 Single Task Program 5 dee e deret rre e eter bee eds 8 Round Robin Program Re Hp ROI pere ER 8 Round Robin Scheduling With 51 8 REXI EVN tS teo RR IR RP RO He EE RA E 9 Compiling and Linking with RTX51 eese 11 REQUIREMENTS AND DEFINITIONS eere 15 Development Tool Requirements essere enne nennen nenne enne eene enne enne 15 Target System Requirements deett net E UNE Shae 15 Interrupt Handling y a W Sh I 15 R entrant Functions 2 e tege epe ed e ue etos 16 C51 Library F nctions ete ee ise TRE eh eR 16 Usage of Multiple Data Pointers and Arithmetic Units 2 2 2 2 16 R sist rban k s onere RIPE m ode RAGS URBEM 17 pbi 17 FER M EnECPIWISIEICHPC n 17 Task Switching titer tete d denohet tnus 18 Vents
46. ntil it receives a signal from any other task When it does receive a signal it will increment counteri and again wait for another signal jobO continuously increments countero until it overflows to 0 When that happens jobO sendsasignalto jobl and RTX51 marks jobl as ready for execution jobl will not be started until RTX51 gets its next timer tick Priorities and Preemption One disadvantage of the above program example is that jobl is not started immediately when it is signaled by jobO In some circumstances this is unacceptable for timing rea sons RTXSI 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 NOTE Preemption and priority levels are not supported by RTX51 Tiny You can modify the above function declaration for jobl to give it a higher priority than jobO By default all tasks are assigned a priority level of 0 This is the lowest priority level The priority level can be 0 through 3 The following example shows how to define job1 with a priority level of 1 void jobl void task 1 priority 1 while 1 loop forever os wait K SIG O 0 wait for a signal counteritt update the counter Now whenever jobO sends signal to jobl job1 will start immediately Compiling and Linking with RTX51 RTX51 is fully integrated into the C5
47. o o oK KOK OK OR R RO R R e e e 0 clock task CLOCK while 1 clock is an endless loop f if ctime sec 60 calculate the second M ctime sec 0 if ctime min 60 calculate the minute 0 ctime min 0 if ctime hour 24 calculate the hour 0 ctime hour 0 if display time if command_status display time 0 os send signal COMMAND signal to task command time changed 0 os wait IVL 100 0 wait interval 1 second 0 struct time rtime temporary storage for entry time x Vl KKK k k k k k k k k k k k k k k k k k k k k k k k k k K K K K K K K K k k k k K K KOK OK KOR R R K KR R K o o o K OO ORO RO RO R R e e e x readtime convert line input to time values amp store in rtime 0 RRR KKK KR IK KKK KKK RIK KKK RIKKI KKK HK RIK KKK KI HK KI KK KKK KI HK KI KKK HK KI KKK KEK He e e e e i bit readtime char idata buffer RTX TINY 53 unsigned char args number of arguments rtime sec 0 preset second UE sscanf buffer bd bd bd scan input line for amp rtime hour hour minute and second amp rtime min amp rtime sec if rtime hour 23 LI rtime min 59 LI check for valid inputs x rtime sec 59 Il args lt 2 args EOF 1 printf Nn ERROR INVALID TIME FORMAT An return 0 return 1 define ESC 0x1B ESCAPE character code bit escape flag mark ESCAPE chara
48. of this time range n the yellow caution lamp is blinking n command syntax n Display D display times n Time T hh mm ss set clock time n Start S hh mm ss set start time n End E hh mm ss set end time n R 4 4 n include lt reg52 h gt special function registers 8052 include lt rtx5ltny h gt RTX 51 tiny functions amp defines KI include lt stdio h gt standard I O h file KI include lt ctype h gt character functions KI include lt string h gt string and memory functions ii RTX TINY extern getline char idata char external function input line serial init external function init serial UART define INIT 0 task number of task init COMMAND 1 task number of task command CLOCK 2 task number of task clock BLINKING 3 task number of task blinking LIGHTS 4 task number of task signal ee KEYREAD 5 task number of task ae GET_ESC 6 task number of task get escape struct time structure of the time record E char hour hour char min minute ANS char sec second 20 struct time ctime 12 0 storage for clock time values 10 time start 71 53 5 307 storage for start time values s time end
49. oland Spain South Africa Sweden Switzerland Taiwan United Kingdom United States and Canada Contact KEIL ELEKTRONIK GmbH to obtain the name and address of the distributor nearest to you Printed in Germany 2 95 Document 9443 1 ake RIX51 TINY REAL TIME OPERATING SYSTEM User s Guide 2 95
50. ound object can request send a remote frame for the specified object can get status get the actual CAN controller status Technical Data Description Number of tasks RAM requirements Code requirements Hardware requirements System clock Interrupt latency Context switch time Mailbox system Memory pool system Semaphores RTX51 Real Time Operating System RTX51 Full 256 max 19 tasks active 40 46 bytes DATA 20 200 bytes IDATA user stack min 650 bytes XDATA 6KB 8KB timer O or timer 1 1000 40000 cycles 50 cycles 70 100 cycles fast task 180 700 cycles standard task depends on stack load 8 mailboxes with 8 int entries each up to 16 memory pools 8 1 bit 51 Tiny 16 7 bytes DATA 3 lt task count gt IDATA 900 bytes timer 0 1000 65535 cycles lt 20 cycles 100 700 cycles depends on stack load not available not available not available RTX Tiny 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 The task definition and the major features of RTX51 Tiny are also described within this chapter Development Tool Requirements The following software products are required to operate RTX51 Tiny e C51 Com
51. pecified on the command line after all object files Refer to the RTX51TINY directive in Utilities manual Optimizing RTX51 Tiny Programs The following items should be noted when creating RTX51 applications If possible disable round robin multitasking Tasks which use round robin multi tasking require 13 bytes of stack space to store the task context registers etc This context storage is not required if task switching is triggered by the os wait function The os wait function also produces an improved system reaction time since a task which is waiting for execution does not have to wait for the entire duration of the round robin time out Do not set the timer tick interrupt rate too fast Setting the tick rate to a low number increases the number of timer ticks per second There is about 100 to 200 CPU cy cles of overhead for each timer tick interrupt Therefore the timer tick rate should be set high enough to minimize interrupt latency 23 RTX Tiny 25 RTX51 Tiny System Functions A number of routines are included in the RTX51 Tiny Library file RTXSITNY LIB that can be found in the C51 LIB subdirectory These routines allow you to create and de stroy tasks send and receive signals from one task to another and delay a task for a num ber of timer ticks These routines are summarized in the following table and described in detail in the func tion reference that follows Routine isr send signal os clear s
52. piler BL51 Code Banking Linker e 51 Macro Assembler The library file RTXSITNY LIB must be stored in the library path specified with the DOS envirionment variable CSILIB Usually this is the directory C51 LIB The include file RTXSITNY H must be stored in the include path specified with the DOS envirionment variable CSIINC Usually this is the directory CSINNC Target System Requirements RTX51 Tiny can run on single chip 8051 systems without any external data memory However the application can access external memory RTXSI Tiny can use all memory models supported by C51 The selected memory model only influences the location of application objects The RTX51 Tiny system variables and the stack area of the applica tion are always stored in internal 8051 memory DATA or IDATA Typically RTX51 Tiny applications are implemented in the SMALL model RTXSI Tiny performs round robin task switching only Preemptive task switching and task priorities are not supported If your application needs preemptive task switching you need to use the RTX51 Full Real Time Executive RTX51 Tiny is not designed for use with bank switching programs If you require real time multitasking in your code banking applications you need to use the RTX51 Full Real Time Executive Interrupt Handling RTX51 Tiny can operate parallel with interrupt functions Similar to other 8051 applica tions the interrupt source must be enabled in the 8051 hardware registers in
53. r tasks Tasks are not executed concurrently but are time sliced The available CPU time is divided into time slices and RTX51 assigns a time slice to every task Each task is allowed to execute for a predetermined amount of time Then RTXSI 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 appears as though the tasks are executing simultaneously RTX Tiny RTXSI uses a timing routine which is interrupt driven by one of the 8051 hardware tim ers The periodic interrupt that is generated is used to drive the RTX51 clock RTXSI does not require you to have a main function in your program It will automati cally begin executing task 0 If you do have a main function you must manually start RTX51 using the os create task function in RTX51 Tiny and the os start system function in RTX51 The following example shows a simple RTX51 application that uses only round robin task scheduling The two tasks in this program are simple counter loops RTX51 starts executing task 0 which is the function names job0 This function adds another task called jobl After jobO executes for a while RTX51 switches to jobl After job1 executes for a while RTX51 switches back to jobO This process is repeated in definitely include lt rtx5ltny h gt int counter0 int counterl void jobO void task 0 os_create 1 mark task 1 as r
54. s create task LIGHTS start lights 0 os delete task BLINKING and stop blinking ei RRR KR KK k k k k k k k k k k k k k k k k k k k k k k k k K k k K K K K K k k k k K KKK KKK KKK R R o o o o R K O OR R R R e e e x Task 4 lights executes if current time is between start amp end time 0 BRR RRR KK RIK KKK KKK RIK e e e KR IH RIK KK KHIR KKK KI HK RIK KKK RIKKI He e e e e e lights task LIGHTS traffic light operation 1 red stop lights i yellow 0 green 0 stop 1 walk 0 while 1 endless loop 0 os wait 30 0 wait for timeout 30 ticks i if signalon if traffic signal time over M os create task BLINKING start blinking f os delete task LIGHTS stop lights 0 yellow 1 os wait K TMO 30 0 wait for timeout 30 ticks gt red 0 green light for cars gt yellow 0 green 1 os clear signal LIGHTS os wait K TMO 30 0 wait for timeout 30 ticks e os wait K TMO K SIG 250 0 wait for timeout amp signal 0 yellow 1 green 0 os wait K TMO 30 0 wait for timeout 30 ticks red 1 red light for cars e yellow 0 RTX TINY os wait K TMO 30 0 wait for timeout 30 ticks stop 0 green light for walkers x walk 1 os wait K TMO 100 0 wait for timeout 100 ticks stop 1 red light for walkers x
55. s marked as ready and is executed according to the rules specified for RTX51 Tiny The os create task function returns a value of 0 if the task was successfully started A value of 1 is returned if the task could not be started or if no task was defined using the specified task number os_delete_task include lt rtx5ltny h gt include lt stdio h gt for printf void new_task void _task_ 2 void tst os create task void task 0 if os create task 2 printf Couldn t start task 2Nn 30 RTX51 Tiny Function Library os delete task Summary include lt rtx51tny h gt 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 Return Value The os delete task function returns a value of O if the task was successfully stopped and deleted A return value of 1 indicates the specified task does not exist or had not been started See Also OS create task Example include rtx5ltny h include stdio h for printf void tst os delete task void task 0 t if os delete task 2 t printf Couldn t stop task 2 n RTX Tiny 31 os running task id Summary Description Return Value See Also Example include lt rtx51tny h gt char os_running_task_id void The os_running_task_id function
56. s supporting message passing with the Intel 8044 Events RTX51 supports the following events for the WAIT function Timeout Suspends the running task for a defined amount of clock ticks Interval RTX51 Tiny only is similar to timeout but the software timer is not reset to allow generation of periodic intervals required for clocks Signal For inter task coordination Message RTX51 Full only for exchange of messages Interrupt RTX51 Full only A task can wait for 8051 hardware interrupts Semaphore RTX51 Full only binary semaphores for management of shared system resources RTX51 Functions The following table shows all RTX51 functions RTX51 Tiny supports only the functions marked with Timings are measured with RTX51 Full Function os create os delete os send signal os clear signal isr send signal os wait sage os attach interrupt os detach interrupt os disable isr os enable isr os send message os send token isr send message isr recv message os create pool os get block os free block os set slice Description move a task to execution queue remove a task from execution queue send a signal to a task call from tasks delete a sent signal send a signal to a task call from interrupt wait for event assign task to interrupt source remove interrupt assignment disable 8051 hardware interrupts enable 8051 hardware interrupts send a messa
57. stem interrupt INT CLOCK defines the interval for the system clock The system clock generates an interrupt using this interval The defined number specifies the number of CPU cycles per interrupt TIMESHARING defines the time out for the round robin task switching The value indicates the number of timer tick interrupts that must elapse before RTX51 Tiny will switch to another task If this value is 0 round robin multitasking is disabled indicates the highest memory location in the internal memory of the 8051 derivative For the 8051 this value would be 7Fh For the 8052 this value would be OFFh FREE STACK specifies the size of the free stack area in bytes When switching tasks RTX51 Tiny verifies that the specified number of bytes is available in the stack If the stack is too small RTX51 Tiny invokes the STACK ERROR macro The default value for FREE STACK is 20 Values 0 OFFH are allowed STACK ERROR is the macro that is executed when RTX51 Tiny detects a stack problem You may change this macro to perform whatever operations are necessary for your application RTX Tiny 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 The RTXSITINY directive must be s
58. t rtx5ltny h gt RTX Tiny 35 include stdio h for printf void tst os wait void task 9 t while 1 t char event event os wait SIG 50 0 switch event default this should never happen break case TMO EVENT time out 50 tick time out occurred break case SIG EVENT signal recvd signal received break 36 RTX51 Tiny Function Library os wait1 Summary Description Return Value See Also Example include lt rtx51tny h gt char os_wait1 unsigned char event_sel events to wait for The os_wait1 function halts the current task and waits for an event to occur The os_waitl function is a subset of the os wait func tion and does not allow all of the events that 08 wait offers The event sel argument specifies the event to wait for and can have only the value K SIG which will wait for a signal When the signal events occurs the task is enabled for execution Execution is restored and a manifest constant that identifies the event that restarted the task is returned by the os vvaitl function Possible return values are Return Value Description SIG EVENT A signal was received NOT OK The value of the event sel argument is invalid os wait os wait2 See os wait RTX Tiny os wait2 Summary Description Return Value include lt rtx51tny h gt char os_wait2 unsigned char event_sel
59. ter incrementing counter0 jobO calls the os wait function to pause for 3 clock ticks At this time RTX51 switches to the next task whichis job1 After jobl increments counterl it too calls os wait to pause for 5 clock ticks Now RTXSI 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 jobO The result of this example is that counterO gets incremented every 3 timer ticks and counterl gets incremented every 5 timer ticks Using Signals with RTX51 You can use the os wait function to pause a task while waiting for a signal or binary semaphore from another task This can be used for coordinating two or more tasks Waiting for a signal works as follows If a task goes to wait for a signal and the signal flag is 0 the task is suspended until the signal is sent If the signal flag is already 1 when the task queries the signal the flag is cleared and execution of the task continues The following example illustrates this include lt rtx5ltny h gt int counter0 int counterl void jobO void task 0 os_create 1 mark task 1 as ready while 1 loop forever if counter0 0 update the counter os_send_signal 1 signal task 1 RTX Tiny void jobl void task 11 while 1 loop forever os wait K SIG 0 0 wait for a signal counter1 update the counter In the above example job1 waits u
60. walk 0 RRR RRR KI HK KKK KKK k k k k k k k k k k k k k k k k K K K K k k k k k k k K K K K K K R RO R KR K K o o O o O O ORO RO RO R R R R KE Task 5 keyread process key stroke from pedestrian push button k k k k k k k k k k k k k k k k k k k k k k k k k k k k k K K K K k k k k k k k K K K K K R R R R R k o o o OO K KOR RO R R R R e e 20 keyread task KEYREAD while 1 endless loop if key if key pressed os_send_signal LIGHTS send signal to task lights os_wait K_TMO 2 0 wait for timeout 2 ticks x SERIAL C RRR KKK k k k k k k k k k k k K k k k k k k k k k k k k k k k k K K K K K k k k k K K KOK K K R KOR K KR K R ooo K K KO R ORO RO RO RO R R e ke e SERIAL C Interrupt Controlled Serial Interface for RTX 51 tiny SH BRR RRR RK KR IK KKK KKK KI KKK k k k k k k k k k k k K K K K K K k k k k K k KOK K K R R He R R R K oo o K K K K K OR RO R R e ke e include reg52 h special function register 8052 rtx5ltny h RTX 51 tiny functions amp defines SH define OLEN 8 size of serial transmission buffer char ostart transmission buffer start index Kum a char oend transmission buffer end index E char outbuf OLEN storage for transmission buffer UR char otask Oxff task number of output task 57 58 Application Examples define ILEN 8 s
Download Pdf Manuals
Related Search
Related Contents
Mailing Designer User Manual 5 0 non Java version Otterlace • Zmap • Blixem • Dotter user manual Copyright © All rights reserved.
Failed to retrieve file