Title: IL2206 Embedded Systems http:www'ict'kth'secoursesIL2206
1IL2206 Embedded Systemshttp//www.ict.kth.se/cour
ses/IL2206
- Exercise 0
- Johan Wennlund, jwd_at_kth.sequestions to
il2206-teachers_at_ict.kth.se - Administrative information
- Laboratory course information
- Laboratory equipement information
- Laboratory exercise 0 information
2IL2206 Embedded Systemshttp//www.ict.kth.se/cour
ses/IL2206
- Exercise 0
- Administration
- Course home page on the webb
- Registration to the course
- Schedule found in daisy system
- Examination, labs (3p) and final exam (4,5p)
3IL2206 Embedded Systemshttp//www.ict.kth.se/cour
ses/IL2206
Nios IDE (rep) I/O polling/interrupt Performan
ceProcessor and Memory RealTime OS
2 sep
2-3 sep
5 sep
4 sep
5 sep
9 sep
15 sep
10 sep
11 sep
18 sep
19 sep
25 sep
23 sep
24 sep
29 sep ...
26 sep
2 okt
7 okt
9 okt
13 okt
10 okt
23 okt
4Laboratory exercises
- Registration using Daisy system
- Each person registrates on each lab
- Laboratory exercise on personal laptops
- 2 students lab together on one DE2-board
- Individual examination
- Labs start time sharp 08.00, 10.00, 13.00
- Preparations must be done in advance
- Laboratory instructions on the webb home-page
5Nios II C-code exampleLaboratory 0 and 1
- int timeloc 0x5957 / startvalue given in
hexadecimal/BCD-code / - define TRUE 1
- extern void puttime(int timeloc)
- extern void tick(int timeloc)
- extern void delay (int millisec)
- extern int hexasc(int invalue)
- int main ()
-
- while TRUE
-
- puttime (timeloc)
- tick (timeloc)
- delay (1000)
-
- return 0
6Laboratory exercise 0
- Install Altera IDE on your laptops
- Write program codes that print time 5957
- puttime is given in C-code
- hexasc write in Nios II assembly-code
- tick updated in C-code
- delay write in Nios II assembly-code
- print characters using C-code putchar()
- Preparations Write all progams and simulate
- Laboration Show programs and run on DE2-board
7Laboratory exercise 1
- Run the program printing time 5957
- Output to Parallel I/O LED/HEX 5957
- Poll parallel input I/O, keys
- keys affect output start/stop, up/down
- Call-back function using hardware Timer
- Interrupts generated from keys
- Calculate primes in background
- All programs written in C-code
8Laboratory exercise 2Performance
- Memory hierarchy, cache ...
- Different CPU-cores
- Program / compiler optimization
- ...
9Laboratory exercise 3RTOS
- Real Time Operating System
- Scheduling
- Semaphores
- Synchronization
- Mutual exclution
- ...
10Some parts of a Computer
CPU
BUS
program
MEM
I/O
data
11Program execution(machine code)
FETCH (update PC)
12Nios-II configurationon DE2-board
bus logic
BUS
...
TIMER
TOGGLES
KEYS
LEDS
13Overview
Nios II CPU in FPGA
Configure FPGA
Load Program
14Computer designis already done
- Choice of components
- CPU Nios II/s
- Memory
- I/O ports
- ...
- Compile and generate configuration files
- HW configuration file.sof
- SW configuration file.ptf
15Nios II C-code exampleLaboratory 1
- int timeloc 0x5957 / startvalue given in
hexadecimal/BCD-code / - define TRUE 1
- extern void puttime(int timeloc)
- extern void tick(int timeloc)
- extern void delay (int millisec)
- extern int hexasc(int invalue)
- int main ()
-
- while TRUE
-
- puttime (timeloc)
- tick (timeloc)
- delay (1000)
-
- return 0
16Nios II Assembly code exampleLaboratory 0, Home
Assignment 4-6
- Laboratory 0, Home Assignment 4-6
- .data Reserve space for time-variable
- time .word 0x5957 give it initial value
"5957" - .text Instructions follow
- .global main Makes "main" globally known
- main movia r4,time parameter for call to
puttime - call puttime present current time
- movia r4,time parameter for call to tick
- call tick update current time
- movi r4,1000 parameter 1000 to delay
- call delay wait milliseconds, (how many?)
- br main Branch to main
- .end Marks the end of the program
17Steps i program development
- Edit program in C-code (or similar)
- Compile C-code to Assembly-code
- Edit code in assembly
- Assemble assembly-code to object module
- Link object modules -gt load module
- Load load module to memory
- Execute run program on CPU
- Simulate program, run on simulator
- Debug debug and test program
18Separate compilation
Advantages ? Split work Fast compiling Disadvant
ages? Long commandstring
19include
Advantages ? Split work Short commandstring Disadv
antages? Slow compiling
20DebuggingProgram executed on CPU
Where in memory ? Linker chooses
Debugging
Wishes Start program at any address (write to
PC) Stop program Stepwise execution 1
instruction at a time (S Step) Execute one
subroutine (N Next) Read/Modify contents in
register and memory Breakpoints add /
remove Run to next brekpoint (C Continue)
21Altera - Literature
- Alt-Intro Introduction to the Altera Nios II
Soft Processor - Alt-HW Nios II Processor Reference Handbook
- Alt-SW Nios II Software Developers Handbook
- Alt-IO Nios II Embedded Peripherals Handbook
- Alt-DE2 DE2 Development and Education Board,
User Manual
22Laboratory exercise 0function hexasc
IN-parameter in r4
4 bits one hexadecimal number
?
7 bits ASCII-code of a hexadecimal character
OUT-parameter in r2
23Laboratory exercise 0function hexasc
Bin --gt ASCII hex 0000 --gt 011 0000
0 0001 --gt 011 0001 1 0010 --gt 011 0010
2 0011 --gt 011 0011 3 0100 --gt 011 0100
4 0101 --gt 011 0101 5 0110 --gt 011 0110
6 0111 --gt 011 0111 7 1000 --gt 011 1000
8 1001 --gt 011 1001 9 1010 --gt 100 0001
A 1011 --gt 100 0010 B 1100 --gt 100 0011
C 1101 --gt 100 0100 D 1110 --gt 100 0101
E 1111 --gt 100 0110 F
Algorithm?
For all these you can do like this ...
For all these you can do like this ...
24delay subroutine, flow chart
25Nios II CPU
- 32 general registers
- Required/Recommended use (by compiler)
- Lots of expected instructions MOV... ADD...
AND... JMP/BR ... BCond CALL ... RET - Several Operand addressing, register/memoryImmedi
ate, Absolute, Relative, Indexed, ... - Processor Reference Handbook Chap 3 and 8
26Nios IIcode examples
- mul10 multiply by 10
- MULINTU unsigned multiply
- getchar read from serial inport
- putchar write to serial outport
27MUL10Multiply by 10 Nios-II-kod
MUL10 MOV r2, r4 r2 inval SLLI r2,
r2, 3 r2 8inval ADD r2, r2, r4 r2
9inval ADD r2, r2, r4 r2
10inval RET SLLI Shift Left Logical
Immediate page
28MULINTU r2 r4 r5 Nios-II-kod
contents of r4 and r5 is expected to be gt0
(unsigned) r4 r5 is expected to fit into 32
bits content of r8 is allowed to be
destroyed MULINTU MOV r2, r0 clear r2
BEQ r4, r0, OUT return if 0 BEQ r5, r0,
OUT return if 0 MOV r8, r5 use r8, not
r5 MORE ADD r2, r2, r4 add once
(more) SUBI r8, r8, 1 decrement BGT r8,
r0, MORE repeat as long as r8 gt 0 OUT RET
29getchar from serial portNios-II-kod(blocking)
int retval getchar(void) .equ indata,
0x860 0x880.equ outdata, 0x864
0x884.equ status, 0x868 0x888
.equ ibfmask, 0x80 0x80 getchar MOVIA r8,
indata LDW r9, 8(r8) statusindata8
ANDI r9, r9, ibfmask BEQ r9, r0,
getchar LDW r2, 0(r8) RET
30putchar from serial portNios-II-kod(blocking)
void putchar(parameter) .equ indata,
0x860 0x880.equ outdata, 0x864
0x884.equ status, 0x868 0x888
.equ obemask, 0x40 0x40 putchar MOVIA r8,
indata LDW r9, 8(r8) statusindata8
ANDI r9, r9, obemask BEQ r9, r0,
putchar STW r4, 4(r8) utdataindata4
RET
31Lab 0 Program structureNis II code / C-code
C code
Nios II code
Nios II code
32Lab 1 Program structureNis II code / C-code
C code
Nios II code
C code
33More to add next year
- More about Nios II CPU Alt-HW chap 3, 8
- Registers, name and use
- Instructions, name and use
- Adressing modes, name and use
- Calling conventionparameterpassing once
moreinput r4, r5, r6, r7return r2, (r3)