Professional Documents
Culture Documents
ESD Merged RL All 803pg
ESD Merged RL All 803pg
§ Maintainability
§ ISP & IAP
§ Portability
§ Time-to-prototype and Market
Specifications
System Architecture
System Integration
System Validation
Software
Embedded System Design - RL1.1.2 © K.R.Anupama & Meetha.V.Shenoy 8
M1: Introduction to Embedded Systems
FPGA/ASIC Memory
Software
Embedded System Design - RL1.2.1 © K.R.Anupama & Meetha.V.Shenoy 2
§ Processors
§ Timers
§ SCI
§ Interrupt Controller
§ Parallel Ports
§ Memory
§ Data
§ Program
§ Power supply
§ Reset- Oscillator circuits
§ Application Specific Circuits
Performance
/ Power DSP, ASIPs Flexibility
Efficiency
FPGA
ASIC
x,÷,+,-
RISC CISC
§ Decode
§ Execute
1. ADD R2,R1,R3
2. SBR R2,R3,R2
3. STR R2,b
9 cycles
5 cycles
Pipeline Hazards
Embedded System Design - RL1.2.1 © K.R.Anupama & Meetha.V.Shenoy 11
§ µc
§ Processor has limited capability
§ Enhanced i/o Functions
§ Appln Specific units [DTMF/MODEM]
§ Stream 1 – 68HC11xx, HC12xx, HC16xx
§ Stream 2 - 8051
§ Stream 3 – PIC16F84 – Microchip
§ Stream 4 – ARM based Microcontrollers
§ µp
§ used when program is large/ large no. of computations have to be
carried out
§ RISC – used when intensive computations have to be done
Inc value
Write value
Read value
Inc value
Restore
Task1
Write value
Write value
§ Image Processing
Software
Embedded System Design - RL1.2.3 © K.R.Anupama & Meetha.V.Shenoy 2
§ RAM
§ Internal/External
§ Flash Memory/EEPROM
§ External/Internal
§ System Ports
§ ROM/PROM
§ Cache
Memory
CPU Data
Inst/Data
Control
IDATA Inst
Memory
ICONTROL
CPU
DADDR
DDATA Data
Memory
DCONTROL
§ SODIMMs
§ PCMIA
Instructions
RAM
NVRAM
Stack
System
Cache
Cntlr
Cache hit/miss
L2 Cache
L1 Cache
CPU
Cache
Cntlr
Cache hit/miss
L2 Cache
L1 Cache
CPU
Cache
MAR
Block N
cache block 1
cache block 2
cache block 3
cache block 4
cache block 5
Address
00 -
1 1000
-
01 -
0
1 0001
1111
-
10 -
0 0110
-
11 - -
0 -
10 -
1000 -01 -0000
1 -
00 -
0101 -10 -0001
§ Main Memory
§ 256 K x 32
§ 512 Blocks - m
§ 64 Groups –n
§ Group No m mod n
0 1 2 3 4 5 6 7
Tag
bank select
data
§ ADC
§ VDD VSS AGnd, AREF, AIP
§ Idle
§ Saves power by stopping the CPU clock
§ Sleep
§ Turns off all units except – Power -0
§ Keeps Power unit thro’ I/O power supply line
Run
10 µs 90 µs
10 µs
160ms
Idle Sleep
90 µs
50 mW 0.16 mW
§ Sources of reset
§ Power on reset
§ Reset
§ RC
§ IC
10ms
t
Control
§ Default Priorities
§ COP Watchdog
§ External Interrupts
§ Timer
§ Serial I/f
§ ADC
§ DAC- PWM
§ Asynchronous
§ Asynchronous
§ Peer- to- Peer
§ Clock Implicit
§ PAL
§ GAL
§ PLDs, CPLD,
§ FPGA
§ Drivers
Software
Embedded System Design - RL1.2.6 © K.R.Anupama & Meetha.V.Shenoy 8
M1: Introduction to Embedded Systems
FPGA/ASIC Memory
Software
Embedded System Design - RL1.3.1 © K.R.Anupama & Meetha.V.Shenoy 2
Appln Layer
RTOS
Hardware
§ Appln tasks
§ ISR
§ RTOS
§ i/p data
§ Vector address
§ Small –Scale ES
µc
.s19/hex
§ Scheduling Algo
§ RMS
§ EDF
§ LLF
§ Does it work?
§ Complex Testing
§ Limited observability and controllability
§ Restricted Development Environment
Architecture
Components
Sys Integration
ASIP
FSK Mod
DESIGN PROCESS
Requirements Every step
Analyze
Architecture
Components
Sys Integration
Rotating Plate
Microwave Vents
Weight Sensor
DESIGN PROCESS
Requirements Every step
Analyze
Architecture
Components
Sys Integration
Turn Table
Open/Close
Door
Magnetron Control
Memory
Hardware Architecture
DESIGN PROCESS
Requirements
Architecture
Components
Sys Integration
Keys Ports
Start/Stop INT0/INT1
Auto cook -3 keys P1.0- P1.2
Weight -2 P1.3 – P1.4
Power Level P1.5
Timer P1.6
10 Min
P2.0- 2.2
1 Min
10 sec
P1.2
P1.3
P1.4
KBD
P1.5
IE1
P1.6
P1.7
R
10
S1 A
EMBEDDED SYSTEM DESIGN – RL2.3.1 © K.R.ANUPAMA & MEETHA.V.SHENOY 8
MODULE 1 - DISPLAY
LT a
RBO
RBI
5V h
A
B
C Vcc Port4, Port 5, Port 2.4-2.7, Port 3.4,3.5
D
GND
7447
P3.6
DESIGN PROCESS
Requirements
Architecture
Components
Sys Integration
Rotating Plate
Microwave Vents
Weight Sensor
TRx (TCON)
EMBEDDED SYSTEM DESIGN – RL2.3.2 © K.R.ANUPAMA & MEETHA.V.SHENOY 6
TIMER0
TMOD
TCON
P2.4
DESIGN PROCESS
Requirements
Architecture
Components
Sys Integration
TX
Enable
T2CON
T2CON
T2CON
T2MOD
T2OE DCEN
DESIGN PROCESS
Requirements
Architecture
Components
Sys Integration
4.4 1.0 BV
4.7 1.1 CH
5.0 1.2 FR
5.7 1.3 WT
1.4 AW
1.5 PL
3.7
1.6 T
Lock 3.6
1.7 TT
3.5
2.0 10M
3.4
2.1 1M
Start 3.3
2.2 10S
Stop 3.2
2.3
TXD 3.1 MAG
2.4
Load Cell RXD 3.0
2.7
X1
24M
X2
supply 8051RE2
EMBEDDED SYSTEM DESIGN – RL2.3.4 © K.R.ANUPAMA & MEETHA.V.SHENOY 4
INTERRUPTS
§ INT0,INT1 § INT0, INT1
§ KBE § Timer2
§ TIMER0 § Timer0
§ TIMER2 § KBE
§ SCI § SCI
IE1
IPH0
IPL2
DESIGN PROCESS
MICROWAVE OVEN
8051RE2 – Software
4.4 1.0 BV
4.7 1.1 CH
5.0 1.2 FR
5.7 1.3 WT
1.4 AW
1.5 PL
3.7
1.6 T
Lock 3.6
1.7 TT
3.5
2.0 10M
3.4
2.1 1M
Start 3.3
2.2 10S
Stop 3.2
2.3
TXD 3.1 MAG
2.4
Load Cell RXD 3.0
2.7
X1
24M
X2
supply 8051RE2
EMBEDDED SYSTEM DESIGN – RL2.3.45 © K.R.ANUPAMA & MEETHA.V.SHENOY 3
MAIN ROUTINE
§ Initialise the following data parameters to the default value
Power Level 10
Weight 0
Auto Weight 1
Timer 0
10 MIN 0
1 MIN 0
10 SEC 0
Start 0
Stop 0
Cook Time 0
Count 100
Magnetron 0
EMBEDDED SYSTEM DESIGN – RL2.3.45 © K.R.ANUPAMA & MEETHA.V.SHENOY 4
PowerLevel’ 0
MAIN ROUTINE
§ Enable Port 1 for Input with Interrupt with Low Select
§ Enable INT0 and INT1
§ Initialise Timer 2 for Auto Reload and enable interrupt but do not
start the timer
§ WAI
Register window
Meetha.V.shenoy
•
• Delayed branches
• Single cycle instructions
2
Register Windowing
Input
Registers
Meetha.V.shenoy
Registers Registers
Sub1 Local
Registers
Output
Registers
3
ARM- Characteristics
• 32- bit RISC
• Pipelined – 3 stage
Fetch
Meetha.V.shenoy
• Two Instruction sets
32-bit ARM
16-bit THUMB – Instruction Compression
4
ARM Cores
Meetha.V.shenoy
next 5
•
•
•
•
SISD
MISD
SIMD
MIMD
Flynn’s Taxonomy
Meetha.V.shenoy
SISD
Meetha.V.shenoy
SIMD
Meetha.V.shenoy
A: I1 A,B
SIMD B: I1 C,D
Data Bus A
Meetha.V.shenoy
A B
9
MISD
back
Int-Latency 24-42 24
Memory No Yes
Protection
Speed 0.95 DMIPS/MHz (A) 1.25 DMIPS/MHz
0.74 DMIPS/MHz (T)
Power 0.28mW/MHz 0.19mW/MHz
Meetha.V.shenoy
12
ARM- Programmer’s
Model & Operating
Modes
M3: Embedded Architectures- 1: RISC Architecture -
ARM
ARM- Characteristics
• 32- bit RISC
• Pipelined – 3 stage
Fetch
Meetha.V.shenoy
• Two Instruction sets
32-bit ARM
16-bit THUMB – Instruction Compression
• Bi-Endian
2
•
•
•
ARM
Thumb
Switching - BX
Operating States
Meetha.V.shenoy
Operating Modes
• 7 modes of operation
Privileged
User Mode – default – executes applns
•
modes
Meetha.V.shenoy
•
• Undefined Mode
4
Registers
• ARM has 37 registers
31 – GPRS, 6 SR
Meetha.V.shenoy
• r13 – Stack Pointer
• CPSR – CCR/Flags
• In privileged modes – SPSR
5
r0 r0 r0 r0 r0 r0
r1 r1 r1 r1 r1 r1
r2 r2 r2 r2 r2 r2
r3 r3 r3 r3 r3 r3
r4 r4 r4 r4 r4 r4
r5 r5 r5 r5 r5 r5
r6 r6 r6 r6 r6 r6
Meetha.V.shenoy
r14 r14_fiq r14_svc r14_abt r14_irq r14_und
r15(PC) r15(PC) r15(PC) r15(PC) r15(PC) r15(PC)
Meetha.V.shenoy
Thumb State Registers
7
r0 r0
r1 r1
r2 r2
r3 r3
r4 r4
r5 r5
r6 r6
r7 r7
Meetha.V.shenoy
r15(PC) r15(PC)
CPSR CPSR
SPSR SPSR
8
Program Status Registers
7 0
I F T M4 M3 M2 M1 M0
- A1- A0
A3 A2 - - - - E A
B3 B2 B1 B0
- GE1- GE0
GE3 GE2 - - GE3 GE2 GE1 GE0
N Z C V Q - - J
Meetha.V.shenoy
10011 Supervisor
10111 Abort
11011 Undefined
11111 System 9
ARM- Instruction Set
-1
M3: Embedded Architectures- 1: RISC Architecture -
ARM
Addressing Modes
• Mode 1: Shifter operands for data processing inst
• Mode 2: Load/Store word/unsigned byte
Meetha.V.shenoy
2
31-28 27 26 25 24-21 20 19-16 15-12 11-0
Meetha.V.shenoy
LS Rm ASR Rs
GE Rm ROR Rs
LT
LE No Condition Taken as AL
AL 3
ADD R2, R2,#1
ADD R4,R5, R5, LSL #2
ADD R10,R15,#8
ADDS R4,R5,R6, LSR R7
R6 = 00 00 00 02
Meetha.V.shenoy
R7 = 00 00 00 03
4
Arithmetic & Logical
Instructions
Arithmetic Logical
• ADC • ORR
• SUB • EOR
• SBC • BIC
• RSB
RSC
Meetha.V.shenoy
•
5
31-28 27 26 25 24 23 22 21 20 19- 15- 11-0
16 12
Cond 0 1 1 P U B W L Rn Rd Addr mode
Meetha.V.shenoy
LS
GE
LT
LE
AL 6
LDR R1, [R0] Address in R0
LDR R8, [R3, #4]
Address = [R3]
LDR R12, [R13, #-4] R3 = R3 +4
STR R2, [R1, #0x100] Address = [R13]
R13 = R13 -4
LDRB R5, [R9]
Address = [R1]
STRB R4, [R10, #0x200] R1 = R1 +0100H
Meetha.V.shenoy
7
Address = [R1]
LDR R11, [R1, R2] R1 = R1 + R2
STRB R10, [R7, -R4] Address = [R7]
R7 = R7 + R4
LDR R11, [R3, R5, LSL #2]
Address = [R13]
LDR R1, [R0, #4]! R13 = R13 + R5 * 4
LDR R3, [R9], #4 R0 = R0 +4
Address = [R0]+4
STR R2, [R5], #8
Meetha.V.shenoy
8
Transfer btwn memory & reg
LDR/LDRB/LDRH/LDRSH
STR/STRB/STRH/STRSH
ADR
Meetha.V.shenoy
2
x = (a+b)-c;
ADR r4,a
LDR r0,[r4]
Meetha.V.shenoy
ADR r4,x
STR r3,[r4]
3
31-28 27 26 25 24 23 22 21 20 19-16 15-0
Examples
Meetha.V.shenoy
Addressing Mode – IA, IB, DA, DB, FD, FA, EA,ED
4
0x204 20304050
0x200 21314151
0x1fc 22324252
0x1f8 23334353
0x1f4 24344454
Meetha.V.shenoy
Stack Fully
EmptyDescending
Descending
5
0x204
0x200
0x1fc
0x1f8
0x1f4
0x1f0 24344454
Meetha.V.shenoy
Stack Fully
EmptyAscending
Ascending
6
Branch instructions
conditional branch forwards /backwards up to 32MB
branch /jump can also be generated by writing a value to R15
31-28 27 26 25 24 23-0
Meetha.V.shenoy
BL func
MOV PC, LR
LDR PC, #func
7
Pipeline in ARM
• 3 stages of pipeline
• Fetch-Decode-Execute
Meetha.V.shenoy
8
add r0,r1,r2 fetch decode execute
sub r2,r3,r6 fetch decode execute
cmp r2,r4 fetch decode execute
Meetha.V.shenoy
10
stall
2 holes
Meetha.V.shenoy
11
bne nxt fetch decode execute
nop fetch decode execute
nop fetch decode execute
sub r2,r3,r6
Delayed Branching
Meetha.V.shenoy
12
ARM- Exceptions
M3: Embedded Architectures- 1: RISC Architecture -
ARM
ARM-Exceptions
• Handled by entering into different operating modes
• Exception Entry
Meetha.V.shenoy
2
Interrupts/ Address Entry F I
Exceptions Mode
Reset 0x 0000 0000 Supervisor 1 1
Undefined 0x 0000 0004 Undefined U 1
SWI 0x 0000 0008 Supervisor U 1
Pre-fetch 0x 0000 000C Abort U 1
Meetha.V.shenoy
3
Main Program
ADR r4,a
LDR r0,[r4]
LDR r4,[r2] FIQ
LDR r1,[r4]
ADD r3,r0,r1
r15 r14_fiq
CPSR SPSR_fiq
r14_fiq - 4 r15
SPSR_fiq CPSR
Meetha.V.shenoy
4
r0
r1
r2
r3
r4
r5
r6
Meetha.V.shenoy
r14 r14_fiq
r15(PC)
CPSR
back-up
SPSR_FIQ SPSR_fiq
User FIQ 5
FIQ
• nFIQ pin –low
Meetha.V.shenoy
6
FIQ - actions
• Actions Taken on FIQ
Meetha.V.shenoy
• Exit From FIQ
7
IRQ
• nIRQ pin –low
Meetha.V.shenoy
• Exit From IRQ
• SUBS PC, R14,#4
8
Supervisor Mode
• Entry-SWI
• Actions Taken on SWI
Meetha.V.shenoy
• Exit From Supervisor
• MOVS PC, R14
9
Undefined
• Inst than cannot be handled by ARM/co-processor
• Actions Taken on Undefined
Meetha.V.shenoy
• Exit From Undefined
• MOVS PC, R14
10
ARM- Exceptions -
Abort
M3: Embedded Architectures- 1: RISC Architecture -
ARM
ARM-Exceptions
• handled by entering into different operating modes
• Exception Entry
Meetha.V.shenoy
2
Abort- Prefetch
• Current inst cannot be completed
Meetha.V.shenoy
3
1
5
4
3
2
0
7
4
2
i
i
i
v
v
v
Page Table
7
2
0
F
A
Physical Memory
A
D
E
B
Disk
F
C
Meetha.V.shenoy
40 ADR R1,A A: ADR R1,A
ADR R2,B
44 ADR R2,B
LDR R0,[R1]
48 LDR R0,[R1]
LDR R1,[R2]
4C LDR R1,[R2]
B: ADD R2,R1,R0
50 ADR R7,D
ADD R2,R1,R0
ADR R1,C
54 ADR R1,C
R8,E
Meetha.V.shenoy
Physical Memory
5
Abort handler
• Works out the causes of abort
Meetha.V.shenoy
Data
6
Pre-fetch Abort
• ARM marks it
Meetha.V.shenoy
7
Prefetch Abort
• Actions Taken on Pre-fetch Abort
• T bit = 0 I=1
Meetha.V.shenoy
• Exit From Pre-fetch Abort
8
Data Abort
• Action depends on inst type
• LDM/STM
• Abort in middle of data t/f –rest of regs not affected
Meetha.V.shenoy
original state
9
00 FE
00 ADR R0,0
CA
04 ADR R1,B DE
08 LDMIA R0!, {R1,R2,R3} 45
0C ADD R1,R1,R2 04 11
78
0F ADD R3,R1,R3 12
Meetha.V.shenoy
MMU
Abort
10
How does it distinguish between
Pre-fetch & Data Abort?
• Pre-fetch abort occurs in fetch stage
• Data abort occurs in execute state
• T bit = 0 I=1
Meetha.V.shenoy
• Exit From Data Abort
12
AMBA
M4: Embedded Architectures- 2: ARM based LPC23xx
Some Common Bus Terminologies
• Bundle
• Handshake
• Timing Diagram
• Changing States
• Stable States
• Timing Constraints
• Wait states
• Burst transfer
• Disconnected/Split Transfers
Split Yes No
Transaction
Clocking Synch Asynch
Bridge
High Speed Bus
Low-Speed
Device
High-Speed
Memory
Device
10
DRAM Speed
Bridge
AHB/ASB APB
Timer
Memory DMAC
• 1 SPI interface
• 2Synchronous Serial Ports (SSP)
• 3 I2C interfaces
• 1 I2S interface,
• 1 MiniBus
Main Osc
PLL cpu
Int RC mux mux clk div
RTC clksrcreg
3.3
2.9
2.65
Int
Reset
Enable - PCON
16 KB Ethern 8 KB USB+4k
SRAM et AHB-AHB Bridge SRAM SRAM+DMA
MAC+
DMA GP DMAC
AHB-APB Bridge
APB peripherals(256M)
Reserved(512M)
Reserved
Bank(1) 64kb
Bank(0) 64kb
8K Boot Block
Reserved
Memory Map
16kb Ethernet RAM
512RL4.1.2
KBEmbedded
NV Meetha.V.shenoy
Memory
System Design © K.R.Anupama &
9
LPC 23XX- GPIO
M3: Embedded Architectures- 2: ARM based LPC23xx
Features
• GPIO PORT0 & PORT1
• accessible
• group of reg providing enhanced features accelerated port access
• legacy group of reg
• IOxPIN
• IOxSET
• IOxCLR
• IOxDIR
• IntEnF
• IntStatR
• IntStatF
• IntClr
• IntStatus
Int2S Int0S
Channel 1 CAP0.1
Channel 2
Channel 3
Timer 0
CF
CI Interrupt Logic
Interrupt Request
PINSEL Registers
Bit12-13 :PCLK_TIMER2
1 1 CCLK/8
Bit14-15 :PCLK_TIMER3
÷1/2/4/8 Pre-Scale+1
CCLK
Counter
CAP
CCR
TR TE
Ack Interrupt
Match
0005Reg
CI INT
Logic
Interrupt
RL4.1.4 Embedded System Design © K.R.Anupama &
19
Meetha.V.shenoy
Output Compare 0.0 P1.28 AltF3, P3.25 AltF2
Output Compare 0.1 P1.29 AltF3, P3.26 AltF2
EMC3 EMC2
Feed Ok
WDFEED
Feed Error
RTC Osc
32-bit down cntr
PCLK ÷4
Internal
RC OSC
Feed Ok
AA
55HH
Feed Error
RTC Osc
FFH
00
PCLK ÷4
Internal
RC OSC
WDINT
1 WDTOF
1 WDRESET WDEN
Int
Reset
CLK Select
PCLKSELREG0 0:1
WDCLKSELECT Reg WDSEL
WDTCReg
Minimum value = 256
32 Int . Vectored
sources Int Controller
.
.
IRQ
Bit 23 22 21 20 19 18 17 16
Bit 15 14 13 12 11 10 9 8
FIQ
Soft Int Int Enable FIQ Status
Int 0-31
IRQ Status
Raw Int
Int Select
Vector Address 0
Vector
Select
IRQ
Status 1
Vect Addr
or
Addr
IRQ ess
Status 31
RL4.2.1 Embedded System Design © K.R.Anupama &
6
Meetha.V.shenoy
VIC Interrupt Selection Registers
(32-bit Reg)
Classifies each Interrupt as IRQ/FIQ
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 9 8 7 6 5 4 3 2 1 0
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
ORED
Peripheral interrupts
VICSoftIntClr
Clearing S/w Interrupt bits
VICIntEnClr
RL4.2.1 Embedded System Design © K.R.Anupama &
8
Meetha.V.shenoy
Vector Address Registers
VICVR0 – VICVR31
P3 P2 P1 P0
ADC clock
10-bit data
PCLKSEL0: 25-24
PINSEL
CLKDIV
EDGE START
000 No Start ADC clock < 4.5 MHz
001 SOC
010 SOC – EINT0
011 SOC-CAP0.1
100 SOC-MAT0.1
101 SOC-MAT0.3
110 SOC-MAT1.0
111 SOC-MAT1.1
RL4.2.2 Embedded System Design © K.R.Anupama &
7
Meetha.V.shenoy
AD0STAT
ADINT
Ack Interrupt
AOUT
VDDA
VSSA
10-bit data
RL4.2.2 Embedded System Design © K.R.Anupama &
11
Meetha.V.shenoy
DAC always on
PCLKSEL0 23:22
PINSEL1, PINMODE1
DATA
BIAS
0 - 1µs
1 - 2.5µs
MISO
Master
Slave SPI
SPI
SCLK
SS
SCLK
CPOL =1
SS
CPHA =0
MOSI
Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7
CPHA =1
MOSI
Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7
1 0 1 0 0 0 1 0 0 0 0 0
BITS BITS
X X X X X X X X
2 1
3
SPDR
MOSI
Shift Reg Shift Reg
SPICLK(0:7) 1 SPDR 3
SPSR
SPF WCOL ROVR MODF ABRT
SPSR
SPICLK(0:7)
SPIR
SPIF SPF WCOL ROVR MODF ABRT
4 SPIR
RL4.2.3 Embedded System Design © K.R.Anupama &
6
2
Meetha.V.shenoy
SPIF
PCONP: 12 – Default on
PCLKSEL0: 16-17
PINSEL
SPCR
SPDR
SPSR
MISO/DR/SI
Master
Slave SPI
SPI
SCLK/CLK/SK
CS/FS/SS
FS
DX/DR
Bit4 Bit3 Bit2 Bit1
FS
TI Format
SS
SO
Microwire Format
SCR
SSPxCR1
SOD MS SSPE LBM
SSPxMISR INT
TXMIS RXMIS RTMIS RORMIS
SSPxICR
RTIC RORIC
TDMAE RDMAE
PE 1 Data
(Master)
Clock
PE 3
(Slave)
Master Mode
Slave
Bus No
free?
Yes
Master
Yes Arbit
lost?
No
RL4.2.4 Embedded System Design © K.R.Anupama &
8
Meetha.V.shenoy
I2C Operating Modes
Appln – I2C may operate - master/ slave/ both
Slave Mode
Addr
=mine
Yes
?
No
No Addr
=bcas
t?
Yes
Int
RL4.2.4 Embedded System Design © K.R.Anupama &
9
Meetha.V.shenoy
Master Transmission
Master Receive
M2
Bus
Arbitration Loss
Arbitration
RL4.2.4 Embedded System Design © K.R.Anupama &
12
Meetha.V.shenoy
CL1
CL2
SCL
Synchronization Process
8
Bit cntr/
APB Bus
I/p Timing PCLK
SCL Filter Arbt/
Sync &
O/p
Control INTR
Stage Serial
Clock
Generato
I2CONSET
r
I2CONCLR Control/CLK Reg 16
I2SCH:I2SCL
Status Status Decoder 8
Reg RL4.2.4 Embedded System Design © K.R.Anupama &
Meetha.V.shenoy I2STAT 14
2
IS
• Supports NXP Inter IC Audio format for 8, 16 & 32 bits audio data
both for stereo & mono modes
WS
SD
SD
SCK Audio i/p
WS
Rx Unit
Mono-16bit
data2 data2 data1 data1
Stereo-16bit
data2r data2l data1l data1r
Mono-32bit
data1 data1 data1 data1
RL4.2.4 Embedded System Design © K.R.Anupama &
20
Meetha.V.shenoy
Digital Audio Output/Input Register
Mute WS_Size
TxFIFO Reg
RxFIFO Reg
TxCLK Reg/ RxCLK Reg – 0:9
Sample Rate – 48 KHz
Then value of clock - 48KHz x 2x16
Object Layer
•Message Filtering
•Message & Status Handling
Transport Layer
•Fault Confinement
•Error Detection & Signaling
•Message Validation
•Ack
•Arbitration
•Message Framing
•T/f rate & Timing
Physical Layer
•Signal level & Bit Repsn
•Tx medium
RL4.3.1 Embedded System Design © K.R.Anupama &
3
Meetha.V.shenoy
Message Transfer is done in frames
Frame Types
Data Frame
Remote Frame
Error Frame
Overload Frame
Frames are separated by IFS
Bit – Dominant/Recessive
CRC
SOF de-limiter
Control Field
R R DL3 DL2 DL1 DL0
Bit
Acceptan Rx Buffers stream
ce Filter 1,2 processor
• Designed
• NRZI – NRZ with zero stuffing when there are more than 6 one’s
• Sync field – sync tx and rx clocks
Device Device
Host/ D+ D+
Device
Hub D- D-
Full Speed
Host/ D+ D+
Device
Hub D- D-
Low Speed
Host Controller
Logic Pipes
End Points
Devices
RL4.3.2 Embedded System Design © K.R.Anupama &
13
Meetha.V.shenoy
Pipes & Endpoints
• A USB device can have - 32 active pipes- 16 into/ 16 out of host
cntlr
• Endpoint can t/f data in one direction only- each pipe is uni-
directional
• Endpoints grouped into i/fs - each i/f is associated with a single
device func
• Exception - endpoint zero- used for device config - not associated
with any i/f
USB ATX
EP_RAM D+
Serial I/f
AHB Bus
EP_RAM
(4k)
AHB Control
AHB Bus Slave Reg &
I/f Logic
16 KB Ethern 8 KB USB+4k
SRAM et AHB-AHB Bridge SRAM SRAM+DMA
MAC+
DMA GP DMAC
AHB-APB Bridge
hn-1 hn-2 hk h0
Y
TAP
FIR Filtering
Sx*h
DSP Processors
u Dynamic Range :
Largest Number
Smallest Number
u usually represented in dB
Radix Point
Sign bit
0 1 0 1 0 0 0 0
1 0 1 0 0 0 0 0
Mantissa
- 23 22 21 20
Mantissa
0 1 0 1 0 0 0 0
1 is assumed to be present
Exponent
0 1 0 1
22 + 20 = 5
S E7 E6 E5 E4 E3 E2 E1
Data Bus B
A B
A: I1 A,B
SIMD B: I1 C,D
RL5.1.3 Embedded System Design © K.R.Anupama & Meetha.V.shenoy 6
Internal Program
Memory (Cache)
8x32
VLIW nx32
L1 S1 M1 D1 L2 S2 M2 D2
Register File A Register File B
Internal
RL5.1.3 Embedded System Design Data
© K.R.Anupama RAM
& Meetha.V.shenoy 7
Superscalar Architecture
56 48
Shifter (-1, 0,+1)
ALU
56 24
Accumulators A (56)
24
B (56)
56 56
Shifter (-1, 0,+1) Limiter
24
24
MX (2x16) MY(2x16)
Mux Mux
16
16 16 16
X Y
Multiplier MF(16)
P
MV Adder/ Subtractor
Mux
RL5.1.4 Embedded System Design © K.R.Anupama &
6
Meetha.V.shenoy
DO dotprod UNTIL CE;
dotprod:
B3 B2 B1 B0 Operand B
Data Converter
Multiplier
S
P
45 40
Floating point adder
40
40
A0(40) Accumulators
A1(40)
A2(40)
A3(40)
32
RL5.1.5 Embedded System Design © K.R.Anupama &
5
Meetha.V.shenoy
Shifter
u In case of arithmetic operation results tend to grow
u Shifters are hence provided in the data path
u Here scaling is done automatically
u Shifter is usually invisible to user
u In case of processors where fixed-point and floating-
point data paths are the same-> shifter can be
controlled by user
u Fixed-point
u Floating-point
u Multiprocessor
u TMS320 DSPs – arch is designed specifically for real-
time signal processing
u C2000, C5000, C6000
u C6000 – 1600 MIPS
8x32 VelociTI
nx32
L1 S1 M1 D1 L2 S2 M2 D2
Register File A Register File B
Internal
RL5.2.1 Embedded System Design Data& Meetha.V.shenoy
© K.R.Anupama RAM 5
Features
u Compact instructions
u Protected mode operation
u Each multiplier can perform 32 x 32 bit multiplies
u Additional insts to support complex multiplies allowing
up to 8 16-bit multiply/add/subtracts/ clock cycle
u Exceptions support for error detection and program
redirection to provide robust code execution
L2 PMC
Cache/
UMC
SRAM IDMA
(2M)
EMC
Program Fetch
SPLOOP Buffer
16/32- bit Inst Dispatch
Inst Decode
64 64
u Loop:
u Stage 1
u Stage 2
u Stage 3
u Stage 4
Stage4
PMC
L2
Cache/
UMC
SRAM IDMA
(2M)
EMC
src1
Reg
src2
.S1 odd dst
even dst
long src 8
src1
.M1 src2
dst1
dst2
ST1b
ST1a
LD1b
LD1a
1X
src1
dst
src1
A p B p C p D p E p F p G p H p
●Fully serial
●Fully parallel
●Partially serial
1 A
2 B,C,D
3 E
4 F,G,H
MV .S1X B0,A0
|| MV .L1X B1,A1
MV .S1X B0,A0
|| MV .L1X B0,A1
|| MV .D1X B0,A2
RL5.2.3 Embedded System Design © K.R.Anupama & Meetha.V.shenoy 6
ADD .S1 A0, A0, A1
BK1 0 0 1 0 0
FFFF FF12
B1
A2 FFFF FF12
B1 039A E4B8
A0 FF 68 48 3D A2 3E 5E 39 42
A1 3F F6 F1 05
X
0 1 1 0
0 0 0 0
0 1 1 0
0 1 1 0
0 0 0 0
0 1 0 0 1 0 0
0 0 1 0 0 1 0 0
FFFF FF12
B1
A2 FFFF FF12
B1 039A E4B8
A0 FF 68 48 3D A2 3E 5E 39 42
A1 3F F6 F1 05
X
0 1 1 0
0 0 0 0
0 1 1 0
0 1 1 0
0 0 0 0
0 1 0 0 1 0 0
0 0 1 0 0 1 0 0
u User Mode
u Supervisor Mode
u control the operation of unprivileged software
u protect access to critical system resources (ints)
u control entry to itself
u Privilege system allows 2 distinct types of op
u Supervisor-only execution
u Two-tiered system
u On reset
u On Interrupt
u On exception
u User Mode Entry
u TSR 6:7 – CXM
u For re-entry into Supervisor Mode
u SWE / SWENR
u AMR
u CSR
u PCE1
u DNUM
u SSR
u TSCH
u TSCL
u TSR
PWRD SAT EN
REV ID
CPU ID
CSR
u ICR
u IER
u IFR
u IRP
u ISR
u ISTP
u NRP
u ITSR
u ECR
u EFR
u IERR
u REP
u GEE -1 (TSR2)
u XEN -1 (TSR3)
u NMIE -1 (IER1)
u EXF (EFR30)
u GEE -1 (TSR2)
u IXF (EFR1)
MSX
TMS 64xx
M5: Embedded Architectures- 3: DSP Architectures
Interrupts
u Reset
u Maskable
u Non-maskable
u Exception
CPU
PMC
L2
Cache/
UMC
SRAM IDMA
(2M)
EMC
¡ H/w
¡ Control
¡ Data
¡ Single Fixed Control pt. – Physically the system may or may not have multiple
CPUs
¡ Single Dynamic Control point
¡ A fixed master - slave structure
¡ Dynamic master – slave structure
¡ Multiple Homogeneous control points – copies of the same controller are used
¡ Multiple Heterogeneous control points – different controllers are used
¡ Centralized Data bases with a single copy of both files and dir
¡ Distributed files with a single centralized dir and no local dir
¡ Replicated database with a copy of files and dir at each site
¡ Partitioned data base with a master that keeps a complete duplicate copy of all
files
¡ Partitioned database with a master that keeps only a complete dir
¡ Partitioned database with no master file/dir
¡ The vehicle is six-wheeled with an on-board robotic arm to pick up samples and
on-board scientific instruments and cameras
¡ The primary aim of the vehicle is to explore the terrain, transmit images
captured by a CCD camera, measure atmospheric conditions in the mine and
assess samples of rocks and soil
¡ This can be controlled remotely from above the ground
¡ All subsystems on the vehicle are controlled by the remote unit and are in
contact with the remote unit through Memory & Alternate Application
subsystem.
¡ There is a UHF antenna with the required transmitter and receiver circuit is
mounted on the vehicle.
¡ The vehicle should be able to uplink data using the UHF antenna to the remote
console available aboveground.
¡ The remote console analyses the data from the camera and also makes the
required navigation decisions.
¡ DC motors are used for rotating the wheels and stepper motors are used for
steering.
¡ The two front wheels are locked together by the same steering mechanism; the
same is done in case of the rear wheels.
¡ A Robotic arm is used for sample collection.
¡ The robotic arm is capable of movement both in the horizontal plane and in the
vertical plane.
¡ Data regarding movement and sample collection is obtained from Memory and
Alternate Program sub-system.
RESET’
ENABLE’
SLEEP’
MS0 0 -GND
MS1 1- 5 V
DIR
STEP
¢ 5
¢ IN0
¢ IN1
¢ How Many
¢ Rear Wheel -1
¢ Front Wheel -1
¢ SCI
¢ TXD
¢ RXD
¢ 9600 Baud – Standard Rate
0 1 0 0 0 0 0 0
0 0 0 0 0 0 1 0
1 0 0 1 0 0 1
CCAPM0-4
Compare Registers 0 - 4
CCON
1 1 0 0 0 0 0 0
IE0
0 0 0 0 0 1 0 0
IE1
¢ HCN ¢ ADC
¢ CH4
¢ CO
¢ C3H8
LPC2378
6
HD0-HD15 P1.16-1.32
HINT EINT0
TMS 6455
HCNTL P3.2
P3.1
HHWIL P3.0
HCS’ P3.5
5V
HAS’
HDS2
HSIZE LPC2378
9
HD0-HD15 P1.16-1.32
HINT EINT0
TMS 6455
HCNTL P3.2
P3.1
HHWIL P3.0
Data DR
AD0 HCN
Clk CLKR HCS’ P3.5
AD1 CH4
5V
STB FSR HAS’ AD2 CO
AD3 C 3 H8
AD6 Temp
HDS2
Camera HSIZE LPC2378
11
LPC 2378
RL6.3.3 EMBEDDED SYSTEM DESIGN © K.R.ANUPAMA & MEETHA.V.SHENOY 5
MOS1
TXD0
Remote unit
RXD0 MISO
Vehicle Sub-system
SS
LPC SCLK
2378
12x2x12x1 = 48MHz
6
12 MHz
Create
Course Info Course
Catalog
Use Case - Relationships
General Browse
<<extends>> <<extends>>
Specialized Search
Use Case - Relationships
case2 Give Price
<<uses> <<uses>
Locate
case1
Book
Actors & Use Cases
Gives
money
ATM Customer
Data Acquisition System
§ Measures Voltage
§ Measure Temp
§ Data – Initial Analysis done and sent for further processing
§ Analysis result sent back
UML
Measure
Volts
Data
Analysis
Measure Data
Actor0 Temp Processing
Textual Description – Measure Volts
User
Select measure volts mode
Select measurement range
System
If range specified
Configure to specified gain
Make Measurement
If in range – display results
If exceed range – display largest value & flash display
If auto range
Configure to midrange gain
Make Measurements
If In range- display result
If above/below range – adjust gain repeat measurement
If exceed range – display largest value & flash display
Textual Description
§ Normal Activity
§ Exceptional Conditions
Class Diagram
§ Help Indentify/Formulate – Modules
§ Describe object/modules
§ Relationship between objects
§ Public i/f to object
§ Properties – op that instances of the object can perform
§ Indentifies any constraints the appln imposes on these op
Class Diagram
Object Name
- Properties
+ Operations()
Class Relationships
§ Parent – Child/ Inheritance/Generalization
§ Interface
§ Wrapper around one piece of functionality
§ Allows to present diff set of capabilities to public view
§ Containment
§ One object made up of several others
§ Whole part relationship
§ Aggregation
Owned module may be used out of aggregation
§ Composition
Ownership is very strong
Inheritance/Generalization
Driver
+port number: unsigned char
+buffer address: int
+status: unsigned char
+ Read(): Boolean
+Write(): Boolean
Serial Parallel
action()
return()
Create & Destroy
:Task i :Task j
<<create>>
<<destroy>>
Send
:Task i :Task j
action()
Sequence Diagrams
§ Objects
§ Lifeline
§ Focus of Control
§ Messages
Sequence Diagram – Time Interval
Measurement
Measur Get Exec
Convert Display
e Task Attrib Meas
measure ()
get range ()
range()
get edge ()
edge()
send data ()
result()
send data ()
formatted data()
Display data ()
ok()
done()
Fork& Join
Parent
Child 0
Child 2
Child 1
Parent
Branch & Merge
Activity 0
When:[guard codn]
Activity 1
Activity 2
Activity 3
Activity 4
Activity Diagram
Activity 0
Activity 1
When:[guard codn]
Activity 5 Activity 3
Activity 2
Activity 4
Activity 6
Activity 7
Activity 8
Measure
Time
Get range
Get edge
Open meas
window
Close meas Update
window Display
Read count
Flash Flash
State Chart Diagrams
Same as state diagrams with some extensions
Transitions
event
State2 State7
State2
State2 State7
Guard Condition
State2 State9
Event [guard]
State10
Composite States
Substate0 Substate1
Event [guard]
Substate 3 Substate 2
astate
Concurrent States
astate
State8 State9
State10 State11
Control & Data Graphs
Program Model - CDFG
Data Operations
Control Operations
a b c d e
w=a+b
x= a–c
+ + -
y= x+d x1
x= a+c +
z= y+e
x2 w y
Single assignment form
w = a+b
x1 = a – c +
y = x1 + d
x2 = a + c
z
z = y+e
if (codn1)
basic_block1();
else
basic_block2(); T
cond1 basic_block1()
basic_block3();
switch(test1){
case c1:basic_block4();break; F
case c2:basic_block5();break; basic_block2()
case c3:basic_block6();break;
}
basic_block3()
test1
§ Measurement Range
§ 3 for signals
§ 2 for events
Pwr Reset
Use Case – Local Mode
Measure
Freq
Measure
Period
Measure
Interval
Count
User Events
Reset
Use Case – Remote Mode
Measure
Freq
Measure
Period
Measure
Interval
Count
User Events
Reset
Measure Frequency
§ Frequency measured continuously
§ Start Trigger
§ Exceeds allowable maximum – flash maximum
§ Exceeds allowable minimum – display ‘0’ and flash
§ Within bounds – display
Use Case – Measure Freq
Select
Mode
Select
Range
Select
User Trigger
Textual Description – Measure Freq
User
Select measure freq mode
Select measurement range
Select measurement Trigger
System
Configure to specified range and trigger
Make Measurement
If in range – display results
If exceed range – display largest value & flash display
If below range – display zero value & flash display
Measure Period
§ Period measured continuously
§ Start Trigger
§ Exceeds allowable maximum – flash maximum
§ Exceeds allowable minimum – display ‘0’ and flash
§ Within bounds – display
Use Case – Measure Period
Select
Mode
Select
Range
Select
User Trigger
Measure Interval
§ Interval measured within a window
§ Start Trigger
§ Stop Trigger
§ Exceeds allowable maximum – flash maximum
§ Exceeds allowable minimum – display ‘0’ and flash
§ Within bounds – display
Use Case – Measure Interval
Select
Mode
Select
Range
Select Start
User Trigger
Select Stop
Trigger
Count Events
§ Event done continuously
§ Start Trigger
§ Exceeds allowable maximum – flash maximum
§ Exceeds allowable minimum – display ‘0’ and flash
§ Within bounds – display
Use Case – Count Events
Select
Mode
Select
Range
Select Edge
User
Other Specifications
§ Automatic Power Line Voltage Regulation
§ Temperature Staability 0 -50C
§ < 6 x10-6
§ Aging Rate
§ 90 day
§ < 3x10-8
§ 6 month
§ <6 x10-7
§ 1 year
§ <25 x10-6
Other Specifications
Safety : IEC-1010
MTBF : 10,000 hrs
Measure Frequency
Get range
Get edge
Open meas
window
Close meas
window Update Display
Read count
Flash Flash
Measure Period
Get range
Get edge
Read count
Flash Flash
Measure Interval
Get range
Read count
Flash Flash
Compilers,
Assemblers &
Debuggers
M7: Embedded Software Design
Embedded Code
Rich functionality
Run at the required rate
Fit within a certain amount of memory
Meet power consumption requirements
Robust, Reliable and Maintainable
Source
code
Pre-
processor Compiler Assembler
Object
code
Linker
.s19/ hex
Loader
Preprocessor
Builds Temporary File – Translation unit
Header File - # include
# define, #ndef
Unresolved external references
Compiler
Cross compiler
a*b + 5*(c - d)
Flow Graph for Statement
Translation
a b c d
1 - 2
* w 5
x
* 3
y
4 +
z
Register Allocation
w=a+b
x= c+w
y= c+d
1 2 3
w=a+b
x= c+w
y= c+d
Color Graphs
Smallest no. of colors to represent all variables
a b
w
d
x
c
y
w=a+b
x= c+w
y= c+d
Compiler
Optimization Tech
Dead Code Elimination
Procedure Inlining
Expression Simplification
a * b + a*c = a*(b+c)
Instruction Selection
Scheduling
ORG $1000
PLC -1000
LABEL1 ADR r4,c
PLC -1004 LDR r0,[r4]
LABEL2 ADR r4,b
LDR r1,[r4]
LABEL3 SUB r0,r0,r1
Linker
Allows program to be stitched together from smaller pieces
Lib - preassembled
Labels
defined and used in same file
defined and used in different files
Entry Point
External Reference
Proceeds in two steps
absolute address of start of each obj file
specified by user
merges all symbol tables relative address – absolute address
DLL
Makefiles
Files to compile
Standard and custom lib
Name of executable
Whether debug info
hw:hw.o
gcc hw.o –o hw
hw.o:hw.c
gcc –c hw.c
Debug & Release Builds
Debugging tool
Larger Executable
Tasks & Task Management
¡ Exchange/share data
¡ Synchronization
¡ Sharing resources (processor)
¡ Schedule
Execution Execution
Threads within a Resource Ownership
process share
resources
Simultaneous
Adv – Backup
Producer T0 T1 Consumer
Bool Full()
Bool Empty()
B0
T0 T1
B1
16
RL8.1.1 Embedded System Design © K.R.Anupama & Meetha.V.Shenoy
Ring Buffers T0 - head
T1- Tail
T0 T1
post pend
send receive
B0 B1
Network Network
T0 T1
send recieve
B0 B1
Stacks
¡ Stack Frame/Activation Record
• Data Inconsistency
• Aberrant/unexpected behavior
3
Co-operating Tasks
Producer Consumer
while(1) while(1)
if not full if not empty
add item get item
inc count dec count
else else
wait for space wait for item
endwhile endwhile
4
Problem ??
• Simultaneous access of count
• 3 different values at any instant of time
• Critical Section – Mutually exclusive access
5
Non-CS
Synchronization
Entry Section
• Mutually exclusive Critical Section
• Condition
Exit Section
Non-CS
6
Requirements – Soln
• Mutual exclusion
• Deadlock
• Bounded Waiting
7
Soln 1: Flags
• Each Task has a flag
• Atomic procedure await
await (codn)
{
statements
} variable
8
Flags
Producer Consumer
While(1) While(1)
if not full if not empty
add item get item
await(!T1Flag) {T0 await(!T0Flag) {T1
Flag= true} Flag = true}
inc count dec count
T0Flag = False T1Flag = False
else else
wait for space wait for item
endwhile endwhile
9
Problems
• Task process not wanting to co-operate can hold
token forever
• Task/Process with token crashes
• Token corrupted/lost
• Task with token terminates without giving up token
• Task added/removed
11
Solution
• Add Task for token management
• Every time a task enters/leaves – registers with
token management
• Disadvantages
▫ No. of tasks increase
▫ IPC reqd for new task
12
Soln 4: Semaphores
• Semaphores: Introduced by Dijkstra in 1960s
Semaphores
• Variables that can be accessed only thro’ atomic op
• wait – p(s)
• signal – v(s)
• p(s) – test & set
• v(s) - reset
15
Semaphores
wait(s) signal(s)
{ {
while(s); s = false;
s = true; }
}
17
Semaphores – Counting
• Takes value 0 – N-1
• List of associated processes
• Process executes wait instruction – semaphore not available
• Task blocks itself
▫ Block – waiting queue of semaphore (task waiting)
▫ Control Transferred to scheduler
• Restarted when signal op is executed
▫ Wake –up
▫ Task in ready state – ready queue
19
Semaphores
wait(s) signal(s)
{ {
s = s+1; s = s -1;
if(s >1) if (s>1)
{ {
add process to waiting remove process from
queue; waiting queue;
block; wakeup(p);
} }
} }
20
Semaphore implementation
typedef struct {
int value;
queue tlist;
} semaphore;
21
Buffer 0
Buffer 1
Buffer n-2
Buffer n-1
23
Requirements
• Imaging System – Producer
• Satellite System – Consumer
• Count no. of free/full buffers
• Controlled access to individual buffers for read/write
24
Algorithm - Producer
• Producer checks if any buffer is empty
• If empty – waits for exclusive access to buffer pool.
• Access gained – data added – then exit
25
Algorithm - Consumer
• Consumer checks whether any buffer has data
available
• If yes waits for exclusive access
• Buffer pool – available consumer gets data and
exits
26
Semaphores
• mutex (1)
• empty (n-1)
• full (0)
27
Camera Satellite
while(1) while(1)
…. wait(full);
produce an item wait(mutex);
…. ….
wait(empty); remove item from
wait(mutex); buffer;
…. ….
add item to buffer; signal(mutex);
…. signal(empty);
signal(mutex); ….
signal(full); consume item
…. ….
endwhile
endwhile
28
Semaphores
wait(empty) signal(empty)
sem_wait (semaphore *S) sem_signal (semaphore *S) {
{ S->value++;
S->value--; if (S->value <= 0) {
if (S->value < 0) { remove thread t from
add this process to S->tlist;
S->tlist;
wakeup(t);
block();
}
}
}
29
Modified Rover
• Imaging System can gather data simultaneously
• Data can be uploaded using several links
• Data object shared by several concurrent processes
▫ Readers – Writers
Readers access data simultaneously
Writer and reader try simultaneously
▫ Reader – Writer Problem
• No Reader waits unless a writer is accessing the buffer
31
Semaphores
• wrtSem (1)
• mutex (1)
• numReaders (0)
32
writer Reader
wait(wrtSem); while(1)
…. wait(mutex);
numReaders++;
perform writing;
if(numReaders==1)
…. wait(wrtSem);
signal(wrtSem); endif
signal(mutex);
….
Perform reading;
…
wait(mutex);
numReaders--;
if(numReaders==0)
signal(wrtSem);
endif
signal(mutex);
endwhile
33
Soln 5: Monitors
• Monitors provide control by allowing only one process to access a
critical resource at a time
▫ A class/module/package
▫ Contains procedures and data
Data – object state
• Data abstraction mechanism that encapsulates a repsn of an
abstract object
34
An Abstract Monitor
monitor monName
{
… some local declarations
… initialize local data
procedure name(…arguments)
… other procedures
permanent variables (static)
}
35
Monitor Rules
• Only procedure names are visible – Public interface
• Permanent variables can be changed only thro’ one of the
procedures
• Any process can access any monitor procedure at any time
• Only one process may enter a monitor procedure
▫ Simultaneous access of two different proc
▫ Two invocations of same proc
• No process may directly access a monitor’s local variables
• A monitor may only access it’s local variables
36
• “wait” operation
▫ Forces running process to sleep
• “signal” operation
▫ Wakes up a sleeping process
• Condition
▫ Synchronisation
37
Monitor - implementation
Monitor boundBuffer
bufferPool;
count = 0;
cond notEmpty;
cond not Full;
39
Monitor - implementation
put(anItem)
{
while(count==n)wait(notFull);
put an item into buffer;
signal(notEmpty);
}
40
Monitor - implementation
get(anItem)
{
while(count==0)wait(notEmpty);
get an item from buffer;
signal(notFull);
}
41
Producer Consumer
while(1) while(1)
…. ….
produce an item boundBuffer.get(anItem)
…. ….
boundBuffer.put(anItem) produce an item
…. ….
endwhile endwhile
42
Problems
• Starvation
▫ Block one process from running – while a
processor is waiting – other process are added and
removed in LIFO
• Deadlock
RTS
Executing
needs data
gets data
& CPU
Pre-empted ready
Chosen to run
Rxd data
Ready Waiting
needs data
P2 P1 P2 P3
0 10 20 30 40 50 60
Deadline
Initiating event
Periodic Process
P1
period
Deadline
Initiating event
Periodic Process
P1
period
Deadline
Initiating event
Periodic Process
P1
period
Deadline
Initiating event
Si=1n ci/pi £ 1
utilization – 100 %
T1 T2 T3 T4
0 5 10 16 20 24 34
T1 T2 T3 T4
0 5 11 15 25