Unformatted text preview:

CS/ECE 5780/6780: Embedded SystemDesignJohn RegehrLecture 4: Software DesignLast TimeIAssembler is the program that converts assembly languageinto object code that can be executed by the processorIAddressing modes are key to reading and writing assemblylanguageICondition codes and subsequent branches are also veryimportantIFor efficiency and convenience, HCS12 provides extensivemath operations wider than 8 bitsIOtherwise, math on the HCS12 is totally standardIAssembly language permits very basic, very serious mistakessuch as failing to save the right registers on a function call,creating mismatched stack frames, improper use of conditioncode registers, etc.IntroductionISuccess of an embedded system project depends on bothhardware and software.IReal-time embedded systems are usually not very large, butare often quite complex.INeeded software skil ls incl ude : modular design, layeredarchitecture, abstraction, and verification.IWriting good software is an art that mus t be devel oped andcannot be added on at the end of a project.IGood software with average hardware will always outperformaverage s oftware with good hardware.What does good software look like?IQuantitative performance measuremen ts:IDynamic efficiency - number of CPU cycles & powe r required.IStatic efficiency - number of RAM/ROM bytes required.IAre given design constraints satisfied?IQualitative performance measurem ents:IEasy to debug (fix mistakes)IEasy to verify (prove correctness)IEasy to maintain (add features)ISacrificing clarity in favor of execution speed often results insoftware that runs fast but doesn’t work and can’t be changed.IYou are a good programmer if (1) you can understand yourown code 12 months later and (2) others can change yourcode.Software MaintenanceIMaintenance is an extremely important phase of development.IIncludes fixing bugs, adding features, optimization, porting tonew hardware, configuring for new situations.IDocumentation should assist software main tenance.IDocumentation resides in and outside of the software.Good CommentsIComments 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 */IWhen variable defined, should expl ain 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 */IWhen constant defined, should explain what it means.V=999; /* 999mV is the maximum possible voltage*/Client and Colleague CommentsIWhen a subroutine is defined, two types of comments needed:IClient comments explain how the function is to be used, howto pass paramete rs, and what errors and results are possible.(in header or start of subroutine)IColleague comments explain how the function works (withinthe body of the function).More on Client CommentsIPurpose of the moduleIInput parametersIHow passed (call by value, call by reference)IAppropriate rangeIFormat (8 bit/16 bit, signed/unsigned, etc.)IOutput parametersIHow passed (return by value, return by reference)IFormat (8 bit/16 bit, signed/unsigned, etc.)IExample inputs and outputs if appropriateIError conditionsIExample calling sequenceILocal variables and their significanceSelf-Documenting CodeISoftware written in a simple and obvious way such that itspurpose and function are self- apparent.IUse descriptive names for var, const, and fun ctions.IFormulate and organize into well-defined subproblems.ILiberal use of #define and equ statements.Use 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;};Naming ConventionsINames should have meaning.IAvoid ambiguities.IGive hints about the type.IUse the same name to refer to the same type of object.IUse a prefix to identify public objects.IUse upper and lower case to specify the scope of an object.IUse capitalization to delim it words.Naming Convention ExamplesType Exampleconstants PORTAlocal variables maxTemperatureprivate global variables MaxTemperaturepublic global variables DACMaxVoltageprivate function ClearTimepublic function Timer ClearTimeThere are many conventions like this one. Often, companies willuse some common set of conven tions, or develop their own.AbstractionIA software abstraction factors common functionality out ofdiverse examples.IAdvantages of abs traction:IFaster to develop because some building blocks exist,IEasier to debug (prove correct) because it separatesconceptual issues from implementation, andIEasier to change.IFinite state machine (FSM) is a good abstraction.IConsists of inputs, outputs, states, and state transitions.IFSM software implementation is easy to understand, debug,and modify.6812 Timer DetailsITCNT 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 kH z1 0 0 16 4µs 250 kH z1 0 1 32 8µs 125 kH z1 1 0 64 16µs 62.5 kHz1 1 1 128 32µs 31.25 kH zIWhen TCNT overflows, TOF flag in the TFLG2 register is set.IOverflow causes an interrupt if the TOI bit in TSCR2 is set.Time Delayvoid Timer_Init(void){TSCR1 = 0x80; // enable TCNTTSCR2 = 0x02; // 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}}Traffic Light InterfaceMoore FSM & State Table10, 1130100001waitN5100010goE30001100waitE501010000, 0110, 1100, 0110, 1100, 1001, 1100, 01goNIInput vector <N,E>IOutput 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 waitEwaitE goN goN goN goNC Implementation of a Moore FSMconst struct State {unsigned char Out;unsigned short Time;const struct State *Next[4];};typedef const struct State STyp;#define goN &FSM[0]#define waitN &FSM[1]#define goE &FSM[2]#define waitE &FSM[3]STyp FSM[4]={{0x21,3000,{goN,waitN,goN,waitN}},{0x22, 500,{goE,goE,goE,goE}},{0x0C,3000,{goE,goE,waitE,waitE}},{0x14, 500,{goN,goN,goN,goN}}};C Implementation of a Moore FSM (cont)void main(void){STyp *Pt; //


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?