File tree 2 files changed +18
-4
lines changed
2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 18
18
#include "freertos/task.h"
19
19
#include "esp_attr.h"
20
20
#include "nvs_flash.h"
21
+ #include <sys/time.h>
21
22
22
23
void yield ()
23
24
{
24
25
vPortYield ();
25
26
}
26
27
28
+ portMUX_TYPE microsMux = portMUX_INITIALIZER_UNLOCKED ;
29
+
27
30
uint32_t IRAM_ATTR micros ()
28
31
{
32
+ static uint32_t lccount = 0 ;
33
+ static uint32_t overflow = 0 ;
29
34
uint32_t ccount ;
35
+ portENTER_CRITICAL_ISR (& microsMux );
30
36
__asm__ __volatile__ ( "rsr %0, ccount" : "=a" (ccount ) );
31
- return ccount / CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ ;
37
+ if (ccount < lccount ){
38
+ overflow += UINT32_MAX / CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ ;
39
+ }
40
+ lccount = ccount ;
41
+ portEXIT_CRITICAL_ISR (& microsMux );
42
+ return overflow + (ccount / CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ );
32
43
}
33
44
34
45
uint32_t IRAM_ATTR millis ()
@@ -45,7 +56,7 @@ void IRAM_ATTR delayMicroseconds(uint32_t us)
45
56
{
46
57
uint32_t m = micros ();
47
58
if (us ){
48
- uint32_t e = (m + us ) % (( 0xFFFFFFFF / CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ ) + 1 ) ;
59
+ uint32_t e = (m + us );
49
60
if (m > e ){ //overflow
50
61
while (micros () > e ){
51
62
NOP ();
@@ -63,14 +74,16 @@ void initVariant() {}
63
74
void init () __attribute__((weak ));
64
75
void init () {}
65
76
66
- void initArduino (){
77
+ void initArduino ()
78
+ {
67
79
nvs_flash_init ();
68
80
init ();
69
81
initVariant ();
70
82
}
71
83
72
84
//used by hal log
73
- const char * IRAM_ATTR pathToFileName (const char * path ){
85
+ const char * IRAM_ATTR pathToFileName (const char * path )
86
+ {
74
87
size_t i = 0 ;
75
88
size_t pos = 0 ;
76
89
char * p = (char * )path ;
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ void loopTask(void *pvParameters)
14
14
{
15
15
setup ();
16
16
for (;;) {
17
+ micros (); // update overflow
17
18
loop ();
18
19
}
19
20
}
You can’t perform that action at this time.
0 commit comments