U of U ECE 3720 - Software Development Lecture Notes
Pages 9

Unformatted text preview:

Slide 1'&$%ECE/CE 3720: Embedded System DesignChris J. MyersLecture 3: Software DevelopmentSlide 2'&$%Introduction• Success of an embedded system project depends on bothhardware and software.• Real-time embedded systems are usually not very large,but are often quite complex.• Needed software skills include: modular design, layeredarchitecture, abstraction, and verification.• Writing good software is an art that must be developedand cannot be added on at the end of a project.• Good software with average hardware will alwaysoutperform average software with good hardware.1Slide 3'&$%Memory Allocation(See Figure 2.2)Slide 4'&$%Pseudo Instructionsorg set location to ORiGinfcc Form Constant Character stringfcb Form Constant Bytefdb Form Double Byteequ EQUate symbol to a valuermb Reserve Memory Bytes2Slide 5'&$%Memory Allocation Exampleorg $0000 ;RAMcnt rmb 1 ;globalorg $B600 ;EEPROMconst fcb 5 ;amount to addorg $E000 ;ROMinit ldaa #$FFstaa DDRC ;outputsclr cntrtsmain lds #$00FF ;sp=>RAMbsr initloop ldaa cntstaa PORTC ;outputadda conststaa cntbra looporg $FFFE ;ROMfdb main ;reset vectorSlide 6'&$%Golden Rule of Software DevelopmentWrite software for others as you wish they would write for you.• Quantitative performance measurements:– Dynamic efficiency - number of CPU cycles required.– Static efficiency - number of memory bytes required.– Are given design constraints satisfied?• Qualitative performance measurements:– Easy to debug (fix mistakes)– Easy to verify (prove correctness)– Easy to maintain (add features)• Sacrificing clarity in favor of execution speed often results insoftware that runs fast but doesn’t work and can’t be changed.• You are a good programmer if (1) you can understand yourown code 12 months later and (2) others can change your code.3Slide 7'&$%Software Maintenance• Maintenance is most important phase of development.• Includes fixing bugs, adding features, optimization,porting to new hardware, configuring for new situations.• Documentation should assist software maintenance.• Most important documentation is in the code itself.• Client comments describe inputs, outputs, and errors.• Colleague comments focus on software mechanisms.Slide 8'&$%Good Comments• Comments that simply restate the operation do not addto the overall understanding.BAD X=X+4; /* add 4 to X */Flag=0; /* set Flag=0 */GOOD X=X+4; /* 4 is added to correct for theoffset (mV) in the transducer */Flag=0; /* means no key has been typed */• When variable defined, should explain how used.int SetPoint; /* Desired temperature, 16-bit signedvalue with resolution of 0.5C,a range of -55C to +125C,a value of 25 means 12.5C */• When constant defined, should explain what it means.V=999; /* 999mV is the maximum possible voltage */4Slide 9'&$%Good Comments (cont)• When a subroutine defined, two types of comments:– Client comments explain how the function is to beused, how to pass parameters, and what errors andresults are possible. (in header or start of subroutine)– Colleague comments explain how the function works(within the body of the function).Slide 10'&$%Self-Documenting Code• Software written in a simple and obvious way such thatits purpose and function are self-apparent.• Use descriptive names for var, const, and functions.• Formulate & organize into well-defined subproblems.• Liberal use of #define and equ statements.• Assembly language style issues:– Begins and ends with a line of *s– States the purpose of the function– Gives the I/O parameters, what they mean, and howthey are passed– Different phases of code delineated by a line of -’s5Slide 11'&$%Software Documentation• Purpose of the module• Input parameters– How passed (call by value, call by reference)– Appropriate range– Format (8 bit/16 bit, signed/unsigned, etc.)• Output parameters– How passed (return by value, return by reference)– Format (8 bit/16 bit, signed/unsigned, etc.)• Example inputs and outputs if appropriate• Error conditions• Example calling sequence• Local variables and their significanceSlide 12'&$%Abstraction• Software abstraction is when we define a complexproblem with a set of basic abstract principles.• Advantages of abstraction:– Faster to develop because some building blocks exist,– Easier to debug (prove correct) because it separatesconceptual issues from implementation, and– Easier to change.• Finite state machine (FSM) is a good abstraction.• Consists of inputs, outputs, states, and state transitions.• An FSM software implementation is easy to understand,debug, and modify.6Slide 13'&$%Mealy FSM(See Figure 2.4)Slide 14'&$%Mealy FSM in Cconst struct State{ unsigned char Time; /* Time to wait in each state */unsigned char Out[2]; /* Output if input=0,1 */const struct State *Next[2]; };/*Next state if inp=0,1*/typedef const struct State StateType;#define SA &fsm[0]#define SB &fsm[1]#define SC &fsm[2]#define SD &fsm[3]StateType fsm[4]={{100,{0,0},{SB,SD}},{100,{0,8},{SC,SA}},{ 15,{0,0},{SB,SD}},{ 15,{8,8},{SC,SA}}};7Slide 15'&$%Mealy FSM in C (cont)void Wait(unsigned int delay){ int Endt;Endt=TCNT+delay; /* Time (125ns cycles) to wait */while((Endt-(int)TCNT)>0); /* wait */};void main(void){ StatePtr *Pt; /* Current State */unsigned char Input;Pt=SA; /* Initial State */DDRC=0x08; /* PortC bit3 is output */while(1){Wait(Pt->Time); /* Time to wait in this state */Input=PORTC<<7; /* Input=0 or 1 */PORTC=Pt->Out[Input]; /* Perform output */Pt=Pt->Next[Input]; /* Move to the next state */}};Slide 16'&$%Mealy FSM in Assemblyorg $B600 Put in EEPROM so it can be changed* Finite State MachineTime equ 0 Index for time to wait in this stateOut0 equ 1 Index for output pattern if input=0Out1 equ 2 Index for output pattern if input=1Next0 equ 3 Index for next state if input=0Next1 equ 5 Index for next state if input=1IS fdb SA Initial stateSA fcb 100 Time to waitfcb 0,0 Outputs for inputs 0,1fdb SB Next state if Input=0fdb SD Next state if Input=18Slide 17'&$%Mealy FSM in Assembly (cont)SB fcb 100 Time to waitfcb 0,8 Outputs for inputs 0,1fdb SC Next state if Input=0fdb SA Next state if Input=1SC fcb 15 Time to waitfcb 0,0 Outputs for inputs 0,1fdb SB Next state if Input=0fdb SD Next state if Input=1SD fcb 15 Time to waitfcb 8,8 Outputs for inputs 0,1fdb SC Next state if Input=0fdb SA Next state if Input=1Slide 18'&$%Mealy FSM in Assembly (cont)org $E000 Place assembly program in ROM* 6811 program* Initialization of 6811 and


View Full Document

U of U ECE 3720 - Software Development Lecture Notes

Course: Ece 3720-
Pages: 9
Download Software Development Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Software Development Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Software Development Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?