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

Acceleration active and deactivate GPS

Dear, 

Im trying to use the motion to activate the GPS and deactivate GPS:

    1. when it moves, GPS will be activated: Position-ON 

   2. when it stops, GPS will be activated again: Position-OFF

Currently, I used the sensor_trigger_set() to enable GPS when it detects the motion as in :https://github.com/NordicPlayground/fw-nrfconnect-nrf/tree/master/applications/asset_tracker

But, I dont know how to implement the step 2:  when it stops, GPS will be activated again: Position-OFF

Could you plz help me, thanks so much 

My HW: THINGY:91 

Modem FW: v1.1.1

ncs_1.2.0

BR, 

Hoang Ng

Parents Reply Children
  • Hi

    I tried: 

    1. accelerate trigger will : 

           1.1. Reset the timer: Timer 

           1.2. Start the timer: Timer

    2. If the Timer > 5mn (no motion in 5mn) -->Stop --> enable GPS to find Stop-Position 

    So, I need a function for the timer , and i found :

     https://devzone.nordicsemi.com/f/nordic-q-a/59950/timers-in-nrf9160-soc/244049#244049

    And, i modified the timer_cb() to test:

    void timer_cb(nrf_timer_event_t event_type, void * p_context) {
        printk("start GPS ..\n");
        gps_control_init(&application_work_q, gps_trigger_handler);
        printk("set_gps_enable----------\r");
        set_gps_enable(true);
    }

    i want i can start the GPS, but I got the error:

    start GPS ..
     gps_control_init(struct k_work_q  gps_trigger_handler_t handler 
    
     device_get_binding ---------- 
    
     gps_trigger_set ---------- 
    
    ASSERTION FAIL [!arch_is_in_isr()] @ C:/Demos/nordic/ncs_09032020/zephyr/kernel/include/ksched.h:269
    	
    [00:00:01.542,327] [1B][1;31m<err> os: r0/a1:  0x00000004  r1/a2:  0x0000010d  r2/a3:  0x00000001[1B][0m
    [00:00:01.551,177] [1B][1;31m<err> os: r3/a4:  0x40008000 r12/ip:  0x00000000 r14/lr:  0x0002e7cb[1B][0m
    [00:00:01.560,058] [1B][1;31m<err> os:  xpsr:  0x6100001f[1B][0m
    [00:00:01.565,368] [1B][1;31m<err> os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000[1B][0m
    [00:00:01.575,988] [1B][1;31m<err> os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000[1B][0m
    [00:00:01.586,639] [1B][1;31m<err> os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000[1B][0m
    [00:00:01.597,259] [1B][1;31m<err> os: s[12]:  0x00000000  s[13]:  0x00000002  s[14]:  0x00000000  s[15]:  0x00000000[1B][0m
    [00:00:01.607,910] [1B][1;31m<err> os: fpscr:  0x4000f000[1B][0m
    [00:00:01.613,220] [1B][1;31m<err> os: Faulting instruction address (r15/pc): 0x00033284[1B][0m
    [00:00:01.621,307] [1B][1;31m<err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0[1B][0m
    [00:00:01.629,180] [1B][1;31m<err> os: Fault during interrupt handling
    

    How can I use the timer to start the GPS?

    Do you have any suggestions?

    Thanks so much 

  • Hi,

     

    You are asserting because a kernel function is called from interrupt context. Try setting a flag and handle it in main, or push the work to a workqueue instead.

    Note that all socket operations will trigger an interrupt to communicate with the modem, so no socket functions should be called from an interrupt.

     

    Kind regards,

    Håkon

  • Thank

    I will read and try to understand your guide. Thanks a lot ( Sorry, I don't have knowledge about programming )

    BR, 

    Hoang Nguyen

  • Hi Hoang,

     

    Its not stated directly that you shouldn't call socket operations directly from interrupt, nor that the kernel timers are executed in interrupt context, and we should document this a bit better. I'll write it down as a improvement and report it internally.

     

    Kind regards,

    Håkon

  • Hi

    in the timer.zip 

    #define TIMEOUT 60000 //milisecond 
    
    static u32_t timestamp_prev;
    int counter ;
    bool gps_enable_timeout; 
    
    nrfx_timer_t my_timer = NRFX_TIMER_INSTANCE(0);
    nrfx_timer_config_t my_timer_config = NRFX_TIMER_DEFAULT_CONFIG;
    
    void timer_cb(nrf_timer_event_t event_type, void * p_context) {
        
        timestamp_prev = k_uptime_get_32();
        counter += 1;
        printk("counter: %d \r",counter);
        printk("timestamp_prev: %d \n\r",timestamp_prev); 
        printk("set_gps_enable----------\r");
        printk("start GPS ..\n");
        set_gps_enable(true);
        gps_enable_timeout = true ; 
    
        printk("gps_enable_timeout: %d \n\r", gps_enable_timeout); 
    }
    
    void main() {
    
        printk("Timer sample started\n");
        counter = 0; 
        gps_enable_timeout = false; 
    
        IRQ_CONNECT(DT_NORDIC_NRF_TIMER_TIMER_0_IRQ_0, 
                    DT_NORDIC_NRF_TIMER_TIMER_0_IRQ_0_PRIORITY, 
                    nrfx_isr, 
                    nrfx_timer_0_irq_handler, 
                    0);
    
    
        my_timer_config.frequency = NRF_TIMER_FREQ_31250Hz;
        
        nrfx_err_t err = nrfx_timer_init(&my_timer, &my_timer_config, timer_cb);
        if (err != NRFX_SUCCESS) {
            printk("timer_init error: %d\n", err);
            return;
        }
    
        // Set the timer to trigger every second.
        
          uint32_t time_ticks = nrfx_timer_ms_to_ticks(&my_timer, TIMEOUT);
          printk("Setting compare, timeout after %d ticks\n", time_ticks ); 
        
      // nrfx_timer_compare(&my_timer, NRF_TIMER_CC_CHANNEL0, nrfx_timer_ms_to_ticks(&my_timer, TIMEOUT), true);
         nrfx_timer_compare(&my_timer, NRF_TIMER_CC_CHANNEL0,time_ticks, true);
       
        
         printk("Starting timer\n");
         nrfx_timer_enable(&my_timer);
        
         printk("Timer started\n");
        
        
    }

    I changed the TIMEOUT to 60000 (miliseconds), I expected the timer will "trigger" after TIMEOUT 

    But, it always trigger after 1s. 

    I check the document:  https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Fgroup__nrfx__timer.html&cp=7_1_6_9_0_37_1_10&anchor=ga949efcc263af88d63ecdce7eaa3d5761

    Did I misunderstand somewhere? 

    Thanks, 

    Best Regards, 

    Hoang

Related