File tree 26 files changed +126
-81
lines changed
26 files changed +126
-81
lines changed Original file line number Diff line number Diff line change 27
27
#include "esp_private/periph_ctrl.h"
28
28
#include "driver/adc_types_legacy.h"
29
29
#include "esp_clk_tree.h"
30
+ #include "rtc_lock.h"
30
31
31
32
#if SOC_DAC_SUPPORTED
32
33
#include "hal/dac_types.h"
@@ -45,11 +46,6 @@ static const char *ADC_TAG = "ADC";
45
46
//////////////////////// Locks ///////////////////////////////////////////
46
47
LOG_MODULE_REGISTER (adc_legacy , CONFIG_ADC_LOG_LEVEL );
47
48
48
- extern int rtc_spinlock ;
49
-
50
- #define RTC_ENTER_CRITICAL () do { rtc_spinlock = irq_lock(); } while(0)
51
- #define RTC_EXIT_CRITICAL () irq_unlock(rtc_spinlock);
52
-
53
49
#define DIGI_ENTER_CRITICAL ()
54
50
#define DIGI_EXIT_CRITICAL ()
55
51
Original file line number Diff line number Diff line change 15
15
#include "hal/gpio_types.h"
16
16
#include "hal/dac_ll.h"
17
17
#include "clk_ctrl_os.h"
18
-
19
- extern int rtc_spinlock ;
20
-
21
- #define RTC_ENTER_CRITICAL () do { rtc_spinlock = irq_lock(); } while(0)
22
- #define RTC_EXIT_CRITICAL () irq_unlock(rtc_spinlock);
18
+ #include "rtc_lock.h"
23
19
24
20
static __attribute__((unused )) const char * TAG = "DAC" ;
25
21
Original file line number Diff line number Diff line change 13
13
#include "driver/rtc_io.h"
14
14
#include "hal/rtc_io_hal.h"
15
15
#include "soc/soc_caps.h"
16
+ #include "rtc_lock.h"
16
17
17
18
static const char __attribute__((__unused__ )) * RTCIO_TAG = "RTCIO" ;
18
19
19
- extern int rtc_spinlock ;
20
-
21
- #define RTCIO_ENTER_CRITICAL () do { rtc_spinlock = irq_lock(); } while(0)
22
- #define RTCIO_EXIT_CRITICAL () irq_unlock(rtc_spinlock);
20
+ #define RTCIO_ENTER_CRITICAL () RTC_ENTER_CRITICAL()
21
+ #define RTCIO_EXIT_CRITICAL () RTC_EXIT_CRITICAL()
23
22
24
23
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
25
24
Original file line number Diff line number Diff line change 20
20
#include "driver/gpio.h"
21
21
#include "hal/touch_sensor_types.h"
22
22
#include "hal/touch_sensor_hal.h"
23
+ #include "rtc_lock.h"
23
24
24
25
static const char * TOUCH_TAG = "TOUCH_SENSOR" ;
25
26
#define TOUCH_CHECK (a , str , ret_val ) ({ \
@@ -43,10 +44,8 @@ static const char *TOUCH_TAG = "TOUCH_SENSOR";
43
44
44
45
_Static_assert (TOUCH_PAD_MAX == SOC_TOUCH_SENSOR_NUM , "Touch sensor channel number not equal to chip capabilities" );
45
46
46
- extern int rtc_spinlock ;
47
-
48
- #define TOUCH_ENTER_CRITICAL () do { rtc_spinlock = irq_lock(); } while(0)
49
- #define TOUCH_EXIT_CRITICAL () irq_unlock(rtc_spinlock)
47
+ #define TOUCH_ENTER_CRITICAL () RTC_ENTER_CRITICAL()
48
+ #define TOUCH_EXIT_CRITICAL () RTC_EXIT_CRITICAL()
50
49
51
50
esp_err_t touch_pad_isr_deregister (intr_handler_t fn , void * arg )
52
51
{
Original file line number Diff line number Diff line change 32
32
#include "esp_private/sar_periph_ctrl.h"
33
33
#include "esp_private/periph_ctrl.h"
34
34
#include "soc/periph_defs.h"
35
+ #include "rtc_lock.h"
36
+
35
37
//For calibration
36
38
#if CONFIG_IDF_TARGET_ESP32S2
37
39
#include "esp_efuse_rtc_table.h"
38
40
#elif SOC_ADC_CALIBRATION_V1_SUPPORTED
39
41
#include "esp_efuse_rtc_calib.h"
40
42
#endif
41
43
42
-
43
44
static const char * TAG = "adc_share_hw_ctrl" ;
44
45
45
- extern int rtc_spinlock ;
46
-
47
- #define RTC_ENTER_CRITICAL () do { rtc_spinlock = irq_lock(); } while(0)
48
- #define RTC_EXIT_CRITICAL () irq_unlock(rtc_spinlock);
49
-
50
46
#if SOC_ADC_CALIBRATION_V1_SUPPORTED
51
47
/*---------------------------------------------------------------
52
48
ADC Hardware Calibration
Original file line number Diff line number Diff line change 5
5
*/
6
6
7
7
#include <zephyr/kernel.h>
8
+ #include <zephyr/sys/atomic.h>
9
+ #include <zephyr/sys/__assert.h>
8
10
9
11
#include "clk_ctrl_os.h"
10
12
#include "soc/rtc.h"
11
13
#include "esp_private/esp_clk_tree_common.h"
12
14
#include "esp_check.h"
13
15
14
- static int periph_spinlock ;
16
+ static int lock ;
17
+ static atomic_t lock_counter ;
15
18
16
- #define ENTER_CRITICAL_SECTION () do { periph_spinlock = irq_lock(); } while(0)
17
- #define LEAVE_CRITICAL_SECTION () irq_unlock(periph_spinlock);
19
+ #define ENTER_CRITICAL_SECTION () \
20
+ do { \
21
+ if (atomic_inc(&lock_counter) == 0) { \
22
+ lock = irq_lock(); \
23
+ } \
24
+ } while (0)
25
+
26
+ #define LEAVE_CRITICAL_SECTION () \
27
+ do { \
28
+ __ASSERT_NO_MSG(atomic_get(&lock_counter) > 0); \
29
+ if (atomic_dec(&lock_counter) == 1) { \
30
+ irq_unlock(lock); \
31
+ } \
32
+ } while (0)
18
33
19
34
static uint8_t s_periph_ref_counts = 0 ;
20
35
static uint32_t s_rc_fast_freq = 0 ; // Frequency of the RC_FAST clock in Hz
@@ -25,7 +40,6 @@ static uint32_t s_cur_apll_freq = 0;
25
40
static int s_apll_ref_cnt = 0 ;
26
41
#endif
27
42
28
-
29
43
bool periph_rtc_dig_clk8m_enable (void )
30
44
{
31
45
ENTER_CRITICAL_SECTION ();
Original file line number Diff line number Diff line change 4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
6
6
#include <zephyr/kernel.h>
7
+ #include <zephyr/sys/atomic.h>
8
+ #include <zephyr/sys/__assert.h>
7
9
8
10
#include "hal/clk_gate_ll.h"
9
11
#include "esp_attr.h"
14
16
#include "esp_private/esp_modem_clock.h"
15
17
#endif
16
18
17
- static int periph_spinlock ;
19
+ static atomic_t lock_counter ;
20
+ static int lock ;
18
21
19
- #define ENTER_CRITICAL_SECTION () do { periph_spinlock = irq_lock(); } while(0)
20
- #define LEAVE_CRITICAL_SECTION () irq_unlock(periph_spinlock);
22
+ #define ENTER_CRITICAL_SECTION () \
23
+ do { \
24
+ if (atomic_inc(&lock_counter) == 0) { \
25
+ lock = irq_lock(); \
26
+ } \
27
+ } while (0)
28
+
29
+ #define LEAVE_CRITICAL_SECTION () \
30
+ do { \
31
+ __ASSERT_NO_MSG(atomic_get(&lock_counter) > 0); \
32
+ if (atomic_dec(&lock_counter) == 1) { \
33
+ irq_unlock(lock); \
34
+ } \
35
+ } while (0)
21
36
22
37
static uint8_t ref_counts [PERIPH_MODULE_MAX ] = {0 };
23
38
Original file line number Diff line number Diff line change 20
20
#include "esp_log.h"
21
21
#include "esp_private/sar_periph_ctrl.h"
22
22
#include "hal/sar_ctrl_ll.h"
23
+ #include "rtc_lock.h"
23
24
24
25
static const char * TAG = "sar_periph_ctrl" ;
25
26
26
- static int rtc_spinlock ;
27
-
28
- #define ENTER_CRITICAL_SECTION () do { rtc_spinlock = irq_lock(); } while(0)
29
- #define LEAVE_CRITICAL_SECTION () irq_unlock(rtc_spinlock);
30
- #define LEAVE_CRITICAL () irq_unlock(rtc_spinlock);
27
+ #define ENTER_CRITICAL_SECTION () RTC_ENTER_CRITICAL()
28
+ #define LEAVE_CRITICAL_SECTION () RTC_EXIT_CRITICAL()
29
+ #define LEAVE_CRITICAL () RTC_EXIT_CRITICAL()
31
30
32
31
void sar_periph_ctrl_init (void )
33
32
{
Original file line number Diff line number Diff line change 22
22
#include "esp_private/sar_periph_ctrl.h"
23
23
#include "hal/sar_ctrl_ll.h"
24
24
#include "hal/adc_ll.h"
25
+ #include "rtc_lock.h"
25
26
26
27
static const char * TAG = "sar_periph_ctrl" ;
27
28
28
- int rtc_spinlock ;
29
-
30
- #define ENTER_CRITICAL_SECTION () do { rtc_spinlock = irq_lock(); } while(0)
31
- #define LEAVE_CRITICAL_SECTION () irq_unlock(rtc_spinlock);
32
- #define LEAVE_CRITICAL () irq_unlock(rtc_spinlock);
29
+ #define ENTER_CRITICAL_SECTION () RTC_ENTER_CRITICAL()
30
+ #define LEAVE_CRITICAL_SECTION () RTC_EXIT_CRITICAL()
31
+ #define LEAVE_CRITICAL () RTC_EXIT_CRITICAL()
33
32
34
33
void sar_periph_ctrl_init (void )
35
34
{
Original file line number Diff line number Diff line change @@ -13,11 +13,10 @@ Don't put any other code into this file. */
13
13
#include "hal/adc_types.h"
14
14
#include "hal/adc_hal_common.h"
15
15
#include "esp_private/adc_share_hw_ctrl.h"
16
+ #include "rtc_lock.h"
16
17
17
- extern int rtc_spinlock ;
18
-
19
- #define ENTER_CRITICAL_SECTION () do { rtc_spinlock = irq_lock(); } while(0)
20
- #define LEAVE_CRITICAL_SECTION () irq_unlock(rtc_spinlock);
18
+ #define ENTER_CRITICAL_SECTION () RTC_ENTER_CRITICAL()
19
+ #define LEAVE_CRITICAL_SECTION () RTC_EXIT_CRITICAL()
21
20
22
21
/**
23
22
* @brief Set initial code to ADC2 after calibration. ADC2 RTC and ADC2 PWDET controller share the initial code.
Original file line number Diff line number Diff line change 22
22
#include "esp_private/sar_periph_ctrl.h"
23
23
#include "hal/sar_ctrl_ll.h"
24
24
#include "hal/adc_ll.h"
25
+ #include "rtc_lock.h"
25
26
26
27
static const char * TAG = "sar_periph_ctrl" ;
27
28
28
- int rtc_spinlock ;
29
-
30
- #define ENTER_CRITICAL_SECTION () do { rtc_spinlock = irq_lock(); } while(0)
31
- #define LEAVE_CRITICAL_SECTION () irq_unlock(rtc_spinlock);
32
- #define LEAVE_CRITICAL () irq_unlock(rtc_spinlock);
29
+ #define ENTER_CRITICAL_SECTION () RTC_ENTER_CRITICAL()
30
+ #define LEAVE_CRITICAL_SECTION () RTC_EXIT_CRITICAL()
31
+ #define LEAVE_CRITICAL () RTC_EXIT_CRITICAL()
33
32
34
33
void sar_periph_ctrl_init (void )
35
34
{
Original file line number Diff line number Diff line change 21
21
#include "esp_private/sar_periph_ctrl.h"
22
22
#include "esp_private/esp_modem_clock.h"
23
23
#include "hal/sar_ctrl_ll.h"
24
+ #include "rtc_lock.h"
24
25
25
26
static const char * TAG = "sar_periph_ctrl" ;
26
27
27
- int rtc_spinlock ;
28
-
29
- #define ENTER_CRITICAL_SECTION () do { rtc_spinlock = irq_lock(); } while(0)
30
- #define LEAVE_CRITICAL_SECTION () irq_unlock(rtc_spinlock);
31
- #define LEAVE_CRITICAL () irq_unlock(rtc_spinlock);
28
+ #define ENTER_CRITICAL_SECTION () RTC_ENTER_CRITICAL()
29
+ #define LEAVE_CRITICAL_SECTION () RTC_EXIT_CRITICAL()
30
+ #define LEAVE_CRITICAL () RTC_EXIT_CRITICAL()
32
31
33
32
void sar_periph_ctrl_init (void )
34
33
{
Original file line number Diff line number Diff line change 20
20
#include "esp_private/sar_periph_ctrl.h"
21
21
#include "esp_private/esp_modem_clock.h"
22
22
#include "hal/sar_ctrl_ll.h"
23
+ #include "rtc_lock.h"
23
24
24
25
static const char * TAG = "sar_periph_ctrl" ;
25
26
26
- static int rtc_spinlock ;
27
-
28
- #define ENTER_CRITICAL_SECTION () do { rtc_spinlock = irq_lock(); } while(0)
29
- #define LEAVE_CRITICAL_SECTION () irq_unlock(rtc_spinlock);
30
- #define LEAVE_CRITICAL () irq_unlock(rtc_spinlock);
27
+ #define ENTER_CRITICAL_SECTION () RTC_ENTER_CRITICAL()
28
+ #define LEAVE_CRITICAL_SECTION () RTC_EXIT_CRITICAL()
29
+ #define LEAVE_CRITICAL () RTC_EXIT_CRITICAL()
31
30
32
31
void sar_periph_ctrl_init (void )
33
32
{
Original file line number Diff line number Diff line change @@ -13,11 +13,10 @@ Don't put any other code into this file. */
13
13
#include "hal/adc_types.h"
14
14
#include "hal/adc_hal_common.h"
15
15
#include "esp_private/adc_share_hw_ctrl.h"
16
+ #include "rtc_lock.h"
16
17
17
- extern int rtc_spinlock ;
18
-
19
- #define ENTER_CRITICAL_SECTION () do { rtc_spinlock = irq_lock(); } while(0)
20
- #define LEAVE_CRITICAL_SECTION () irq_unlock(rtc_spinlock);
18
+ #define ENTER_CRITICAL_SECTION () RTC_ENTER_CRITICAL()
19
+ #define LEAVE_CRITICAL_SECTION () RTC_EXIT_CRITICAL()
21
20
22
21
/**
23
22
* @brief Set initial code to ADC2 after calibration. ADC2 RTC and ADC2 PWDET controller share the initial code.
Original file line number Diff line number Diff line change 22
22
#include "esp_private/sar_periph_ctrl.h"
23
23
#include "hal/sar_ctrl_ll.h"
24
24
#include "hal/adc_ll.h"
25
+ #include "rtc_lock.h"
25
26
26
27
static const char * TAG = "sar_periph_ctrl" ;
27
28
28
- static int rtc_spinlock ;
29
-
30
- #define ENTER_CRITICAL_SECTION () do { rtc_spinlock = irq_lock(); } while(0)
31
- #define LEAVE_CRITICAL_SECTION () irq_unlock(rtc_spinlock);
32
- #define LEAVE_CRITICAL () irq_unlock(rtc_spinlock);
29
+ #define ENTER_CRITICAL_SECTION () RTC_ENTER_CRITICAL()
30
+ #define LEAVE_CRITICAL_SECTION () RTC_EXIT_CRITICAL()
31
+ #define LEAVE_CRITICAL () RTC_EXIT_CRITICAL()
33
32
34
33
void sar_periph_ctrl_init (void )
35
34
{
Original file line number Diff line number Diff line change 22
22
#include "esp_private/sar_periph_ctrl.h"
23
23
#include "hal/sar_ctrl_ll.h"
24
24
#include "hal/adc_ll.h"
25
+ #include "rtc_lock.h"
25
26
26
27
static const char * TAG = "sar_periph_ctrl" ;
27
28
28
- static int rtc_spinlock ;
29
-
30
- #define ENTER_CRITICAL_SECTION () do { rtc_spinlock = irq_lock(); } while(0)
31
- #define LEAVE_CRITICAL_SECTION () irq_unlock(rtc_spinlock);
32
- #define LEAVE_CRITICAL () irq_unlock(rtc_spinlock);
29
+ #define ENTER_CRITICAL_SECTION () RTC_ENTER_CRITICAL()
30
+ #define LEAVE_CRITICAL_SECTION () RTC_EXIT_CRITICAL()
31
+ #define LEAVE_CRITICAL () RTC_EXIT_CRITICAL()
33
32
34
33
void sar_periph_ctrl_init (void )
35
34
{
Original file line number Diff line number Diff line change 13
13
#include "esp_types.h"
14
14
#include "esp_log.h"
15
15
#include "soc/rtc_periph.h"
16
+ #include "rtc_lock.h"
16
17
#include "soc/syscon_periph.h"
17
18
#include "soc/rtc.h"
18
19
#include "soc/periph_defs.h"
@@ -35,7 +36,6 @@ static const char *TAG = "rtc_module";
35
36
36
37
#define NOT_REGISTERED (-1)
37
38
38
- int rtc_spinlock ;
39
39
static DRAM_ATTR int s_rtc_isr_handler_list_lock ;
40
40
#define RTC_ISR_HANDLER_ENTER_CRITICAL () do { s_rtc_isr_handler_list_lock = irq_lock(); } while(0)
41
41
#define RTC_ISR_HANDLER_EXIT_CRITICAL () irq_unlock(s_rtc_isr_handler_list_lock);
Original file line number Diff line number Diff line change 10
10
#include "soc/soc_caps.h"
11
11
#include "esp_private/sar_periph_ctrl.h"
12
12
#include "esp_log.h"
13
+ #include "rtc_lock.h"
13
14
14
15
#if SOC_TEMP_SENSOR_SUPPORTED
15
16
#include "hal/temperature_sensor_ll.h"
18
19
#include "esp_private/periph_ctrl.h"
19
20
#include "esp_private/adc_share_hw_ctrl.h"
20
21
21
- extern int rtc_spinlock ;
22
-
23
- #define RTC_ENTER_CRITICAL () do { rtc_spinlock = irq_lock(); } while(0)
24
- #define RTC_EXIT_CRITICAL () irq_unlock(rtc_spinlock);
25
-
26
-
27
22
/*------------------------------------------------------------------------------------------------------------
28
23
-----------------------------------------Temperature Sensor---------------------------------------------------
29
24
------------------------------------------------------------------------------------------------------------*/
You can’t perform that action at this time.
0 commit comments