EE 319K Introduction to Embedded Systems - PowerPoint PPT Presentation

About This Presentation
Title:

EE 319K Introduction to Embedded Systems

Description:

Introduction to Embedded Systems Lecture 9: Local Variables, Stack Frames, Recursion, Fixed-Point Numbers, LCD Bill Bard, Andreas Gerstlauer, Jon Valvano, Ramesh ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 33
Provided by: BillBardA5
Category:

less

Transcript and Presenter's Notes

Title: EE 319K Introduction to Embedded Systems


1
EE 319KIntroduction to Embedded Systems
  • Lecture 9 Local Variables, Stack Frames,
    Recursion, Fixed-Point Numbers, LCD

2
Agenda
  • Recap
  • Interrupts
  • DAC, Sound
  • Agenda
  • Local Variables
  • Stack frames
  • Recursion
  • Fixed-point numbers
  • LCD Interfacing

3
Local Variables
  • Scope gt from where can it be accessed
  • local means restricted to current program segment
  • global means any software can access it
  • Allocation/Lifetime gt when is it created
    destroyed
  • dynamic allocation using registers or stack
  • permanent allocation assigned a block of memory

4
Local Variables
  • Local variables gt local scope, dynamic
    allocation
  • temporary information
  • used only by one software module
  • allocated, used, then deallocated
  • not permanent
  • implement using the stack or registers
  • R0-R3 and R12 temporary data
  • R4-R11 more permanent data

5
In C
  • Local variables
  • Public local scope, dynamic allocationvoid
    MyFunction(void) short myLocalVariable
  • Private local scope, permanent allocationvoid
    MyFunction(void) static short count
    count
  • Global Variables
  • Public global scope, permanent allocation//
    accessible by all modules short
    myGlobalVariable void MyFunction(void)
  • Private global scope(only to the file),
    permanent allocation//accessible in this file
    onlystatic short myPrivateGlobalVariable//
    callable by other // routines in this file only
    void static MyPrivateFunction(void)

6
Why use Stack for Locals?
  • Dynamic allocation/release allows for reuse of
    memory
  • Limited scope of access provides for data
    protection
  • Only the program that created the local can
    access it
  • The code is reentrant.
  • The code is relocatable
  • The number of variables is more than available
    registers

7
Recall Stack Rules
  • Program segments should have an equal number of
    pushes and pulls
  • Push with multiple registers will always put the
    lower numbered registers contents in the lower
    address.
  • Pop with multiple registers will always get the
    lower numbered registers contents from the lower
    address.
  • Push
  • SPSP-4
  • Store 32 bits at SP
  • Pop
  • Read 32 bits at SP
  • SPSP4

8
Stack frame using SP
binding phase sum EQU 0 32-bit unsigned number n EQU 4 32-bit unsigned number 1)allocation phase calc PUSH R4,LR SUB SP,8 allocate n,sum 2)access phase MOV R0,0 STR R0,SP,sum sum0 MOV R1,1000 STR R1,SP,n n1000 loop LDR R1,SP,n R1n LDR R0,SP,sum R0sum ADD R0,R1 R0sumn STR R0,SP,sum sumsumn LDR R1,SP,n R1n SUBS R1,1 n-1 STR R1,SP,n nn-1 BNE loop 3)deallocation phase ADD SP,8 deallocation POP R4,PC R0sum unsigned long calc(void) unsigned long sum, n sum 0 for(n1000 ngt0 n--) sumsumn return sum
Program 7.3. Stack pointer implementation of a
function with two local 32-bit variables.
9
Stack frame using R11
binding phase sum EQU 0 32-bit unsigned number n EQU 4 32-bit unsigned number 1)allocation phase calc PUSH R4,R11,LR SUB SP,8 allocate n,sum MOV R11,SP frame pointer 2)access phase MOV R0,0 STR R0,R11,sum sum0 MOV R1,1000 STR R1,R11,n n1000 loop LDR R1,R11,n R1n LDR R0,R11,sum R0sum ADD R0,R1 R0sumn STR R0,R11,sum sumsumn LDR R1,R11,n R1n SUB R1,1 n-1 STR R1,R11,n nn-1 BNE loop 3)deallocation phase ADD SP,8 deallocation POP R4,R11,PC R0sum unsigned long calc(void) unsigned long sum,n sum 0 for(n1000 ngt0 n--) sumsumn return sum
Program 7.4. Stack frame pointer implementation
of a function with two local 32-bit variables.
10
Push parameters on stack
Inputs R0 is x R1 is y R2 is z Output R0 is return value sum EQU 0 32-bit signed number x EQU 4 32-bit signed number y EQU 8 32-bit signed number z EQU 12 32-bit signed number Add3 PUSH R0,R1,R2,LR SUB SP,4 allocate sum body of the function LDR R0,SP,x ADD R0,R0,SP,y ADD R0,R0,SP,z STR R0,SP,sum ADD SP,16 deallocate POP PC long Add3(long x, long y, long z) long sum sum xyz return sum
Pushing parameters on stack makes them similar to
local variables
11
Recursion using the stack
Input R0 is n Output R0 is return value n EQU 0 input parameter Fact PUSH R0,LR CMP R0,1 BLS base SUB R0,1 n-1 BL Fact Fact(n-1) LDR R1,SP,n MUL R0,R0,R1 nFact(n-1) B done base MOV R0,1 done ADD SP,4 deallocate POP PC unsigned long Fact(unsigned long n) if(nlt1) return 1 return nfact(n-1)
Recursion requires putting parameters and locals
on the stack
12
Fixed-Point Numbers
  • How? (value I?)
  • I (Variable Integer) is a 16-bit unsigned
    integer. It is stored and manipulated in memory.
  • ? (Fixed Constant) that represents the
    resolution. It is not stored but is usually
    written in comments implicit.
  • (What about negative numbers?)
  • Why? (wish to represent non-integer values)
  • Next lab measures distance from 0 to 3 cmE.g.,
    1.234 cm
  • When? (range is known, range is small)
  • Range is 0 to 3cm
  • Resolution is 0.003 cm

