在我在社区内进行了足够的研究之后,我在这里发布了这个问题。但是,我还没有找到适合我的问题的解决方案。所以,我在这里发布我的问题。
#define EXPAND_AS_ENUMERATION(a) CODE_##a,
#define EXPAND_AS_ARRAY(a) a,
#define CODE_TABLE(EXPAND)\
EXPAND(0x00E30054uL)\
EXPAND(0x00ED3581uL)\
EXPAND(0x00ED3983uL)\
EXPAND(0x00EE0368uL)\
EXPAND(0x00EE0368uL)\
EXPAND(0x00D01087uL)\
EXPAND(0x00ED4181uL)\
EXPAND(0x00505602uL)\
// Actual Event IDs which need to be selected at run time
#define SWC_FAULT_CODE_0x00E30054_EVENT 113
#define SWC_FAULT_CODE_0x00ED3581_EVENT 213
#define SWC_FAULT_CODE_0x00ED3983_EVENT 432
#define SWC_FAULT_CODE_0x00EE0368_EVENT 411
#define SWC_FAULT_CODE_0x00EE0368_EVENT 311
#define SWC_FAULT_CODE_0x00D01087_EVENT 231
#define SWC_FAULT_CODE_0x00ED4181_EVENT 471
#define SWC_FAULT_CODE_0x00505602_EVENT 419
#define prefix_str SWC_FAULT_CODE
#define postfix_str _EVENT
#define Get_EventID_FROM_CODE(code) ????? // ex: when code= 0x00ED3581, then it should return SWC_FAULT_CODE_0x00ED3581_EVENT macro or it's value 213
#define Get_EventID_FROM_ENUM(code_enum) ????? // ex: when code_enum= CODE_0x00ED3581, then it should return SWC_FAULT_CODE_0x00ED3581_EVENT macro or it's value 213
#define Get_CodeEnumName(code) ????? // ex: when code = 0x00ED3581, then it should return DTC_0x00ED3581 which is enum element
typedef enum
{
CODE_TABLE(EXPAND_AS_ENUMERATION)
CODE_COUNT
}codeList_t ;
void Cycle_1ms(const uint32 code)
{
// Based on code value, I want to get the macro value of SWC_FAULT_CODE_0xZZZZZZZZ_EVENT.
// ex: when code = 0x00ED3581, then eventID = SWC_FAULT_CODE_0x00ED3581_EVENT = 213
uint16 eventID_FromCode = Get_EventID(code);
}
void Cycle_1ms_anotherFunc(codeList_t code_enum)
{
// Based on code value, I want to get the macro value of SWC_FAULT_CODE_0xZZZZZZZZ_EVENT.
// ex: when code = 0x00ED3581, then eventID = SWC_FAULT_CODE_0x00ED3581_EVENT = 213
uint16 eventID_FromCodeEnum = Get_EventID_FROM_ENUM(code_enum);
}
void callback_func(uint32 code, uint8* buf)
{
// here, based on code value Get_CodeEnumName() should provide the enum element for that code. ex: when code= 0x00ED3581, enum_var = DTC_0x00ED3581
codeList_t enum_var = Get_CodeEnumName(code);
}
在这里,CODE_TABLE 将从项目到项目以及此表中的元素数量进行更改。在阅读了几篇关于 Xmacros 的文章和主题后,我想在这里使用 Xmacros 概念来避免循环和大量使用 RAM 内存。