1 / 30

EE 319K Introduction to Embedded Systems

EE 319K Introduction to Embedded Systems. Lecture 6: Stack and Local Variables, Fixed-Point Numbers, LCD and Recursion. Agenda. Local Variables Stack and Activation Records Fixed-point numbers LCD Interfacing Recursion. Local Variables. Scope => from where can it be accessed

Download Presentation

EE 319K Introduction to Embedded Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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=> from where can it be accessed local means restricted to current program segment global means any software can access it Allocation/Lifetime=> when is it created & destroyed dynamic allocation using registers or stack permanent allocation assigned a block of memory

  4. Local variables => 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 Local Variables

  5. In C Global Variables Public: global scope, permanent allocation// accessible by all modulesint16_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 onlyvoid static MyPrivateFunction(void){…} Local variables Public: local scope, dynamic allocationvoid MyFunction(void){ int16_t myLocalVariable; } Private: local scope, permanent allocationvoid MyFunction(void){ static int16_t count; count++; }

  6. 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 Why use Stack for Locals?

  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 register’s contents in the lower address. Pop with multiple registers will always get the lower numbered register’s contents from the lower address. Push • SP=SP-4 • Store 32 bits at SP Pop • Read 32 bits at SP • SP=SP+4

  8. Stack frame using SP Program 7.3. Stack pointer implementation of a function with two local 32-bit variables.

  9. Push parameters on stack Pushing parameters on stack makes them similar to local variables

  10. Recursion using the stack Recursion requires putting parameters and locals on the stack

  11. Fixed-Point 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 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?)

  12. Fixed-Point Numbers: Decimal Decimal Fixed-Point (Value = I*10m) 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…) = I*10-3 => I = Integral approximation of (3.14159…*103) 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 = I*2m) 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…)= I*2-8 => I = Integral approximation of(3.14159…*28) 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(0x30+n/1000) ;thousand’s digit n = n%1000LCD_OutChar(0x30+n/100);hundred’s digit n = n%100LCD_OutChar(0x30+n/10);ten’s digit LCD_OutChar(0x30+n%10);one’s 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(0x30+n/1000)//thousand’s digit n = n%1000LCD_OutChar(0x2E)//decimal point OutChar(0x30+n/100)//hundred’s digit n = n%100LCD_OutChar(0x30+n/10)//ten’s digit LCD_OutChar (0x30+n%10)//one’s 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 doesn’t 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 I=1, 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 -> LaunchPad pin 6-VCC -> power (3.3V) 8-GND -> ground 2-CE -> to PA3 1-RST -> to PA7 3-DC -> to PA6 4-DIN -> to PA5 5-CLK -> to PA2 7-LIGHT -> not connected Show Datasheet for LCD in LCD.pdf

  26. Module Call Graph main Print Nokia 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/C=PA6 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/C=PA6 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.

More Related