13
Fixed-Point Numbers Decimal
  • Decimal Fixed-Point
  • (Value I10m)
  • I is a 16-bit unsigned integer (variable
    integer)
  • ? 10m decimal fixed-point (fixed constant)
  • For example with m-3 (resolution of 0.001 or
    milli) the value range is 0.000 to 65.535
  • What is ? represented as, in Decimal
    Fixed-Point? ? (3.14159) I10-3 gt I
    Integral approximation of (3.14159103)
  • I Integral approximation of (3141.59)
  • I 3142
  • Decimal Fixed-Point numbers are human-friendly
  • -easy to input/output to humans

14
Fixed-Point Numbers Binary
  • Binary Fixed-Point
  • (Value I2m)
  • I is a 16-bit unsigned integer (variable
    integer)
  • ? 2m binary fixed-point (fixed constant)
  • For example with m-8 (resolution of 1/256)
  • What is ? represented as, in binary Fixed Point?
  • ? (3.14159) I2-8
  • gt I Integral approximation of(3.1415928)
  • I Integral approximation of(804.2477)
    I 804
  • Binary Fixed-Point numbers are computer-friendly
  • -runs very fast because shifting is fast

15
Output
  • Output an integer.
  • Assume integer, n, is between 0 and 9999.
  • OutChar(0x30n/1000) thousands digit
  • n n1000OutChar(0x30n/100)hundreds digit
  • n n100OutChar(0x30n/10)tens digit
  • OutChar (0x30n10)ones digit
  • Output a fixed-point decimal number.
  • Assume the integer part of the fixed point
    number, n, is between 0 and 9999, and resolution
    is 0.001.
  • OutChar(0x30n/1000)thousands digit
  • n n1000OutChar(0x2E)decimal
    pointOutChar(0x30n/100)hundreds digit
  • n n100OutChar(0x30n/10)tens digit
  • OutChar (0x30n10)ones digit

16
Input/Output Synchronization
  • Processor-Peripheral Timing Mismatch
  • Peripherals, e.g., displays, sensors, switches,
    generally operate MUCH slower than processor
    instruction times
  • Processor MHz
  • Peripheral kHz or Hz
  • MANY instructions can be executed while
    peripheral processes information

17
Input/Output Sync. (cont.)
  • Peripheral primitive states
  • READY
  • Peripheral is ready to initiate an I/O transfer
  • NOT READY
  • Peripheral is unable to perform I/O transfer
  • BUSY
  • READY peripheral becomes BUSY when I/O transfer
    initiated
  • Peripheral remains BUSY for duration of I/O
    transfer
  • Another transfer can NOT be initiated
  • NOT BUSY
  • READY peripheral is able to initiate another I/O
    operation

18
Input/Output Sync. (cont.)
INPUT
OUTPUT
19
I/O Sync Options (1)
  • What to do while the peripheral is BUSY?
  • BLIND CYCLE TRANSFER
  • Suppose that a BUSY control signal is not
    available
  • Perform I/O operation
  • Wait for a period of time that is guaranteed to
    be sufficient for operation to complete
  • Initiate next operation

