21
21
#include "nvs.h"
22
22
#include "esp_partition.h"
23
23
#include "esp_log.h"
24
- #include "pthread .h"
24
+ #include "esp_timer .h"
25
25
#include <sys/time.h>
26
26
27
27
//Undocumented!!! Get chip temperature in Farenheit
@@ -38,51 +38,14 @@ void yield()
38
38
vPortYield ();
39
39
}
40
40
41
- portMUX_TYPE microsMux = portMUX_INITIALIZER_UNLOCKED ;
42
- static pthread_key_t microsStore = NULL ; // Thread Local Storage Handle
43
-
44
- void microsStoreDelete (void * storage ) { // release thread local data when task is delete.
45
- if (storage ) free (storage );
46
- }
47
-
48
41
unsigned long IRAM_ATTR micros ()
49
42
{
50
- if (!microsStore ) { // first Time Ever thread local not init'd
51
- portENTER_CRITICAL_ISR (& microsMux );
52
- pthread_key_create (& microsStore ,microsStoreDelete ); // create initial holder
53
- portEXIT_CRITICAL_ISR (& microsMux );
54
- }
55
-
56
- uint32_t * ptr ;// [0] is lastCount, [1] is overFlow
57
-
58
- ptr = pthread_getspecific (microsStore ); // get address of storage
59
-
60
- if (ptr == NULL ) { // first time in this thread, allocate mem, init it.
61
- portENTER_CRITICAL_ISR (& microsMux );
62
- ptr = (uint32_t * )malloc (sizeof (uint32_t )* 2 );
63
- pthread_setspecific (microsStore ,ptr ); // store the pointer to this thread's values
64
- ptr [0 ] = 0 ; // lastCount value
65
- ptr [1 ] = 0 ; // overFlow
66
- portEXIT_CRITICAL_ISR (& microsMux );
67
- }
68
-
69
- unsigned long ccount ;
70
-
71
- portENTER_CRITICAL_ISR (& microsMux );
72
- __asm__ __volatile__ ( "rsr %0, ccount" : "=a" (ccount ) ); //get cycle count
73
- if (ccount < ptr [0 ]) { // overflow occurred
74
- ptr [1 ] += UINT32_MAX / CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ ;
75
- }
76
-
77
- ptr [0 ] = ccount ;
78
- portEXIT_CRITICAL_ISR (& microsMux );
79
-
80
- return ptr [1 ] + (ccount / CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ );
43
+ return (unsigned long ) esp_timer_get_time ();
81
44
}
82
45
83
46
unsigned long IRAM_ATTR millis ()
84
47
{
85
- return xTaskGetTickCount () * portTICK_PERIOD_MS ;
48
+ return ( unsigned long ) ( esp_timer_get_time () / 1000 ) ;
86
49
}
87
50
88
51
void delay (uint32_t ms )
0 commit comments