L5 - Embedded System Programming
L5 - Embedded System Programming
Roger Johansson
Short history
Cross development
Software libraries
Embedded assembly code
Interrupts
Roger Johansson
Cross development
HOST
HOST TARGET
TARGET
RS-232
Cross monitor/
Development debugger
tools
Roger Johansson
TARGET
TARGET
HOST
HOST
BDM
BDM adapter
adapter BDM
RS-232
Cross
Development
tools
Host
Hostsystem
system
•Cross
•Crosscompilers
compilers(C/C++/Java/Ada/Fortran...)
(C/C++/Java/Ada/Fortran...)
•Cross assemblers
•Cross assemblers
•Linker
•Linker
•Terminal
•Terminalemulation,
emulation,download
download
•Simulators
•Simulators
•Debug
•Debugadapters
adaptersand
andsoftware
software
Roger Johansson
The compiler
Assembly source code
CC mc68000
mc68000
mc68020
mc68020
C++
C++
ASL
ASL mc68hc11
Ada
Ada mc68hc11
mc68hc12
mc68hc12
Java
Java I80386
I80386
Source code Pentium
PentiumIII
III
The assembler
mc68hc12
mc68hc12 Assembler
Assembler o12
o12
Assembly source code
Roger Johansson
Linking
Motorola
MotorolaS-S-
o12
o12 format
format
Binary code for download to
target
o12
o12 Linker
Linker
Library ”script-file”
”script-file”
Library o12
module(s)
module(s) Instructions
Instructionsfor for o12
linking
linking
Library
Library
module
module
Roger Johansson
’Project’
All source code files belonging to an application.
Result is an executable program
’Workspace’
A practical way of grouping related
projects.
XCC12 ’Application’
Roger Johansson
Three different
libraries with
common
functions
Roger Johansson
CC12 ’segment’
The compiler distinguishes the generated code by placing it in one of four
possible segments.
text – this is the segment for machine instructions (executable code)
data – this is the segment for initialised variables. These variables have user
defined values when the program starts but they may be changed by the
program.
cdata - this segment is also for initialised variables. These variables have user
defined values when the program starts and they can not be changed by the
program.
bss – this segment provides space for variables which don’t have initialised
values
Roger Johansson
//
// [Link]
// script for QLD
// for XCC12 applications in RWM
//
...
XCC12 ’[Link]’
// OPTIONS SECTION
-M // generate listfile <basename>.map
group ( c , const_group )
{
abs
}
group( r , test_group)
{
startupseg,
text,
cdata,
data,
bss
}
group( r, interrupt_vectors )
{
vectors
}
layout
{
0x1000,0x3C80 <= test_group,
0x3F80,0x3FFF <= interrupt_vectors
}
Roger Johansson
/*
/* EXAMPLE
EXAMPLE */
*/
void
void main(
main( void
void ))
{{
__asm(
__asm( "" andcc
andcc #$F0");
#$F0"); /*
/* clear
clear condition
condition flags
flags */
*/
}}
NOTE: This is not a part of the ’C’-language and may be compiler dependent.
void
void callfunc(
callfunc( int
int aa
aa ,, int
int ab
ab )) void
void callfunc(
callfunc( int
int aa
aa ,, int
int ab
ab ))
{{ {{
aa
aa == 1; __asm("
1; __asm(" movw
movw #1,%a",
#1,%a", aa);
aa);
ab
ab == 2;
2; __asm(" movw #2,%a", ab);
__asm(" movw #2,%a", ab);
}} }}
Roger Johansson
IRQ
Service
interrupt Address (hex) Funktion
3FFE Not used
RWM
3FFC ClockFailHandler
3FFA COPFailHandler
3FF8 IllOpHandler
__interrupt
__interrupt void
void name(
name( void
void );
);
Roger Johansson
#pragma
#pragma DATA
DATA vectors
vectors
__interrupt
__interrupt void
void *irqvecs
*irqvecs == IRQHandler;
IRQHandler;
group(
group( r,
r, interrupt_vectors
interrupt_vectors ))
script file {{
vectors
vectors
}}
layout
layout
{{
....,
....,
0x3FF2,0x3FF4
0x3FF2,0x3FF4 <=
<= interrupt_vectors
interrupt_vectors
}}
Roger Johansson
#pragma
#pragma DATA
DATA vectors
vectors
__interrupt
__interrupt void
void *irqvecs;
*irqvecs;
#pragma
#pragma DATA
DATA data
data
void
void main(void)
main(void)
{{
irqvecs
irqvecs == IRQHandler;
IRQHandler;
...
...
}}
void
void main(void)
main(void)
{{
*(unsigned
*(unsigned short
short *)
*) 0x3FF2
0x3FF2 == (unsigned
(unsigned short)
short) IRQHandler;
IRQHandler;
...
...
}}
alternatively...
#define
#define SET_IRQ_VECTOR(x,y)
SET_IRQ_VECTOR(x,y) *(unsigned
*(unsigned short
short *)
*) yy == (unsigned
(unsigned short)
short) xx
void
void main(void)
main(void)
{{
SET_IRQ_VECTOR(
SET_IRQ_VECTOR( IRQHandler
IRQHandler ,, 0x3FF2
0x3FF2 )) ;;
...
...
}}
Roger Johansson
Roger Johansson
Roger Johansson
Summary
we
we have
have got
got aa brief
brief introduction
introduction to
to
which
which finishes
finishes today’s
today’s lecture
lecture ...
...