Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions platform/mbed_retarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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>
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

10 changes: 0 additions & 10 deletions platform/mbed_rtc_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand Down