20
I/O Sync Options (2)
  • What to do while the peripheral is BUSY?
  • BUSY-WAIT (e.g., ready-busy, test-transfer)
  • Poll peripheral status wait for READY/NOT BUSY
  • Perform other tasks between polls
  • Unless timed correctly, under/over run possible
  • One solution POLL CONTINUOUSLY

21
I/O Sync Options (3)
  • What to do while the peripheral is BUSY?
  • INTERRUPT/TRANSFER
  • Hardware INTERRUPTS processor on condition of
    READY/NOT BUSY
  • Facilitates performing other background -
    processing between I/O transfers
  • Processor changes context when current transfer
    complete
  • Requires program structure to process context
    change

22
I/O Sync Options (4)
  • What to do while the peripheral is BUSY?
  • DIRECT MEMORY ACCESS TRANSFER
  • Special purpose hardware logic monitors status of
    BUSY signal and maintains addresses of data to be
    communicated
  • Requires address and block size initialization
  • On the condition of NOT BUSY logic communicates
    next data element and increments address
  • When transfer is complete, logic provides
    COMPLETE INTERRUPT

Our LM4F120/TM4C123 supports DMA (but EE319K
doesnt use it)
23
Latency
  • Software latency or interface latency
  • Time from when new input is ready until time
    software reads data.
  • Time from when output is idle until time software
    writes new data.
  • Execute tasks at periodic intervals, latency is
    delay from when it should run until it does run
  • Interrupts guarantee an upper bound on the
    software response time
  • Count maximum time running with I1, plus
  • Time to process the interrupt.

24
Real-Time System
  • Real-time system
  • a system that can guarantee a worst case latency
  • Throughput/bandwidth
  • maximum data flow (bytes/s) that can be processed
    by the system
  • Priority
  • determines the order of service among two or more
    requests

25
Kentec EB-LM4F120-L35
  • A 3.5 inch QVGA TFT LCD module
  • Connects to the LaunchPad as a booster pack
  • Quarter VGA WxD of 320x240 pixels
  • Color display with 16-bits per pixel
  • Is a capacitive touchscreen we will not use the
    touchscreen in EE319K
  • Device driver library SSD2119.c provided to you
  • Each partnership checks one out of the second
    floor, but it will cost you over 100 if you
    loose it

26
LCD Operation
  • Simplified Interface to Kentec EB-LM4F120-L35

Data Bus (PB0-7)
Control Bus (PA4-7)
27
Interface signals
  • Data bus
  • PB0-7 hold the 8-bit command or Data to be sent
  • We will use 8-bit commands and 16-bit data.
  • Send 16-bit data as two consecutive 8-bit writes
    on the bus
  • 8-bit command means MSbyte is zero
  • Control bus
  • PA7(CS) Chip Select
  • PA6(RS) Command/Data Select
  • PA5(WR) Write control signal for LCD
  • PA4(RD) Read control signal for LCD
  • PA3,2 and PE4,5 used for touchscreen
  • PF2 controls backlight

28
LCD Programming
LCD_WriteCommand Involves 7 steps performed to
send 8-bit Commands to the LCD
RD is high throughout
CS is low during communication
RS is low during command write
Microcontroller must do these steps
All control signals are high before and after the
command write
29
LCD Programming
LCD_WriteData Involves 7 steps performed to send
16-bit data to the LCD
RD is high throughout
CS is low during communication
RS is high during data write
Microcontroller must do these steps
All control signals are high before and after the
data write
30
LCD Lab7
  • Lab assignment (Lab7Starter.zip)
  • Interface LCD to TI board
  • Develop device driver to serve as interface
    between TM4C123 and Kentec display
  • Use main program (in lab7.s) that employs device
    driver in Lcd.s

31
Lab7 Your responsibility
  • IO.s Switch and Heartbeat module
  • IO_Init
  • IO_HeartBeat
  • IO_Touch
  • Lcd.s LCD Device driver module
  • LCD_WriteData
  • LCD_WriteCommand
  • Wait10ms
  • Print.s Print module
  • LCD_OutFix
  • LCD_OutDec

Do not use SysTick for this wait, because we will
add SysTick interrupts in Labs 8, 9, 10.
32
Summary
  • Stack is useful for local variables, parameter
    passing
  • Draw stack picture by hand executing assembly
    code
  • Fixed-point allows non-integers without FP
    hardware
  • LCD is an output device for embedded systems
  • Text, graphics, touch pads, color
Write a Comment
User Comments (0)
About PowerShow.com