Programming & Development of Mobile & Embedded Systems
description
Transcript of Programming & Development of Mobile & Embedded Systems
![Page 1: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/1.jpg)
Programming & Development of Mobile & Embedded Systems
Lin ZhongELEC424, Fall 2010
![Page 2: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/2.jpg)
Outline
• Programming basics• Programming MSP430• Programming Windows Mobile devices
2
![Page 3: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/3.jpg)
Programming basics
• How programmable systems work
3
executables
Execution unit
Instruction fetching
Non-volatile storage Processing
Programming is about changing the content of non-volatile storage• PC: Hard drive• Mobile Devices: Flash ROM• MSP430: Flash ROM
Many input channels can work• PC: DVD/CD drive M, USB drive, Ethernet, Wi-Fi• Mobile Devices: USB port, Bluetooth, Cellular, Wi-Fi• MSP430: Any input (even analog!!!!)
![Page 4: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/4.jpg)
Programming basics (Contd.)
• How executables are generated?
4
High-level language• C/C++/C#/Java• Matlab/Labview• Perl
Intermediate format•Assembly•Java byte code
Machine code101010100
Compile Compile
Machine code101010100
Machine code101010100
Machine code101010100
Link
Compile & link can be done at run-time• Java & C#: second stage compilation• Perl/BASIC (interpretive languages)
![Page 5: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/5.jpg)
Cross platform development
• Cross compile & Cross link– Produce the machine code for a foreign platform– PCMobile devices
• X86 processorsARM processors– PCOrbit sensors
• X86 processorsMSP430
• Cross development tool chains– Linux GNU ARM tool chains– Integrated development environment (IDE)
• Microsoft Visual Studio• IAR Embedded Workbench
5
![Page 6: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/6.jpg)
IDE concepts
• Projects– Organized source files– Properties of target platform
• Run-time debug– Debug/release modes
• Emulators– Development without a physical device
6
![Page 7: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/7.jpg)
Programming MSP430
7
JTAG
JTAG
USB cable
![Page 8: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/8.jpg)
IAR Embedded Workbench
• C and C++• Software emulator • Free evaluation version
8
![Page 9: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/9.jpg)
IAR Embedded Workbench
• Project options
9
![Page 10: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/10.jpg)
Run-time debugging
10
![Page 11: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/11.jpg)
Getting help
11
![Page 12: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/12.jpg)
Memory space
• Unified address space
• No “cache”
12
![Page 13: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/13.jpg)
Tilt 2 vs. PC
13
CPUCache
Registers
Main memory
Hard disk
File system cache
![Page 14: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/14.jpg)
Special function registers (SFRs)
• 16 registers (R0-R15)• Program counter (PC)/R0
– Pointer to the next instruction
14
![Page 15: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/15.jpg)
Stack pointer (SP/R1)• Store the return addresses of subroutine calls and
interrupts• Stack
– Last-In, First Out– PUSH– POP– Automatic allocated memory in C
• You don’t need to worry about it– Take care by the compiler– Subroutine calls– Interrupt handlers
15
![Page 16: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/16.jpg)
Status register (SR/R2)
• Can be read and written
16
Clock
![Page 17: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/17.jpg)
Load-store architecture
17
MEM/Cache
Register file
Execution unit
Load/store
a.k.a. RISC architecture
![Page 18: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/18.jpg)
Interrupt-driven programming
18
TimerA() USARTRX()
Interrupt handlers
System idle
Interrupt Interrupt
Start
Initialization
• Clock• I/O pins• Interrupt• Periperals
![Page 19: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/19.jpg)
Initialization
19
![Page 20: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/20.jpg)
Interrupt properties
• Maskable vs. non-maskable
• Nested
• Priority
20
![Page 21: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/21.jpg)
IAR EWR interrupt
• Enable interrupt
21
![Page 22: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/22.jpg)
IAR EWR interrupt
• Interrupt handler is a special subroutine
22
![Page 23: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/23.jpg)
A problem
– A[0]=1;– B[0]=1;
• enable interrupt there• while () {
– if (A[0]!=B[0]) exit;– else continue ;
• }
23
Interrupt_handler() { A[0]=2; B[0]=2;}
![Page 24: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/24.jpg)
A problem
• A[0]=1;• B[0]=1;• while () {
– if (A[0]!=B[0]) exit;– else continue ;
• }
24
Interrupt_handler() { A[0]=2; B[0]=2;}
LD R13, (A[0]);LD R14, (B[0]) ;CMP R13, R14;JEQ EXIT
![Page 25: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/25.jpg)
Critical section
• A[0]=1;• B[0]=1;• while () {
– if (A[0]!=B[0]) exit;– else continue ;
• }
25
Interrupt_handler() { A[0]=2; B[0]=2;}
LD R13, (A[0]);LD R14, (B[0]) ;CMP R13, R14;JEQ EXIT;…….
Section of code that access a shared resource that must not be concurrently accessed by more than one thread of execution
![Page 26: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/26.jpg)
Atomic operation
• A set of operations that appears to be one to the system– System state change due to the operations invisible until
all the operations are successful– If any of the operations fails, the entire set fails; and no
change to the system state
• Examples– An assembly instruction– Interrupt-disabled
26
![Page 27: Programming & Development of Mobile & Embedded Systems](https://reader031.fdocuments.us/reader031/viewer/2022012919/56815f5d550346895dce404e/html5/thumbnails/27.jpg)
When do we need an OS?
27