Real-Time Library: RTX

Slides:



Advertisements
Similar presentations
The OS kernel: Implementing processes and Threads Kernel Definitions and Objects Queue Structures Threads Implementing Processes and Threads Implementing.
Advertisements

Operating Systems Process Scheduling (Ch 3.2, )
Development of Real Time Kernel Master of Technology In EMBEDDED SYSTEM SCHOOL OF ELECTRONICS DEVI AHILYA VISWAVIDYALAYA INDORE. April 2010 Guided by -
The Process Control Block From: A Process Control Block (PCB, also called Task Control Block or Task Struct) is.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
UEE072HM Developing a small scheduler. Processes Understanding the process is the key to a system –Created through compilation, linking and loading –Requires.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
OS Spring’03 Introduction Operating Systems Spring 2003.
CSSE Operating Systems
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
P ORTING F REE RTOS TO MCB2140 BOARD Ashwini Athalye Sravya Kusam Shruti Ponkshe.
Chapter 6 Real-Time Embedded Multithreading The Thread – The Essential Component.
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
MicroC/OS-II Embedded Systems Design and Implementation.
Process Description and Control A process is sometimes called a task, it is a program in execution.
Outline Introduction to MQX Initializing and starting MQX
ΜC/OS-III Tasks Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
Real Time Operating System
Chapter 8 Windows Outline Programming Windows 2000 System structure Processes and threads in Windows 2000 Memory management The Windows 2000 file.
System Clocks.
Introduction to Processes CS Intoduction to Operating Systems.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Getting Started with the µC/OS-III Real Time Kernel Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University.
Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Tami Meredith, Ph.D. CSCI  Devices need CPU access  E.g., NIC has a full buffer it needs to empty  These device needs are often asynchronous.
Operating Systems Process Management.
CE Operating Systems Lecture 11 Windows – Object manager and process management.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
OPERATING SYSTEMS CS 3530 Summer 2014 Systems with Multi-programming Chapter 4.
Overview Task State Diagram Task Priority Idle Hook AND Co-Routines
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
ECGR-6185 µC/OS II Nayana Rao University of North Carolina at Charlotte.
Real Time Operating Systems Michael Thomas Date: Rev. 1.00Date.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
MicroC/OS-II S O T R.  MicroC/OS-II (commonly termed as µC/OS- II or uC/OS-II), is the acronym for Micro-Controller Operating Systems Version 2.  It.
1 VxWorks 5.4 Group A3: Wafa’ Jaffal Kathryn Bean.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
1 Run-to-Completion Non-Preemptive Scheduler. 2 In These Notes... What is Scheduling? What is non-preemptive scheduling? Examples Run to completion (cooperative)
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
1 J.O. KLEIN Institut Universitaire de Technologie de CACHAN Université PARIS SUD - FRANCE An Introduction to Real Time Operating System.
Copyright © Curt Hill More on Operating Systems Continuation of Introduction.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Scheduling.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
LPC2148's RTOS Bruce Chhuon 4/10/07. What is a Real Time Operating System? ● A Real Time Operating System (RTOS) manages hardware and software resources.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
REAL-TIME OPERATING SYSTEMS
Processes and threads.
Process concept.
Advanced Operating Systems CIS 720
Process Management Process Concept Why only the global variables?
PROCESS MANAGEMENT IN MACH
Topics Covered What is Real Time Operating System (RTOS)
OPERATING SYSTEMS CS3502 Fall 2017
CS4101 嵌入式系統概論 Tasks and Scheduling
Real-time Software Design
Writing and Testing Your First RTOS Project with MQX
Process management Information maintained by OS for process management
Introduction What is an operating system bootstrap
Multithreading.
LPC2148 ARM7 myKernel Details
CSE 153 Design of Operating Systems Winter 19
Chapter 3: Process Management
Presentation transcript:

Real-Time Library: RTX AG & AH

What is an RTOS? An RTOS is a special version of an operating system that provides a more deterministic behaviour for the tasks under its control. At its core is a Real-Time Executive(RTX). The RTX provides the primitives to Create, Manage and Schedule tasks Manage and use time in controlling tasks allow inter-task communication through: semaphores mutexes events mailboxes

