reflow-oven-control-sw/stm-firmware/include/stm-periph/clock-enable-manager.h

49 lines
1.6 KiB
C
Raw Normal View History

#ifndef __CLOCK_ENABLE_MANAGER_H__
#define __CLOCK_ENABLE_MANAGER_H__
#include <stdint.h>
2020-02-12 21:00:35 +01:00
#include <stm-periph/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
#define RCC_ENABLE_MANAGER_COUNT 30U
#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
*/
int rcc_manager_enable_clock(volatile uint32_t *rcc_enable_register, uint8_t bit_no);
/**
* @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
*/
int rcc_manager_disable_clock(volatile uint32_t *rcc_enable_register, uint8_t bit_no);
#endif /* __CLOCK_ENABLE_MANAGER_H__ */