Beispiel #1
0
    /* NOTE: config.h doesn't have guard includes! */
    #define INCLUDED_CONFIG_H_
    #include "config.h"
#endif /* defined(HAVE_CONFIG_H) && !defined(INCLUDED_CONFIG_H_) */

#include "headers.h"
#include "gettimeofday.h"

#ifdef __cplusplus
extern "C"
#endif /* __cplusplus */
int wiced_gettimeofday( struct timeval* tv, void* timezone ) {
    UNUSED_PARAMETER( timezone );

    wwd_time_t time_ms = host_rtos_get_time( );
    tv->tv_sec = ( time_ms / 1000 /* to convert ms to sec */ );
    tv->tv_usec = ( time_ms - ( tv->tv_sec * 1000 ) ) * 1000;

    /* Success */
    return 0;
} // end gettimeofday
Beispiel #2
0
wwd_result_t wwd_wifi_get_random( void* data_buffer, uint16_t buffer_length )
{
    wiced_buffer_t buffer;
    uint8_t* tmp_buffer_ptr;
    wiced_buffer_t response;
    wwd_result_t ret = WWD_PENDING;
    static uint16_t pseudo_random = 0;
    static uint16_t random_seed   = 0;

    /* Seed the pseudo random number generator. */
    if ( ( pseudo_random == 0 ) || ( random_seed == 0 ) )
    {
        if ( random_seed == 0 )
        {
            if ( wwd_sdpcm_get_ioctl_buffer( &buffer, (uint16_t) 2 ) != NULL ) /* Do not need to put anything in buffer hence void cast */
            {
                ret = wwd_sdpcm_send_ioctl( SDPCM_GET, WLC_GET_RANDOM_BYTES, buffer, &response, WWD_STA_INTERFACE );
            }
            if ( ret == WWD_SUCCESS )
            {
                uint8_t* data = (uint8_t*) host_buffer_get_current_piece_data_pointer( response );
                memcpy( &random_seed, data, (size_t) 2 );
                host_buffer_release( response, WWD_NETWORK_RX );
            }
        }
        if ( pseudo_random == 0 )
        {
            pseudo_random = (uint16_t)host_rtos_get_time();
        }
        if ( random_seed != 0 )
        {
            pseudo_random = (uint16_t)(pseudo_random * random_seed);
        }
    }

    tmp_buffer_ptr = (uint8_t*) data_buffer;
    while( buffer_length != 0 )
    {
        pseudo_random = (uint16_t)((pseudo_random * 32719 + 3) % 32749);

        *tmp_buffer_ptr = ((uint8_t*)&pseudo_random)[0];
        buffer_length--;
        tmp_buffer_ptr++;

        if ( buffer_length > 0 )
        {
            *tmp_buffer_ptr = ((uint8_t*)&pseudo_random)[1];
            buffer_length--;
            tmp_buffer_ptr++;
        }
    }

    /*@+branchstate@*/
    return WWD_SUCCESS;
}
wiced_result_t wiced_update_system_monitor(wiced_system_monitor_t* system_monitor, uint32_t permitted_delay)
{
    uint32_t current_time = host_rtos_get_time();
    /* Update the system monitor if it hasn't already passed it's permitted delay */
    if ((current_time - system_monitor->last_update) <= system_monitor->longest_permitted_delay)
    {
        system_monitor->last_update             = current_time;
        system_monitor->longest_permitted_delay = permitted_delay;
    }

    return WICED_SUCCESS;
}
void system_monitor_thread_main( wiced_thread_arg_t arg )
{
    UNUSED_PARAMETER(arg);

    memset(system_monitors, 0, sizeof(system_monitors));

    if (wiced_rtos_init_semaphore(&system_monitor_thread_semaphore) != WICED_SUCCESS)
    {
        wiced_assert("semaphore init failed", 0);
    }

    /* - Can watch threads
     * Each thread can set a counter that is decremented every event.
     * Once any timer == 0, the watchdog is no longer kicked
     *
     * - Can watch packet buffer status
     * If no RX packets are available, take timestamp (T). If (current time - T) > X seconds, stop kicking watchdog.
     * X can be 10 second default. Time will be set to zero once RX buffer is freed
     *
     * - Can watch bus data credits
     * If no credits are available, take timestamp (B). If (current time - B) > X seconds, stop kicking watchdog.
     * This will be dependent on if WLAN is up. Timer will be set to 0 if credits become available.
     */
    while (1)
    {
        int a;
        uint32_t current_time = host_rtos_get_time();

        for (a = 0; a < MAXIMUM_NUMBER_OF_SYSTEM_MONITORS; ++a)
        {
            if (system_monitors[a] != NULL)
            {
                if ((current_time - system_monitors[a]->last_update) > system_monitors[a]->longest_permitted_delay)
                {
                    /* A system monitor update period has been missed and hence explicitly resetting the MCU rather than waiting for the watchdog to bite */
                    wiced_framework_reboot();
                }
            }
        }
        wiced_watchdog_kick();
        wiced_rtos_get_semaphore(&system_monitor_thread_semaphore, DEFAULT_SYSTEM_MONITOR_PERIOD);
    }
    /* Should never get here */
    wiced_rtos_deinit_semaphore(&system_monitor_thread_semaphore);

    WICED_END_OF_CURRENT_THREAD( );
}
wiced_result_t wiced_register_system_monitor(wiced_system_monitor_t* system_monitor, uint32_t initial_permitted_delay)
{
    int a;

    /* Find spare entry and add the new system monitor */
    for ( a = 0; a < MAXIMUM_NUMBER_OF_SYSTEM_MONITORS; ++a )
    {
        if (system_monitors[a] == NULL)
        {
            system_monitor->last_update = host_rtos_get_time();
            system_monitor->longest_permitted_delay = initial_permitted_delay;
            system_monitors[a] = system_monitor;
            return WICED_SUCCESS;
        }
    }

    return WICED_ERROR;
}