简体   繁体   中英

How to access and change value of struct members

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; 

Assign values:

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;

if i have already assign values to all the struct members, how can i access and change the frequency during runtime?

Runtime:

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;
};

this part do not work:

g_TomTimerConfig->defaultSettings->base->frequency

I'm trying to create a default settings and a array of user settings to initialize some settings. thanks in advance

g_TomTimerConfig is a struct, so use .

g_TomTimerConfig.defaultSettings

defaultSettings is a pointer to a struct, so use ->

g_TomTimerConfig.defaultSettings->base

base is a struct, so use .

g_TomTimerConfig.defaultSettings->base.frequency

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM