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.
Dependencies: EthernetInterface NTPClient iothub_amqp_transport iothub_client mbed-rtos mbed
Fork of iothub_client_sample_amqp by
tickcounter_mbed.cpp
00001 // Copyright (c) Microsoft. All rights reserved. 00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 00003 00004 #include <cstdlib> 00005 00006 #ifdef _CRTDBG_MAP_ALLOC 00007 #include <crtdbg.h> 00008 #endif 00009 00010 #include <cstdio> 00011 #include <cctype> 00012 #include "mbed.h" 00013 #include "azure_c_shared_utility/tickcounter.h" 00014 00015 class TICK_COUNTER_INSTANCE_TAG 00016 { 00017 public: 00018 clock_t last_clock_value; 00019 tickcounter_ms_t current_ms; 00020 }; 00021 00022 TICK_COUNTER_HANDLE tickcounter_create(void) 00023 { 00024 TICK_COUNTER_INSTANCE_TAG* result; 00025 result = new TICK_COUNTER_INSTANCE_TAG(); 00026 result->last_clock_value = clock(); 00027 result->current_ms = result->last_clock_value * 1000 / CLOCKS_PER_SEC; 00028 return result; 00029 } 00030 00031 void tickcounter_destroy(TICK_COUNTER_HANDLE tick_counter) 00032 { 00033 if (tick_counter != NULL) 00034 { 00035 delete tick_counter; 00036 } 00037 } 00038 00039 int tickcounter_get_current_ms(TICK_COUNTER_HANDLE tick_counter, tickcounter_ms_t * current_ms) 00040 { 00041 int result; 00042 if (tick_counter == NULL || current_ms == NULL) 00043 { 00044 result = __LINE__; 00045 } 00046 else 00047 { 00048 TICK_COUNTER_INSTANCE_TAG* tick_counter_instance = (TICK_COUNTER_INSTANCE_TAG*)tick_counter; 00049 00050 clock_t clock_value = clock(); 00051 00052 tick_counter_instance->current_ms += (clock_value - tick_counter_instance->last_clock_value) * 1000 / CLOCKS_PER_SEC; 00053 tick_counter_instance->last_clock_value = clock_value; 00054 *current_ms = tick_counter_instance->current_ms; 00055 00056 result = 0; 00057 } 00058 return result; 00059 }
Generated on Tue Jul 12 2022 12:43:24 by
