0% found this document useful (0 votes)
134 views23 pages

RTOS Slides

This document provides an overview and introduction to real-time operating systems using the micrium uC/OS-II RTOS. It discusses key RTOS concepts like tasks, interrupts, semaphores, mailboxes, and memory buffers. It also describes the uC/OS-II objects and shows examples of creating tasks and using interrupts, timers, semaphores, and mailboxes. The document concludes with an outline for a training course covering RTOS lectures and labs.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views23 pages

RTOS Slides

This document provides an overview and introduction to real-time operating systems using the micrium uC/OS-II RTOS. It discusses key RTOS concepts like tasks, interrupts, semaphores, mailboxes, and memory buffers. It also describes the uC/OS-II objects and shows examples of creating tasks and using interrupts, timers, semaphores, and mailboxes. The document concludes with an outline for a training course covering RTOS lectures and labs.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Institut Universitaire de Technologie de CACHAN Universit PARIS SUD - FRANCE

Simple Portable Royalty Free

Readable Source
Well Suited for MCU Well documented

www.micrium.com
Jean Labrosse

An Introduction to Real Time Operating System with UCOS-II


J.O. KLEIN
[email protected]
1

Background / Interrupt Model Limitation


INT INT ISR ISR Background ISR Loop

INT

ISR < 100 us

INT 0 INT 1 BCKGND

ISR 0 INT 1-Pending

ISR > 1 ms Latency


Time
2

RTOS-Solution
INT 0
ISR1 ISR0 ISR1
Task 1

ISR0

INT 1

Task 1 IDLE

Task 1

Time
3

Practical Timing Ranges


ISR RT-Tasks

BackGnd-Tasks
Processing Time

1 us

1 ms

1s

T RTOS Tick = Time unit for delay & timeout

UC/OS-II RTOS Objects


System

INT

ISR

Timer INT
Semaphore Task 0 T 10

Ticks

INT

Memory Buffers

Message Queue

T61

T63 IDLE

INT ISR

ISR
Tx-FIFO

T60
T30

Mailbox
5

Task

Simple Tasks
Task

Ticks

void myTask (void*pdata){ while (TRUE){ OSTimeDly(ticks); } } void myTask (void*pdata){ while (TRUE){ OS???Pend(ticks); } }

Task

??? := Sem | Mbox | Q

Task

Polling & scheduling


while ((PTH & 8)==0){}
Task

PORTH [3]

No context switching : Lower tasks are waiting

while ((PTH & 8)==0){ OSTimeDly(1); } Context switching : Lower tasks can run
7

ISR

Interrupt Service Routine


OSIntNesting++

interrupt VECTOR_NUM void myISR (void){ OSIntEnter(); OSIntExit(); } INT Task 5 Task 10 ISR

if (OSIntNesting-- == 0){ OSIntCtxSw(); }

Preemption

RT Ticks & Timer Interrupt


RT Timer OSTimeDly(tick) 1 ms

ISR

OSTimeTick

OS???Pend( event, tick, &err)

Ticks

Semaphore
ISR
Task Task

OS_EVENT* mySem

if(mySem=OSSemCreate(InitialVal) != NULL)

OSSemPend(mySem, tick, &err)

err=OSSemPost(mySem)

tick:
Initial Value = 0

Optional Timeout
10

Initial Value = 1

Mail Box

OS_EVENT* myMbox

if (myMbox=OSMboxCreate(NULL)) != NULL)
RxMessage = OSMboxPend(myMBox, tick,&err)

err=OSMboxPost( myMbox, TxMessage)

Task

tick:
void*TxMessage

Optional Timeout

void*RxMessage

11

Message Queue
void*Buffer[N] err = OSQPost(myQ,TxMsg ) OSQPostFront( myQ,TxMsg)

OS_EVENT* myQ

If (myQ = OSQCreate(Buffer,N)) != NULL)

RxMsg=OSQPend( myQ, ticks,&err)


Task

OSQFlush(myQ)

tick: void*RxMsg

Optional Timeout

void*TxMsg

12

Memory Buffer
INT8U buf[N*blksize]

OS_MEM* myMem

If (myMem=OSMemCreate(buf,N,blksize,&err) != NULL) OSMemGet(myMem,&err)

OSMemPut(myMem,&err)

Buffer Buffer

NO Timeout

No wait

Task

13

