Unformatted text preview:

ECE/CS 5780/6780: Embedded System DesignScott R. LittleLecture 4: Software DesignScott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 1 / 96AdministriviaHow is Lab 1?Don’t forget Lab 2 has a pre-lab assignment.Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 2 / 96IntroductionSuccess of an embedded system project depends on bothhardware and software.Real-time embedded systems are usually not very large, but areoften quite complex.Needed software skills include: modular design, layeredarchitecture, abstraction, and verification.Writing good software is an art that must be develop ed andcannot be added on at the end of a project.Good software with average hardware will always outperformaverage software with good hardware.Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 3 / 96Golden Rule of Software DevelopmentWrite software for others as you wish they would write for you.Quantitative performance measurements:Dynamic efficiency - number of CPU cycles & power 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 your owncode 12 months later and (2) others can change your code.Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 4 / 96Software MaintenanceMaintenance is the most important phase of development?Includes fixing bugs, adding features, optimization, porting tonew hardware, configuring for new si tuations.Documentation should assist software maintenance.Most important documentation is in the code itself.Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 5 / 96Good CommentsComments that simply restate the operation do not add to theoverall 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 */Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 6 / 96Client and Colleague CommentsWhen a subroutine is defined, two types of comments needed:Client comments explain how the function is to be used, how topass parameters, and what errors and results are possible. (inheader or start of subroutine)Colleague comments explain how the function works (within thebody of the function).Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 7 / 96More on Client CommentsPurpose of the moduleInput parametersHow passed (call by value, call by reference)Appropriate rangeFormat (8 bit/16 bit, signed/unsigned, etc.)Output parametersHow passed (return by value, return by reference)Format (8 bit/16 bit, signed/unsigned, etc.)Example inputs and outputs if appropriateError conditionsExample calling sequenceLocal variables and their significanceScott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 8 / 96Self-Documenting CodeSoftware written in a simple and obvious way such that itspurpose and function are self-apparent.Use descriptive names for var, const, and fun ctions.Formulate and organize into well-defined subproblems.Liberal use of #define and equ statements.Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 9 / 96Use of #define// An inappropriate use of #define.#define size 10short data[size];void initialize(void){ short jfor(j=0;j<10;j++)data[j]=0;};// An appropriate use of #define.#define size 10short data[size];void initialize(void){ short jfor(j=0;j<size;j++)data[j]=0;};Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 10 / 96Naming ConventionNames should have meaning.Avoid ambiguities.Give hints about the type.Use the same name to refer to the same type of object.Use a prefix to identify public objects.Use upper and lower case to specify the scope of an object.Use capitalization to delimit words.Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 11 / 96Naming Convention ExamplesType Exampleconstants PORTAlocal variables maxTemperatureprivate global variables MaxTemperaturepublic global variables DACMaxVoltageprivate function ClearTimepublic function Timer ClearTimeScott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 12 / 96AbstractionSoftware abstraction is when we define a complex problem witha set of basic abstract principles.Advantages of abstraction:Faster to develop because some building blocks exist,Easier to debug (prove correct) because it separates conceptualissues from implementation, andEasier to change.Finite state machine (FSM) is a good abstraction.Consists of inputs, outputs, states, and state transitions.FSM software implementation is easy to unde rstand, debug, andmodify.Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 13 / 966812 Timer DetailsTCNT is a 16-bit unsigned counter that increments at a ratedetermined by PR2, PR1, and PR0 in the TSCR2 register.PR2 PR1 PR0 Divide by TCNT Period TCNT Frequency0 0 0 1 250ns 4 MHz0 0 1 2 500ns 2 MHz0 1 0 4 1µs 1 MHz0 1 1 8 2µs 500 kHz1 0 0 16 4µs 250 kHz1 0 1 32 8µs 125 kHz1 1 0 64 16µs 62.5 kHz1 1 1 128 32µs 31.25 kHzWhen TCNT overflows, TOF flag in the TFLG2 register is set.Overflow causes an interrupt if the TOI bit in TSCR2 is set.Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 14 / 96Time Delayvoid Timer_Init(void){TSCR1 = 0x80; // enable TCNTTSCR2 = 0x04; // 1us TCNT}void Timer_Wait(unsigned short cycles){unsigned short startTime = TCNT;while((TCNT-startTime) <= cycles){}}// 10000us equals 10msvoid Timer_Wait10ms(unsigned short delay){unsigned short i;for(i=0; i<delay; i++){Timer_Wait(10000); // wait 10ms}}Scott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 15 / 96Traffic Light InterfaceScott R. Little (Lecture 4: Software Design) ECE/CS 5780/6780 16 / 96Moore FSM & State Table10, 1130100001waitN5100010goE30001100waitE501010000, 0110, 1100, 0110, 1100, 1001, 1100, 01goNInput vector <N,E>Output vector<RE,YE,GE,RN,YN,GN>No cars Car E Car N Car N,EgoN goN waitN goN waitNwaitN goE goE goE goEgoE goE goE waitE


View Full Document

U of U CS 5780 - Software Design

Documents in this Course
Lab 1

Lab 1

5 pages

FIFOs

FIFOs

10 pages

FIFOs

FIFOs

5 pages

FIFO’s

FIFO’s

12 pages

MCU Ports

MCU Ports

12 pages

Serial IO

Serial IO

26 pages

Load more
Download Software Design
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 Design 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 Design 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?