72
OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming: Street Smarts from OOP 119th Convention Audio Engineering Society October 10, 2005

Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

  • Upload
    others

  • View
    16

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

1

Tutorial T24

Assembly Language Programming: Street Smarts from OOP

119th Convention

Audio Engineering Society October 10, 2005

Page 2: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

2

John Strawn, Ph.D.

S Systems Inc. [email protected]

http://www.s-systems-inc.com

© Copyright 2005 John Strawn

Page 3: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

3

What we will cover

•  Real-world case study: Inside an MP3 player

•  OOP Principles for Embedded – Object – Encapsulation –  Inheritance

•  Summary: Benefits of OOP for Embedded

Page 4: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

4

iPOD

http://www.chipmunk.nl/iPod/ipodChipmunk1.jpg

Page 5: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

5

What’s in a typical DSP-based consumer audio

device?

Page 6: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

6

What’s in a typical DSP-based consumer audio

device?

Page 7: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

7

•  µP •  DSP chip

– D/A converter •  FireWire port •  Memory •  Disk Drive

•  User Interface – Buttons – LCD – Knobs

•  On-chip clock •  Power

– Battery – Regulator

“Typical” MP3 Player

Page 8: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

8

MP3 Player

DSP chip LCD

Power Regulator

Battery D/A converter

Switches

FireWire Port

Memory

Buttons

Oscillator

Microprocessor

Knobs

Page 9: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

11

What we will cover

•  Real-world case study: Inside an MP3 Player

•  OOP Principles for Embedded – Object – Encapsulation –  Inheritance

•  Summary: Benefits of OOP for Embedded

Page 10: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

12

Object

•  A set of software •  Corresponds to something: (physical object,

person, peripheral, algorithm, ...) •  Cleanly defined boundaries

Page 11: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

13

Sample Objects •  µP •  Serial Port •  External Memory •  FFT routine •  Filter routine •  One interrupt service routine •  All the interrupt service routines •  ...

Page 12: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

14

Sample Object: Serial Port ---

What’s in one?

Page 13: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

15

TI C672x Serial Port

Page 14: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

16

Prototypical Serial Port

Registers

Data

Clock Data

Addr Input buffers

Memory

IRQ

Page 15: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

17

Prototypical serial port: Hardware

•  Memory buffer – Base address – Length (“mod”) – Current read, write pointers – Storage for other pointers for double-buffer

•  Registers

Page 16: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

18

Prototypical serial port: Software

•  Interrupt service routine: handle one sample •  Initialization •  Start/Stop •  Routine to deal with full buffer

– Swap buffer pointers – Tell DSP that the buffer is full

Page 17: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

19

Serial Port Elements

Registers

Input buffer(s)

Interrupt service routine

Initialization/reset

Start transfer

Stop transfer

Check buffer full

Setup transfer

Allocate buffers

Page 18: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

20

µP Serial Port: where are the object boundaries?

Registers

Data

Clock Data

Addr Input buffers

Memory

IRQ

Page 19: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

21

µP Serial Port Object: Boundaries Version 1

Registers

Data

Clock Data

Addr Input buffers

Memory

IRQ

Page 20: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

22

One Object: Serial Port

Registers

Input buffer(s)

Interrupt service routine

Initialization/reset

Start transfer

Stop transfer

Check buffer full

Setup transfer

Allocate buffers

Object Boundary

Page 21: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

23

µP Serial Port Object: Boundaries Version 2

Registers

Data

Clock Data

Addr Input buffers

Memory

IRQ

Page 22: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

24

3 Objects: Serial Port, Memory, ISRs

Registers

Input buffer(s)

Interrupt service routine

Initialization/reset

Start transfer

Stop transfer

Notify buffer full

Setup transfer

Allocate buffers

Memory

ISRs

Serial Port

Object Boundary

Page 23: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

25

How to make an “object” •  Group similar things •  Decide the boundaries •  Header

–  file, or section of file – “#define” –  interface for other objects --- more later

•  Code file (or section of file) –  details inside

