Download presentation
Presentation is loading. Please wait.
Published byLinda Dean Modified over 8 years ago
1
SOC Consortium Course Material SoC Design Laboratory Lab 8 Real-time OS - 2 Speaker: Yung-Chih Chen Advisor: Prof. Chun-Yao Wang November 17, 2003 Department of Computer Science National Tsing Hua University
2
SOC Consortium Course Material Real-time OS SoC Design Laboratory 1 Outline Introduction to μC/OS-II – uC/OS-II Kernel – Context switch – Resource management using Semaphore – Memory management – Interrupt
3
SOC Consortium Course Material Real-time OS SoC Design Laboratory 2 uC/OS-II Kernel Basic jobs of uC/OS-II kernel Task management Interrupt handling Inter-process communication
4
SOC Consortium Course Material Real-time OS SoC Design Laboratory 3 Kernel API Service routines provided by uC/OS-II Kernel Task management APIs Time management APIs Memory management APIs Inter-process communication APIs Synchronization APIs To make a System Call means to call Kernel API
5
SOC Consortium Course Material Real-time OS SoC Design Laboratory 4 Context Switching Context Switching The process of swap in/out the context of tasks when scheduler choose a new task to run. Context Usually means values in registers used by the task. Switching Steps 1.Save registers of current task to stack (curr) 2.Load new task’s SP into CPU 3.Restore registers of new task from stack (new) 4.Resume execution of new task
6
SOC Consortium Course Material Real-time OS SoC Design Laboratory 5 Context Switching Time ISR Low-priority Task High-priority Task ISR makes the high-priority task ready Context Switching Context Switching high-priority task Relinquishes the CPU
7
SOC Consortium Course Material Real-time OS SoC Design Laboratory 6 Critical Region Code need to be treated indivisibly Code have to be executed without interrupt creating task…etc Non-reentrant code accessing shared variable…etc
8
SOC Consortium Course Material Real-time OS SoC Design Laboratory 7 Critical Region Protecting critical region OS_ENTER_CRITICAL( ) temporarily disable interrupt OS_EXIT_CRITICAL( ) re-enable interrupt
9
SOC Consortium Course Material Real-time OS SoC Design Laboratory 8 Events A way for Synchronization and Communication Pend(Wait for an event) Post(Signal an event) Events in uC/OS-II Semaphore Counting Semaphore Message Mailbox Message Queues
10
SOC Consortium Course Material Real-time OS SoC Design Laboratory 9 Semaphore Semaphore serves as a key to the resource A flag represent the status of the resource Prevent re-entering Critical Region Can extend to counting Semaphore Task 1 Task 2 RS-232 Send data via RS232 Semaphore Request/Release
11
SOC Consortium Course Material Real-time OS SoC Design Laboratory 10 Semaphore Using Semaphore in uC/OS-II OSSemCreate() OSSemPend() OSSemPost() OSSemQuery() OSSemAccept()
12
SOC Consortium Course Material Real-time OS SoC Design Laboratory 11 Message Mailbox Used for Inter-Process Communication (IPC) A pointer in MailBox points to the transmitted message Task ISR Task “message” Mail Box Post Pend
13
SOC Consortium Course Material Real-time OS SoC Design Laboratory 12 Message Queues Array of MailBox FIFO & FILO configuration Task ISR Task “message” Mail Queues Post Pend
14
SOC Consortium Course Material Real-time OS SoC Design Laboratory 13 MailBox & Queues Using MailBox in uC/OS-II OSMboxCreate() OSMboxPend() OSMboxPost() OSMboxQuery() OSMboxAccept() Using Queue in uC/OS-II OSQCreate() OSQPend() OSQPost() OSQPostFront() OSQQuery() OSQAccept() OSQFlush()
15
SOC Consortium Course Material Real-time OS SoC Design Laboratory 14 Memory Management Semi-dynamic memory allocation Allocate statically and dispatch dynamically Explore memory requirements at design time Task 1 Task 2 Task 3 allocate statically partition into memory blocks dispatch dynamically OS InitializingOS running
16
SOC Consortium Course Material Real-time OS SoC Design Laboratory 15 Memory Management Using Memory in uC/OS-II OSMemCreate() OSMemGet() OSMemPut() OSMemQuery()
17
SOC Consortium Course Material Real-time OS SoC Design Laboratory 16 Interrupt Interrupt Controller A device that accepts up to 22 interrupt sources from other pheripherals and signals ARM processor Interrupt Handler A routine executed whenever an interrupt occurs. It determines the interrupt source and calls corresponding ISR. Usually provided by OS. Interrupt Service Routine (ISR) Service routines specific to each interrupt source. This is usually provided by hardware manufacturer.
18
SOC Consortium Course Material Real-time OS SoC Design Laboratory 17 Interrupt Peripheral sends interrupt request to interrupt controller Interrupt controller sends masked request to ARM ARM executes interrupt handler to determine int. source Peripheral B Interrupt Controller Interrupt Controller Peripheral A ARM Processor ARM Processor bus
19
SOC Consortium Course Material Real-time OS SoC Design Laboratory 18 Interrupt Default interrupt handler: uHALr_TrapIRQ() 1.Save all registers in APCS-compliant manner 2.Call StartIRQ(), if defined 3.Determine interrupt source, call the corresponding interrupt service routine (ISR) 4.Call FinishIRQ(), if defined 5.Return from interrupt
20
SOC Consortium Course Material Real-time OS SoC Design Laboratory 19 Interrupt When an interrupt occurs, no further interrupt accepted To achieve real-time, the period of interrupt disabled should be as short as possible Do only necessary jobs in ISR, leave other jobs in a deferred Task
21
SOC Consortium Course Material Real-time OS SoC Design Laboratory 20 Lab 7:Real-time OS - 2 Goal – A guide to use RTOS and port programs to it Principles – Basic concepts and capabilities of RTOS Context switch Resource management using Semaphore Memory management – Coding guideline for a program running on the embedded RTOS Guidance Steps – Context switch example – Using Inter-Process Communication (IPC) Requirements and Exercises – Write an embedded software for ID checking engine and a front-end interface Discussion – Explain and describe executing process of eg2 (context switch example)
22
SOC Consortium Course Material Real-time OS SoC Design Laboratory 21 References [1] AFS_Reference_Guide.pdf
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.