CRINSA-team2025 V1
Documentation du Club Robot INSA Rennes 2025
Chargement...
Recherche...
Aucune correspondance
My_Clock.h
1#ifndef __CLOCK_H__
2#define __CLOCK_H__
3
4#include <Arduino.h>
5#include <FreeRTOS.h>
6#include <FreeRTOS/Source/include/task.h>
7
15
19__STATIC_INLINE void DWT_Init(void) {
20 CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // разрешаем использовать счётчик
21 DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; // запускаем счётчик
22}
26__STATIC_INLINE void DWT_delay_us(uint32_t us) {
27 uint32_t us_count_tic = us * (SystemCoreClock / 1000000U);
28 DWT->CYCCNT = 0U;
29 while (DWT->CYCCNT < us_count_tic);
30}
35__STATIC_INLINE uint32_t DWT_micros(void) {
36 return DWT->CYCCNT / (SystemCoreClock / 1000000U);
37}
42__STATIC_INLINE uint32_t DWT_value(void) {
43 return DWT->CYCCNT ;
44}
45
46static void poly_delay(uint32_t ms) {
47 if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) {
48 delay(ms);
49 } else {
50 vTaskDelay(pdMS_TO_TICKS(ms));
51 }
52}
53
54class Clock {
55private:
56 unsigned long m_startTime;
57public:
59
63 :
64 m_startTime(DWT_micros())
65 {
66 }
67
69
74 {
75 unsigned long currentTime = DWT_value();
76 float elapsedTimeInSeconds = (currentTime - m_startTime)/ (SystemCoreClock / 1000000U) / float(1e6);
77 if(currentTime<m_startTime) {
78 unsigned long dp=-m_startTime;
79 //printf("%lu \n",dp);
80 elapsedTimeInSeconds=(currentTime + dp)/ (SystemCoreClock / 1000000U) / float(1e6);
81 }
82 return elapsedTimeInSeconds;
83 }
84
86
90 float restart()
91 {
92 unsigned long currentTime = DWT_value();
93 float elapsedTimeInSeconds = (currentTime - m_startTime)/ (SystemCoreClock / 1000000U) / float(1e6);
94 if(currentTime<m_startTime) {
95 unsigned long dp=-m_startTime;
96 //printf("%lu %lu %lu \n",dp,-m_startTime,m_startTime);
97 elapsedTimeInSeconds=(currentTime + dp)/ (SystemCoreClock / 1000000U) / float(1e6);
98 }
99 m_startTime = currentTime;
100 return elapsedTimeInSeconds;
101 }
102};
103
104
105#endif // __CLOCK_H__
float getElapsedTime()
Récupère le temps depuis le dernier reset.
Definition My_Clock.h:73
float restart()
Reset le temps.
Definition My_Clock.h:90
Clock()
Constructeur de Clock.
Definition My_Clock.h:62