•  Test file

Page 24: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

26

Review: Boundaries Version 1

Registers

Data

Clock Data

Addr Input buffers

Memory

IRQ

Page 25: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

27

Review, One Object: Serial Port

Registers

Input buffer(s)

Interrupt service routine

Initialization/reset

Start transfer

Stop transfer

Check buffer full

Setup transfer

Allocate buffers

Object Boundary

Page 26: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

28

Files, 1 Object Memory.inc ISR.inc Serial_port.inc Serial_port.asm includes memory.inc, ISR.inc, Serial_port.inc contains implementation for registers, buffers, ISR contains implementation of rest of serial port

Page 27: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

29

µP Serial Port Object: Boundaries Version 2

Registers

Data

Clock Data

Addr Input buffers

Memory

IRQ

Page 28: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

30

Review, 3 Objects: Serial Port, Memory, ISRs

Registers

Input buffer(s)

Interrupt service routine

Initialization/reset

Start transfer

Stop transfer

Notify buffer full

Setup transfer

Allocate buffers

Memory

ISRs

Serial Port

Object Boundary

Page 29: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

31

Files, 3 Objects Memory.inc Memory.asm includes memory.inc contains implementation for registers, buffers ISR.inc ISR.asm includes ISR.inc contains implementation for ISR Serial_port.inc Serial_port.asm includes Memory.inc, ISR.inc, Serial_port.inc calls on implementation in Memory.asm, ISR.asm contains implementation of rest of serial port

Page 30: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

32

Real-world example: objects

NR.inc NR.asm NR_init.asm test_NR.asm NR_mem.asm NR_mem.inc NR_io.asm NR_io.inc

NR_fft_hann.inc NR_fft_sincos.inc NR_atan2.asm test_atan2 NR_sqrt.asm test_sqrt.asm NR_fft.asm NR_fft.inc test_fft.asm

Page 31: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

33

What we will cover

•  Real-world case study: Inside an Ipod •  OOP Principles for Embedded

– Object – Encapsulation –  Inheritance

•  Summary: Benefits of OOP for Embedded

Page 32: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

34

Encapsulation

•  (from Object): Cleanly defined boundaries •  Gather the details inside those boundaries •  Hide the details from the outside world •  Provide an interface to the outside world

Page 33: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

35

Encapsulation: levels of access (inspired by C++)

•  “Public”: •  “Private”: •  “Protected”:

Page 34: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

36

Encapsulation: levels of access (inspired by C++)

•  “Public”: anybody can modify/see •  “Private”: nobody else can modify/see directly •  (“Protected”: only trusted entities can modify/

see)

Page 35: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

37

Serial Port Object: What is public/private?

Registers

Input buffer(s)

Interrupt service routine

Initialization/reset

Start transfer

Stop transfer

Notify buffer full

Setup transfer

Allocate buffers

Page 36: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

38

Serial Port Object: What is public/private?

Registers

Input buffer(s)

Interrupt service routine

“public:”

Initialization/reset

Start transfer

Stop transfer

Notify buffer full

Setup transfer

Allocate buffers

“private”

Page 37: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

39

Private: C++ code class Serial_Port { private: int * buf_read_ptr; int * buf_write_ptr; int buf_len; void IRQ(); int buf[SP_MAX_NUM_BUF][SP_MAX_BUF_LEN]; int control_reg;

Page 38: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

40

Interface: Public in C++ code

public: ... void SP_Reset(); void SP_Allocate_Buffers( int Num_Buffers, int Num_Points_Per_Buffer); void SP_Setup_Xfer(); void SP_Start_Xfer(); int SP_Buffer_Ready(); void SP_Stop_Xfer(); int * SP_getReadPtr(); };

Page 39: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

41

Interface: C++ Main Loop

#include "serial_port.h" void main() { Serial_Port s; s.SP_Reset(); s.SP_Allocate_Buffers(2, 256); s.SP_Setup_Xfer(); s.SP_Start_Xfer();

Page 40: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

42

