mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-25 14:35:51 +08:00
fix log time overflow (#3056)
This commit is contained in:
@@ -79,6 +79,22 @@ uint32_t get_sys_time_usec(void)
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time in microseconds divided by 100 since startup.
|
||||
* WARNING: overflows after 7000min!
|
||||
* @return 100microseconds since startup as uint32_t
|
||||
*/
|
||||
uint32_t get_sys_time_usec100(void)
|
||||
{
|
||||
chMtxLock(&sys_time_mtx);
|
||||
uint32_t current = chSysGetRealtimeCounterX();
|
||||
uint32_t t = sys_time.nb_sec * 10000 +
|
||||
TIME_I2US(sys_time.nb_sec_rem)/100 +
|
||||
RTC2US(STM32_SYSCLK, current - cpu_counter)/100;
|
||||
chMtxUnlock(&sys_time_mtx);
|
||||
return t;
|
||||
}
|
||||
|
||||
uint32_t get_sys_time_msec(void)
|
||||
{
|
||||
chMtxLock(&sys_time_mtx);
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#endif
|
||||
|
||||
extern uint32_t get_sys_time_usec(void);
|
||||
extern uint32_t get_sys_time_usec100(void);
|
||||
extern uint32_t get_sys_time_msec(void);
|
||||
extern void sys_time_usleep(uint32_t us);
|
||||
extern void sys_time_msleep(uint16_t ms);
|
||||
|
||||
@@ -171,6 +171,29 @@ uint32_t get_sys_time_usec(void)
|
||||
return d_sec * 1000000 + d_nsec / 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time in 100microseconds since startup.
|
||||
* WARNING: overflows after 7000 minutes!
|
||||
* @return current system time as uint32_t
|
||||
*/
|
||||
uint32_t get_sys_time_usec100(void)
|
||||
{
|
||||
/* get current time */
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
||||
/* time difference to startup */
|
||||
time_t d_sec = now.tv_sec - startup_time.tv_sec;
|
||||
long d_nsec = now.tv_nsec - startup_time.tv_nsec;
|
||||
|
||||
/* wrap if negative nanoseconds */
|
||||
if (d_nsec < 0) {
|
||||
d_sec -= 1;
|
||||
d_nsec += 1000000000L;
|
||||
}
|
||||
return d_sec * 10000 + d_nsec / 100000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time in milliseconds since startup.
|
||||
* @return milliseconds since startup as uint32_t
|
||||
|
||||
@@ -38,6 +38,13 @@
|
||||
*/
|
||||
extern uint32_t get_sys_time_usec(void);
|
||||
|
||||
/**
|
||||
* Get the time in microseconds since startup.
|
||||
* WARNING: overflows after 7000 minutes!
|
||||
* @return current system time as uint32_t
|
||||
*/
|
||||
extern uint32_t get_sys_time_usec100(void);
|
||||
|
||||
/**
|
||||
* Get the time in milliseconds since startup.
|
||||
* @return milliseconds since startup as uint32_t
|
||||
|
||||
@@ -42,6 +42,16 @@ static inline uint32_t get_sys_time_usec(void)
|
||||
usec_of_cpu_ticks(sys_time.nb_sec_rem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time in 100microseconds since startup.
|
||||
* @return 100microseconds since startup as uint32_t
|
||||
*/
|
||||
static inline uint32_t get_sys_time_usec100(void)
|
||||
{
|
||||
return sys_time.nb_sec * 10000 +
|
||||
usec_of_cpu_ticks(sys_time.nb_sec_rem)/100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time in milliseconds since startup.
|
||||
* @return milliseconds since startup as uint32_t
|
||||
|
||||
@@ -51,6 +51,18 @@ static inline uint32_t get_sys_time_usec(void)
|
||||
usec_of_cpu_ticks(systick_get_reload() - systick_get_value());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time in 100microseconds since startup.
|
||||
* WARNING: overflows after 7000min!
|
||||
* @return 100microseconds since startup as uint32_t
|
||||
*/
|
||||
static inline uint32_t get_sys_time_usec100(void)
|
||||
{
|
||||
return sys_time.nb_sec * 10000 +
|
||||
usec_of_cpu_ticks(sys_time.nb_sec_rem)/100 +
|
||||
usec_of_cpu_ticks(systick_get_reload() - systick_get_value())/100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time in milliseconds since startup.
|
||||
* @return milliseconds since startup as uint32_t
|
||||
|
||||
@@ -30,7 +30,7 @@ struct pprzlog_transport pprzlog_tp;
|
||||
|
||||
void pprzlog_tp_init(void)
|
||||
{
|
||||
pprzlog_transport_init(&pprzlog_tp, get_sys_time_usec);
|
||||
pprzlog_transport_init(&pprzlog_tp, get_sys_time_usec100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
Submodule sw/ext/pprzlink updated: 9b2d03c824...1a07e89092
Reference in New Issue
Block a user