PWM和NVS冲突,造成PWM无输出
时间:12-23
整理:3721RD
点击:
NVS_Handle ptNvsHandle; NVS_Attrs ptRegionAttrs; void vNVSInit(void) { NVS_Params tNvsParams; NVS_init(); NVS_Params_init(&tNvsParams); ptNvsHandle = NVS_open(Board_NVS0, &tNvsParams); if (ptNvsHandle == NULL) { return ; } NVS_getAttrs(ptNvsHandle, &ptRegionAttrs); } PWM_Handle ptgPwmHandleLed0 = NULL; void vSetLed0(teLedState teState, uint32_t uiFreq, float fDuty) { uint32_t uiDuty; if(fDuty > 1) fDuty = 1; uiDuty = (uint32_t)(PWM_DUTY_FRACTION_MAX * fDuty); if(teState == E_LED_OFF) { /* 如果修改PWMInit->eIdleLevel达到停止PWM时输出的电平*/ if(ptgPwmHandleLed0 == NULL) { ptgPwmHandleLed0 = ptPwmInit(CC1310DK_4XD_PWM0, PWM_IDLE_LOW, 1, 0); PWM_stop(ptgPwmHandleLed0); } else { PWM_stop(ptgPwmHandleLed0); } return; } else { if(ptgPwmHandleLed0 == NULL) { ptgPwmHandleLed0 = ptPwmInit(CC1310DK_4XD_PWM0, PWM_IDLE_LOW, uiFreq, uiDuty); } else { PWM_stop(ptgPwmHandleLed0); PWM_setPeriod(ptgPwmHandleLed0, uiFreq); PWM_setDuty(ptgPwmHandleLed0, uiDuty); PWM_start(ptgPwmHandleLed0); } } } void vMainTaskFunction(UArg arg0, UArg arg1) { float j=0.01; #if 0 //A vNVSInit(); vSetLed0(E_LED_ON, 50, j); #else vSetLed0(E_LED_ON, 50, j); vNVSInit(); #endif for(;;) { Task_sleep(100000); j += 0.05; if(j>1) j=0.01; vSetLed0(E_LED_ON, 50, j); } }
实际使用时,NVS在一个更高优先级的任务中初始化,PWM在低优先级任务中初始化,为方便测试整合到一个任务中发现问题如下:
不初始化NVS时PWM工作正常(NVS代码在其它项目中已经验证过没有问题).
将NVS放到PWM之后初始化,PWM工作正常.
NVS放到PWM之前初始化PWM无输出.
如何解决此问题,不可能调整初始化顺序后就不管了吧