@@ -45,11 +45,6 @@ static const char *ADC_TAG = "ADC";
45
45
//////////////////////// Locks ///////////////////////////////////////////
46
46
LOG_MODULE_REGISTER (adc_legacy , CONFIG_ADC_LOG_LEVEL );
47
47
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
48
#define DIGI_ENTER_CRITICAL ()
54
49
#define DIGI_EXIT_CRITICAL ()
55
50
@@ -142,9 +137,9 @@ esp_err_t adc2_pad_get_io_num(adc2_channel_t channel, gpio_num_t *gpio_num)
142
137
#if SOC_ADC_RTC_CTRL_SUPPORTED
143
138
esp_err_t adc_set_clk_div (uint8_t clk_div )
144
139
{
145
- DIGI_CONTROLLER_ENTER ();
140
+ unsigned int key = irq_lock ();
146
141
adc_ll_digi_set_clk_div (clk_div );
147
- DIGI_CONTROLLER_EXIT ( );
142
+ irq_unlock ( key );
148
143
return ESP_OK ;
149
144
}
150
145
@@ -195,15 +190,17 @@ esp_err_t adc_common_gpio_init(adc_unit_t adc_unit, adc_channel_t channel)
195
190
196
191
esp_err_t adc_set_data_inv (adc_unit_t adc_unit , bool inv_en )
197
192
{
193
+ unsigned int key ;
194
+
198
195
if (adc_unit == ADC_UNIT_1 ) {
199
- SARADC1_ENTER ();
196
+ key = irq_lock ();
200
197
adc_oneshot_ll_output_invert (ADC_UNIT_1 , inv_en );
201
- SARADC1_EXIT ( );
198
+ irq_unlock ( key );
202
199
}
203
200
if (adc_unit == ADC_UNIT_2 ) {
204
- SARADC2_ENTER ();
201
+ key = irq_lock ();
205
202
adc_oneshot_ll_output_invert (ADC_UNIT_2 , inv_en );
206
- SARADC2_EXIT ( );
203
+ irq_unlock ( key );
207
204
}
208
205
209
206
return ESP_OK ;
@@ -213,6 +210,7 @@ esp_err_t adc_set_data_width(adc_unit_t adc_unit, adc_bits_width_t width_bit)
213
210
{
214
211
ESP_RETURN_ON_FALSE (width_bit < ADC_WIDTH_MAX , ESP_ERR_INVALID_ARG , ADC_TAG , "unsupported bit width" );
215
212
adc_bitwidth_t bitwidth = 0 ;
213
+ unsigned int key ;
216
214
#if CONFIG_IDF_TARGET_ESP32
217
215
if ((uint32_t )width_bit == (uint32_t )ADC_BITWIDTH_DEFAULT ) {
218
216
bitwidth = SOC_ADC_RTC_MAX_BITWIDTH ;
@@ -241,14 +239,14 @@ esp_err_t adc_set_data_width(adc_unit_t adc_unit, adc_bits_width_t width_bit)
241
239
#endif
242
240
243
241
if (adc_unit == ADC_UNIT_1 ) {
244
- SARADC1_ENTER ();
242
+ key = irq_lock ();
245
243
adc_oneshot_ll_set_output_bits (ADC_UNIT_1 , bitwidth );
246
- SARADC1_EXIT ( );
244
+ irq_unlock ( key );
247
245
}
248
246
if (adc_unit == ADC_UNIT_2 ) {
249
- SARADC2_ENTER ();
247
+ key = irq_lock ();
250
248
adc_oneshot_ll_set_output_bits (ADC_UNIT_2 , bitwidth );
251
- SARADC2_EXIT ( );
249
+ irq_unlock ( key );
252
250
}
253
251
254
252
return ESP_OK ;
@@ -263,9 +261,9 @@ esp_err_t adc_set_data_width(adc_unit_t adc_unit, adc_bits_width_t width_bit)
263
261
#if !CONFIG_IDF_TARGET_ESP32
264
262
esp_err_t adc_rtc_reset (void )
265
263
{
266
- FSM_ENTER ();
264
+ unsigned int key = irq_lock ();
267
265
adc_ll_rtc_reset ();
268
- FSM_EXIT ( );
266
+ irq_unlock ( key );
269
267
return ESP_OK ;
270
268
}
271
269
#endif
@@ -286,10 +284,10 @@ esp_err_t adc1_config_channel_atten(adc1_channel_t channel, adc_atten_t atten)
286
284
#endif //#if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
287
285
288
286
adc_common_gpio_init (ADC_UNIT_1 , channel );
289
- SARADC1_ENTER ();
287
+ unsigned int key = irq_lock ();
290
288
adc_rtc_chan_init (ADC_UNIT_1 );
291
289
adc_oneshot_ll_set_atten (ADC_UNIT_1 , channel , atten );
292
- SARADC1_EXIT ( );
290
+ irq_unlock ( key );
293
291
294
292
return ESP_OK ;
295
293
}
@@ -325,9 +323,9 @@ esp_err_t adc1_config_width(adc_bits_width_t width_bit)
325
323
bitwidth = ADC_BITWIDTH_12 ;
326
324
#endif
327
325
328
- SARADC1_ENTER ();
326
+ unsigned int key = irq_lock ();
329
327
adc_oneshot_ll_set_output_bits (ADC_UNIT_1 , bitwidth );
330
- SARADC1_EXIT ( );
328
+ irq_unlock ( key );
331
329
332
330
return ESP_OK ;
333
331
}
@@ -341,10 +339,10 @@ esp_err_t adc1_dma_mode_acquire(void)
341
339
342
340
sar_periph_ctrl_adc_continuous_power_acquire ();
343
341
344
- SARADC1_ENTER ();
342
+ unsigned int key = irq_lock ();
345
343
/* switch SARADC into DIG channel */
346
344
adc_ll_set_controller (ADC_UNIT_1 , ADC_LL_CTRL_DIG );
347
- SARADC1_EXIT ( );
345
+ irq_unlock ( key );
348
346
349
347
return ESP_OK ;
350
348
}
@@ -356,10 +354,10 @@ esp_err_t adc1_rtc_mode_acquire(void)
356
354
SARADC1_ACQUIRE ();
357
355
sar_periph_ctrl_adc_oneshot_power_acquire ();
358
356
359
- SARADC1_ENTER ();
357
+ unsigned int key = irq_lock ();
360
358
/* switch SARADC into RTC channel. */
361
359
adc_ll_set_controller (ADC_UNIT_1 , ADC_LL_CTRL_RTC );
362
- SARADC1_EXIT ( );
360
+ irq_unlock ( key );
363
361
364
362
return ESP_OK ;
365
363
}
@@ -386,7 +384,7 @@ int adc1_get_raw(adc1_channel_t channel)
386
384
adc_set_hw_calibration_code (ADC_UNIT_1 , atten );
387
385
#endif //SOC_ADC_CALIBRATION_V1_SUPPORTED
388
386
389
- SARADC1_ENTER ();
387
+ unsigned int key = irq_lock ();
390
388
#ifdef CONFIG_IDF_TARGET_ESP32
391
389
adc_ll_hall_disable (); //Disable other peripherals.
392
390
adc_ll_amp_disable (); //Currently the LNA is not open, close it by default.
@@ -397,7 +395,7 @@ int adc1_get_raw(adc1_channel_t channel)
397
395
#if !CONFIG_IDF_TARGET_ESP32
398
396
adc_ll_rtc_reset (); //Reset FSM of rtc controller
399
397
#endif
400
- SARADC1_EXIT ( );
398
+ irq_unlock ( key );
401
399
402
400
adc1_lock_release ();
403
401
return adc_value ;
@@ -413,7 +411,7 @@ void adc1_ulp_enable(void)
413
411
{
414
412
sar_periph_ctrl_adc_oneshot_power_acquire ();
415
413
416
- SARADC1_ENTER ();
414
+ unsigned int key = irq_lock ();
417
415
adc_ll_set_controller (ADC_UNIT_1 , ADC_LL_CTRL_ULP );
418
416
/* since most users do not need LNA and HALL with uLP, we disable them here
419
417
open them in the uLP if needed. */
@@ -422,7 +420,7 @@ void adc1_ulp_enable(void)
422
420
adc_ll_hall_disable ();
423
421
adc_ll_amp_disable ();
424
422
#endif
425
- SARADC1_EXIT ( );
423
+ irq_unlock ( key );
426
424
}
427
425
#endif
428
426
@@ -452,10 +450,10 @@ esp_err_t adc2_config_channel_atten(adc2_channel_t channel, adc_atten_t atten)
452
450
#endif
453
451
454
452
//avoid collision with other tasks
455
- SARADC2_ENTER ();
453
+ unsigned int key = irq_lock ();
456
454
adc_rtc_chan_init (ADC_UNIT_2 );
457
455
adc_oneshot_ll_set_atten (ADC_UNIT_2 , channel , atten );
458
- SARADC2_EXIT ( );
456
+ irq_unlock ( key );
459
457
460
458
#if CONFIG_IDF_TARGET_ESP32
461
459
adc_lock_release (ADC_UNIT_2 );
@@ -553,7 +551,7 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int *
553
551
554
552
//avoid collision with other tasks
555
553
adc2_init (); // in critical section with whole rtc module. because the PWDET use the same registers, place it here.
556
- SARADC2_ENTER ();
554
+ unsigned int key = irq_lock ();
557
555
558
556
#if SOC_ADC_ARBITER_SUPPORTED
559
557
adc_arbiter_t config = ADC_ARBITER_CONFIG_DEFAULT ();
@@ -593,7 +591,7 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int *
593
591
}
594
592
#endif //CONFIG_PM_ENABLE
595
593
#endif //CONFIG_IDF_TARGET_ESP32
596
- SARADC2_EXIT ( );
594
+ irq_unlock ( key );
597
595
598
596
sar_periph_ctrl_adc_oneshot_power_release ();
599
597
#if CONFIG_IDF_TARGET_ESP32
@@ -606,6 +604,7 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int *
606
604
607
605
esp_err_t adc_vref_to_gpio (adc_unit_t adc_unit , gpio_num_t gpio )
608
606
{
607
+ unsigned int key ;
609
608
#ifdef CONFIG_IDF_TARGET_ESP32
610
609
if (adc_unit == ADC_UNIT_1 ) {
611
610
return ESP_ERR_INVALID_ARG ;
@@ -625,13 +624,13 @@ esp_err_t adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio)
625
624
626
625
sar_periph_ctrl_adc_oneshot_power_acquire ();
627
626
if (adc_unit == ADC_UNIT_1 ) {
628
- VREF_ENTER ( 1 );
627
+ key = irq_lock ( );
629
628
adc_ll_vref_output (ADC_UNIT_1 , ch , true);
630
- VREF_EXIT ( 1 );
629
+ irq_unlock ( key );
631
630
} else if (adc_unit == ADC_UNIT_2 ) {
632
- VREF_ENTER ( 2 );
631
+ key = irq_lock ( );
633
632
adc_ll_vref_output (ADC_UNIT_2 , ch , true);
634
- VREF_EXIT ( 2 );
633
+ irq_unlock ( key );
635
634
}
636
635
637
636
//Configure RTC gpio, Only ADC2's channels IO are supported to output reference voltage.
@@ -650,10 +649,6 @@ esp_err_t adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio)
650
649
---------------------------------------------------------------*/
651
650
#include "esp_check.h"
652
651
653
- int adc_reg_lock ;
654
- #define ADC_REG_LOCK_ENTER () do { adc_reg_lock = irq_lock(); } while(0)
655
- #define ADC_REG_LOCK_EXIT () irq_unlock(adc_reg_lock);
656
-
657
652
static adc_atten_t s_atten1_single [ADC1_CHANNEL_MAX ]; //Array saving attenuate of each channel of ADC1, used by single read API
658
653
#if (SOC_ADC_PERIPH_NUM >= 2 )
659
654
static adc_atten_t s_atten2_single [ADC2_CHANNEL_MAX ]; //Array saving attenuate of each channel of ADC2, used by single read API
@@ -703,6 +698,7 @@ static esp_err_t adc_digi_gpio_init(adc_unit_t adc_unit, uint16_t channel_mask)
703
698
esp_err_t adc_vref_to_gpio (adc_unit_t adc_unit , gpio_num_t gpio )
704
699
{
705
700
esp_err_t ret ;
701
+ unsigned int key ;
706
702
uint32_t channel = ADC2_CHANNEL_MAX ;
707
703
if (adc_unit == ADC_UNIT_2 ) {
708
704
for (int i = 0 ; i < ADC2_CHANNEL_MAX ; i ++ ) {
@@ -718,13 +714,13 @@ esp_err_t adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio)
718
714
719
715
sar_periph_ctrl_adc_oneshot_power_acquire ();
720
716
if (adc_unit == ADC_UNIT_1 ) {
721
- RTC_ENTER_CRITICAL ();
717
+ key = irq_lock ();
722
718
adc_ll_vref_output (ADC_UNIT_1 , channel , true);
723
- RTC_EXIT_CRITICAL ( );
719
+ irq_unlock ( key );
724
720
} else { //ADC_UNIT_2
725
- RTC_ENTER_CRITICAL ();
721
+ key = irq_lock ();
726
722
adc_ll_vref_output (ADC_UNIT_2 , channel , true);
727
- RTC_EXIT_CRITICAL ( );
723
+ irq_unlock ( key );
728
724
}
729
725
730
726
ret = adc_digi_gpio_init (ADC_UNIT_2 , BIT (channel ));
@@ -778,10 +774,10 @@ int adc1_get_raw(adc1_channel_t channel)
778
774
adc_set_hw_calibration_code (ADC_UNIT_1 , atten );
779
775
#endif
780
776
781
- ADC_REG_LOCK_ENTER ();
777
+ unsigned int key = irq_lock ();
782
778
adc_oneshot_ll_set_atten (ADC_UNIT_1 , channel , atten );
783
779
adc_hal_convert (ADC_UNIT_1 , channel , clk_src_freq_hz , & raw_out );
784
- ADC_REG_LOCK_EXIT ( );
780
+ irq_unlock ( key );
785
781
786
782
sar_periph_ctrl_adc_oneshot_power_release ();
787
783
periph_module_disable (PERIPH_SARADC_MODULE );
@@ -834,10 +830,10 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int *
834
830
adc_set_hw_calibration_code (ADC_UNIT_2 , atten );
835
831
#endif
836
832
837
- ADC_REG_LOCK_ENTER ();
833
+ unsigned int key = irq_lock ();
838
834
adc_oneshot_ll_set_atten (ADC_UNIT_2 , channel , atten );
839
835
ret = adc_hal_convert (ADC_UNIT_2 , channel , clk_src_freq_hz , raw_out );
840
- ADC_REG_LOCK_EXIT ( );
836
+ irq_unlock ( key );
841
837
842
838
sar_periph_ctrl_adc_oneshot_power_release ();
843
839
periph_module_disable (PERIPH_SARADC_MODULE );
0 commit comments