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

nRF9160 device functionality after a week

Hi,

I'm using latest master branch of nRF Connect SDK and pre-released modem FW 1.1.2 which is including ANT->AUX switching. I'm developing a firmware for a custom board that has nRF9160 SiP.

I would like to set the device to start GPS once a week. I have read the Date-Time Library and wondered if it's possible to use that library to set the device to start GPS at the specific time. Does anyone any suggestions how to do that?

But for now I have done it with k_delayed_work_submit_to_queue() and set the delay to one week. One week is 168 hours but that value is not working, I tested some different values and noticed that 163h is the maximum that is working in that function. If the value is 164 hours or more it seems to start the work immediately.

Why is that happening? Is there any other way to get 168 hours working than for example adding another delayed work with 8 hours to queue after 160 hours?

Here is some parts of the code:

static int gps_start_delay_hours = 160;		// one week - 8 hours

/* Stack definition for application workqueue */
K_THREAD_STACK_DEFINE(application_stack_area,
			CONFIG_APPLICATION_WORKQUEUE_STACK_SIZE);		// 2048
static struct k_work_q application_work_q;

static struct k_delayed_work start_gps_work;


/**@brief Callback for GPS events */
static void gps_handler(struct device *dev, struct gps_event *evt)
{
    ...
	case GPS_EVT_SEARCH_STOPPED:
		LOG_INF("GPS_EVT_SEARCH_STOPPED");
		gps_control_set_active(false);

		if (gps_failed_fix_attempts >= CONFIG_GPS_CONTROL_MAX_FAILED_FIX_ATTEMPTS) {
            k_delayed_work_submit_to_queue(&application_work_q,
                    &start_gps_work, K_HOURS(gps_start_delay_hours));
		}

		break;
    ...
}

/**@brief Start GPS. */
static void start_gps(struct k_work *work)
{
	gps_control(1);
}

void main(void)
{
    ...
	k_work_q_start(&application_work_q, application_stack_area,
			K_THREAD_STACK_SIZEOF(application_stack_area),
			CONFIG_APPLICATION_WORKQUEUE_PRIORITY);

    k_delayed_work_init(&start_gps_work, start_gps);
    ...
}

Regards,
Tero

Parents
  • And when I'm using K_HOURS(160) in k_delayed_work_submit_to_queue(), the device seems to start GPS after 14h 20min. All of about 5 devices with that 160h has done that, they have been running through the weekend. Any ideas why?

  • This is a very important part of our device right now and I would really use a help.

  • Hi Simon,

    I test your the project you shared and I'm still having the same problem. It is working with some values but not all. See below:

    	//k_delayed_work_submit_to_queue(&my_work_q, &my_device.work, K_SECONDS(15));	//working
    	//k_delayed_work_submit_to_queue(&my_work_q, &my_device.work, K_HOURS(160));	//working
    	//k_delayed_work_submit_to_queue(&my_work_q, &my_device.work, K_MINUTES(5040));	//working
    	//k_delayed_work_submit_to_queue(&my_work_q, &my_device.work, K_MINUTES(4320));	//not working
    	//k_delayed_work_submit_to_queue(&my_work_q, &my_device.work, K_MINUTES(2880));	//working
    	//k_delayed_work_submit_to_queue(&my_work_q, &my_device.work, K_MINUTES(2160));	//not working
    	//k_delayed_work_submit_to_queue(&my_work_q, &my_device.work, K_MINUTES(1500));	//not working
    	k_delayed_work_submit_to_queue(&my_work_q, &my_device.work, K_MINUTES(1440));	//not working

  • That is strange. 

    I will be gone until Monday (22 June) but I will do some testing then and try to get to the bottom of it.

    Best regards,

    Simon

  • I looked some at this, but have not figured out the cause yet. I'll share my temporary findings.

    I checked if K_MINUTES worked properly for different values and got these results (blue text-->K_MINUTES worked):

    • K_MINUTES(2880)
      • This should be (2880 minutes)*(60 seconds/minute)*(1000ms/sec) = 172 800 000 ms
      • This should be (172 800 000* 32768 + 999)/1000 = 5.662 × 10^9 ticks
      • printk("2880 minutes to ticks to ms: %llu\n",__ticks_to_ms(K_MINUTES(2880).ticks)); gives: 2880 minutes to ticks to ms: 41728000 ms (~695 minutes)
      • printk("2880 minutes in ticks: %llu\n",K_MINUTES(2880).ticks); gives: 2880 minutes in ticks: 1367343104 ticks
    • K_MINUTES(2160)
      • This should be (2160 minutes)*(60 seconds/minute)*(1000ms/sec) = 129 600 000 ms
      • This should be (129 600 000* 32768 + 999)/1000 = 4.2467 × 10^9 ticks
      • printk("2160 minutes in ticks: %llu\n",K_MINUTES(2160).ticks) gives: 4 246 732 800
      • printk("2160 minutes to ticks to ms: %llu\n",__ticks_to_ms(K_MINUTES(2160).ticks)) gives: 129 600 000
    • K_MINUTES(5040)
      • This should be (5040 minutes)*(60 seconds/minute)*(1000ms/sec) = 302 400 000 ms ()
      • This should be (302 400 000* 32768 + 999)/1000 = 9.909 × 10^9 ticks
      • printk("5040 minutes in ticks: %llu\n",K_MINUTES(5040).ticks) gives: 5040 minutes in ticks: 1319108608
      • printk("5040 minutes to ticks to ms: %llu\n",__ticks_to_ms(K_MINUTES(5040).ticks)) gives: 5040 minutes to ticks to ms: 40256000
    • K_MINUTES(4320)
      • This should be (4320minutes)*(60 seconds/minute)*(1000ms/sec) = 2.592 × 10^8
      • This should be (2.592 × 10^8* 32768 + 999)/1000 = 8.49347 × 10^9 ticks
      • printk("4320 minutes in ticks: %llu\n",K_MINUTES(4320).ticks) gives: 4320 minutes in ticks: 4.1985x 10^9
      • printk("4320 minutes to ticks to ms: %llu\n",__ticks_to_ms(K_MINUTES(4320).ticks)) gives: 4320 minutes to ticks to ms: 1.2813 x 10^8

    I will continue investigating this when I get time

    Best regards,

    Simon

  • My apologies for the delay, I've been quite busy lately. Hopefully, this issue isn't keeping you stuck. I will try to get to the bottom of this within this week.

    Best regards,

    Simon

  • Hi Simon,

    No worries, it's not keeping me stuck. For now it's in "would be nice to have" state so it's not that urgent case.

    BR, Tero

Reply Children
Related