gpt4 book ai didi

c - 如何访问和更改结构体成员的值

转载 作者:行者123 更新时间:2023-11-30 16:30:28 24 4
gpt4 key购买 nike

typedef struct
{
float32 frequency;
Ifx_Priority isrPriority;
IfxSrc_Tos isrProvider;
float32 minResolution;
IfxStdIf_Timer_TrigConfig trigger;
float32 startOffset;
} IfxStdIf_Timer_Config;

typedef struct
{
IfxStdIf_Timer_Config base;
Ifx_GTM *gtm;
IfxGtm_Tom tom;
IfxGtm_Tom_Ch timerChannel;
IfxGtm_Tom_ToutMap *triggerOut;
IfxGtm_Tom_Ch_ClkSrc clock;
IfxGtm_IrqMode irqModeTimer;
IfxGtm_IrqMode irqModeTrigger;
} IfxGtm_Tom_Timer_Config;

typedef struct {
uint32 size;
HAL_IF_TIMER_userConfig *table;
IfxGtm_Tom_Timer_Config *defaultSettings;
} HAL_IF_Tom_Timer_Config;

指定值:

HAL_IF_TIMER_userConfig userConfig[NUM_TIMER_CHANNEL] = {
{ 1000, ISR_PRIORITY_1ms_Task, 0, IfxSrc_Tos_cpu0, IfxGtm_Tom_Ch_1, IfxGtm_Tom_Ch_ClkSrc_cmuFxclk1, OneMs, 00 },
{ 5000, ISR_PRIORITY_200us_Critical_Task, 0, IfxSrc_Tos_cpu0, IfxGtm_Tom_Ch_2, IfxGtm_Tom_Ch_ClkSrc_cmuFxclk1, TwoHundredus, 01 },
{ 1, ISR_PRIORITY_1s, 0, IfxSrc_Tos_cpu0, IfxGtm_Tom_Ch_4, IfxGtm_Tom_Ch_ClkSrc_cmuFxclk4, Ones, 02 }

IfxGtm_Tom_Timer_Config defaultTomTimerConfig =
{{1000, 0, IfxSrc_Tos_cpu0, 0, {FALSE, 0, 0, IfxSrc_Tos_cpu0, IfxPort_OutputMode_pushPull, IfxPort_PadDriver_cmosAutomotiveSpeed1, FALSE, FALSE }, IfxStdIf_Timer_CountDir_up, 0.0}, &MODULE_GTM, IfxGtm_Tom_0, IfxGtm_Tom_Ch_0, NULL_PTR, IfxGtm_Tom_Ch_ClkSrc_cmuFxclk0, IfxGtm_IrqMode_level, IfxGtm_IrqMode_level};

HAL_IF_Tom_Timer_Config TomTimerConfig =
{NUM_TIMER_CHANNEL, userConfig, &defaultTomTimerConfig};

HAL_IF_Tom_Timer_Config g_TomTimerConfig;

如果我已经为所有结构成员分配了值,我如何在运行时访问和更改频率?

运行时:

g_TomTimerConfig = TomTimerConfig;
HAL_IF_TIMER_userConfig *userTable = TomTimerConfig.table;
uint32 i;

for (i = 0; i < g_TomTimerConfig.size; i++, ++userTable) {
g_TomTimerConfig.defaultSettings->base.frequency = userTable->frequency;
};

这部分不起作用:

g_TomTimerConfig->defaultSettings->base->frequency

我正在尝试创建默认设置和一组用户设置来初始化某些设置。提前致谢

最佳答案

g_TomTimerConfig 是一个结构体,因此使用 .

g_TomTimerConfig.defaultSettings

defaultSettings 是一个指向结构体的指针,因此使用 ->

g_TomTimerConfig.defaultSettings->base

base 是一个结构体,因此使用 .

g_TomTimerConfig.defaultSettings->base.frequency

关于c - 如何访问和更改结构体成员的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51129103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com