Skip navigation
Home > All Places > WICED Studio Wi-Fi/Combo > WICED Studio Wi-Fi/Combo Forums > Blog > 2016 > May
2016
seyhana_

Simple Usage Of Timers

Posted by seyhana_ May 18, 2016

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

Here is how to enable UART4 on WICED SDK to receive set number of data within given timeout after requesting it from the simulated device.

Device is simulated using Tera Term macro script, uart_data_exchange.ttl.

 

Below is the sequence of data exchange:

- Data is requested on the UART4 interface by sending 0x0A ('\n') to the Tera Term terminal.

- A macro running on the Tera Term waits for the requesting data then sends a response to the Wiced device.

- The Wiced device receives the data on the UART4 interface with a given timeout.

- Data received on the UART4 is relayed to the STDIO_UART (USART6) for logging.

- The continuous receive and transmission of data could be interrupted on the Wiced debug interface STDIO_UART (USART6) by typing 'x'. If not the sequence repeats with a timeout of 4 seconds.

 

Both UART4 Rx and Tx pins are routed to the "Breakout Header" on the evaluation platforms.

 

To connect the UART4 on the BCM943341WCD1 use the following connections:

     UART4-Tx -> J7-20

     UART4-Rx -> J7-8

 

To connect the UART4 on the BCM943362WCD4 use the following connections:

     UART4-Tx -> J7-9

     UART4-Rx -> J7-6

 

For more information on Uart connections please check Enable UART4 on BCM943362WCD4 and BCM943341WCD1 as Terminal Output blog post.

 

Hardware setup:

 

- Connect UART4 on the Wiced device to PC and open a Tera Term for the connection.

- Connect a PC terminal to the serial port of the WICED Evaluation board and open a second Tera Term terminal for the debug interface.

- Copy attached uart_data_exchange snippet application to .../apps/snip directory of the Wiced SDK or apply the attached patch file.

    

- Start the uart_data_exchange.ttl macro on the Tera Term connected to the Wiced UART4.

 

Build, download and run the uart_data_exchange snippet application:

    

     snip.uart_data_exchange-BCM943341WCD1 download run

     or

     snip.uart_data_exchange-BCM943362WCD4 download run

   

Here is outputs on the Tera Term terminals for both UART4 and STDIO_UART:

Filter Blog

By date:
By tag: