Course Content

advertisement
1
Embedded Systems Education
at NC State University
Alex Dean
Dept. of ECE
alex_dean@ncsu.edu
2
Overall Goals
• Teach students
–
–
–
–
how MCUs are different from MPUs
how to use the peripherals
how to write efficient C code
how to debug for function and
performance
• Provide students with hands-on
experience
• Give them a development kit which
they can build on in the future
• Collaborators
– Suleyman Sair
– Jim Conrad (UNC-Charlotte)
3
Curriculum Overview
ECE 206 – Intro. to
Computer Organization
-Microprocessor Concepts
-Assembly Language
Programming (LC-3)
-C Programming
ECE 306 – Introduction to
Embedded Systems
-Introduction to Microcontrollers
-Embedded SW/HW Development
and Debugging
-Multithreaded Programming
ECE 460 – Digital
Systems Interfacing
Hardware Design Focus
ECE 481 – Senior Design
ECE 212 – Digital
Logic Design
ECE 406 – Design of
Complex Digital Systems
ECE 463 – Computer
Design and Technology
ECE 492D/561 –
Embedded System
Design
-Software Design
-Software Analysis
-C Compiler Use Expertise
4
ECE 306 – Introduction to Embedded Systems
• Goal:
– Familiarity with microcontroller
programming in C
– Know how to use peripherals
– Have a gut feeling for time and
memory impact of C features
• my own compiler bias...
• Mechanics
– MCU Renesas SKP16C26, M16C
architecture
• 16-bit CISC, 64 kB FLASH ROM,
2 kB SRAM, 2x8 LCD,
– Tool chain
• IDE with C compiler, assembler,
linker, on-chip debugger
• Tools never expire
• Low-cost ($50-$100). Students buy boards, develop code on own PCs.
– Lab with DSOs and PCs for office hours, debugging and demos
– Core course for Computer Engineering majors
– 125 students in fall, 75 in spring, some even in summer
5
306 Topics
• M16C ISA
– Instruction set
– Addressing modes
• How C is implemented in
assembly language
–
–
–
–
–
Memory sections
Subroutine call mechanism
Call stack and activation records
CRT0 introduction
C Stdlib Emulation
• Interrupts
– Vectors
– ISRs
z
SP
FB
2.
x
1.
y
2.
Old FB
Return
Adx.
c
b
a
##########################################
# (2) SECTION INFORMATION
#
##########################################
# SECTION
ATR TYPE
START LENGTH ALIGN
data_SE
ABS DATA
000400 000000
bss_SE
REL DATA
000400 000000 2
data_SO
REL DATA
000400 000000
bss_SO
REL DATA
000400 000000
data_NE
REL DATA
000400 000000 2
REL DATA
000400 000014
REL DATA
000414 000002
REL DATA
000416 00000C
bss_NE
REL DATA
000422 000000 2
REL DATA
000422 000218
REL DATA
00063A 000004
REL DATA
00063E 000108
data_NO
REL DATA
000746 000000
bss_NO
REL DATA
000746 000000
REL DATA
000746 00026A
stack
REL DATA
0009B0 000200
heap
REL DATA
000BB0 000000
etc…..
MODULENAME
NCRT0_UART
NCRT0_UART
NCRT0_UART
NCRT0_UART
NCRT0_UART
GLOBALS
ERRNO
INFINITY
NCRT0_UART
GLOBALS
SPRINTF
PRINT
NCRT0_UART
NCRT0_UART
PRINT
NCRT0_UART
NCRT0_UART
6
306 Topics
• Peripherals
– GPIO, ADC, DAC, Timer, UART+RS232, WDT
• Schedulers
– Run-to-completion scheduler
• Simple: core ~20 lines of code
• Used in projects
– Preemptive
• Context switching
• Kernel activity
• Task states, intertask synchronization
• Fixed-point and floating point math
• Digital oscilloscope
– Debugging and performance (timing) analysis
7
306 Topics
• External memory interfacing D7-D0
– Parallel
– Serial (DataFlash)
A15-A0
Read
Write
Data from SRAM
Data from MCU
Adx from MCU
Adx from MCU
~WR
~RD
• Good coding practices
– Modular programming
– Incremental testing and debugging
– Software testing
• Run-time robustness
–
–
–
–
Watchdog Timer
Stack Pointer monitor
Data structure health checks
Voltage brown-out detector
RDY/BSY
RESET
FLASH MEMORY ARRAY
PAGE SIZE = BUFFER SIZE
WP
BUFFER 2
BUFFER 1
CS
I/O INTERFACE
SI
SO
SCK
8
306 Lab Projects
• Digital voltmeter
• Hardware and software
voltage-controlled oscillators
• Digital sampling oscilloscope
• Etch-a-sketch
• et cetera
9
ECE 561
• Goals
– Once again, gut feeling for how C code will be implemented
• How to squeeze the best performance from the compiler
– Techniques to analyze complex software
– Techniques to guarantee real-time performance
• Mechanics
– Renesas M16C architecture (16-bit): labs
– Atmel AVR architecture (8-bit): optional for final project
– ARM7 Architecture (32-bit): optional for final project
10
561 Topics
• Code analysis basics
– Control flow graphs
– Call graphs
– Static timing analysis
Cycle Counts
+2 for taken
conditional jump
4
_timer_isr
L0
22
_timer_isr_0
L1
8
55
• C Compiler
– C run-time environment initialization
– How to stay out of the optimizer’s way
– C type promotion rules for expressions
i
• Real-time systems
– Worst-case execution timing
analysis
– Scheduling
– Response time analysis
a0   T j  1  2  3  6
j 0
i 1 
6
6
6
a1  3    T j  3    *1    * 2  3  2  2  7
4
6
j  0  j 
i 1 
7
7
7
a2  3    T j  3    *1    * 2  3  2  4  9
4
6
j  0  j 
i 1 
9
9
9 
a3  3    T j  3    *1    * 2  3  3  4  10
4
6
j  0  j 
i 1 
10 
10 
10 
a4  3    T j  3    *1    * 2  3  3  4  10
4
6
j  0  j 
11
561 Topics
• Profiling through PC sampling
• Scheduler Instrumentation
• Stack size bounding
main
SMax=9 bytes
C=9 bytes
f1
SMax=11 bytes
C=20 bytes
– Analytical
– Approximate (high-water-marking)
__i4tof4
SMax=21 bytes
C=41 bytes
__f4mul
SMax=40 bytes
C=60 bytes
• Hardware reliability
• Software reliability: testing, defensive programming
• Energy and power
__ltof
SMax=15 bytes
C=56 bytes
–
–
–
–
CMOS power dissipation
Idle modes
DFS and DVS
Predicting energy use
Normal
16.5 mW
5.5 mA
250
ns
1.75 ms
Idle
4.8 mW
1.6 mA
__f4lto4
SMax=11 bytes
C=52 bytes
250
ns
var
.
Power-Down
0.003-0.030 mW
0.001-0.010 mA
250
ns
var
.
Power-Save
0.009 mW
0.003 mA
Download