stopwatch 计时
This commit is contained in:
@@ -0,0 +1 @@
|
||||
#include <stopwatch.h>
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef INCLUDED_STOPWATCH_H
|
||||
#define INCLUDED_STOPWATCH_H
|
||||
|
||||
#ifndef INCLUDED_OS_SYSTICK_H
|
||||
#include <os_systick.h>
|
||||
#endif /*INCLUDED_OS_SYSTICK_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
typedef struct {
|
||||
volatile os_tick_t start_tick;
|
||||
volatile os_tick_t end_tick;
|
||||
}stopwatch_t;
|
||||
|
||||
OS_STATIC_FORCE_INLINE
|
||||
void stopwatch_init(stopwatch_t* self) {
|
||||
self->start_tick = os_systick_safe_get();
|
||||
}
|
||||
|
||||
OS_STATIC_FORCE_INLINE
|
||||
void stopwatch_start(stopwatch_t* self) {
|
||||
self->start_tick = os_systick_safe_get();
|
||||
}
|
||||
|
||||
OS_STATIC_FORCE_INLINE
|
||||
void stopwatch_stop(stopwatch_t* self) {
|
||||
self->end_tick = os_systick_safe_get();
|
||||
}
|
||||
|
||||
OS_STATIC_FORCE_INLINE
|
||||
os_tick_t stopwatch_elapsed_ticks(stopwatch_t* self) {
|
||||
return self->end_tick - self->start_tick;
|
||||
}
|
||||
|
||||
|
||||
#endif /*INCLUDED_STOPWATCH_H*/
|
||||
Reference in New Issue
Block a user