I followed the sample code provided with power_manager_hal_demo_frdmk22f to switch between HSrunmode and Run mode. I am using CLOCK_SYS_UpdateConfiguration() and POWER_SYS_SetMode() to switch between the two modes which according to documentation should notify the registered drivers. My UART is working fine but the timer is not.
Here is the procedure I follow in my code:
Start a periodic timer
Whenever the timer expires (it's a loop as the timer is periodic),
Process some data and switch between HSrun and Run modes to be able to write to flash
Wait for the timer to expire
end of loop
I see that if I restart the HW timer using HWTIMER_SYS_Stop and HWTIMER_SYS_Start, the periodic timer never gets fired after the first time and if I don't restart the timer, the timer gets fired but after a very long time as if it's period got changed.
I also tried calling HWTIMER_SYS_SetPeriod(&systimer, BSP_ALARM_PERIOD); in the callback function but it didn't have any effect.
Please let me know what is the best way to make the periodic timer work even if the clock changes without restarting it.
Regards,
Priya
Hello Priya Dwivedula:
In the next thread I shared an example project about changing clock configurations and adapting the HWTIMER with MQX, please take a look at it. The project is for K64 but the same concept applies for the FRDM-K22F:
Re: KDSK CLOCK_SYS_SetConfiguration() no uptade ticks in _time_delay() MQX
If not using Processor Expert you still can look at the Events.c file to see the method I used to reconfigure the HWTIMER before and after the clock change by using the clock system notification framework. This is the code I used:
clock_manager_error_code_t clockMan1_SysTickCallback(clock_notify_struct_t * notify, void * callbackData)
{
clock_manager_error_code_t result = kClockManagerSuccess;
switch(notify->notifyType)
{
case kClockManagerNotifyBefore:
HWTIMER_SYS_Stop(&systimer);
break;
case kClockManagerNotifyRecover:
break;
case kClockManagerNotifyAfter:
HWTIMER_SYS_Init(&systimer, &BSP_SYSTIMER_DEV, BSP_SYSTIMER_ID, NULL);
HWTIMER_SYS_SetPeriod(&systimer, BSP_ALARM_PERIOD);
HWTIMER_SYS_RegisterCallback(&systimer,(hwtimer_callback_t)_time_notify_kernel, NULL);
HWTIMER_SYS_Start(&systimer);
break;
default:
result = kClockManagerError;
break;
}
return result;
}
Let me know if you have any doubts.
Best Regards!
Jorge Gonzalez
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Jorge,
I followed the same example earlier to start and stop the HW timer but once I restart HW timer, the periodic timer that I created stops working.
Thanks,
Priya
Hi Priya:
Could you explain what do you mean by "the periodic timer that I created"? How is that periodic timer implemented?
If possible share your project to give it a check from my side.
Regards!
Jorge Gonzalez
Jorge,
I created a timer using _timer_start_periodic_every().
I have a pretty big project.. I don't think I will be able to share it. I will see if I can create a smaller project that I can share with you.
Regards,
Priya