periph_ctrl.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "freertos/FreeRTOS.h"
  15. #include "hal/clk_gate_ll.h"
  16. #include "driver/periph_ctrl.h"
  17. static portMUX_TYPE periph_spinlock = portMUX_INITIALIZER_UNLOCKED;
  18. void periph_module_enable(periph_module_t periph)
  19. {
  20. portENTER_CRITICAL_SAFE(&periph_spinlock);
  21. periph_ll_enable_clk_clear_rst(periph);
  22. portEXIT_CRITICAL_SAFE(&periph_spinlock);
  23. }
  24. void periph_module_disable(periph_module_t periph)
  25. {
  26. portENTER_CRITICAL_SAFE(&periph_spinlock);
  27. periph_ll_disable_clk_set_rst(periph);
  28. portEXIT_CRITICAL_SAFE(&periph_spinlock);
  29. }
  30. void periph_module_reset(periph_module_t periph)
  31. {
  32. portENTER_CRITICAL_SAFE(&periph_spinlock);
  33. periph_ll_reset(periph);
  34. portEXIT_CRITICAL_SAFE(&periph_spinlock);
  35. }