Azure IoT common library
Fork of azure_c_shared_utility by
tickcounter_mbed.cpp@19:2e0811512ceb, 2017-01-28 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Sat Jan 28 09:35:22 2017 -0800
- Revision:
- 19:2e0811512ceb
- Parent:
- 16:18e7ebd42bb2
- Child:
- 21:b92006c5b9ff
1.1.6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Azure.IoT Build | 0:fa2de1b79154 | 1 | // Copyright (c) Microsoft. All rights reserved. |
Azure.IoT Build | 0:fa2de1b79154 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
Azure.IoT Build | 0:fa2de1b79154 | 3 | |
Azure.IoT Build | 0:fa2de1b79154 | 4 | #include "mbed.h" |
Azure.IoT Build | 0:fa2de1b79154 | 5 | #include "azure_c_shared_utility/tickcounter.h" |
Azure.IoT Build | 0:fa2de1b79154 | 6 | |
Azure.IoT Build | 0:fa2de1b79154 | 7 | class TICK_COUNTER_INSTANCE_TAG |
Azure.IoT Build | 0:fa2de1b79154 | 8 | { |
Azure.IoT Build | 0:fa2de1b79154 | 9 | public: |
Azure.IoT Build | 0:fa2de1b79154 | 10 | clock_t last_clock_value; |
Azure.IoT.Build | 16:18e7ebd42bb2 | 11 | tickcounter_ms_t current_ms; |
Azure.IoT Build | 0:fa2de1b79154 | 12 | }; |
Azure.IoT Build | 0:fa2de1b79154 | 13 | |
Azure.IoT Build | 0:fa2de1b79154 | 14 | TICK_COUNTER_HANDLE tickcounter_create(void) |
Azure.IoT Build | 0:fa2de1b79154 | 15 | { |
Azure.IoT Build | 0:fa2de1b79154 | 16 | TICK_COUNTER_INSTANCE_TAG* result; |
Azure.IoT Build | 0:fa2de1b79154 | 17 | result = new TICK_COUNTER_INSTANCE_TAG(); |
Azure.IoT Build | 0:fa2de1b79154 | 18 | result->last_clock_value = clock(); |
Azure.IoT Build | 0:fa2de1b79154 | 19 | result->current_ms = result->last_clock_value * 1000 / CLOCKS_PER_SEC; |
Azure.IoT Build | 0:fa2de1b79154 | 20 | return result; |
Azure.IoT Build | 0:fa2de1b79154 | 21 | } |
Azure.IoT Build | 0:fa2de1b79154 | 22 | |
Azure.IoT Build | 0:fa2de1b79154 | 23 | void tickcounter_destroy(TICK_COUNTER_HANDLE tick_counter) |
Azure.IoT Build | 0:fa2de1b79154 | 24 | { |
Azure.IoT Build | 0:fa2de1b79154 | 25 | if (tick_counter != NULL) |
Azure.IoT Build | 0:fa2de1b79154 | 26 | { |
Azure.IoT Build | 0:fa2de1b79154 | 27 | delete tick_counter; |
Azure.IoT Build | 0:fa2de1b79154 | 28 | } |
Azure.IoT Build | 0:fa2de1b79154 | 29 | } |
Azure.IoT Build | 0:fa2de1b79154 | 30 | |
Azure.IoT.Build | 16:18e7ebd42bb2 | 31 | int tickcounter_get_current_ms(TICK_COUNTER_HANDLE tick_counter, tickcounter_ms_t * current_ms) |
Azure.IoT Build | 0:fa2de1b79154 | 32 | { |
Azure.IoT Build | 0:fa2de1b79154 | 33 | int result; |
Azure.IoT Build | 0:fa2de1b79154 | 34 | if (tick_counter == NULL || current_ms == NULL) |
Azure.IoT Build | 0:fa2de1b79154 | 35 | { |
Azure.IoT Build | 0:fa2de1b79154 | 36 | result = __LINE__; |
Azure.IoT Build | 0:fa2de1b79154 | 37 | } |
Azure.IoT Build | 0:fa2de1b79154 | 38 | else |
Azure.IoT Build | 0:fa2de1b79154 | 39 | { |
Azure.IoT Build | 0:fa2de1b79154 | 40 | TICK_COUNTER_INSTANCE_TAG* tick_counter_instance = (TICK_COUNTER_INSTANCE_TAG*)tick_counter; |
Azure.IoT Build | 0:fa2de1b79154 | 41 | |
Azure.IoT Build | 0:fa2de1b79154 | 42 | clock_t clock_value = clock(); |
Azure.IoT Build | 0:fa2de1b79154 | 43 | |
Azure.IoT Build | 0:fa2de1b79154 | 44 | tick_counter_instance->current_ms += (clock_value - tick_counter_instance->last_clock_value) * 1000 / CLOCKS_PER_SEC; |
Azure.IoT Build | 0:fa2de1b79154 | 45 | tick_counter_instance->last_clock_value = clock_value; |
Azure.IoT Build | 0:fa2de1b79154 | 46 | *current_ms = tick_counter_instance->current_ms; |
Azure.IoT Build | 0:fa2de1b79154 | 47 | |
Azure.IoT Build | 0:fa2de1b79154 | 48 | result = 0; |
Azure.IoT Build | 0:fa2de1b79154 | 49 | } |
Azure.IoT Build | 0:fa2de1b79154 | 50 | return result; |
Azure.IoT Build | 0:fa2de1b79154 | 51 | } |