Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more
tickcounter_mbed.cpp
- Committer:
- AzureIoTClient
- Date:
- 2018-03-20
- Revision:
- 42:0cc3c211ad26
- Parent:
- 21:b92006c5b9ff
File content as of revision 42:0cc3c211ad26:
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include "mbed.h"
#include "azure_c_shared_utility/optimize_size.h"
#include "azure_c_shared_utility/tickcounter.h"
class TICK_COUNTER_INSTANCE_TAG
{
public:
    clock_t last_clock_value;
    tickcounter_ms_t current_ms;
};
TICK_COUNTER_HANDLE tickcounter_create(void)
{
    TICK_COUNTER_INSTANCE_TAG* result;
    result = new TICK_COUNTER_INSTANCE_TAG();
    result->last_clock_value = clock();
    result->current_ms = result->last_clock_value * 1000 / CLOCKS_PER_SEC;
    return result;
}
void tickcounter_destroy(TICK_COUNTER_HANDLE tick_counter)
{
    if (tick_counter != NULL)
    {
        delete tick_counter;
    }
}
int tickcounter_get_current_ms(TICK_COUNTER_HANDLE tick_counter, tickcounter_ms_t * current_ms)
{
    int result;
    if (tick_counter == NULL || current_ms == NULL)
    {
        result = __FAILURE__;
    }
    else
    {
        TICK_COUNTER_INSTANCE_TAG* tick_counter_instance = (TICK_COUNTER_INSTANCE_TAG*)tick_counter;
        clock_t clock_value = clock();
        tick_counter_instance->current_ms += (clock_value - tick_counter_instance->last_clock_value) * 1000 / CLOCKS_PER_SEC;
        tick_counter_instance->last_clock_value = clock_value;
        *current_ms = tick_counter_instance->current_ms;
        result = 0;
    }
    return result;
}
            
    