What is a Task? For our purposes we can consider a task to be a basic unit of programming that the operating system controls. Our tasks will be written in 'C' and be of the form of an endless while(1) loop. We will use a simple RTX to create and manage our tasks. Our application programs will consist of a number of tasks which are controlled by the RTX and that communicate with each other using some of the RTX features. Covered later! void task1(void) { while(1) // do task 1 } void task2(void) // do task 2 void task3(void) // do task 3

The Scheduler At the Kernel of the RTX is the scheduler Responsible for allocating CPU time to the tasks. A hardware timer provides a basic "tick" to measure time. "tick" time is configurable and affects responsiveness of the system. Default RTX tick time is 10ms. This scheduler is essentially a timer interrupt that allots a certain amount of execution time to each task. So task1 may run for 100ms then be de-scheduled to allow task2 to run for a similar period; task 2 will give way to task3, and finally control passes back to task1. By allocating these slices of runtime to each task in a round-robin fashion, we get the appearance of all three tasks running in parallel to each other.

The Scheduler In order to make the task-switching process happen, we have the code overhead of the RTOS and we have to dedicate a CPU hardware timer to provide the RTOS time reference. For ARM7 and ARM9 this must be a timer provided by the microcontroller peripherals. In a Cortex-M microcontroller, RTX will use the SysTick timer within the Cortex-M processor.

The Scheduler Each time we switch running tasks the RTOS saves the state of all the task variables to a task stack and stores the runtime information about a task in a Task Control Block. The “context switch time”, that is, the time to save the current task state and load up and start the next task, is a crucial value and will depend on both the RTOS kernel and the design of the underlying hardware.

Task states A task can be in one of four basic states, RUNNING, READY, WAITING, or INACTIVE. In a given system only one task can be running, that is, the CPU is executing its instructions while all the other tasks are suspended in one of the other states If, during our RTOS program, there is no task running and no task ready to run (e.g. they are all waiting on delay functions), then RTX uses the spare runtime to call an “Idle Demon

Simple Round Robin Scheduler All tasks have the same priority and tasks run in turn on the CPU for a given number of "time quanta" or "ticks". CPU Task at front of queue selected to run The running task Round Robin time out. Task put on end of ready queue. Ready Queue of tasks.

Example with three tasks T1, T2 and T3 Each task runs for the Round Robin time. Running task T1 T2 T3 etc. Time

Round Robin with task waiting queues Typically a running task often has to wait for some resource therefore is removed from the CPU and is placed in a queue. CPU Task at front of queue selected to run The running task Tasks waiting for event(s) Round Robin time out Tasks waiting for mutex, semaphore or mailbox Delayed and periodic tasks Queue of ready to run tasks NB. There is a system task called os_idle_demon that runs when there are no tasks in the ready queue. Tasks becomes ready and rejoin queue of ready tasks

Example with three tasks T1, T2 and T3 T1 execution time is 50ms then delays for 180ms second,T2 and T3 never delay and the round robin time is 50ms. Assume ready queue is T1,T2,T3. T1 T2 T3 T2 T3 T2 T1 T3 T2 Time ms 50 100 150 200 250 300 350 T1 delays for 180ms T1 now joins ready queue, at time 230ms. T1run after T2. Remember it joins the end of the queue. T1 delays itself for 180ms

Round Robin with Priority scheduling CPU Highest priority task is selected when CPU free. Delayed and periodic tasks Running task doesn't need to run for a certain time so relinquishes the CPU. Tasks becomes ready and rejoin queue of ready tasks The running task Tasks waiting for event(s) Round Robin time up Tasks waiting for mutex, semaphore or mailbox Queue of ready Tasks queue sorted into priority order

Round Robin with Priority Scheduling E.g.Three tasks T1, T2 with priority 4 in the ready queue and T3 with priority 6 is in a waiting queue.T3 is an event driven task that executes in 30ms. T1 T2 T1 T3 T2 T1 T2 T1 Time ms 50 100 150 200 250 300 350 Time 125ms: T3 becomes ready and joins ready queue. Time 180ms: T3 runs for 30ms then relinquishes CPU and joins a waiting queue again. Scheduler runs next task from the ready queue. Time 150ms: T3 now runs because highest priority ready task.

Round Robin Priority scheduling with pre-emption. Pre-empt running task if a higher priority task is ready. CPU Delayed and periodic tasks Running task doesn't need to run for a certain time so relinquishes the CPU. Tasks becomes ready and rejoin queue of ready tasks Highest priority task is selected when CPU free. The running task Tasks waiting for event(s) Round Robin time up Tasks waiting for mutex, semaphore or mailbox Queue of ready Tasks queue sorted into priority order

Round Robin Priority scheduling with pre-emption. E.g.Tasks T1, T2 with priority 4 both in the ready queue and T3 with priority 6 is in a waiting queue. Priority 6 T3 5 4 T1 T2 T1 T1 T2 T1 T2 T1 Time ms 50 100 150 200 250 300 350 Time 125ms: T3 becomes ready and immediately pre-empts the currently running task. because it is higher priority. Time 155ms: T3 runs for 30ms then relinquishes the CPU and joins a waiting queue again. Pre-empted T1 is restarted and runs for the rest of its round robin time - assuming it is still the highest priority.

The ARM RL-RTX We will be using a Real Time eXecutive with the ARM based board Keil MCB 2300 To use the RTX the file RTL.h must be included in the 'C' source file and the operating system project option set to use the RTX Kernel. #include <RTL.h> There are 35 RTX related functions providing facilities for: task creation and management time management events mutexes semaphores mailboxes

The RTX Scheduler - Timer Tick Interrupt The RTX kernel for ARM7™ uses one of the standard ARM timers to generate a periodic interrupt. This interrupt is called the RTX kernel timer tick. For some of the RTX library functions, you must specify timeouts and delay intervals as a number of RTX kernel timer ticks. The parameters for the RTX kernel timer are selected in the RTC_Config.c configuration file. For example, the RTX_Config.c file for NXP LPC23XX use Timer 0, 1,2 or 3 for the RTX kernel timer.

RTX_Config.c The timer clock value specifies the input clock frequency and depends on CPU clock and APB clock. For a device with CPU clock 48 MHz and VPB divider 4 the peripheral clock is 12MHz and therefore the value is set to 12000000. The time tick value specifies the interval of the periodic RTX interrupt. The value 10000 us configures timer tick period of 0.01 seconds.

Starting the OS and Task Creation Start the OS and creating the first task with a default priority of 1. void os_sys_init(task_name); os_sys_init (begin); // start os then start task begin Create tasks OS_TID os_task_create(task_name, priority); t1_ID = os_tsk_create (task1, 4); t2_ID = os_tsk_create (task2, 6); t1_ID and t2_ID must have been declare globals in the program :- OS_TID t1_ID, t2_TID;

Task Creation Start the OS and create the initial task. void os_sys_init(task_name); /* priority defaults to 1 os_sys_init (begin); // start os then start task begin To create further tasks the initial task uses: OS_TID os_task_create(task_name, priority); Example OS_TID t1_ID; // define a task ID variable // now create the task t1_ID = os_task_create (task1, 4); priority is from 1 to 255. 1 being the lowest priority. Beware: If task1 is now the highest priority it will pre-empt the current task!! Tasks are basically 'C' functions with the special attribute __task added before the function definition.

Other Task Management Functions os_tsk_delete - Terminates a selected task os_tsk_delete_self -Terminates the running task os_tsk_self - Returns the task ID of the running task os_tsk_pass - Passes control to the next task ready to run os_tsk_prio - Changes the priority of a given task os_tsk_prio_self - Changes the priority of the running task –

Typical task A task is nothing more than a 'C' function. The task will usually be in the form of an endless while loop that never terminates. Many tasks are periodic E.g. __task void mytask(void) { /* create variables for this task */ while(1) { /* do stuff */ os_dly_wait(100); /* periodic - so have a rest */ }

Time Management functions void os_dly_wait(n_ticks) Pauses the calling task for a specified interval. void os_itv_set(n_ticks) Enables the calling task for periodic wake up. void os_itv_wait(n_ticks) Pauses the calling task until the periodic wake up interval expires. Examples – void task1 (void) __task { os_itv_set(20); while(1) { FIO2PIN ^= LED_A; // toggle led os_itv_wait(); } FIO2SET = LED_A; os_dly_wait(10); FIO2CLR = LED_A;

Event Flag Management functions Used to provide very simple inter-task signalling. os_evt_clr Clears one or more event flags of a task. os_evt_get Retrieves the event flags that caused os_evt_wait_or to complete. os_evt_set Sets one or more event flags of a task. os_evt_wait_and Waits for one or more event flags to be set. os_evt_wait_or Waits for any one event flag to be set. isr_evt_set Sets one or more event flags of a task. Better inter-task communication methods are available - coming soon!

RTX Based Program Operation 'C' main function should Start OS and first task. First task will:- initialise system ready for other tasks initialise I/O create and initialise global systems feature such as : mutexes semaphores filesystems etc Start the other tasks Terminate self Now other tasks run & operate concurrently.

A first example - RTX01.c Before any of the RTX functions can be used the RTX must be started. os_sys_init (taskname); This function initialises and starts the RTX and then starts the taskname task. The initial task is given the default priority of 1 NOTES: The os_sys_init function must be called from the main C function. The os_sys_init function NEVER returns!

Starting the OS and the application tasks. #include <RTL.h> /* ... */ OS_TID t1_ID, t2_ID, t3_ID; /* create task IDs */ int main (void) { uint32_t volatile start; /* Wait for debugger connection */ for (start = 0; start < 1000000; start++) { ; } os_sys_init (begin);/* Initialize OS and start the initial task */ } __task void begin (void) { os_tsk_prio_self(10); /* increase priority of this task */ /* initialise system peripherals etc. here */ t1_ID = os_tsk_create (task1, 4); /* start task1 */ t2_ID = os_tsk_create (task2, 2); /* start task2 */ t3_ID = os_tsk_create (task3, 1); /* start task3 */ os_tsk_delete_self (); }