RTX51TINY is a small MCS5l series MCU multi-task real-time operating system.
It is fully integrated in the Keil C5l compiler, has run speed, on hardware requirements, the advantages of using a convenient and flexible, thus becoming more and more widely to SCM software development. It can be managed on a single CPU for several jobs (tasks), while there is no extended external storage of single-chip system.RTX51 TINY allows simultaneous "quasi parallel" to perform multiple tasks: the task is not running, but at a pre-determined time slice (time slice).
CPU execution time is divided into several time slices, RTX51 TINY for each task is assigned a time slice, the slice at a time are allowed to perform a task, and then RTX51 TINY switch to another place tasks and allow it to in its provisions within the time slice. Because each time slice is very short, often only a few ms, so each task appears is being implemented.RTX51 TINY using MCU internal timer 0 interrupt function regularly, with periodic timer interrupt driven RTX51 TINY clock.
It can define up to 16 tasks, all tasks can be activated at the same time, allows the circulation task switch, only supports non-preemptive task switch, the operating system for each task is assigned a separate stack area, while the task switch to change the stack pointer, and save and restore register values. RTX51 TINY no special time service functions and tasks pending function, but rather through os_wait () parameter set. When using TINY RTX51 users do not need to include in your main () function, it will automatically start running from the task 0. If the user program contains main () function, you need to start using os_create_task function RTX51 real-time operating system.2 task switching
2.1 RTX51 TINY task status
RTX51 TINY user tasks have the following status:
① run (RUNNING)-the task is running.
There is only one task at a time can be in "RUNNING" State.② ready (READY) — waiting for running tasks at the "READY" State.
In the currently running task exit the running state, the ready queue of tasks according to the scheduling policy is scheduled for execution, into the running state.③ blocking (BLOCKED) — waiting for an event of the task is in the "BLOCKED" status.
If you wait for the event occurs, the task into the "READY" State of the waiting to be scheduled.④ dormant (SLEEPING) — was declared but not started running tasks in a sleep state.
Run but has been deleted tasks also in the sleep state.⑤ timeout (TIMEOUT) — task because of the time slices used up and is in the "TIMEOUT" status, and wait for it to run again.
The State and the "READY" State is similar, but due to internal operational processes makes a loop task switching, so a separate count as a State.In "READY/TIMEOUT" and "RUNNING" and "BLOCKED" in the status of tasks is believed to be activated State, between can toggle.
"SLEEPING" State of the task is not activated, cannot be implemented or considered to have terminated.2.2 RTX51 TINY task switching
Task switching is RTX51 TINY provision of basic services.
RTX51 TINY is based on the time slice scheduling algorithm of the operating system that supports a non-preemptive task switching. So in a task is executed not interrupt, unless the task took the initiative to give up the CPU's resources, the interrupt can interrupt the current task, interrupt is complete control of the CPU and the return of the task is interrupted. Task switching is available in two cases, one is currently active up CPU resources tasks; another is in the current task time slice has been used up, to task switching. CPU execution time is divided into several time slices, RTX51 TINY for each task is assigned a time slice. Time slices are variable settings to determine the TIMESHARING, i.e. 5 ";" TIMESHARING EQU Sets the number of system clock cycles for a time slice. System default 5 system clock to a time slice, if MHz crystal oscillator frequency 11.0592, time slice 10.8507 × 5 = 54.2535 ms.RTX51 TINY task switch total TASKSWITCHING and SWITCHINGNOW two entrances, the former for the timer interrupt service routine T0 calls, the latter for system function os_delete and os_wait calls.
Accordingly there are two different export, namely the recovery protection in situ and clearing the status flag bits. The system first saves the current task to "TIMEOUT" State of the waiting for next time slice loop, and then locate the next is in the "READY" status of task management through the stack, will free stack space allocated to the task, making it the current task. Clear the enable this task into the "READY" or "TIMEOUT" status-related bits, perform the task. Task switching process as shown in Figure 1.RTX51TINY because is a multitasking operating system, so
It would be several tasks use the same resources, these resources may be a variable, or input/output devices. This requires a mandate in the use of a shared resource, you must be exclusive to the resource, it may cause data corruption.Implement the RTX51 TINY exclusive method for shared resources.
For example, you can pass the variable to prohibit TIMESHARING timeslice Web, make it a value of 0, you can achieve the prohibition of task switch to the current task can monopolize the shared resource. You can close the interrupt, the EA = 0, timer T0 interrupt is turned off, no longer as time slice Web provides benchmarks, thus preventing the task switching. But either way with certain limitations, the previous method can only apply to real-time performance requirements of occasions, the latter method because the shutdown time T0 interrupts cannot be too long, you can only apply to some simple variable action. Based on the above, the following via another method to achieve the shared use of resources.In full in RTX51 can use semaphores to implement the actions on shared resources, or you can put this idea into RTX51 TINY; in RTX51 TINY in does not support the semaphore, this requires the user's own definition semaphores and operational processes.
The following is part of the code:
With the function definition and implementation, you can use wait semaphore and release the semaphore to complete exclusive to shared resources.
For example:Application to achieve shared semaphore resources use, do not prohibit the time slice Web and off T0 is interrupted, you can effectively achieve exclusive to shared resources; but increased code, wait and release the semaphore spent a certain amount of time, in the specific application depends on the circumstances of the case.
Need to be aware of the problem
When you apply RTX51 TINY should note the following:
① as far as possible not to use loop task switching.
When using the loop task switch requires 13 bytes of stack area in which to save the task content (working registers, etc.). If os_wait () function to trigger a task, you do not need to save the task. Because is in waiting for the running task does not need to wait for all cycle through end of time, therefore os_wait () function can produce an improved system response time.② don't break the beat the clock rate is set too high, set to a lower value can increase the clock beats per second.
Each clock cycle time interrupt takes approximately 100 ~ 200 CPU cycles, so you should set the clock tempo rate high enough, in order to enable interrupt response time.③ in os_wait () function has three arguments: K_TMO, K_IVL and K_SIG.
Including for the use of K_IVL K_TMO and want to be different. When used, there seems to be the difference is not great. Fact, there exists considerable differences: K_TMO refers to wait for a timeout signal, only time will produce a signal. It produces a signal is not cumulative, signal, the task into the ready state. While K_IVL refers to the periodic signals, every one of the specified period, a time signal, the signal is generated can be cumulative. This allows specifying the event did not respond within the signal, the number of signal, the signal processing in the future, back to response, thereby ensuring the signal will not be lost. By way of delay K_TMO task, for some reason the signal did not receive a timely response, then this might lose part of the signal is not responding. But both are effective ways of task switch, when used according to the application to determine the use of both.Conclusion
RTX51 real-time operating system both TINY guarantee on outside information fast enough to handle, and can run multiple tasks in parallel, with real-time and concurrent sexual characteristics, so well done on multiple information real-time measurement, processing, and accordingly more real-time control.
Task switching is a TINY RTX51 basic services. This article on task switch made a detailed analysis, in practice but also on the stack when switching tasks management have a certain understanding in order to better grasp the task switching mechanism. Shared resource use in a multitasking operating system is inevitable, no TINY RTX51 specialized processing shared resource function, so in practice depends on the circumstances mentioned in practical ways.Reference documents
[1] al Jean, sui xueqing, segment-bin. Embedded real-time operating system and application development [M]. Beijing: Beijing University Press, 2006: 44-49.
[2] Keil Software Inc.RTX51 Tiny User’s Guide,2004.
[3] Jun Xu, Peng love Sau wah. MCU high level language C51 Windows environment programming and application [M]. Beijing: electronic industry press, 2001.
No comments:
Post a Comment