This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Long timer expires immediately

Hi,

I'm having an issue with timers. They work fine for shorter timeout values (<8hours) but after trying with a timeout value of 24 hours, my timers expired immediately. After a bit more digging, I found that how I declare my timer variables seems to matter. This smells like some sort of memory issue but the application code I've written so far looks fine to me.

The following code works as expected
void expiry_fn( struct k_timer* timer )
{
printk("Timer expired!\n");
}
void main(void) {
s32_t period = K_HOURS( 24 );
struct k_timer timer1;
k_timer_init( &timer1, expiry_fn, NULL );
k_timer_start( &timer1, period, period );
struct k_timer timer2;
k_timer_init( &timer2, expiry_fn, NULL );
k_timer_start( &timer2, period, period );
}
But this next snippet (declaring the timers all at once) causes both timers to expire immediately
void main(void) {
s32_t period = K_HOURS( 24 );
struct k_timer timer1;
struct k_timer timer2; // declaring both here causes both timers to expire immediately
k_timer_init( &timer1, expiry_fn, NULL );
k_timer_start( &timer1, period, period );
k_timer_init( &timer2, expiry_fn, NULL );
k_timer_start( &timer2, period, period );
}
Also noteworthy is if I use a shorter period, the timers work as expected
void main(void) {
s32_t period = K_HOURS( 12 );
struct k_timer timer1;
struct k_timer timer2; // works fine
k_timer_init( &timer1, expiry_fn, NULL );
k_timer_start( &timer1, period, period );
k_timer_init( &timer2, expiry_fn, NULL );
k_timer_start( &timer2, period, period );
}
I also tried the following snippet to see if variable scoping was the cause but this also has the issue of both timers expiring immediately.
static struct k_timer timer1;
static struct k_timer timer2;
void main(void) {
s32_t period = K_HOURS( 24 );
k_timer_init( &timer1, expiry_fn, NULL );
k_timer_start( &timer1, period, period );
k_timer_init( &timer2, expiry_fn, NULL );
k_timer_start( &timer2, period, period );
while (1) {
k_sleep( 1000 );
}
}
I'm using a nRF9160-based board and the nRF SDK v1.1.
Any ideas on what might be going on?
Thanks,
Jeff
Parents Reply Children
Related