This is for an embedded application that runs low on UC. Another part of the system requires parameters to be set, and the local UC must maintain a list of parameters. Each parameter consists of an 8-bit identifier and an 8-bit value. The identifier starts at 0x70 due to memory limitations at the other end.
To support the maximum possible memory usage, I implemented the parameter store as an array containing identifiers and values ββfor all writable parameters. After that, a list of these parameters is listed in the header file so that other parts of the application can access the parameters.
Is there a way to make sure that the list of enumerations and the array of parameters have the same entries in the same order? I have documented the code carefully enough (not all are included in the excerpts), but I would like to include some form of verification at compile time to make sure the list and array match.
Another thing I'm not sure about is the most effective way to implement it. I need to be able to iterate over the parameters in order to transfer them to another part of the system, and I need to use as little memory as possible.
From parameters.h :
/*******************************************************************************/ /* IDs for all parameters must be defined */ /* Defaults only need to be defined for rut-time writable parameters */ /* All parameters must have an ID define */ /* Writable parameters must also have: */ /* * DefaultValue define */ /* * Entry in ParamIndex */ /* * Initialesed default entry in Parameters (contained in C file) */ /* * If min and max values are not 0x00 and 0xFF then define those too */ /*******************************************************************************/ // Parameter IDs - All parameters need this defining #define Param_ActualTemp_ID 0xE0 #define Param_OperationMode_ID 0xE1 #define Param_MaintenanceModePID0_ID 0xE5 #define Param_MaintenanceModePID1_ID 0xE6 #define Param_FirmwareVersionL_ID 0xEB #define Param_FirmwareVersionH_ID 0xEC #define Param_SerialNumberL_ID 0xED #define Param_SerialNumberH_ID 0xEE #define Param_SerialNumberHH_ID 0xEF #define Param_MaxTemperature_ID 0xFC #define Param_NULL_ID 0xFF // Parameter Default Values - All writable parameters need this defining #define Param_NULL_DefaultValue 0xFF #define Param_OperationMode_DefaultValue 0 #define Param_MaintenanceModePID0_DefaultValue 0xFF #define Param_MaintenanceModePID1_DefaultValue 0xFF #define Param_MaxTemperature_DefaultValue 0x54 typedef struct { const uint8 id; uint8 value; } PARAMETER; // Parameter Index, any writable parameters need an entry here // Used as array index for parameters[], do not edit existing values typedef enum { Param_NULL = 0, Param_OperationMode, Param_MaintenanceModePID0, Param_MaintenanceModePID1, Param_MaxTemperature, /* Additional values must be entered above this line */ Param_NUMBER_OF_IMPLEMENTED_PARAMS } ParamIndex; extern PARAMETER parameters[];
From parameters.c :
PARAMETER parameters[] = { { .id = Param_NULL_ID, .value = Param_NULL_DefaultValue}, { .id = Param_OperationMode_ID, .value = Param_OperationMode_DefaultValue}, { .id = Param_MaintenanceModePID0_ID, .value = Param_MaintenanceModePID0_DefaultValue}, { .id = Param_MaintenanceModePID1_ID, .value = Param_MaintenanceModePID1_DefaultValue}, { .id = Param_MaxTemperature_ID, .value = Param_MaxTemperature_DefaultValue} };