Docsity

Modular Software Development in Embedded Systems: Principles and Practices, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
Slide 1
'
&
$
%
ECE/CE 3720: Embedded System Design
(ECE 6960/2 and CS 6968)
Chris J. Myers
Lecture 4: Software Development (cont)
Slide 2
'
&
$
%
Modular Software Development
•Modular programming breaks software problems in
distinct and independent modules.
•Modular software development provides:
–Functional abstraction to allow software reuse.
–Complexity abstraction (i.e., divide and conquer).
–Portability.
•Aprogram module is a self-contained software task with
clear entry and exit points.
•Can be a collection of subroutines or functions that in
their entirety perform a well-defined set of tasks.
1
Slide 3
'
&
$
%
Software Module
Slide 4
'
&
$
%
Stack Contents
movb ss,1,-sp ;push parameter onto stack
jsr sqrt ;call sqrt subroutine
ins
stab tt ;save result
2
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Modular Software Development in Embedded Systems: Principles and Practices and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

& '

% $

ECE/CE 3720: Embedded System Design

(ECE 6960/2 and CS 6968)

Chris J. Myers

Lecture 4: Software Development (cont)

& '

% $

Modular Software Development

distinct and independent modules.Modular programming breaks software problems in

Modular software development provides:

Functional abstraction to allow software reuse.

Complexity abstraction (i.e., divide and conquer).

Portability.

A

program module

is a self-contained software task with

clear

entry

and

exit points

their entirety perform a well-defined set of tasks.Can be a collection of subroutines or functions that in

1

Slide 3

& '

Software Module

Slide 4

& '

Stack Contents

jsr movb ss,1,-sp ;push parameter onto stack

sqrt

;call sqrt subroutine

stab ttins

;save result

2

& '

% $

Example Module in Assembly

sqrt pshy

leas -4,sptsy

;allocate t,oldt,s

bne nextdec cnt,ystab t,y...ldaa s8,yclrb

done tys

rtspuly

& '

% $

Returning Multiple Parameters in Assembly 1

module: ldaa #

ldxldab #

ldy

rts

;returns 4 parameters in 4 registers

********calling sequence******

jsr module

  • Reg A,B,X,Y have four results

3

Slide 7

& '

Returning Multiple Parameters in Assembly 2

module movb #2,data2,sp ;2nd parameter onto stackmodule movb #1,data1,sp ;1st parameter onto stackdata2 equ 3 data1 equ 2

rts

*******calling sequence******

pulajsr moduleleas -2,sp ;allocate space for results

;1st parameter from stack

pulastaa first

;2nd parameter from stack

staa second

Slide 8

& '

More Issues in Modular Software

stack and return parameters in the same way.All exit points in an assembly routine must balance the

harder to reuse at a later time.Performing unnecessary I/O in a subroutine makes it

of modules that can access them should be restricted.I/O devices must be considered global, and the number

Information hiding

means to separate mechanism from

policies (i.e., hiding the inner workings from the user).

4

Slide 13

& '

% $

Layered Approach for Parallel Port

Slide 14

& '

% $

Three-Layer Software System (High Level)

org

$E

main:

lds

#$00FF

bsr

Initialize ;simple call to a function

loop:

bsr

PrintInfo

;simple call to a function

bra

loop

Initialize:

ldaa #

;function code for InitPrinter

swi

;call to middle level

org $FFFErts

;high level vector (reset)

fdb

main

7

Slide 15

& '

Three-Layer Software System (Middle Level)

org

$F

swihandler:

cmpa #

;function code for InitPrinter

bne

notIP

bsr

InitPrinter

bra

swidone

notIP:

cmpa #

;function code for PrintInfo

bne

notPI

bsr

PrintInfo

bra

swidone

notPI:

;****error

swidone:

rti

InitPrinter: ldaa #

;function code for InitIEEE

ldx

$FF

;vector into low level

jsr

0,x

;call lower level

orgrts

$FFF

;middle level vector (SWI)

fdb

swihandler

Slide 16

& '

Three-Layer Software System (Low Level)

org

$F

lowhandler:

cmpa #

;function code for InitIEEE

bne

notInit

bsr

InitIEEE

bra

lowdone

notInit:

cmpa #

;function code for SetDAV

bne

notDAV

bsr

SetDAV

bra

lowdone

notDAV:

;rest of the functions

lowdone:

rts

InitIEEE:

;access to hardware

