1 / 42

ELN5622 Embedded Systems Class 3 Spring, 2003

ELN5622 Embedded Systems Class 3 Spring, 2003. Kent Orthner korthner@hotmail.com. Assembly Language Programming. Programming Conventions. Conventions: Rules that a designer follows to make his/her program easier to understand, communicate to other, debug, and less prone to mistakes.

lorant
Download Presentation

ELN5622 Embedded Systems Class 3 Spring, 2003

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. ELN5622Embedded SystemsClass 3Spring, 2003 Kent Orthnerkorthner@hotmail.com

  2. Assembly Language Programming

  3. Programming Conventions • Conventions: • Rules that a designer follows to make his/her program easier to understand, communicate to other, debug, and less prone to mistakes. • Includes: • Comment conventions • Naming conventions • Drawing Conventions

  4. Assembly Language Style • Program Header • What the program does • Author’s Name • File Name • Date • Version • History • Function Header • What the function does/How it works • Author’s Name • Date • History

  5. Assembly Language Style • Equates vs. In-line constants • Use constants wherever possible • Easier to understand, • Easier to fix • Easier to maintain • Location of Equate Statements • All together • Point-of-use

  6. Assembly Language Style • Types of Equates • System Equates • System Functions • Location of I/O Registers • Port Addresses • Constant Equates • CR/LF, End of String, NIL • Memory Map Equates • Program Location • Flash Memory Location • Stack Pointer Location

  7. Assembly Language Style • Constant Data Definitions • Tables, Strings, Etc. • Located in ROM • Often best to have at the end of the program to lessen the chance of them executed • Variable Data Definitions • System-wide Variables • Located in RAM • Non-volatile ROM Data • Database for user settings • Maintained when power is shut off

  8. Assembly Language Style • Indenting • Not commonly used for assembly programs • Can ease understanding by making program flow more obvious. • Up to the individual designer. • Use ‘Boilerplate’ files • All files use the same flow • Saves Typing • Less potential Mistakes

  9. Assembly Language Style • Commenting Style • Headers for functional blocks • Headers per line • Goal: To make it so the person maintaining the code can understand the program.

  10. Assembly Language Style • Naming Conventions • Very important to prevent errors and make code easy to understand. • Examples: LDX SP LDB X,p_operand Stack variable LDA g_timer Global variable JSR s_timercheck Subroutine LDB X,Operand Stack variable LDA G_TimerVar Global variable JSR TIMERCHECK Subroutine

  11. Assembly Language Style • Pseudocode • Self-commenting, less prone to error • Makes it natural to • design first with pseudo code • Implement second with assembly language * Get Temp * If Temp > MaxAllowed * Turn valve off * Else * turn the valve on * End if

  12. Assembly Language Style • Pseudocode * Get Temp LDAA TEMP_PORT * If Temp > MaxAllowed IF_TEMPMAX: CMPA MaxAllowed A-MaxAllowed BLE EL_TEMPMAX Branch if <= 0 * Turn valve off LDAA ValveOff STAA CONTROL_PORT BRA EI_TEMPMAX * Else turn the valve on EL_TEMPMAX: LDAA ValveOn STAA CONTROL_PORT * End if EI_TEMPMAX: <Next Inst>

  13. Assembly Language Style • While-Do Loop * While Temperatue > MaxAllowed WH_MAXALL: CMPA MaxAllowed A-MaxAllowed BLS EW_MAXALL Branch if < 0 * Do * End While BRA WH_MAXALL EW_MAXALL: <Next Inst>

  14. Assembly Language Style • Repeat-Until Loop * Repeat RP_SWSTATE: * Until SwitchState = END_STATE LDAA SwitchState CMPA END_STATE BNE RP_SWSTATE <Next Inst>

  15. Assembly Language Style • For Loop * For (I=COUNT, I--, I==0) LDAA COUNT * Begin FOR_LOOP: PUSH A . . . * Next PULA DECA BNE FOR_LOOP <Next Inst>

  16. Anatomy of an Embedded Program

  17. Embedded System Characteristics • A computing system embedded within a device. • A system intended for a single purpose, which includes a general purpose processor. • Often used for • providing user control over a product • to observe or control something in the “real world” (i.e. analog)

  18. Embedded System Startup • What is the first thing the user expects when an embedded system starts up? • Begin application execution. • When should the software in an embedded system finish? • It shouldn't. It should (normally) run until the power is turned off.

  19. Embedded Program Flow • Environment setup • System Equates • Constant Equates • Memory Map Equates • Initialization • Set stack pointer • Special Register Setup • Initialize Tasks • Enable Interrupts • Main Loop • Execute Applications

  20. Embedded Program Flow Initialize Stack Pointer Special Register Setup Initialize Task 1 Initialize Task 2 Initialize Task 3 Enable Interrupts. ( Go! ) Execute Task 1 Execute Task 2 Execute Task 3

  21. Environment Setup • Types of Equates • System Equates • System Functions • Location of I/O Registers • Port Addresses • Constant Equates • CR/LF, End of String, NIL • Memory Map Equates • Program Location • Flash Memory Location • Stack Pointer Location

  22. Execution Start • 68HC11 jumps to the 'Reset Vector' located at 0xFFFE, 0xFFFF PC <- M(0xFFFE, 0xFFFF)

  23. Initialization • Initialize Stack Pointer • Interrupts • Functions • Temporary Storage • Special Register Setup • Memory Mapping registers • Determine the location of RAM & the register block within the memory map. • Can only be written at Startup

  24. Initialization • Special Register Setup (Continued) • System Configuration Registers • A/D Powerup • Clock Select • IRQE Edge-Sensitive Select • Clock Monitor Enable • COP Timer Rate • I/O Control Registers • Timer Registers • Interrupt Mask Registers • SCI & SPI Registers • ADC/DAC Control Registers

  25. Initialization • Task Initializatoin • Set initial state for state machines • Set initial values for task variables • Pre-compute tables where necessary • Clear / pre-set buffers

  26. Main Loop Architecture • 3 buttons need to be checked at least 10 times a second: repeat for (i=2; i--; i==0) Checkbutton(i); end for until ( false )

  27. Main Loop Architecture • 3 buttons need to be checked at least 10 times a second, and 3 pins must be set 5 times a second. repeat for (i=2; i--; i==0) CheckButton(i); end for if (FifthSecondIsUp) for (i=2; i<3; i--) SetPin(i); end for end if until ( false )

  28. Main Loop Architecture • 3 buttons need to be checked at least 10 times a second, and 3 pins must be set 5 times a second. repeat for (i=2; i--; i==0) CheckButton(i); end for if (FifthSecondIsUp) for (i=2; i<3; i--) SetPin(i); end for end if until ( false )

  29. Main Loop Architecture • And if there are a couple more things to be done, all at different times … repeat CheckButtons() SetPins() ControlMotors() SetDisplay() until ( false )

  30. Cyclical Executive • Architecture Repeat Task1 () Task2 () Task3 () Until ( false )

  31. Cyclical Executive • Architecture * Repeat MAINLOOP: * Task1 () JSR TASK1 * Task2 () JSR TASK2 * Task3 () JSR TASK3 * Until ( false ) JMP MAINLOOP

  32. Cyclical Executive • Adequate for simple applications. • Other Names: • Round Robin Executive • Round Robin Kernel • Super Loop • Rules: • Tasks may not employ busy waiting • Tasks must do their work quickly and return to the main loop so that other tasks can run • Tasks must save their place by using a state variable

  33. Cyclical Executive • Advantages: • Small • Compact • Easy to use • Easy to understand • Disadvantages • No priorities • Polls for events • Timing responsibility is put on the programmer

  34. 68HC11 On-Chip Peripherals:Parallel I/O

  35. Parallel I/O • Three Functions per pins: • Output (1 or 0) • Wired-or output (1 or 0) • Input • Up to 40 I/O pins. • Each pin can be used as I/O or another function. • Some pins are fixed-direction, some are bidirectional.

  36. Parallel I/O • Port A • Shared with Timer & Pulse Accumulator • PA7: Bidir • PA6-PA3: Output Only • PA2-PA0 : Input Only • Port B • Shared as Expanded bus Address pins • Output Only • Port C • Shared as Expanded bus Data / Multiplexed Address pin. • Bidirectional

  37. Parallel I/O Registers • PORTn • 8-bit register for each port • Reads return the level of the pin itself for input/bidirectional pins, or the state of the logic inside the output buffer at the pin output. • Writes cause the data to be latched, so it can be used for output operation. (not input pins.) • PORTCL • Special Port C register for handshake writes.

  38. Parallel I/O Registers • DDRn • Register for each bidirectional pin. • Controls the direction of data flow. • 0 = Input • 1 = Output • Subsystem function overrides this pin function • Ie. SCI Tx/Rx • Control Registers • Determine if the pin is going to be used as General Purpose I/O, or as a subsystem pin. • Determines if an output will be a wired-or (open collector) output.

  39. Handshaking • Ports B&C, with STRA input & STRB output • 3 modes: • Simple Strobe (default) • Port B = Simple Strobe Output • Port C = Simple Strobe Input • Full-input Handshake • Full-output Handshake • Configured with PIOC register

  40. Handshaking - Simple Mode • Port B: Output with STAB • Port C: Input with STAA

  41. Handshaking - Full-Input Handshake • Port C: Input with both STAA & STAB

  42. Handshaking - Full-Output Handshake • Port C: Output with both STAA & STAB

More Related