Design of Sw for Embedded Systems

Embed Size (px)

Citation preview

  • 8/9/2019 Design of Sw for Embedded Systems

    1/59

     

    Embedded Software Design

    Peter R. Wihl(former Guest Lecturer)

  • 8/9/2019 Design of Sw for Embedded Systems

    2/59

     

    Oeriew

    ! Data flow "ractices (#hrough"ut)

    ! Real time s$stems

    ! Software design oeriew

    ! %ommunication "rotocols

    ! &n e'am"le software design

     Feel free to ask questions at any time

  • 8/9/2019 Design of Sw for Embedded Systems

    3/59

     

    E'ecution low

    ! & diagram that describes the maor ste"s in these*uential software flow.

    ! +llustrates each logical ste" and decision "oint inthe oerall design of the software.

    ! Proides a starting "oint for the design of thesoftware.

    ! +s to embedded software as logical architecture isto hardware.

    ! +s ma""ed later to Routines, unctions or Obects

  • 8/9/2019 Design of Sw for Embedded Systems

    4/59

     

    -efore Designing E'ecution low

    . +dentif$ which logical architecturalmodules are ma""ed to software.

    /. +dentif$ what time "eriod all logicalsoftware function must be com"leted in.

    0. +dentif$ an$ additional oerhead

    functionalit$ due to modules ma""ed tosoftware and1or characteristics of the "h$sical design. ie. Polling1+nterru"ts

  • 8/9/2019 Design of Sw for Embedded Systems

    5/59

     

    Logical Design &rchitecture

    E'am"le

  • 8/9/2019 Design of Sw for Embedded Systems

    6/59

     

    Ph$sical &rchitecture 2a""ing

  • 8/9/2019 Design of Sw for Embedded Systems

    7/59

     

    Logical Design &rchitecture

    E'am"le

  • 8/9/2019 Design of Sw for Embedded Systems

    8/59

     

    Role of 2icrocontroller 

    ! Read 34bit word from &D%

    ! %alculate Error %orrection %ode (/4bit)

    ! +nect "ossible error 

    ! Detect if there is an error 

    ! +f there is an error correct it! Write new 34bit word to D&%

  • 8/9/2019 Design of Sw for Embedded Systems

    9/59

     

    E'ecution low Diagram

  • 8/9/2019 Design of Sw for Embedded Systems

    10/59

     

    Data #hrough"ut in SW

    ! What is s$nchronous data flow5

     6 Data arries at regular interals

    ! What is as$nchronous data flow5

     6 Data does not arrie at regular interals

    ! What is isochronous data flow5

     6 Data must be deliered within certain time

    constraints

  • 8/9/2019 Design of Sw for Embedded Systems

    11/59

     

    Data low Practices

    ! Polling

    ! +nterru"t triggered (bloc7ing)

    ! +nterru"t triggered (non4bloc7ing)

    ! Eent drien

     6 Often referred to as interru"t drien

  • 8/9/2019 Design of Sw for Embedded Systems

    12/59

     

    Sam"le Problem

    !  8eed to receie 3 b$tes into a buffer and

    then "rocess the buffer 

    ! -$tes arrie as$nchronousl$

  • 8/9/2019 Design of Sw for Embedded Systems

    13/59

     

    Polling Oeriew

  • 8/9/2019 Design of Sw for Embedded Systems

    14/59

     

    Polling

     main

      do forever

      count = 0

      while count < 16

      while byte not ready

      nop

      get byte

      buffer[count] = byte

      incr count

      process buffer

  • 8/9/2019 Design of Sw for Embedded Systems

    15/59

     

    +nterru"t (-loc7ing) Oeriew

  • 8/9/2019 Design of Sw for Embedded Systems

    16/59

     

    +nterru"t #riggered

    (-loc7ing)interrupt rx_byte

      disable interrupts

      count = 0

      while count < 16  get byte

      buffer[count] = byte

      incr count

      process buffer

      enable interrupts

      return

     main

      enable interrupts

      do forever

      nop

  • 8/9/2019 Design of Sw for Embedded Systems

    17/59

     

    +nterru"t (8on4-loc7ing) Oeriew

  • 8/9/2019 Design of Sw for Embedded Systems

    18/59

     

    +nterru"t #riggered

    (8on4bloc7ing)interrupt rx_byte

      if count < 16

      get byte

      buffer[count] = byte  incr count

      else if count = 16

      process buffer

      count = 0

      return

     main

      count = 0

      enable interrupts

      do forever  nop

  • 8/9/2019 Design of Sw for Embedded Systems

    19/59

     

    Eent Drien Oeriew

  • 8/9/2019 Design of Sw for Embedded Systems

    20/59

     

    Eent Drien

    interrupt rx_byte

      if count < 16

      get byte

      buffer[count] = byte  incr count

      return

     main

      count = 0

      enable interrupts

      do forever  if count = 16

      process buffer

      count = 0

  • 8/9/2019 Design of Sw for Embedded Systems

    21/59

     

    Real #ime

    ! 9ard real time

     – Absolute deterministic response to an

    event

    ! Soft real time

     – Average response to an event

  • 8/9/2019 Design of Sw for Embedded Systems

    22/59

     

  • 8/9/2019 Design of Sw for Embedded Systems

    23/59

     

    Embedded Software Practices

    Peter R. Wihl

    E%E 3: S"ring /;;:

  • 8/9/2019 Design of Sw for Embedded Systems

    24/59

     

    Oeriew

    ! Data flow "ractices

    ! Real time s$stems

    ! %ommunication "rotocols

    ! Software design oeriew

    ! &n e'am"le software design

     Feel free to ask questions at any time

  • 8/9/2019 Design of Sw for Embedded Systems

    25/59

     

    Data low #$"es

    ! What is s$nchronous data flow5

    ! What is as$nchronous data flow5

    ! What is isochronous data flow5

  • 8/9/2019 Design of Sw for Embedded Systems

    26/59

     

    Data low #$"es

    ! What is s$nchronous data flow5

     6 Data arries at regular interals

    ! What is as$nchronous data flow5

     6 Data does not arrie at regular interals

    ! What is isochronous data flow5

     6 Data must be deliered within certain time

    constraints

  • 8/9/2019 Design of Sw for Embedded Systems

    27/59

     

    Data low Practices

    ! Polling

    ! +nterru"t triggered (bloc7ing)

    ! +nterru"t triggered (non4bloc7ing)

    ! Eent drien

     6 Often referred to as interru"t drien

  • 8/9/2019 Design of Sw for Embedded Systems

    28/59

     

    Sam"le Problem

    !  8eed to receie 3 b$tes into a buffer and

    then "rocess the buffer 

    ! -$tes arrie as$nchronousl$

  • 8/9/2019 Design of Sw for Embedded Systems

    29/59

     

    Polling

     main

      do forever

      count = 0

      while count < 16

      while byte not ready

      nop

      get byte

      buffer[count] = byte

      incr count

      process buffer

  • 8/9/2019 Design of Sw for Embedded Systems

    30/59

     

    +nterru"t #riggered

    (-loc7ing)interrupt rx_byte

      disable interrupts

      count = 0

      while count < 16  get byte

      buffer[count] = byte

      incr count

      process buffer

      enable interrupts  return

     main

      enable interrupts

      do forever

      nop

  • 8/9/2019 Design of Sw for Embedded Systems

    31/59

     

    +nterru"t #riggered

    (8on4bloc7ing)interrupt rx_byte

      if count < 16

      get byte

      buffer[count] = byte  incr count

      else if count = 16

      process buffer

      count = 0

      return

     main

      count = 0

      enable interrupts

      do forever  nop

  • 8/9/2019 Design of Sw for Embedded Systems

    32/59

     

    Eent Drien

    interrupt rx_byte

      if count < 16

      get byte

      buffer[count] = byte  incr count

      return

     main

      count = 0

      enable interrupts

      do forever  if count = 16

      process buffer

      count = 0

  • 8/9/2019 Design of Sw for Embedded Systems

    33/59

     

    Real #ime

    ! 9ard real time

     – Absolute deterministic response to an

    event! Soft real time

     – Average response to an event

  • 8/9/2019 Design of Sw for Embedded Systems

    34/59

     

    #ric7

  • 8/9/2019 Design of Sw for Embedded Systems

    35/59

     

    %ommunication Protocols

    ! What is a communication "rotocol5

     6 &n established set of conentions b$ which

    multi"le s$stems e'change data

    ! #he s"eech analog$

     6 #he sounds $ou can ma7e are the

    communication medium 6 #he language $ou use is the "rotocol

  • 8/9/2019 Design of Sw for Embedded Systems

    36/59

     

    Sam"le Protocol

    Byte Data

    ; S$nchroni=ation

    Pa$load si=e

    />/?si=e Pa$load

    /?si=e? Pac7et chec7sum

  • 8/9/2019 Design of Sw for Embedded Systems

    37/59

     

    Protocol +nterru"t

    interrupt rx_byte

      get byte

      checksum = byte ⊕ checksum

      switch (state

      !"#$  if byte = sync

      checksum = byte

      state = !%&'

      !%&'

      sie = byte

      if sie ) 0  count = 0

      state = *+",-+.

      else

      state = $/'$!2

      *+",-+.

      buffer[count] = byte

      incr count

      if count = sie  state = $/'$!2

      $/'$!2

      if checksum = 0

      state = +$$'*3

      else

      state = !"#$  +$$'*3

      drop byte

      return

  • 8/9/2019 Design of Sw for Embedded Systems

    38/59

     

    Protocol 2ain

     main

      state = !"#$

      enable interrupts

      do forever  if state = +$$'*3

      process buffer

      state = !"#$

    ! #his is a sim"le eent

    loo" that "roides

    mutual e'clusion forthe buffer 

  • 8/9/2019 Design of Sw for Embedded Systems

    39/59

     

    #ime or & -rea7 

  • 8/9/2019 Design of Sw for Embedded Systems

    40/59

     

    Software Design Oeriew

    ! Re*uirements &nal$sis

    ! &rchitecture

    ! Design

    ! +m"lementation

    ! 2odule #esting

    ! Design @alidation #esting

  • 8/9/2019 Design of Sw for Embedded Systems

    41/59

     

    E'am"le Problem

    ! + want to build a 9eads A" Dis"la$ for m$

    car.

    ! + would li7e to see both m$ engine RP2and fuel econom$ on m$ windshield.

    ! 2$ car has a serial diagnostic interface that

     "roides this data.

  • 8/9/2019 Design of Sw for Embedded Systems

    42/59

     

    Re*uirements

    ! S$stem shall hae a 9eads A" Dis"la$

    (9AD)

    ! S$stem shall interface with ehicleBsonboard diagnostic s$stem

    ! 9AD shall dis"la$ current RP2

    ! 9AD shall dis"la$ current fuel econom$

    (2PG)

  • 8/9/2019 Design of Sw for Embedded Systems

    43/59

     

    9ardware %onstraints

    ! @ehicleBs onboard diagnostic s$stem

     6   8eeds a wa7e4u" signal sent eer$ second

     6  O"erates at ;,C;; b"s

    ! 9eads A" Dis"la$

     6  /C3'/ "i'els

     6  ull dis"la$ must be calculated and mirrored

     6  O"erates at C,/;; b"s

  • 8/9/2019 Design of Sw for Embedded Systems

    44/59

     

    Processor Re*uirements

    ! Processor shall hae / A&R#s

    . @ehicleBs onboard diagnostic s$stem

    /. 9eads A" Dis"la$

    ! Processor shall hae a timer  6  @ehicleBs onboard diagnostic s$stem wa7e4u"

    ! Processor shall hae more than / b$tes of

    memor$ 6  Processed dis"la$ image (:;3 b$tes)

     6  2irrored dis"la$ image (:;3 b$tes)

  • 8/9/2019 Design of Sw for Embedded Systems

    45/59

     

    9ardware Design

    Heads Up

    Display

    Vehicle

    data

    Processor /

    microcontroller 

    Serial vehicle data

    Serial display control

  • 8/9/2019 Design of Sw for Embedded Systems

    46/59

     

    Software &rchitecture

    Heads Up

    Display

    Vehicle

    dataSerial vehicle data

    Serial display control

    Vehicle data

    interface

    RP dataformatting

    P! dataformatting

    Display processing

    RP data P! data

    P! te"tRP te"t

    Display control

    interface

    Display image

  • 8/9/2019 Design of Sw for Embedded Systems

    47/59

     

    Software Design

    ! 2odules

     6 @ehicle Diagnostic +nterface (@D+)

     6 RP2 Data ormatting (RD)

     6 2PG Data ormatting (2PG)

     6 Dis"la$ Processing (DP)

     6 Dis"la$ %ontrol +nterface (D%+)

  • 8/9/2019 Design of Sw for Embedded Systems

    48/59

     

    Software Design

    ! 2odules

     6 @ehicle Diagnostic +nterface (@D+)

     6 RP2 Data ormatting (RD)

     6 2PG Data ormatting (2PG)

     6 Dis"la$ Processing (DP)

     6 Dis"la$ %ontrol +nterface (D%+)

    ! 2ain1+nitiali=ation

  • 8/9/2019 Design of Sw for Embedded Systems

    49/59

     

    @ehicle Diagnostic +nterface

    RP data P! data

    Serial vehicle data Serial vehicle data

    Receive bloc#Send $a#e up

    signal%imer 

    Data type&

    '"tract RP data '"tract P! data

    RP P!

    Data bloc#

  • 8/9/2019 Design of Sw for Embedded Systems

    50/59

     

    @ehicle Diagnostic +nterface

    interrupt rx_byte

      4

      r5state = +$$'*3

      4

      return

    extract_data

      if data type = 7*2

      e5tract 7*2 data

      rpmformat(data

      else if data type = 2*8  e5tract 2*8 data

      mpgformat(data

      return

     main

      4

      do forever

      4

      if r5state = +$$'*3

      e5tractdata

      r5state = !"#$

      4

  • 8/9/2019 Design of Sw for Embedded Systems

    51/59

     

    @ehicle Diagnostic +nterface

    interrupt timer

      wakeup = 1

      return

    tx_wakeup

      send wakeup control

    block

      return

     main

      …

      do forever

      4  if wakeup = 1

      t5wakeup

      wakeup = 0

      4

  • 8/9/2019 Design of Sw for Embedded Systems

    52/59

  • 8/9/2019 Design of Sw for Embedded Systems

    53/59

     

    2PG Data ormatting

    P! integer data

    %e"t formatting

    )nteger to floating

    point conversion

    (loating point to

    te"t conversion

    %e"t P! value

    (ormatted P! te"t

    (loating point P! value

  • 8/9/2019 Design of Sw for Embedded Systems

    54/59

     

    Dis"la$ Processing(ormatted RP te"t (ormatted P! te"t

    Display image

    generation

    irrored display image

    irror image

    RP placement P! placement

    P! image

    generation

    RP image

    generation

    RP image P! image

    Placed P!Placed RP

    Display image

  • 8/9/2019 Design of Sw for Embedded Systems

    55/59

     

    Dis"la$ %ontrol +nterface

    irrored display image

    Serial display control

    )mage to

    command

    conversion

    *ommand send

    Display command

  • 8/9/2019 Design of Sw for Embedded Systems

    56/59

     

    #est Plan

    . #est functionalit$ of eer$ module

    /. #est functionalit$ of eer$ module

    interaction

    0. #est functionalit$ of the final s$stem

  • 8/9/2019 Design of Sw for Embedded Systems

    57/59

     

    +m"lementation

    #his is when $ou actuall$ write $our code.

  • 8/9/2019 Design of Sw for Embedded Systems

    58/59

     

    2odule #esting

    ! Sim"le im"lementations to test a single

    module or module interaction

    ! #otal testing code will often be larger thanthe actual s$stemBs code base

    ! +s this good or bad5

  • 8/9/2019 Design of Sw for Embedded Systems

    59/59

    Design @erification #esting

    ! & scri"ted test "lan that guides a tester

    through use of the s$stem

    ! & table with the followingF 6 Eer$ s$stem re*uirement

     6 Whether or not the re*uirement was met