[英]What do two consecutive parameter definitions mean for a function in C?
I am going through the source code at work and I keep seeing this function definition style:我正在查看工作中的源代码,我一直看到这种函数定义样式:
FUNC(Std_ReturnType, SMTN_CODE)SendSignalArray(uint8* NUMPTR, int size) {
}
What does it mean/do?这是什么意思/做什么? Thanks
谢谢
This is from AUTOSAR CompilerAbstraction FUNC(rettype, memclass)
is defined usually in Compiler.h and Compiler_Cfg.h.这是来自 AUTOSAR CompilerAbstraction
FUNC(rettype, memclass)
通常在 Compiler.h 和 Compiler_Cfg.h 中定义。 Include hierarchy is:包含层次结构是:
file.c
Std_Types.h
Compiler.h
Compiler_Cfg.h
Compiler_Cfg.h is usually configured in the AUTOSAR stack configuration tool, and then generated. Compiler_Cfg.h 通常在 AUTOSAR 堆栈配置工具中配置,然后生成。 Some compilers / architectures still might require the usage of
@far
and @near
for data access, or some compilers supporting #pragma section ...
, while other compilers only __attribute__(( ... ))
.某些编译器/体系结构可能仍然需要使用
@far
和@near
进行数据访问,或者某些编译器支持#pragma section ...
,而其他编译器仅需要__attribute__(( ... ))
。
There is another code part you did not mention here, which comes from AUTOSAR MemoryMapping:还有一个你在这里没有提到的代码部分,它来自 AUTOSAR MemoryMapping:
#define XXX_START_SEC_...
#include "XXX_MemMap.h"
...
#define XXX_STOP_SEC_...
#include "XXX_MemMap.h"
Here is an example for the usage, consider a module XXX:下面是一个用法示例,考虑一个模块 XXX:
The files 1 and 2 are static code, maybe with optional code wrapped by compiler/feature switches.文件 1 和 2 是静态代码,可能带有由编译器/功能开关包装的可选代码。 The rest is usually generated by a configuration tool.
其余的通常由配置工具生成。
XXX.h: XXX.h:
#include "Std_Types.h"
#include "XXX_Cfg.h"
#if (XXX_LCFG_SUPPORT == STD_ON)
#include "XXX_LCfg.h"
#endif
#if (XXX_POSTBUILD_SUPPORT == STD_ON)
#include "XXX_PBCfg.h"
#endif
#define XXX_FOO_DISABLED 0u
#define XXX_FOO_ENABLED 1u
// --- Functions
#define XXX_START_SEC_CODE
#include "XXX_MemMap.h"
FUNC(void, XXX_CODE) XXX_Init(P2CONST(XXX_ConfigType, AUTOMATIC, XXX_CONFIG_DATA) ConfigPtr);
FUNC(Std_ReturnType, XXX_CODE) XXX_IsDetectionEnabled(void);
#define XXX_STOP_SEC_CODE
#include "XXX_MemMap.h"
XXX_PBCfg.h: XXX_PBCfg.h:
typedef struct {
VAR(uint8, TYPEDEF) NumChn;
VAR(uint8, TYPEDEF) FooInitStatus;
P2CONST(uint8, TYPEDEF, TYPEDEF) ChannelCfgPtr;
} XXX_ConfigType;
#define XXX_START_SEC_CONFIG_DATA
#include "XXX_MemMap.h"
EXTERN CONST(XXX_ConfigType, XXX_CONFIG_DATA) XXX_Config;
#define XXX_STOP_SEC_CONFIG_DATA
#include "XXX_MemMap.h"
XXX_PBCfg.c: XXX_PBCfg.c:
#include "XXX.h"
#define XXX_START_SEC_CONFIG_DATA
#include "XXX_MemMap.h"
STATIC CONST(uint8, XXX_CONFIG_DATA) XXX_InitVals[] = {
10,
20,
30,
};
EXTERN CONST(XXX_ConfigType, XXX_CONFIG_DATA) XXX_FooInit = {
sizeof(XXX_InitVals)/sizeof(XXX_InitVals[0]),
XXX_FOO_ENABLED,
XXX_InitVals,
};
#define XXX_STOP_SEC_CONFIG_DATA
#include "XXX_MemMap.h"
XXX.c XXX.c
// --- Variables
#define XXX_START_SEC_VAR_INIT_ASILB_8
#include "XXX_MemMap.h"
VAR(uint8, XXX_DATA) XXX_DetectEnable = 0;
P2CONST(XXX_Config, XXX_DATA, XXX_CONFIG_DATA) XXX_ConfigPtr = NULL_PTR;
#define XXX_STOP_SEC_VAR_ASILB_8
#include "XXX_MemMap.h"
// --- Functions
#define XXX_START_SEC_CODE
#include "XXX_MemMap.h"
FUNC(void, XXX_CODE) XXX_Init(P2CONST(XXX_ConfigType, AUTOMATIC, XXX_CONFIG_DATA) ConfigPtr)
{
if (ConfigPtr != NULL)
{
XXX_ConfigPtr = ConfigPtr;
XXX_DetectEnable = ConfigPtr->FooInitValue;
}
}
FUNC(Std_ReturnType, XXX_CODE) XXX_IsDetectionEnabled(void)
{
return XXX_DetectEnable;
}
#define XXX_STOP_SEC_CODE
#include "XXX_MemMap.h"
XXX_MemMap.h
is now generated depending on the configuration, eg for a DIAB or TASKING compiler like this: XXX_MemMap.h
现在根据配置生成,例如对于像这样的 DIAB 或 TASKING 编译器:
#if defined(XXX_START_SEC_CODE)
#undef XXX_START_SEC_CODE
#pragma section CODE ".text_ASILB"
#elif defined(XXX_STOP_SEC_CODE)
#undef XXX_STOP_SEC_CODE
#pragma section CODE /* default section e.g. .text */
#elif defined(XXX_START_SEC_VAR_INIT_ASILB_8)
#undef XXX_START_SEC_VAR_INIT_ASILB_8
#pragma section DATA ".bss_asilb" ".data_asilb"
#elif defined(XXX_STOP_SEC_VAR_INIT_ASILB_8)
#undef XXX_STOP_SEC_VAR_INIT_ASILB_8
#pragma section DATA /* default section e.g. .data */
#elif defined(XXX_START_SEC_CONFIG_DATA)
#undef XXX_START_SEC_CONFIG_DATA
#pragma section CONST ".rodata_pbconfig"
#elif defined(XXX_STOP_SEC_CONFIG_DATA)
#undef XXX_STOP_SEC_CONFIG_DATA
#pragma section CONST
#else
#error "MemClass not defined"
#endif
the Compiler_Cfg.h should configure the FUNC(), VAR(), CONST() as: Compiler_Cfg.h 应将 FUNC()、VAR()、CONST() 配置为:
#define FUNC(rettype, memclass) rettype
#define VAR(t, memclass) t
#define CONST(t, memclass) const t
or with a compiler not understanding #pragma section
like gcc using the __attribute__((section *section-name*))
:或者使用
__attribute__((section *section-name*))
编译器不理解#pragma section
如 gcc:
#if defined(XXX_START_SEC_CODE)
#undef XXX_START_SEC_CODE
#define XXX_CODE ".text_ASILB"
#elif defined(XXX_STOP_SEC_CODE)
#undef XXX_STOP_SEC_CODE
/* attribute is only on a single entity */
#elif defined(XXX_START_SEC_VAR_INIT_ASILB_8)
#undef XXX_START_SEC_VAR_INIT_ASILB_8
#define XXX_DATA ".data_asilb"
#elif defined(XXX_STOP_SEC_VAR_INIT_ASILB_8)
#undef XXX_STOP_SEC_VAR_INIT_ASILB_8
/* attribute is only on a single entity */
#elif defined(XXX_START_SEC_CONFIG_DATA)
#undef XXX_START_SEC_CONFIG_DATA
#define XXX_CONFIG_DATA ".rodata_pbconfig"
#elif defined(XXX_STOP_SEC_CONFIG_DATA)
#undef XXX_STOP_SEC_CONFIG_DATA
/* attribute is only on a single entity */
#else
#error "MemClass not defined"
#endif
Therefore, the Compiler_Cfg.h should define the FUNC() macros as:因此,Compiler_Cfg.h 应将 FUNC() 宏定义为:
#define FUNC(rettype, memclass) __attribute__((section memclass)) rettype
#define VAR(t, memclass) __attribute__((section memclass)) t
#define CONST(t, memclass) __attribute__((section memclass)) const t
This might look strange in the code, but at least it does not clutter the code with:这在代码中可能看起来很奇怪,但至少它不会使代码混乱:
#if __DIAB__
#pragma section CODE ".text_asilb"
#elif __MSVC__
/* No Mapping */
#elif __GCC__
__attribute__((section ".text_asilb"))
#endif
void XXX_Init(XXX_ConfigType *ConfigPtr)
{
...
}
And the part for XXX_START/STOP_SEC_CONFIG_DATA
allows also to collect and place POSTBUILD_LOADABLE configuration data in a specific memory section (eg FLASH Block), which can later separately be replaced by a donwload tool with different data without reflashing the whole application. XXX_START/STOP_SEC_CONFIG_DATA
的部分还允许收集和放置POSTBUILD_LOADABLE配置数据在特定的内存部分(例如 FLASH 块),稍后可以分别由具有不同数据的下载工具替换,而无需重新刷新整个应用程序。 Consider here a use case like a gateway which just needs a new network routing table.这里考虑一个用例,比如网关,它只需要一个新的网络路由表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.