Interface: C++ Main Loop while (...) { iReady = s.SP_Buffer_Ready(); if (iReady == ...) { ... } } s.SP_Stop_Xfer(); }

Page 41: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

43

Private: Motorola 56K example

MAX_BUF_LEN EQU 512 MAX_NUM_BUF EQU 4 org x:0 ; private: buf_base dsm MAX_BUF_LEN*MAX_NUM_BUF buf_read ds MAX_NUM_BUF buf_write ds MAX_NUM_BUF

Page 42: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

44

Public Interface: 56K example ; public: org p: SP_Allocate_Buffers ; ... rts SP_Setup_Xfer ; ... rts SP_Start_Xfer ; ... rts

Page 43: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

45

Interface: Typical main loop (56K) move #2,r0 ; 2 buffers move #256,r1 ; 256 points per buffer jsr SP_Allocate_Buffers ; ... jsr SP_Setup_Xfer ; ... jsr SP_Start_Xfer main_loop: ; ... jsr SP_Buffer_Ready ; a = flag tst a ; if a = 0 jne main_loop ; ... ; process buffer jmp main_loop

Page 44: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

46

Interface Useage: Typical startup (56K)

reset: ; ... jsr Stack_Reset

jsr SP_Reset jsr DAC_Reset jsr GUI_Reset jsr Mem_Reset jsr Clock_Reset ; ...

Page 45: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

47

How to make “encapsulation”

•  Plan “private,” “public”, (“protected”). •  Make objects (see above). •  Keep the details inside the object. •  Provide an interface for the outside world. •  Don’t let the outside world muck with

what’s inside the object (except through the interface).

Page 46: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

48

What we will cover

•  Real-world case study: Inside an Ipod •  OOP Principles for Embedded

– Object – Encapsulation –  Inheritance

•  Summary: Benefits of OOP for Embedded

Page 47: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

49

Inheritance

•  OOP: child class can inherit from the parent class

•  Embedded: Find what is common, create a parent, inherit from it (abstraction)

Page 48: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

50

MP3 Player: what is common?

DSP chip LCD

Power Regulator

Battery D/A converter

Switches

FireWire Port

Memory

Buttons

Oscillator

Microprocessor

Knobs

Page 49: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

51

MP3 Player: what is common?

DSP chip LCD

Power Regulator

Battery D/A converter

Switches

FireWire Port

Memory

Buttons

Oscillator

Microprocessor

Knobs

Page 50: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

52

Inheritance: Relationship of Objects (Abstraction)

DSP chip LCD

Power Regulator Battery D/A converter

Switches

FireWire Port

Memory Buttons

Oscillator

Microprocessor Knobs

User Interface

Page 51: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

54

Inheritance: Shared Memory

DSP chip LCD

Power Regulator Battery D/A converter

Switches

FireWire Port

Memory Buttons

Oscillator

Microprocessor Knobs

User Interface

Page 52: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

55

Prototypical Plugin Architecture

Shared Memory

Host

DSP

Page 53: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

56

Inheritance: Biquad structure

z-1

z-1 -a1

-a2

b1

b2

b0

Page 54: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

57

Inheritance: DSP ... a1 a2 b0 b1 b2 ...

Shared Memory

Current values as used by DSP, in “DSP Space”

Page 55: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

58

Interpolate Biquad Coefficients

Current value: DSP

Target value: host

b0

b0’

time

Page 56: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

59

Inheritance: µP + DSP ... a1 a2 b0 b1 b2 ... a1 a2 b0 b1 b2 ...

Shared Memory

Current values as used by DSP, in “DSP Space”

Target values written by host, in “Host Space”

Page 57: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

60

Inheritance:Macro define, call Biquad MACRO name name + _a1: allocate one memory location name + _a2: allocate one memory location name + _b0: allocate one memory location name + _b1: allocate one memory location name + _b2: allocate one memory location MACRO END #define BIQUAD_LEN 5

... Biquad HostSpace ... Biquad DSPSpace ...

Page 58: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

61

