View
218
Download
1
Embed Size (px)
Citation preview
EENG449b/SavvidesLec 6.1
2/1/05
Feb 1, 2005
Prof. Andreas Savvides
Spring 2005
http://www.eng.yale.edu/courses/2005s/eeng449b
EENG 449b/CPSC 439b Computer Systems
Lecture 6
ARM Architecture & Programming
EENG449b/SavvidesLec 6.2
2/1/05
Where is ARM Today?
EENG449b/SavvidesLec 6.3
2/1/05
Announcements
• Need to register for lab access• Lab located in CO-40• You need to see Ed Jackson to get
access to the lab– Take your Yale id with you
• Reading for next lecture– Get by without and RTOS by Melkonian
• Camera based projects:– Camera description lecture tomorrow – Prof. Eugenio Culurciello, AKW 000 @ 4:00pm
EENG449b/SavvidesLec 6.4
2/1/05
EENG449b/SavvidesLec 6.5
2/1/05
EENG449b/SavvidesLec 6.6
2/1/05
EENG449b/SavvidesLec 6.7
2/1/05
EENG449b/SavvidesLec 6.8
2/1/05
Not the case when you have loads and stores!!!!
EENG449b/SavvidesLec 6.9
2/1/05
EENG449b/SavvidesLec 6.10
2/1/05
EENG449b/SavvidesLec 6.11
2/1/05
EENG449b/SavvidesLec 6.12
2/1/05
EENG449b/SavvidesLec 6.13
2/1/05
EENG449b/SavvidesLec 6.14
2/1/05
EENG449b/SavvidesLec 6.15
2/1/05
EENG449b/SavvidesLec 6.16
2/1/05
EENG449b/SavvidesLec 6.17
2/1/05
EENG449b/SavvidesLec 6.18
2/1/05
3-State ARM7 Pipeline
EENG449b/SavvidesLec 6.19
2/1/05
Stalls in 3-stage pipeline
EENG449b/SavvidesLec 6.20
2/1/05
How do we improve the design?
• Where are the bottlenecks? • In the memory subsystem: we have a
Von Neumann Architecture– Include separate Instruction and Data Caches
• How do we minimize stalls from data dependencies?
– ?
• When does this solution not work?• Load instructions
LDR rN, [..]ADD r2, r1, rN
EENG449b/SavvidesLec 6.21
2/1/05
5-stage ARM9Improvement
EENG449b/SavvidesLec 6.22
2/1/05
ARM Instructions
3-type instruction classification• Data processing• Data transfer• Control flow
EENG449b/SavvidesLec 6.23
2/1/05
Data Processing Instructions
• Arithmetic operationsADD r0, r1, r2;ADC r0, r1, r2; add w/curry r0 :=r1+r2+cSUB r0, r1, r2; SBC r0, r1, r2; r0 :=r1 – r2 + C – 1etc …
• Bitwise Logical OperationsAND r0, r1, r2OR r0, r1, r2EOR r0, r1, r2BIC r0, r1, r2; r0 := r1 and not r2
EENG449b/SavvidesLec 6.24
2/1/05
Data Processing Instructions II
• Register Movement Operations
MOV r0, r2; r0 := r2
MVN r0, r2;r0 := not r2• Comparison Operations
CMP r1, r2 ; set cc on r1 – r2
CMN r1, r2;set cc on r1 + r2
TST r1, r2; set cc on r1 and r2
TEQ r1, r2; set cc on r1 xor r2• Immediate Operands
ADD r3, r3, #1; r3 := r3 + 1
AND r8, r7, #&ff;
EENG449b/SavvidesLec 6.25
2/1/05
Data Transfer Instructions
• Most common are load and store but there is support for multiple loads,
• Register Indirect Addressing
LDR r0, [r1]
STR r0, [r1]
LDR r0, [r1,#4]
LDR r0, [r1,#4]! ; also increments r1 ; by the immediate
EENG449b/SavvidesLec 6.26
2/1/05
Control Flow Instructions
• Unconditional BranchesB LABEL…
LABEL …
• Conditional BranchesMOV r0, #0
LOOP …ADD r0, r0, #1CMP r0, #10BNE LOOP…
EENG449b/SavvidesLec 6.27
2/1/05
Writing a simple assembly language program
EENG449b/SavvidesLec 6.28
2/1/05
Reverse Engineering a Program
• In the lab we will be using the GNU tools
– Slight difference in syntax
• As a first step we will compile and analyze programs
– Main compiler arm-elf-gcc– To compile a program to assembly
» arm-elf-gcc –S hello.c– Using objdump
» Arm-elf-objdump –source hello
EENG449b/SavvidesLec 6.29
2/1/05
Example Program#include <stdio.h>int a_global = 10;int foo (int arg ){
static foo_counts = 0; foo_counts++; return foo_counts + arg;}int main (void){
int nloops;char* charstr = "hello world\n";
for( nloops=0; nloops < 10; nloops ++){printf("%s",charstr);foo(nloops);
}return 0;
}
EENG449b/SavvidesLec 6.30
2/1/05
An Example Embedded System Application: A Mobile Terminal
Processor
LCD DisplayKeyboard
Serial PortRS232
Radio
Bar-code Scanner
(IO_Scan)
Receipt Printer
EENG449b/SavvidesLec 6.31
2/1/05
Minimal Mobile Terminal Program
int main(void) {
Init_All(); for (;;) {
IO_Scan(); // bar-code scanner
IO_ProcessOutputs(); KBD_Scan(); // keyboardPRN_Print(); // printerLCD_Update(); // displayRS232_Receive(); // serial portRS232_Send(); TIMER_Process(); // timer
} // should never ever get here
}
EENG449b/SavvidesLec 6.32
2/1/05
Minimal Mobile Terminal Program
int main(void) {
Init_All(); for (;;) {
IO_Scan(); IO_ProcessOutputs(); KBD_Scan(); PRN_Print(); LCD_Update();
RS232_Receive(); RS232_Send();
TIMER_Process(); } // should never ever get here
}
•Each function is an independent task•Tasks should return in a reasonable time•Frequency of main loop execution is non-deterministic•Tasks are event-driven
– Tasks do not execute unless a suitable message is received
EENG449b/SavvidesLec 6.33
2/1/05
Task Requirements
• Some tasks are periodic– Blink the LCD cursor once every second
• Tasks may not need to run at the same frequency
• Some tasks may be event triggered– RS-232 receive only needs to execute of there is a
character received– PRN_Print() only needs to execute when a receipt is
required
• Need a method to communicate between tasks
EENG449b/SavvidesLec 6.34
2/1/05
Event Driven Tasks & Task Communication
Task 3
Task 1
Task 2
Task Event Queue
Task3_PutEvent()
Task3_PutEvent()
Task3_GetEvent()
EENG449b/SavvidesLec 6.35
2/1/05
Task Execution Frequency
• Different tasks may need to execute at different frequencies OR
• Task execution frequency may change during the lifetime of an application
• Example:• You may not need to refresh the
LCD every 1ms if the information to be displayed does not change
• You may not want to delay execution of other tasks too long
EENG449b/SavvidesLec 6.36
2/1/05
State-Driven LCD Driver(from Melkonian)
void Window_Update(void) { switch (WinTaskState) { case WIN_TASK_IDLE: return; case WIN_TASK_CONST: UpdateWinConst(); WinTaskState++; break; case WIN_TASK_VARS: UpdateWinVars(); WinTaskState++; break; case WIN_TASK_GRAPH:
UpdateWinGraph(); WinTaskState++;
break; }}
EENG449b/SavvidesLec 6.37
2/1/05
Software Timers
• Timers are needed to provide multitasking ability to your software
• Need to schedule a large number of periodic or single shot events
– Blinking cursor– Flashing leds– Be able to put your device to sleep after some
idle time– Timers in the implementation of communication
protocols
• You could use hardware timers for some tasks BUT
– There is a very limited number of hardware timers compared to the needs of an application
EENG449b/SavvidesLec 6.38
2/1/05
Designing a Software TimerTasks deposit theirevents in a queue
Application handler functions
Software timer processHandler for the hardware 10ms timer check Delta Queue
For expired timers
EENG449b/SavvidesLec 6.39
2/1/05
Using A Software Timer
• word TMR_InstallTimeoutHandler(word timer_handle, void(*timeout_func)(word, dword))
• word TMR_Start(word timer_handle, word timeout, dword parameter);
• word TMR_Stop(word timer_handle);
EENG449b/SavvidesLec 6.40
2/1/05
Features of RTOS (hard)
• Structure - OS components and user defined Tasks
• Multi-tasking• Provides hard time guarantee
– Schedulability test guarantees task deadline
• Priority Support– Pre-emption of tasks
EENG449b/SavvidesLec 6.41
2/1/05
Drawbacks of RTOS
• Interrupt latency of context switching may introduce inefficiency
• Pre-emption requires extra attention to shared memory
• Multi-tasking requires private stack for each task.
• RTOS is difficult to debug• Commercial RTOS
– Portability can be difficult– License Fee– Learning Curve
EENG449b/SavvidesLec 6.42
2/1/05
Next-time
• Programming assignment 1