Move clock() function from mbed_rtc_time.cpp to mbed_retarget.cpp.

pull/5099/head
Przemyslaw Stekiel 2017-09-14 12:07:51 +02:00
parent de6d2918b8
commit 035c0896ed
2 changed files with 25 additions and 10 deletions

View File

@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <time.h>
#include "platform/platform.h"
#include "platform/FilePath.h"
#include "hal/serial_api.h"
#include "hal/us_ticker_api.h"
#include "platform/mbed_toolchain.h"
#include "platform/mbed_semihost_api.h"
#include "platform/mbed_interface.h"
@ -24,6 +26,7 @@
#include "platform/mbed_error.h"
#include "platform/mbed_stats.h"
#include "platform/mbed_critical.h"
#include "platform/PlatformMutex.h"
#include <stdlib.h>
#include <string.h>
#include <limits.h>
@ -33,6 +36,8 @@
#include <errno.h>
#include "platform/mbed_retarget.h"
static SingletonPtr<PlatformMutex> _mutex;
#if defined(__ARMCC_VERSION)
# include <rt_sys.h>
# define PREFIX(x) _sys##x
@ -985,3 +990,23 @@ void operator delete[](void *ptr)
free(ptr);
}
}
/* @brief standard c library clock() function.
*
* This function returns the number of clock ticks elapsed since the start of the program.
*
* @note Synchronization level: Thread safe
*
* @return
* the number of clock ticks elapsed since the start of the program.
*
* */
extern "C" clock_t clock()
{
_mutex->lock();
clock_t t = us_ticker_read();
t /= 1000000 / CLOCKS_PER_SEC; // convert to processor time
_mutex->unlock();
return t;
}

View File

@ -15,10 +15,8 @@
*/
#include "hal/rtc_api.h"
#include <time.h>
#include "platform/mbed_critical.h"
#include "platform/mbed_rtc_time.h"
#include "hal/us_ticker_api.h"
#include "platform/SingletonPtr.h"
#include "platform/PlatformMutex.h"
@ -76,14 +74,6 @@ void set_time(time_t t) {
_mutex->unlock();
}
clock_t clock() {
_mutex->lock();
clock_t t = us_ticker_read();
t /= 1000000 / CLOCKS_PER_SEC; // convert to processor time
_mutex->unlock();
return t;
}
void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) {
_mutex->lock();
_rtc_read = read_rtc;