Here is a simple usage of timers with Wiced SDK.

 

Two timers are initialized with timeouts and callbacks. Both timers are set to count on each callback.

One of the timer is stopped when it expires and the other timer keeps counting. Second timer is kicked within the while loop after longer delay.

The both count values are printed within the while loop.

 

Attached is the simple snip application of timers.

 

timers.c:

/*
 * Copyright 2016, Broadcom Corporation
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
 * the contents of this file may not be disclosed to third parties, copied
 * or duplicated in any form, in whole or in part, without the prior
 * written permission of Broadcom Corporation.
 */

/** @file
 *
 * Timers Application
 *
 * Features demonstrated
 *  - WICED Timer API
 *
 * This application snippet demonstrates the timer usage.
 *
 * Application Instructions
 *   Connect a PC terminal to the serial port of the WICED Eval board,
 *   then build and download the application as described in the WICED
 *   Quick Start Guide
 *
 */

#include <stdlib.h>
#include "wiced.h"

/******************************************************
 *                      Macros
 ******************************************************/

/******************************************************
 *                    Constants
 ******************************************************/

/******************************************************
 *                   Enumerations
 ******************************************************/
#define DELAY_TIMEOUT1          (500)
#define DELAY_TIMEOUT2          (500)
#define LOOP_DELAY              (1000)

/******************************************************
 *                 Type Definitions
 ******************************************************/
wiced_timer_t test_timer1;
wiced_timer_t test_timer2;

/******************************************************
 *                    Structures
 ******************************************************/

/******************************************************
 *               Static Function Declarations
 ******************************************************/
static void timer_cb1( void );
static void timer_cb2( void );

/******************************************************
 *               Variable Definitions
 ******************************************************/
int cb_count1 = 0;
int cb_count2 = 0;

/******************************************************
 *               Function Definitions
 ******************************************************/

void application_start( )
{
    wiced_init( );

    wiced_rtos_init_timer( &test_timer1, DELAY_TIMEOUT1, (timer_handler_t) timer_cb1, NULL );
    wiced_rtos_init_timer( &test_timer2, DELAY_TIMEOUT2, (timer_handler_t) timer_cb2, NULL );
    wiced_rtos_start_timer( &test_timer1 );

    while(1)
    {
        WPRINT_APP_INFO( ( "Print from while loop: cb_count1:%d; cb_count2:%d ...\n", cb_count1, cb_count2 ) );
        wiced_rtos_start_timer( &test_timer2 );

        wiced_rtos_delay_milliseconds(LOOP_DELAY);
    }
}

static void timer_cb1(void)
{
    cb_count1++;
    wiced_rtos_start_timer( &test_timer1 );
}

static void timer_cb2(void)
{
    wiced_rtos_stop_timer(&test_timer2);
    cb_count2++;
}

 

timers.mk:

#
# Copyright 2016, Broadcom Corporation
# All Rights Reserved.
#
# This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
# the contents of this file may not be disclosed to third parties, copied
# or duplicated in any form, in whole or in part, without the prior
# written permission of Broadcom Corporation.
#

NAME := App_Timers

$(NAME)_SOURCES := timers.c