Download presentation
Presentation is loading. Please wait.
Published byBuddy Terry Modified over 8 years ago
1
1 J.O. KLEIN JOK@IEF.U-PSUD.FR Institut Universitaire de Technologie de CACHAN Université PARIS SUD - FRANCE An Introduction to Real Time Operating System with UCOS-II www.micrium.com Jean Labrosse Portable Royalty Free Readable Source Simple Well Suited for MCU Well documented
2
2 Background / Interrupt Model Limitation INT Background Loop … Time BCKGND INT 1 ISR INT INT 0 ISR < 100 us ISR > 1 ms Latency ISR 0 INT 1-Pending
3
3 RTOS-Solution ISR1 Time IDLE INT 1 INT 0 Task 1 ISR0 ISR1 Task 1 ISR0
4
4 Practical Timing Ranges RTOS Tick = Time unit for delay & timeout 1 us1 ms1 s ISR RT-Tasks Processing Time BackGnd-Tasks T
5
5 UC/OS-II RTOS Objects System ISR INT ISR INT Task 0 T60 Ticks ISR T 10 Semaphore T63 IDLE Message Queue Tx-FIFO Mailbox Timer INT T61 T30 Memory Buffers
6
6 Simple Tasks void myTask (void*pdata){ while (TRUE){ … OSTimeDly(ticks); } Task Ticks Task void myTask (void*pdata){ while (TRUE){ … OS???Pend(ticks); } ??? := Sem | Mbox | Q
7
7 Polling & scheduling while ((PTH & 8)==0){} Task PORTH [3] while ((PTH & 8)==0){ OSTimeDly(1); } No context switching : Lower tasks are waiting Context switching : Lower tasks can run
8
8 Interrupt Service Routine interrupt VECTOR_NUM void myISR (void){ OSIntEnter(); … OSIntExit(); } OSIntNesting++ ISR if (OSIntNesting-- == 0){ … OSIntCtxSw(); } Task 10 Task 5 ISR INT Preemption
9
9 RT Ticks & Timer Interrupt ISR RT Timer 1 ms OSTimeTick Ticks OSTimeDly(tick) OS???Pend( event, tick, &err)
10
10 Semaphore ISR Task Initial Value = 1Initial Value = 0 if(mySem=OSSemCreate(InitialVal) != NULL)… err=OSSemPost(mySem) OS_EVENT* mySem OSSemPend(mySem, tick, &err) Optional Timeout tick:
11
11 Mail Box Task if (myMbox=OSMboxCreate(NULL)) != NULL)… Optional Timeout err=OSMboxPost( myMbox, TxMessage) RxMessage = OSMboxPend(myMBox, tick,&err) OS_EVENT* myMbox void*TxMessage tick: void*RxMessage
12
12 Message Queue Task If (myQ = OSQCreate(Buffer,N)) != NULL)… …OSQPost(myQ,TxMsg ) RxMsg=OSQPend( myQ, ticks,&err) OS_EVENT * myQ …OSQPostFront( myQ,TxMsg) …OSQFlush(myQ) void*TxMsg void*Buffer[N] Optional Timeout tick: void*RxMsg err =…
13
13 Memory Buffer If (myMem=OSMemCreate(buf,N,blksize,&err) != NULL)… OSMemPut(myMem,&err) OS_MEM* myMem Buffer Task NO Timeout No wait Buffer OSMemGet(myMem,&err) INT8U buf[N*blksize]
14
14 Code Architecture XXX.C XXX.H XXX_EVENTS_INIT MYTASK_CREATE MYTASK MAIN.CALL_INCLUDES.H Task MAIN INIT StartRTOS.C STAR12_InitAPP_Task_CREATE RTOS_Checking ALL_Events_Init (Hardware Configuration)
15
15 Creating a Task err = OSTaskCreateExt (myTask, pdata, ptos, prio, id, pbos, MYTASK_stk_size, pext, opt); 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
16
16 XXX.H Code Generator XXX.C XXX_EVENTS_INIT MYTASK_CREATE MYTASK
17
17 Training Course 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 Load the demo Add a commented task Debug ! Writing an Application Use Code Generator Adding the Files to project Adding the task to the App. Debug 1H30 LectureLabs 1H00 2H00 3H00 ISR Task 0
18
18 Starsky 1 LineControl 2 MotorControl 3 LineSensor (I2C) 4 USSensor 5 Monitor (RS232) 6 Function Application Tasks 60 RS232 61 LCD 62 Init (+RTOS Checking) 63 Idle Service & System Tasks
19
19 Monitoring 5 Monitor 60 RS232 62 Init (+RTOS Checking) CPU Usage Stack Usage Delay 1s Wait for RS232 Q Constitute Frames Copy msg to TxFIFO Enable SCI Tx ISR Send Sensors & Variables values through RS232 Print To LCD buffer Delay 100 ms 61 LCD Copy LCD buffer to LCD controller Delay 100 ms
20
20 Application Starsky 1 LineControl 2 MotorControl Wait for MotorCtrlSem Read Speed PI Controller or Open loop Setting PWM Values 4 USSensor Emit Ultrasound Delay 5ms Sample echo Delay 30 ms 3 LineSensor Read line position /I2C Delay 1 ms Wait for LineCtrlSem ShortCut & Crossing Detection End Detection Line Tracking 6 Function (Main Task) Select Mode (Stop,demo,normal…) Delay (variable) Set Motor Order or post LineCtrlSem 5 Monitor Emit variable values via RS232 & LCD Delay 100 ms /
21
21 HC12 Enhanced Capture Timer Free running Timer Timer Capture Register Timer Capture Holding Register Pulse Accumulator Holding Register PA Overflow Read ICHReg 16 8 Frequency = Periodic PA sampling Period = TC - TCH
22
22 Frequency = Periodic PA sampling Period = TC - TCH The choice Frequency Measurement 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); } Modulus Down Counter 5 ms MotorCtrlSem Motor Control 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; }
23
23 Starsky Project Professor –STAR 12 Board design 3 months –STAR12 Software Lib 2 months –UCOS-II Port to STAR12 Board 1 month –UCOS-II/Star12 Service1 month 20 Students group –Frequency, Motor controller, H-bridge, RS232 Monitor, I2C6 weeks –All together, Line tracking6 weeks 3 students –Starsky & Hutch design8 weeks
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.