KSDK1.2中带双指针的函数只能在main()中使用吗?

2020-02-19 20:51发布

看例程HelloWorld用LPTMR初始化一定时器:
  // LPTMR configurations
  lptmr_user_config_t lptmrConfig =
  {
    .timerMode = kLptmrTimerModeTimeCounter,
    .freeRunningEnable = false,
    .prescalerEnable = true,
    .prescalerClockSource = kClockLptmrSrcLpoClk,
    .prescalerValue = kLptmrPrescalerDivide2,
    .isInterruptEnabled = true,
  };
  lptmr_state_t lptmrState;    // LPTMR driver state information

  LPTMR_DRV_Init(LPTMR0_IDX, &lptmrState, &lptmrConfig);    // Initialize LPTMR
  LPTMR_DRV_SetTimerPeriodUs(LPTMR0_IDX, TMR_PERIOD);       // Set timer period for TMR_PERIOD seconds
  LPTMR_DRV_InstallCallback(LPTMR0_IDX, lptmr_call_back);   // Install interrupt call back function for LPTMR
  LPTMR_DRV_Start(LPTMR0_IDX);    // Start LPTMR

将这段代码放在main()中可以正确初始化LPTMR,可在中断中闪烁一LED。
但将这段代码放在一函数中,如:
void lptmr_func(void)
{
  // LPTMR configurations
  lptmr_user_config_t lptmrConfig =
  {
    .timerMode = kLptmrTimerModeTimeCounter,
    .freeRunningEnable = false,
    .prescalerEnable = true,
    .prescalerClockSource = kClockLptmrSrcLpoClk,
    .prescalerValue = kLptmrPrescalerDivide2,
    .isInterruptEnabled = true,
  };
  lptmr_state_t lptmrState;    // LPTMR driver state information

  LPTMR_DRV_Init(LPTMR0_IDX, &lptmrState, &lptmrConfig);    // Initialize LPTMR
  LPTMR_DRV_SetTimerPeriodUs(LPTMR0_IDX, TMR_PERIOD);       // Set timer period for TMR_PERIOD seconds
  LPTMR_DRV_InstallCallback(LPTMR0_IDX, lptmr_call_back);   // Install interrupt call back function for LPTMR
  LPTMR_DRV_Start(LPTMR0_IDX);    // Start LPTMR
}
再在main()中调用lptrm_func(),则无法正确初始化LPTMR。

查API Reference,原型为:


不是是否是const指针的问题?


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
10条回答
security
2020-02-20 21:02
xtrig 发表于 2015-6-17 16:18
目前还没有新的进展,stack和heap检查均为0x2000,对调用一个简单函数足够了。
不知是否和库的使用有关,看 ...
  1. 问题的关键是
  2. lptmr_status_t LPTMR_DRV_Init(uint32_t instance, lptmr_state_t *userStatePtr, const lptmr_user_config_t* userConfigPtr)
  3. 的userStatePtr,需要是指向一个全局变量的userState变量,这样整个驱动内部,才能随时访问得到,驱动才会表现正常。。
复制代码