420 likes | 582 Views
EENG 449b/CPSC 439b Computer Systems Lecture 6 ARM Architecture & Programming. Feb 1, 2005 Prof. Andreas Savvides Spring 2005 http://www.eng.yale.edu/courses/2005s/eeng449b. Where is ARM Today?. Announcements. Need to register for lab access Lab located in CO-40
E N D
EENG 449b/CPSC 439b Computer SystemsLecture 6 ARM Architecture & Programming Feb 1, 2005 Prof. Andreas Savvides Spring 2005 http://www.eng.yale.edu/courses/2005s/eeng449b
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
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
5-stage ARM9 Improvement
ARM Instructions 3-type instruction classification • Data processing • Data transfer • Control flow
Data Processing Instructions • Arithmetic operations ADD r0, r1, r2; ADC r0, r1, r2; add w/curry r0 :=r1+r2+c SUB r0, r1, r2; SBC r0, r1, r2; r0 :=r1 – r2 + C – 1 etc … • Bitwise Logical Operations AND r0, r1, r2 OR r0, r1, r2 EOR r0, r1, r2 BIC r0, r1, r2; r0 := r1 and not r2
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;
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
Control Flow Instructions • Unconditional Branches B LABEL … LABEL … • Conditional Branches MOV r0, #0 LOOP … ADD r0, r0, #1 CMP r0, #10 BNE LOOP …
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
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; }
An Example Embedded System Application: A Mobile Terminal Processor Receipt Printer Radio Bar-code Scanner (IO_Scan) Serial Port RS232 Keyboard LCD Display
Minimal Mobile Terminal Program int main(void) { Init_All(); for (;;) { IO_Scan(); // bar-code scanner IO_ProcessOutputs(); KBD_Scan(); // keyboard PRN_Print(); // printer LCD_Update(); // display RS232_Receive(); // serial port RS232_Send(); TIMER_Process(); // timer } // should never ever get here }
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 Minimal Mobile Terminal Program
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
Event Driven Tasks & Task Communication Task 2 Task 1 Task3_PutEvent() Task3_PutEvent() Task3_GetEvent() Task 3 Task Event Queue
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
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; }}
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
Designing a Software Timer Tasks deposit their events in a queue Application handler functions Handler for the hardware 10ms timer check Delta Queue For expired timers Software timer process
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);
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
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
Next-time • Programming assignment 1