2020-02-03 19:19:31 +01:00
|
|
|
#ifndef __CLOCK_ENABLE_MANAGER_H__
|
|
|
|
#define __CLOCK_ENABLE_MANAGER_H__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stm32-gpio-macros.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The RCC Enable Manager uses static memory with a fixed maximum
|
|
|
|
*/
|
|
|
|
#define RCC_ENABLE_MANAGER_STATIC 1U
|
|
|
|
|
|
|
|
#if RCC_ENABLE_MANAGER_STATIC
|
2020-02-03 19:40:59 +01:00
|
|
|
#define RCC_ENABLE_MANAGER_COUNT 30U
|
2020-02-03 19:19:31 +01:00
|
|
|
#else
|
|
|
|
#error "RCC Enable Manager not yet implemented with dynamic memory"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enable Clock for peripheral by setting the corresponding bit (@p bit_no) to one
|
|
|
|
*
|
|
|
|
* This function also keeps a enable count on each bit that is set, in order to allow nested enables/disables
|
|
|
|
*
|
|
|
|
* If there is no more space to track a new register bit in memory (either due to the static limit or due to no remaining heap space),
|
|
|
|
* the function still enables the peripheral clock but does not track it and returns -1
|
|
|
|
*
|
|
|
|
* @param rcc_enable_register
|
|
|
|
* @param bit_no
|
|
|
|
*
|
|
|
|
* @return 0 if successful
|
|
|
|
*/
|
2020-02-03 19:40:59 +01:00
|
|
|
int rcc_manager_enable_clock(volatile uint32_t *rcc_enable_register, uint8_t bit_no);
|
2020-02-03 19:19:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable clock for peripheral and decrement the enaböe-counter of that bit.
|
|
|
|
*
|
|
|
|
* If there is no bit entry in the counting table yet, teh peripheral clock is not disabled and error code
|
|
|
|
* -1 is returned.
|
|
|
|
*
|
|
|
|
* If the count reaches zero, the element is removed from the list to make room for new ones
|
|
|
|
*
|
|
|
|
* @param rcc_enable_register Register to disable the bit in
|
|
|
|
* @param bit_no Bit number (0 to 31) of the bit to disable
|
|
|
|
* @return 0 if successful
|
|
|
|
*/
|
2020-02-03 19:40:59 +01:00
|
|
|
int rcc_manager_disable_clock(volatile uint32_t *rcc_enable_register, uint8_t bit_no);
|
2020-02-03 19:19:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
#endif /* __CLOCK_ENABLE_MANAGER_H__ */
|