Presentation is loading. Please wait.

Presentation is loading. Please wait.

ELN5622 Embedded Systems Class 3 Spring, 2003 Kent Orthner

Similar presentations


Presentation on theme: "ELN5622 Embedded Systems Class 3 Spring, 2003 Kent Orthner"— Presentation transcript:

1 ELN5622 Embedded Systems Class 3 Spring, 2003 Kent Orthner

2 Assembly Language Programming

3  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 Programming Conventions

4  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 Assembly Language Style

5  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 Assembly Language Style

6  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 Assembly Language Style

7  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 Assembly Language Style

8  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 Assembly Language Style

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

10  Naming Conventions –Very important to prevent errors and make code easy to understand. –Examples: LDX SP LDB X,p_operandStack variable LDA g_timerGlobal variable JSR s_timercheckSubroutine LDB X,OperandStack variable LDA G_TimerVarGlobal variable JSR TIMERCHECK Subroutine Assembly Language Style

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

12  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: Assembly Language Style

13  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: Assembly Language Style

14  Repeat-Until Loop * Repeat RP_SWSTATE: * Until SwitchState = END_STATE LDAA SwitchState CMPA END_STATE BNE RP_SWSTATE Assembly Language Style

15  For Loop * For (I=COUNT, I--, I==0) LDAACOUNT * Begin FOR_LOOP: PUSH A... * Next PULA DECA BNE FOR_LOOP Assembly Language Style

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  Environment setup –System Equates –Constant Equates –Memory Map Equates  Initialization –Set stack pointer –Special Register Setup –Initialize Tasks –Enable Interrupts  Main Loop –Execute Applications Embedded Program Flow

20 Initialize Stack Pointer Special Register Setup Initialize Task 1 Initialize Task 2 Enable Interrupts. ( Go! ) Initialize Task 3 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  68HC11 jumps to the 'Reset Vector' located at 0xFFFE, 0xFFFF PC <- M(0xFFFE, 0xFFFF) Execution Start

23  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 Initialization

24  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 Initialization

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

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


Download ppt "ELN5622 Embedded Systems Class 3 Spring, 2003 Kent Orthner"

Similar presentations


Ads by Google