orgrts

$FF

; Lower level vector

fdb

lowhandler

8

& '

% $

Layered Software Rules

  1. A module may not directly access any function or2. A module may call a lower-level module only using gate. 1. A module may make simple call to modules in same layer.

variable in another layer (w/o going through a gate).

  1. A module may not modify the vector address of another4. A module may not call a higher-level routine.

level’s handler(s).

  1. (Optional) All user interface I/O is in highest level unless7. (Optional) All I/O hardware access is in lowest level.6. (Optional) A module may not call farther than one level.

it is the purpose of the module to do such I/O.

& '

% $

Threads

9

Slide 19

& '

Interrupts and Threads

Slide 20

& '

Recursion

A program segment is

reentrant

if it can be concurrently

executed by two (or more) threads.

A

recursive

program is one that calls itself.

When we draw a calling graph, a circle is formed.

Recursive subroutines must be reentrant.

void OutUDec(unsigned int number){memory, but use more stack space and are slower.Often easy to prove correct and use less permanent

if (number>=10){

OutUDec(number%10); }OutUDec(number/10);

else

OutChar(number+’0’); }

10

& '

% $

SCI Initialization

BAUD

SCCR

SCCR

init

ldaa #$

;1200 baud

ldaa #$00staa BAUD

;mode

ldaa #$0Cstaa SCCR

;tie=rie=0,

rtsstaa SCCR2 ;te=re=

& '

% $

SCI Input

SCSR

SCDR

InChar ldaa SCSR

;status

bita #$

;rdrf?

beq

InChar

ldaa SCDR

;SCI data

rts

13

Slide 27

& '

SCI Output

SCSR

SCDR

OutChar ldab SCSR

;status

bitb #$

;tdre?

beq

OutChar

staa SCDR

;output

rts

Slide 28

& '

Input Decimal Number

; Inputs: ; Input a byte from the SCI

none

; ; Outputs: Reg B 0 to 255

C=1 if error

DIGIT

rmb

1

;global

InUDec

clrb

;N=

InUDloop bsr

InChar

;Next input

bsr

OutChar ;Echo

cmpa #

;done if cr

beq

InUDret ;with C=

blocmpa #’

InUDerr ;error?

bhicmpa #’

InUDerr ;error?

14

Slide 29

& '

% $

Input Decimal Number (cont)

anda #$0F

;0-9 digit

tstamulldaa #10staa DIGIT

;overflow?

bne

InUDerr

braaddb DIGIT ;N=10*N+DIGIT

InUDloop

InUDerr

bsrldaa #’?

OutChar

secclrb

;error flag

InUDret

rts

Slide 30

& '

% $

SCI Output String

; Inputs: ; Output a string to the SCI

Reg X points to string

String ends with 0

OutString ldaa 0,X; Outputs: none

beq

OSdone

;0 at end

bsr

OutChar

brainx

OutString

OSdone

rts

15

Slide 31

& '

SCI Output Decimal Number

; Inputs: ; Output unsigned byte to the SCI

Reg B= 0 to 255,

print as 3 digit ascii

OutUDec; Outputs: none

clra

;Reg D=number

ldx

idiv

;X=num/100,

xgdx

;B=100s digit

bsradda #’0 ;A=100’s asciitba

OutChar

xgdx

;D=num

ldx

Slide 32

& '

SCI Output Decimal Number (cont) idiv

;X=num/10,

xgdx

;B=tens digit

bsradda #’0 ;A=tens asciitba

OutChar

xgdx

;D=num

bsradda #’0 ;A=ones asciitba

OutChar

rts

16

& '

Performance (Dynamic) Debugging

Performance debugging

is verification of timing behavior.

System is run and dynamic behaviors of I/O checked.

  1. Instrumentation: measuring with a counter.1. Count bus cycles using the assembly listing.

before

rmb

2

;TCNT value before the call

elasped rmb

2

;# of cycles to execute sqrt

movw

TCNT,before

movb

ss,1,-sp

;push parameter on stack

jsr

sqrt

;call sqrt module

stabins

tt

;save result

ldd

TCNT

;TCNT value after the call

subd

before

std

elasped

;execute time in cycles

  1. Instrumentation: output port.

& '

Profiling

Profiling

collects time history of strategic variables.

  1. Use an output port.1. Use a software dump to study execution pattern.

techniques to determine the thread activity.When multiple threads are running can use these

19