embedded real-time operating systems for socosnet.cs.nchu.edu.tw/powpoint/soc_93/talk - embedded...
TRANSCRIPT
1
Embedded RealEmbedded Real--Time Operating Time Operating Systems for Systems for SoCSoC
Hsung-Pin ChangDepartment of Computer ScienceNational ChungHsing University
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
2
OutlineOutline
• SoC Design
• Embedded Real-Time Systems Overview
• Embedded Real-Time Operating System
• Case Study: Porting
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
3
SoCSoC DesignDesign
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
4
SoCSoC
• SoB (System on Borad) => SoC (System on Chip)• SoCà CPU + ASIC + Software
CPU/ASIC
Operating System
Middleware
ApplicationsMonitoring, Control,Remote Management,Consumer Devices
Databases, Graphics, Java
Linux, VxWorks, others...
PPC, MAC 68k, MIPS, ARM,x86, etc.
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
5
SoCSoC
• SoC: A complex chip and usually includes– Generic modules: CPU, memory controller– Application-specific modules: DSP, Coprocessors
(encryption/decryption)– Interconnects: bus, switch, crossbar– Software: embedded operating system, embedded
applications• SoC usually isn’t just a complex chip
– Pentium 4: No
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
6
SoCSoC Design: Example 1Design: Example 1
IEEEMAC Protocol
Hardware/Software Partition
MAC Protocol by Hardware
802.11 MAC Protocol
MAC Protocol by Software
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
7
SoCSoC Design: Example 1Design: Example 1
ARM Core
PCMCIAHostDriver AHB
BB
DMA Ctrl
CRC32
Lyra
802.11 (SDL)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
8
Example 2: Wireless Multimedia PDA Example 2: Wireless Multimedia PDA SoCSoC
CPU Core
System Bus
LCD control
DMA control
Bridge MemoryController
DRAM
UARTRTC 1
Interrupt control
GPIO
PowerMgr.
Wireless LAN Baseband/MAC RF
Antenna
UART
IO pins
RTC 2
Soundcodec
SpeakerMIC Reset
Reset
DSP
Image Sensor
LCD
Cache
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
9
Embedded RealEmbedded Real--Time Systems Time Systems OverviewOverview
• Embedded system• Characteristics of an
embedded system• Real-Time system
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
10
Embedded SystemsEmbedded Systems
• Computing systems are everywhere• Most of us think of “desktop” computers
– PC’s– Laptops– Workstations– Mainframes– Servers
• But there’s another type of computing system– Far more common...
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
11
Embedded Systems (Cont.)Embedded Systems (Cont.)
• Embedded computing systems– Computing systems embedded within
electronic devices– Hard to define. Nearly any computing
system other than a desktop computer– Billions of units produced yearly, versus
millions of desktop units– Perhaps 50 per household and per
automobile
Computers are in here...
and here...
and even here...
Lots more of these, though they cost a lot
less each.
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
12
A A ““short listshort list”” of embedded systemsof embedded systems
And the list goes on and on
Anti-lock brakesAuto-focus camerasAutomatic teller machinesAutomatic toll systemsAutomatic transmissionAvionic systemsBattery chargersCamcordersCell phonesCell-phone base stationsCordless phonesCruise controlCurbside check-in systemsDigital camerasDisk drivesElectronic card readersElectronic instrumentsElectronic toys/gamesFactory controlFax machinesFingerprint identifiersHome security systemsLife-support systemsMedical testing systems
ModemsMPEG decodersNetwork cardsNetwork switches/routersOn-board navigationPagersPhotocopiersPoint-of-sale systemsPortable video gamesPrintersSatellite phonesScannersSmart ovens/dishwashersSpeech recognizersStereo systemsTeleconferencing systemsTelevisionsTemperature controllersTheft tracking systemsTV set-top boxesVCR’s, DVD playersVideo game consolesVideo phonesWashers and dryers
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
13
An Embedded System Example An Embedded System Example -- a Digital a Digital CameraCamera
Microcontroller
CCD preprocessor Pixel coprocessorA2D
D2A
JPEG codec
DMA controller
Memory controller ISA bus interface UART LCD control
Display ctrl
Multiplier/Accumulator
Digital camera chip
lens
CCD
• Single-functioned -- always a digital camera• Tightly-constrained -- Low cost, low power, small, fast• Reactive and real-time -- only to a small extent
SoC is one way to the fulfillment of embedded system.
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
14
Characteristics of Embedded SystemsCharacteristics of Embedded Systems
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
15
Characteristics of Embedded SystemsCharacteristics of Embedded Systems
• Single-functioned– Dedicated to specific tasks– Executes a single program, repeatedly
• Tightly-constrained– Low cost, low power, small size, fast, etc.
• Reactive and real-time– Continually reacts to changes in the system’s environment– Must compute certain results in real-time without delay
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
16
Characteristics of Embedded Systems (Cont.)Characteristics of Embedded Systems (Cont.)
• Software failure are much severe than desktop systems– Watchdog timer
• Have power constraints– HW + SW problems– Becoming the dominant system constraint
• Have far fewer system resources than desktop system
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
17
Characteristics of Embedded Systems (Cont.)Characteristics of Embedded Systems (Cont.)
• Store object code in ROM/Flash– Do not equal with a hard disk
• Require specialized tools and design methods– ICE – FPGA– Logic analyzer
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
18
Characteristics of Embedded Systems (Cont.)Characteristics of Embedded Systems (Cont.)
• Software Requirements– Real Time– Robust– Small Code Size– Low Power
• Hardware Requirements– Low Power– Cost effective
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
19
RealReal--Time SystemTime System
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
20
RealReal--Time SystemTime System
• Real-time– Does not denote speed/fast– But meet the timing constraints or deadlines
• Goal: make the system predictable and robust• Predictability: have deterministic behavior
– Usually use the worst-case analysis– Guaranteed response/reaction times
• Robustness: the job with granted performance will not be interfered with other job
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
21
Release Time and DeadlinesRelease Time and Deadlines
• Release time– the instant of time at which the job becomes available for
execution– Jobs have no release time if all the jobs are released when
the system begins execution
• Deadline or Absolute Deadline– The instant of time by which its execution is required to be
completed– Equal to the release time plus the relative deadline– A job has no deadline if its deadline is at infinity
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
22
FeasibilityFeasibility
• Timing Constraints– A constraints imposed on the timing behavior of a job– Specified in terms of
• Release time• Deadline
• The set of rules that determines the order in which tasks are executed is called a scheduling algorithm– A schedule is feasible if all tasks can be completed
according to the timing constraints
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
23
Type of RealType of Real--Time SystemTime System
• Hard Real-Time
• Soft Real-Time
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
24
Hard RealHard Real--Time SystemTime System
• Timing is critical and deadline cannot be missed– If the failure to meet the deadline is considered to
be a fatal fault
• Examples:– Nuclear reactors– Flight controller
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
25
Soft RealSoft Real--Time SystemTime System
• A miss of timing constraints is undesirable. However, a few misses do no serious harm– The timing requirements are often specified in probability
terms– The time constraints are guaranteed on a statistical basis
• Examples:– Multimedia Streaming– Electronic games– Quality-of-Service (QoS) guarantees
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
26
ComparisonComparison
Time
Value
Hard RTS
Soft RTS
FirmRTS
Deadline
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
27
Embedded RealEmbedded Real--Time Operating Time Operating SystemSystem
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
28
OutlineOutline
• Embedded RTOS Feature• Task• Synchronization • IPC• Interrupt Service Routine• Device Driver• Case Studies: LyraOS
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
29
Embedded RTOS FeaturesEmbedded RTOS Features
• Small size• Preemptive kernel• Respond to external interrupts quickly• Multitasking • Inter-Process Communication (IPC) scheme• Fast context switch• Minimization of intervals during which interrupts are
disabled
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
30
Embedded RTOS ArchitectureEmbedded RTOS Architecture
User Process
Hardware
User Mode
Kernel Mode
System Call to ask the kernel provide services
Interrupt causethe kernel to service I/O devices
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
31
TasksTasks
• A task is an independent thread of execution
• Task – In User Mode: executes user-layer code in User-Mode (the least
privilege level)– In Kernel Mode: executes kernel code in Kernel-Mode (the
most privilege level)– Task switches repeatlly between User Mode and Kernel Mode
• A task may synchronize and/or communicate with other tasks
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
32
Task States and TransitionsTask States and Transitions
Scheduled
Descheduled (pre-emption)
Wait for Event
Event or Time-out
Prio 1
Prio n
Descheduled(time slicing)
Runable
Runable
Running
Waiting
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
33
Task SchedulingTask Scheduling
• The set of rules that determines the order in which tasks are executed is called a scheduling algorithm
• Well-known scheduling algorithms– Round-Robin– Priority– EDF (Earliest-Deadline-First)– Rate Monotonic
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
34
Tasking ModelsTasking Models
• Cyclic Executives
• Event-Driven
• Multitasking Model
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
35
Cyclic ExecutiveCyclic Executive
• Round Robin Scheduling• Advantages : Simplicity• Disadvantages: Breaks down when application
requirements get complex
Task 1 Task 2 Task n
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
36
InterruptInterrupt--DrivenDriven
• Rely on processors hardware to activate multiple tasks
• Pseudo-concurrency achieved with multiple interrupt levels
• Advantages– Simple
• Disadvantages– Support only tasks reactive to external events
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
37
MultitaskingMultitasking
• Nonpreemptive: context switch is occurred only when a task explicitly give the control to other task– Makes a kernel call– Terminate itself– Wait for an external event to occur– Wait for a shared resource that is currently in use– Sleep for some specified amount of time
• Preemptive
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
38
Multitasking (Cont.)Multitasking (Cont.)
• Advantages: Flexibility
• Disadvantages: Need a RTOS (Real-Time Operating System)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
39
SynchronizationSynchronization
• Data or Resource Protection, i.e., synchronization– Atomic Operations
• atomic_read(v): return *v• atomic _set (v, i): set *v to i
– Disable Interrupt• No context switch or ISR can occur
– Mutex (also called Binary Semaphore)• Mutual exclusion
– Semaphore (also called Counting Semaphore)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
40
InterInter--Process CommunicationProcess Communication
• Inter-Task Communication (IPC)– FIFO (First-In-First-Out)
– Message Queue
– Shared Memory
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
41
Interrupt Service RoutineInterrupt Service Routine
• An Interrupt Service Routine (ISR) is activated by an Interrupt
• The CLI and STI instructions are used to turn the interrupt system on and off
• Minimum action required to support device– read, write, and etc.
• Some RTOS system calls should not be made from ISRs– Calls which could block the caller, waiting for a message or event
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
42
Device DriversDevice Drivers
• Device I/O can be done completely outside of RTOS
• Device Driver Interface Model– _init(), _open(), _close(), _read(), _write(), _ctrl()
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
43
RTOS MarketRTOS Market
• A vast of RTOS on the market– Nucleus Plus, OSE, Virtuoso, ThreadX, WinCE, AMX,
RTX, LynxOS, VRTX, uC/OS II, OS-9, On Time, VxWork, pSOS, EPOC, eCos
– Proprietary OS’s• LyraOS/Vega
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
44
Case Study: Case Study: LryaOSLryaOS
• What is LyraOS ?• LyraOS v.s. Linux • LyraOS architecture• Hardware Abstraction Layer• Pthread• IPC – Message Queue• Memory management• Kernel Summary
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
45
LyraOSLyraOS
• LyraOS is an operating system for embedded devices
• LyraOS is suitable for embedded devices with limited storage capacity
• Features– Multi-threading (Pthread)– Inter-process communication– Memory management– Tiny kernel– Etc.
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
46
LyraOSLyraOS ArchitectureArchitecture
Hardware ( Altera EXPA10 )
Hardware Abstraction Layer
Memorymanagement
PthreadIPC Library
Application Interface ( API )
Application Programs
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
47
Hardware Abstraction LayerHardware Abstraction Layer
• Why we need HAL ?– Hardware independent– Easy porting
• Components :– Timer– Interrupt handler
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
48
PthreadPthread• Pthread
– void pthread_init(void)– int pthread_create(pthread_t *, const
pthread_attr_t *, void *, void *)– int pthread_equal(pthread_t, pthread_t)– pthread_t pthread_self(void)
• Pthread Queue– void pthread_queue_init(struct pthread_queue *)– int pthread_queue_is_empty(struct pthread_queue *)– void pthread_queue_enq(struct pthread_queue
*,struct pthread *)– struct pthread *pthread_queue_deq(struct
pthread_queue *)• Scheduling
– void pthread_sched_prevent(void)– void pthread_sched_resume(void)– void pthread_resched_resume(enum pthread_state)– void pthread_sched_other_resume(struct pthread *)– void pthread_yield(void)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
49
IPC IPC –– Message QueueMessage Queue
• Interfaces– int msgget (key_t, int) – int msgctl (int, int, struct msqid_ds *)– int msgsnd (int, struct msgbuf *, size_t, int)– int msgrcv (int, struct msgbuf *, size_t, long, int)
• Message Queue structure & Message structurestruct msqid_ds {
struct ipc_perm msg_perm;struct msg *msg_first;struct msg *msg_last;time_t msg_stime;time_t msg_rtime;time_t msg_ctime;struct pthread_queue *wwait;struct pthread_queue *rwait;unsigned short msg_cbytes; unsigned short msg_qnum;unsigned short msg_qbytes; ipc_pid_t msg_lspid; ipc_pid_t msg_lrpid;
};
struct msqid_ds {struct ipc_perm msg_perm;struct msg *msg_first;struct msg *msg_last;time_t msg_stime;time_t msg_rtime;time_t msg_ctime;struct pthread_queue *wwait;struct pthread_queue *rwait;unsigned short msg_cbytes; unsigned short msg_qnum;unsigned short msg_qbytes; ipc_pid_t msg_lspid; ipc_pid_t msg_lrpid;
};
struct msg {/* next message on queue */struct msg *msg_next;long msg_type;/* message text address */char *msg_spot;/* msgsnd time */time_t msg_stime;/* message text size */short msg_ts;
};
struct msg {/* next message on queue */struct msg *msg_next;long msg_type;/* message text address */char *msg_spot;/* msgsnd time */time_t msg_stime;/* message text size */short msg_ts;
};
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
50
Message QueueMessage Queue
structmsqid_dsstruct
msqid_ds structmsg
structmsg struct
msgstructmsg struct
msgstructmsg
msgques
msg_last
msg_first
msg_spot msg_spot msg_spot
msg_next msg_next
Message Text
Message Text
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
51
Memory managementMemory management
• void* malloc (size_t nbytes)• void free (void *cp)• void* realloc (void *cp, size_t nbytes)• int memcmp (const void *cs, const void *ct, size_t
count)• void* memcpy (void * dest, const void * src, size_t
count)• void* memchr (const void *s, int c, size_t n)• void* memmove (void * dest, const void * src, size_t
count)• void* memscan (const void * addr, int c, size_t size)• void* memset (void * s, int c, size_t count)
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
52
Memory management (Cont.)Memory management (Cont.)
1 2 3 4 5
8 bytes16 bytes
2 kbytes
Memory Buckets
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
53
Kernel SummaryKernel Summary
• Code size– About 50 kbytes
• Total C and assembly code – About 55300 lines
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
54
Case Study: PortingCase Study: Porting
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
55
Case Studies: PortingCase Studies: Porting
• Goal– Porting LyraOS on Excalibur EPXA10 device
• LyraOS– a Single-Task, Multi-Threaded embedded OS
• EPXA10 is an ARM-based device– ARM922T– SRAM– CPLD– …
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
56
Excalibur EPXA10 DeviceExcalibur EPXA10 Device
• ARM922T • Single-Port SRAM 256 KB• Dual-Port SRAM 128 KB• DIMM Module ( for SDRAM)• SDRAM Controller• 4M Flash• Timer• UART
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
57
Excalibur EPXA10 DeviceExcalibur EPXA10 Device
128M SDRAM
Interface to PCMCIA
ARM 922T
FPGA gates 4MB Flash Memory
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
58
Porting WorksPorting Works
• Understanding the directory arrangement– Find out the hardware dependent files
• Initialization before entering the kernel• Memory map for EPXA10• Interrupt setting and ISR• Timer• UART• Testing
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
59
LyraOSLyraOS Directory OverviewDirectory Overview
LyraOS
*Include Lib *api Dbg
*HalLib++*pthread
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
60
Hardware Dependent FilesHardware Dependent Files
• armc_startup.s– initialize interrupt vector table, stack, memory map and
hardware setting• irq.c (IRQ:Interrupt ReQuest )
– irq_init (initialize interrupt controller), irqhandler, ISR• page.c
– page_init, page_alloc, page_free• stripe.h
– Altera EPXA10 Device Setting• uartcomm.c
– uart_init, uart_tx_handler, uart_rx_handler, fgetc, fputc
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
61
PortingPorting
• Initialization– Divide Stacks – Define the Interrupt vector table– Read ID code: read the hardware ID code– Registers setting
• PLL• Setup memory map
– Flash, Single-Port SRAM, Double-Port SRAM, SDRAM• CPLD (Complex Programmable Logic Device)• SDRAM Controller, Timer and UART• Copy image from Flash to SDRAM, and jump to the SDRAM
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
62
Porting (Cont.)Porting (Cont.)
• System Memory Map– Flash :0x40000000
• 4Mb
– SDRAM:0x00000000• 128Mb
– SRAM:0x10000000• 2*128k
– PLD:0x80000000
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
63
Porting (Cont.)Porting (Cont.)
• Interrupt– Handle all hardware exception
• Timer• UART
– Interrupt Service Routine (ISR)• Determined what kinds of interrupt• To do the suitable services
• Timer• UART Driver
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
64
Porting (Cont.)Porting (Cont.)
• Debugger and Development Tools– ARM Development Suite (ADS)– AXD– Muti-ICE
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com
65
ü Question ?
PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com