Code Architecture
MAIN.C MAIN XXX.C INIT XXX_EVENTS_INIT ALL_Events_Init StartRTOS.C STAR12_Init APP_Task_CREATE MYTASK_CREATE ALL_INCLUDES.H XXX.H

Task
MYTASK (Hardware Configuration) RTOS_Checking
14

Task

Creating a Task

void myTask (void*pdata); static OS_STK MYTASK_stack[MYTASK_stk_size]; void * ptos = (void*)&MYTASK_stack[MYTASK_stk_size-1]; void * pbos = (void*)&MYTASK_stack[0]; INT8U prio = ; // 0(higher) to 63(idle) INT8U id = 0; // unused INT16U opt = OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR; void*pdata = NULL; //optional data ptr void*pext = NULL; // optional ptr err = OSTaskCreateExt (myTask, pdata, ptos, prio, id, pbos, MYTASK_stk_size, pext, opt);
15

Code Generator
XXX.H XXX.C

XXX_EVENTS_INIT

MYTASK_CREATE

MYTASK
16

Training Course
Lecture
1H30

Labs

3H00

Introduction to RTOS Multitasking, Scheduling Task States Preemptive/Cooperative Task Stacks Introduction to uCOSII Task, Semaphore, Mbox,Q,Mem Starting the OS Code Architecture Code Generator

Getting Start 1H00 Load the demo Add a commented task Debug !

2H00
Writing an Application Use Code Generator Adding the Files to project Adding the task to the App. Debug

ISR

Task 0
17

Starsky
Application Tasks
1 2 3 4 5 6 LineControl MotorControl LineSensor (I2C) USSensor Monitor (RS232) Function
18

Service & System Tasks


60 RS232 61 LCD 62 Init (+RTOS Checking) 63 Idle

Monitoring
5 Monitor Send Sensors & Variables values through RS232 Print To LCD buffer Delay 100 ms 60 RS232 Wait for RS232 Q Constitute Frames Copy msg to TxFIFO Enable SCI Tx ISR

61 LCD Copy LCD buffer to LCD controller Delay 100 ms


62 Init (+RTOS Checking) CPU Usage Stack Usage Delay 1s

19

Application Starsky
1 LineControl 2

USSensor

Wait for LineCtrlSem ShortCut & Crossing Detection End Detection Line Tracking

Emit Ultrasound Delay 5ms Sample echo Delay 30 ms

MotorControl

Monitor

Wait for MotorCtrlSem Read Speed PI Controller or Open loop Setting PWM Values

Emit variable values via RS232 & LCD Delay 100 ms Function (Main Task)

LineSensor

Read line position /I2C Delay 1 ms

Select Mode (Stop,demo,normal) Delay (variable) Set Motor Order or post LineCtrlSem

20

HC12 Enhanced Capture Timer


Free running Timer 16 Timer Capture Register Pulse Accumulator Timer Capture Holding Register Read ICHReg 8

Frequency = Periodic PA sampling

PA Overflow

Period = TC - TCH

Pulse Accumulator Holding Register

21

Frequency Measurement
Modulus Down Counter 5 ms MotorCtrlSem Motor Control

Period = TC - TCH
UINT16 ECT_MOTOR_PT1_speed ( void ){ UINT16 Speed, Delta; Delta = (TC1 - TC1H); TotalPa1 += PA1H ; Speed_mm_per_sec = DiffPA1 * 21; return ( (Speed> 100) ? (3272490UL / Delta) : Speed); }

ISR
1/10 50 ms

void ECT_MOTOR_update(void) { Delta_ic1 = (TC1 - TC1H); // Tfer PA -> PAH Delta_ic3 = (TC3 - TC3H); // Tfer PA -> PAH TotalPa1 += PA1H; TotalPa3 += PA3H; DiffPA1 = TotalPa1 - TotalPa1_old; DiffPA3 = TotalPa3 - TotalPa3_old; TotalPa1_old = TotalPa1; TotalPa3_old = TotalPa3; }

The choice Frequency = Periodic PA sampling

22

Starsky Project
Professor
STAR 12 Board design STAR12 Software Lib UCOS-II Port to STAR12 Board UCOS-II/Star12 Service 3 months 2 months 1 month 1 month

20 Students group
Frequency, Motor controller, H-bridge, RS232 Monitor, I2C All together, Line tracking 6 weeks 6 weeks

3 students
Starsky & Hutch design 8 weeks
23

You might also like