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

Adding new timers to BLE proximity sample app

I'm trying to add another timer to the BLE proximity app sample code in a new source file which is a driver for a GSM modem. My timer handler function is never called.

In main(), right after the existing timers_init() function, I call gsm_init() in my gsm.c. That function does some UART stuff and then creates and starts a new timer.

    // Create and start timeout timer.
    m_response_timed_out = 0;
    err_code = app_timer_create(&m_response_timeout_timer_id, APP_TIMER_MODE_SINGLE_SHOT, response_timeout_handler);
    APP_ERROR_CHECK(err_code);
    err_code = app_timer_start(m_response_timeout_timer_id, GSM_RESPONSE_TIMEOUT, NULL);
    APP_ERROR_CHECK(err_code);

It then loops on a app_uart_get() call until it sees the end of a response to an AT command, or until the timer handler has set a timeout variable to true. That loop does a lot of calling sd_app_evt_wait() when there's no character to be read on the UART. If the loop ever completes, the function then stops the timer.

    // Stop waiting for a response timeout.
    err_code = app_timer_stop(m_response_timeout_timer_id);
    APP_ERROR_CHECK(err_code);

A breakpoint in my timeout handler function is never reached:

void response_timeout_handler(void * p_context)
{
    UNUSED_PARAMETER(p_context);
    m_response_timed_out = 1;
}

However, if I take all my GSM code out of the picture and instead create and start a new timer in the bottom of main() with its own handler in main.c, that one gets called. I can't for the life of me see the difference, but my timer in gsm.c is never called. All error codes on calls to create and start it return 0.

My timeout ticks are set as follows:

// Value of the RTC1 PRESCALER register.
#define GSM_TIMER_PRESCALER 0

// How many ticks do we wait for a response to an AT command, in the absence of an "OK"?
#define GSM_RESPONSE_TIMEOUT APP_TIMER_TICKS(5000, GSM_TIMER_PRESCALER)

What am I doing wrong?

Parents Reply Children
No Data
Related