HI, i want to have a application in which a timer timeout say 5 second. and during this timeout there is another timer say 1 second. whenever the 1sec timer timeouts then it executes some function. and whenever the 5 second timer timeouts then it restarts it again.
how do i do this.
i tried something below is my code:
// Timeout handler for the repeated timer
static void timer_handler(void * p_context)
{
SEGGER_RTT_WriteString (0, "--> in timeout handler\n");
SEGGER_RTT_printf(0, "Time Out. \n");
}
static void wait_timer_handler(void * p_context)
{
SEGGER_RTT_printf(0, "wait Time Out. \n");
}
// Create timers
static void init_timers()
{
uint32_t err_code;
// Initialize the Application timer Library.
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
SEGGER_RTT_printf(0, "APP_TIMER_INTI initialised. \n");
// Create timers
err_code = app_timer_create(&m_led_a_timer_id,
APP_TIMER_MODE_REPEATED,
timer_handler);
APP_ERROR_CHECK(err_code);
}
static void init_waiting_timers()
{
uint32_t err_code;
// Initialize the Application timer Library.
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
SEGGER_RTT_printf(0, "APP_TIMER_INTI initialised. \n");
// Create timers
err_code = app_timer_create(&wait_timer_id,
APP_TIMER_MODE_REPEATED,
wait_timer_handler);
APP_ERROR_CHECK(err_code);
}
static void start_timer()
{
uint32_t err_code;
// Start application timers.
err_code = app_timer_start(m_led_a_timer_id, APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER), NULL);
APP_ERROR_CHECK(err_code);
SEGGER_RTT_printf(0, "Timer Started \n");
err_code = app_timer_start(wait_timer_id, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
APP_ERROR_CHECK(err_code);
SEGGER_RTT_printf(0, "Wait Timer Started \n");
}
my main function :
// Main function.
int main(void)
{
SEGGER_RTT_printf(0, "Hello World \n");
// Request LF clock.
lfclk_request();
SEGGER_RTT_printf(0, "LF Clock Requested!! \n");
// Configure GPIO's.
//gpio_config();
//SEGGER_RTT_printf(0, "GPIO Configured! \n");
// Create application timer instances.
init_timers();
SEGGER_RTT_printf(0, "Application Timer Created. \n");
start_timer();
// Main loop.
while (true)
{
//SEGGER_RTT_printf(0, "Blinking.. %d times\n",count);
// Wait for interrupt.
__WFI();
}
}