EE 319K Introduction to Embedded Systems - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

EE 319K Introduction to Embedded Systems

Description:

Title: Lecture 9: Locals, LCD Subject: EE319K: Introduction to Embedded Systems Author: Bill Bard Andreas Gerstlauer Jon Valvano Ramesh Yerraballi – PowerPoint PPT presentation

Number of Views:238
Avg rating:3.0/5.0
Slides: 31
Provided by: BillBa76
Category:

less

Transcript and Presenter's Notes

Title: EE 319K Introduction to Embedded Systems


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

2
Agenda
  • Local Variables
  • Stack and Activation Records
  • Fixed-point numbers
  • LCD Interfacing
  • Recursion

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) int16_t myLocalVariable
  • Private local scope, permanent allocationvoid
    MyFunction(void) static int16_t count
    count
  • Global Variables
  • Public global scope, permanent allocation//
    accessible by all modules int16_t
    myGlobalVariable void MyFunction(void)
  • Private global scope(only to the file),
    permanent allocation//accessible in this file
    onlystatic int16_t 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 uint32_t calc(void) uint32_t 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
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 int32_t Add3(int32_t x, int32_t y, int32_t z) int32_t sum sum xyz return sum
Pushing parameters on stack makes them similar to
local variables
10
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 uint32_t Fact(uint32_t n) if(nlt1) return 1 return nfact(n-1)
Recursion requires putting parameters and locals
on the stack
11
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.001 cm

12
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 (with
    16-bit)
  • 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

13
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

14
Output
  • Output an integer.
  • Assume integer, n, is between 0 and 9999.
  • LCD_OutChar(0x30n/1000) thousands digit
  • n n1000LCD_OutChar(0x30n/100)hundreds
    digit
  • n n100LCD_OutChar(0x30n/10)tens digit
  • LCD_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.
  • LCD_OutChar(0x30n/1000)//thousands digit
  • n n1000LCD_OutChar(0x2E)//decimal point
  • OutChar(0x30n/100)//hundreds digit
  • n n100LCD_OutChar(0x30n/10)//tens digit
  • LCD_OutChar (0x30n10)//ones digit

15
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

16
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

17
Input/Output Sync. (cont.)
INPUT
OUTPUT
18
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

19
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

20
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

21
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)
22
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.

23
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

24
NOKIA 5110 LCD
  • A low power CMOS LCD module
  • Has a Phillips PCD8544 controller/driver
  • Resolution WxD of 48x84 pixels
  • Dot Matrix display with 1-bit per pixel
  • Has a DDRAM (48 84 bit static RAM) which stores
    the display data.
  • Device driver library Nokia5110.c provided to you
    Implements the SPI protocol
  • Max Rate 4 Mbps

25
LCD Operation
  • Possible Interface to Launchpad

Nokia 5110 -gt LaunchPad pin 6-VCC -gt power
(3.3V) 8-GND -gt ground 2-CE -gt to
PA3 1-RST -gt to PA7 3-DC -gt to PA6 4-DIN -gt to
PA5 5-CLK -gt to PA2 7-LIGHT -gt not connected
Show Datasheet for LCD in LCD.pdf
26
Module Call Graph
main
Nokia
Print
IO
LCD Low-level
27
LCD Programming
  • LCD_WriteCommand Involves 6 steps performed to
    send 8-bit Commands to the LCD
  • Read SSI0_SR_R and check bit 4,
  • If bit 4 is set loop back to step 1 (wait for
    BUSY bit to be zero)
  • Clear D/CPA6 to zero (D/C pin configured for
    COMMAND)
  • Write the command to SSI0_DR_R
  • Read SSI0_SR_R and check bit 4,
  • If bit 4 is set loop back to step 5 (wait for
    BUSY bit to be zero)

28
LCD Programming
  • LCD_WriteData Involves 4 steps performed to
    send 8-bit Commands to the LCD
  • Read SSI0_SR_R and check bit 1,
  • If bit 1 is clear loop back to step 1 (wait for
    TNF bit to be one)
  • Set D/CPA6 to one (D/C pin configured for DATA)
  • Write the data to SSI0_DR_R

29
LCD Lab6
  • Lab assignment (Lab6.zip)
  • Interface LCD to TI board
  • Develop device driver to serve as interface
    between TM4C123 and Nokisa display
  • Use main program (in lab6.c)
  • Write the modules you are responsible for
  • Test on Simulator first
  • Build circuit and test on real board

30
Lab6 Your responsibility
  • IO.c Switch and Heartbeat module
  • IO_Init
  • IO_HeartBeat
  • IO_Touch
  • Lcd.c LCD Device driver module
  • LCD_WriteData
  • LCD_WriteCommand
  • Wait10ms
  • Print.c Print module
  • LCD_OutFix
  • LCD_OutDec

Do not use SysTick for this wait, because we will
add SysTick interrupts in Labs 7, 8, 9.
Write a Comment
User Comments (0)
About PowerShow.com