mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
periph_clk_gating: add reference counter
This commit is contained in:
parent
99f0dc78c8
commit
e0b9f7be6d
@ -28,6 +28,10 @@ extern "C" {
|
||||
*
|
||||
* Clock for the module will be ungated, and reset de-asserted.
|
||||
*
|
||||
* @note If periph_module_enable is called a number of times,
|
||||
* periph_module_disable has to be called the same number of times
|
||||
* in order to put the peripheral into disabled state.
|
||||
*
|
||||
* @return NULL
|
||||
*
|
||||
*/
|
||||
@ -40,6 +44,10 @@ void periph_module_enable(periph_module_t periph);
|
||||
*
|
||||
* Clock for the module will be gated, reset asserted.
|
||||
*
|
||||
* @note If periph_module_enable is called a number of times,
|
||||
* periph_module_disable has to be called the same number of times
|
||||
* in order to put the peripheral into disabled state.
|
||||
*
|
||||
* @return NULL
|
||||
*
|
||||
*/
|
||||
|
@ -17,22 +17,33 @@
|
||||
|
||||
static portMUX_TYPE periph_spinlock = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
static uint8_t ref_counts[PERIPH_MODULE_MAX] = {0};
|
||||
|
||||
void periph_module_enable(periph_module_t periph)
|
||||
{
|
||||
assert(periph < PERIPH_MODULE_MAX);
|
||||
portENTER_CRITICAL_SAFE(&periph_spinlock);
|
||||
periph_ll_enable_clk_clear_rst(periph);
|
||||
if (ref_counts[periph] == 0) {
|
||||
periph_ll_enable_clk_clear_rst(periph);
|
||||
}
|
||||
ref_counts[periph]++;
|
||||
portEXIT_CRITICAL_SAFE(&periph_spinlock);
|
||||
}
|
||||
|
||||
void periph_module_disable(periph_module_t periph)
|
||||
{
|
||||
assert(periph < PERIPH_MODULE_MAX);
|
||||
portENTER_CRITICAL_SAFE(&periph_spinlock);
|
||||
periph_ll_disable_clk_set_rst(periph);
|
||||
ref_counts[periph]--;
|
||||
if (ref_counts[periph] == 0) {
|
||||
periph_ll_disable_clk_set_rst(periph);
|
||||
}
|
||||
portEXIT_CRITICAL_SAFE(&periph_spinlock);
|
||||
}
|
||||
|
||||
void periph_module_reset(periph_module_t periph)
|
||||
{
|
||||
assert(periph < PERIPH_MODULE_MAX);
|
||||
portENTER_CRITICAL_SAFE(&periph_spinlock);
|
||||
periph_ll_reset(periph);
|
||||
portEXIT_CRITICAL_SAFE(&periph_spinlock);
|
||||
|
@ -55,6 +55,7 @@ typedef enum {
|
||||
PERIPH_AES_MODULE,
|
||||
PERIPH_SHA_MODULE,
|
||||
PERIPH_RSA_MODULE,
|
||||
PERIPH_MODULE_MAX
|
||||
} periph_module_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -54,6 +54,7 @@ typedef enum {
|
||||
PERIPH_CRYPTO_DMA_MODULE, //this DMA is shared between AES and SHA
|
||||
PERIPH_AES_DMA_MODULE,
|
||||
PERIPH_SHA_DMA_MODULE,
|
||||
PERIPH_MODULE_MAX
|
||||
} periph_module_t;
|
||||
|
||||
typedef enum {
|
||||
|
Loading…
x
Reference in New Issue
Block a user