Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

How to design, and implement simple interface

Our embedded product is based on Renesas RH850F1L Microcontroller.  We have large code base written in 'C' language.

The following function returns EEPROM value to calling library.

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

REQUIREMENT:
Another software module needs to control value returned by GetDeltaMin ( ).   If another software module passes 1, return value from EEPROM, just like it's implemented above.  
If another module passes 0, return 0 to calling library instead of returning value from EEPROM.

How to design, and code this requirement ?

I'm thinking about providing following input interface to the user or another module.
I'll create new .c  and .h file as follows:

New File Activate_Deactive_I.c

void Enable_Disable ( Boolean State)
{
     /* user will pass 1 or 0 to this function. */
    /* Please finish wirting this function. */
   /* How will this function interact with GetDeltaMin ( ) function above ?  Please modify GetDeltaMin ( ).   */
}

New File Activate_Deactivate.h
extern void Enable_Disable ( Boolean State);   /* user will need to include this header file */
/* I don't think Activate_Deactive_I.c needs to include this header file ?   */
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

From your post, it's not particularly clear what your question is. Can you be more specific on what it is you are asking the experts? The more specific your question the more chance there is we can help you, specially when you are dealing with something like micro-controllers, which are not ubiquitously understood.
Avatar of naseeam

ASKER

// 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.  */
    /* 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 ?   */
Avatar of naseeam

ASKER

When Enable_Disable( ) is called, I can assign value of state to a global variable. Then, in GetDeltaMin( ), I can use the value of global variable to decide whether to return value from NVM or 0 to the calling library.

 I'm asking for a better solution than a global variable.
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of naseeam

ASKER

Thank  you for providing a very different solution.