Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Few Questions about Embedded Software design

Status
Not open for further replies.

scorrpeio

Full Member level 5
Full Member level 5
Joined
Dec 26, 2006
Messages
286
Helped
10
Reputation
20
Reaction score
9
Trophy points
1,298
Activity points
3,496
I am confused about implementation of software in Embedded C.

1. If I have a set of different functions used by different peripherals...which of the following software design is standard(for reusability, readability and ofcourse performance)

Approach for transferring calls and controls of execution -

Approach 1: -
Declare all the function associated with the peripheral as static so that no other file can see it. And create one function in that file which communicates with the external world.
For ex, In case of display interface, only UpdateDisplay() is not static while other functions like clearDisplay(), MsgDisplay() etc remain static.
The UpdateDisplay will take commands and calls from other files and pass on these calls to the static functions.

Approach 2: -
Making all the functions of any peripheral non static that is can be accessed by other files as and when required.

Approach for sharing data between files and function -

Approach 1: -
Declare maximum data as volatile, const (whichever is suitable) global and access it using different functions as and when required.
I have heard that declaring too many variables as global is a bad design....I dont know why :( :( :(

Further, instead of passing value as arguments in the function, the value is updated at global location as a variable or a flag which is accessed by other function.

I thought of this option because I think it will make functions modular since it doesnt have argument list, it can be called easily. It always looks for global database and flags for data and checks.

Approach 2: -
Declare maximum variables as local and use them as function arguments to pass the value to other function.
Only variables which are required through out the program and which has to be necessarily global should be made global otherwise mostly global variables are avoided.


My project is mostly related to the keypad operated graphics display where in which there are many
messages to be displayed.

I am at beginner level of Embedded Software Architecture design. There might be other approaches to design the s/w architecture (I know only 2 :( ). If possible please enlist the other approaches too.
Please suggest me the approach which one is standard.
 

Recommended C Style and Coding Standards
**broken link removed**
 

that link is for coding standard rather than design standard which I am looking for
 

hi,
regarding the first issue i prefer the first approach, because you will get a more portable code when creating an api just for using the peripheral without internal unneccesary functions.

regarding the second issue, my vote goes to the second approach because (a) you will use less RAM this way which is usually a limited resouce in embedded systems, and (b) you avoid a situation that while doing some operation on a variable, the variable value is changed externally by an interrupt.
 
There are some general rules, but many people use the most convenient approach for them.

scorrpeio said:
Approach for transferring calls and controls of execution -
I don't see a reason why the shared function must be one for each file. Staying in your example, the DisplayInit() function should also be shared, as well as other functions. The static keyword is a way for you to understand from the function's declaration, if this function is called by other files of the project or not. It is good to use the static keyword for local functions.


scorrpeio said:
Approach for sharing data between files and function -
Variables that are not meant to be changed after declaration, should be stored in flash in order to save as much RAM memory as you can. Strictly speaking, the const keyword prevents a variable to be changed during runtime, by throwing an error if you try to do so. But it is not ensured that this variable will be a flash variable, it dependes on the compiler. There are special keywords from some compilers on flash variables. Also the volatile keyword has nothing to do with static variables. Shared variables between main program and interrupts are declared as volatile, as well as variables that read or write values from/to the real world (ADC, ports etc).
Volatile variable - Wikipedia, the free encyclopedia

About those two approaches mentioned above... Too many global variables means more RAM memory (a global variable lifetime is equal to the program's lifetime). On the other hand a global variable is easier to be accessed from different places from the code. However let's not focus on the effect, but on your needs. Variables that must be accessed by anywhere in the program, are global variables. All other variables are local. There are also local variables with lifetime equal to global variables. Please open the below reference to find that out.
Static Keyword in ANSI-C - Stack Overflow
I believe it is good to use all cases of static variables when possible, as long as you really need those variables to have lifetime equal to the program's lifetime.
Finally keep in mind that you want to write functions for a peripheral only once and then carry those files from project to project. Thus there are cases where you "sacrifice" some RAM memory for example, in order to have this portability. Fortunately everything could be optimized by the user after files are added to a project.

Hope this enlightened things a bit.
 
Last edited:
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top