Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tickcounter_mbed.cpp

raw
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 #include "mbed.h"
5 #include "azure_c_shared_utility/optimize_size.h"
6 #include "azure_c_shared_utility/tickcounter.h"
7
8 class TICK_COUNTER_INSTANCE_TAG
9 {
10 public:
11 clock_t last_clock_value;
12 tickcounter_ms_t current_ms;
13 };
14
15 TICK_COUNTER_HANDLE tickcounter_create(void)
16 {
17 TICK_COUNTER_INSTANCE_TAG* result;
18 result = new TICK_COUNTER_INSTANCE_TAG();
19 result->last_clock_value = clock();
20 result->current_ms = result->last_clock_value * 1000 / CLOCKS_PER_SEC;
21 return result;
22 }
23
24 void tickcounter_destroy(TICK_COUNTER_HANDLE tick_counter)
25 {
26 if (tick_counter != NULL)
27 {
28 delete tick_counter;
29 }
30 }
31
32 int tickcounter_get_current_ms(TICK_COUNTER_HANDLE tick_counter, tickcounter_ms_t * current_ms)
33 {
34 int result;
35 if (tick_counter == NULL || current_ms == NULL)
36 {
37 result = MU_FAILURE;
38 }
39 else
40 {
41 TICK_COUNTER_INSTANCE_TAG* tick_counter_instance = (TICK_COUNTER_INSTANCE_TAG*)tick_counter;
42
43 clock_t clock_value = clock();
44
45 tick_counter_instance->current_ms += (clock_value - tick_counter_instance->last_clock_value) * 1000 / CLOCKS_PER_SEC;
46 tick_counter_instance->last_clock_value = clock_value;
47 *current_ms = tick_counter_instance->current_ms;
48
49 result = 0;
50 }
51 return result;
52 }