How to design and implement simple interface ?

// Some_Filename.c - This file already exists /* This function fetches two bytes from Non-Volatile Memory(NVM) and returns to the calling library. */

signed short GetDeltaMin ( void ) { signed short param; NVM_Read ( ( unsigned char * ) &param ); return (signed short) param; }

// New File - Activate_Deactive_I.c

void Enable_Disable ( Boolean State) { /* user will pass 1 or 0 to this function. */ /* If State =1, there is no change to GetDeltaMin ( ). It'll still pass two byte value from NVRAM to the calling library */

/* If State = 0, GetDeltaMin ( ) needs to pass 0 to calling library instead of two byte value from

from NVRAM. */ /* Please write this function and modify GetDeltaMin ( ). */ }

New File - Activate_Deactivate.h extern void Enable_Disable ( Boolean State); /* This header file must be included in file from where Enable_Disable ( ) will be called. */

/* I don't think Activate_Deactive_I.c needs to include this header file ? */

--------------------------------------- Posted through

formatting link

Reply to
learn
Loading thread data ...

Am 19.07.2015 um 20:32 schrieb learn:

[an obvious homework task]

That's _your_ homework, so _you_ do it. Who knows, you might even change "learn" from your silly moniker to something you actually did.

Reply to
Hans-Bernhard Bröker

I am not in school. I know how to do this with a global variable. When Enable_Disable( ) is called, I can set a global variable to 1 or 0. Then, in GetDeltaMin( ) I can use the value of the global variable to decide whether to send NVM value or 0 to calling library.

The reason I am asking this question is because I'm looking for better solution than a global variable.

--------------------------------------- Posted through

formatting link

Reply to
learn

Other options would be a file scope variable, and either putting the function into the file of the original function, or adding a call to a function to get the value of the variable.

In Enable_Disable returns the previous value, then it could be used to get the value (and called again to set it back if needed) and then the flag could be stored in a function static variable.

Reply to
Richard Damon

When

get

I would like to add a call to a function to get the value of the variable. This means GetDeltaMin( ) will call Enable_Disable( ) at a fast rate, maybe every 1.25ms to fetch the value.

And some other function will call Enable_Disable( ) infrequently to pass value of 0 or 1.

We have non-preemptive Operating System. Will there be any mutually Exclusion problem with calling Enable_Disable( ) from Two places ?

--------------------------------------- Posted through

formatting link

Reply to
learn

did.

decide

better

variable.

Thank you for the solution and replies.

--------------------------------------- Posted through

formatting link

Reply to
learn

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.