Inheritance: Macro results ...

HostSpace_a1 HostSpace_a2 HostSpace_b0 HostSpace_b1 HostSpace_b2

... DSPSpace_a1 DSPSpace_a2 DSPSpace_b0 DSPSpace_b1 DSPSpace_b2

...

Shared Memory

Current values as used by DSP, in “DSP Space”

Target values written by host, in “Host Space”

Page 59: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

62

Inheritance: interp using memory

pHost = &HostSpace_a1; pDSP = &DSPSpace_a1; for (i=0; i< BIQUAD_LEN; i++) {

*pDsp = *pHost ... *pDSP ...; pHost++; pDSP++;

}

Page 60: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

63

Inheritance: Using memory move #HostSpace_a1,r0 ; init pHost move #DSPSpace_a1,r1 ; init pDSP move #BIQUAD_LEN,y0 ; do 0<=i<n { do y0,p_interp move x:(r0),x0 ; *pHost move x:(r4),x1 ; *pDSP ; ... ; *pDSP = ... move (r0)+ ; pHost++; move (r1)+ ; pDSP++ p_interp: ; }

Page 61: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

64

Inheritance: Modify the Biquad

Biquad MACRO name name + _a1: allocate one memory location name + _a2: allocate one memory location name + _b0: allocate one memory location name + _b1: allocate one memory location name + _b2: allocate one memory location

name + _gain: allocate one memory location MACRO END #define BIQUAD_LEN 6

Page 62: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

65

Inheritance: Macro results HostSpace_a1 HostSpace_a2 HostSpace_b0 HostSpace_b1 HostSpace_b2 HostSpace_gain

... DSPSpace_a1 DSPSpace_a2 DSPSpace_b0 DSPSpace_b1 DSPSpace_b2 DSPSpace_gain

...

Shared Memory

Current values as used by DSP, in “DSP Space”

Target values written by host, in “Host Space”

Page 63: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

66

How to make “abstraction” and “inheritance”

•  Look for objects that have similar properties.

•  Abstract those properties into a common header file and source file.

•  Include the header file. •  Invoke the common properties.

Page 64: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

67

Inheritance: header files Project master .h

µP master .h DSP master .h

Memory master .h

GUI master .h DSP memory .h µP memory .h

DSP memory µP memory Knob Switch

Page 65: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

68

Abstraction: header files Project master .h

µP master .h DSP master .h

Memory master .h

GUI master .h DSP memory .h µP memory .h

DSP memory µP memory Knob Switch

Page 66: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

69

What we will cover

•  Real-world case study: Inside an Ipod •  OOP Principles for Embedded

– Object – Encapsulation –  Inheritance

•  Summary: Benefits of OOP for Embedded

Page 67: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

70

Benefits of OOP for Embedded

•  Speed up my development time. •  Improve reliability of my code. •  Easier to isolate my bugs. •  Easier for me to modify my own code now. •  Easier for me to modify my own code later. •  Easier for others to modify my code. •  Easier to re-use code for new projects

(maybe)

Page 68: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

71

Street Smarts to apply

• Object • Encapsulation •  Inheritance

Page 69: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

72

iPOD

http://www.chipmunk.nl/iPod/ipodChipmunk1.jpg

Page 70: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

73

MP3 Player

DSP chip LCD

Power Regulator Battery D/A converter

Switches

FireWire Port

Memory Buttons

Oscillator

Microprocessor Knobs

User Interface

Page 71: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

74

OOP Resources

•  http://www.objectfaq.com/oofaq2/ •  Grady Booch, Object-Oriented Analysis and

Design with Applications •  Grady Booch, The Unified Modeling

Language User Guide

Page 72: Tutorial T24 Assembly Language Programming: Street Smarts ... · OOP/Assembly 10 October 2005 NY AES 119 1 Tutorial T24 Assembly Language Programming:

OOP/Assembly 10 October 2005 NY AES 119

75

John Strawn, Ph.D.

S Systems Inc. [email protected]

http://www.s-systems-inc.com