Chip-specific system clock management functions.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
Macros | |
#define | ASM __asm__ |
#define | SYSCLK_PSDIV_1 0 /* !< Do not prescale */ |
#define | SYSCLK_PSDIV_2 1 /* !< Prescale CLKper4 by 2 */ |
#define | SYSCLK_PSDIV_4 2 /* !< Prescale CLKper4 by 4 */ |
#define | SYSCLK_PSDIV_8 3 /* !< Prescale CLKper4 by 8 */ |
#define | SYSCLK_PSDIV_16 4 /* !< Prescale CLKper4 by 16 */ |
#define | SYSCLK_PSDIV_32 5 /* !< Prescale CLKper4 by 32 */ |
#define | SYSCLK_PSDIV_64 6 /* !< Prescale CLKper4 by 64 */ |
#define | SYSCLK_PSDIV_128 7 /* !< Prescale CLKper4 by 128 */ |
#define | SYSCLK_PSDIV_256 8 /* !< Prescale CLKper4 by 256 */ |
Functions | |
Querying the system clock and its derived clocks | |
static uint32_t | sysclk_get_main_hz (void) |
Return the current rate in Hz of the main system clock To know the clock value at what frequency the main clock is running. More... | |
static uint32_t | sysclk_get_source_clock_hz (void) |
Return the current rate in Hz of source clock in Hz. More... | |
static uint32_t | sysclk_get_cpu_hz (void) |
Return the current rate in Hz of the CPU clock. More... | |
static uint32_t | sysclk_get_rc_osc_hz (void) |
Return the current rate in Hz of the clock from internal oscillator. More... | |
void | sysclk_enable_module (enum power_red_id port, uint8_t id) |
Enable the clock to peripheral id on port port. More... | |
void | sysclk_disable_module (enum power_red_id port, uint8_t id) |
Disable the clock to peripheral id on port port. More... | |
static void | sysclk_enable_peripheral_clock (const volatile void *module) |
Enable a peripherals clock from its base address. More... | |
static void | sysclk_disable_peripheral_clock (const volatile void *module) |
Disable a peripheral's clock from its base address. More... | |
static void | sysclk_set_prescalers (uint8_t psdiv) |
Set system clock prescaler configuration. More... | |
static uint32_t | sysclk_get_peripheral_bus_hz (const volatile void *module) |
Retrieves the current rate in Hz of the Peripheral Bus clock attached to the specified peripheral. More... | |
static bool | sysclk_module_is_enabled (enum power_red_id port, uint8_t id) |
Check if the synchronous clock is enabled for a module. More... | |
void | sysclk_init (void) |
Function to initialize the clock and disable clock for not required modules. More... | |
#define ASM __asm__ |
Referenced by sysclk_set_prescalers().
#define SYSCLK_PSDIV_1 0 /* !< Do not prescale */ |
Referenced by sysclk_get_rc_osc_hz(), sysclk_get_source_clock_hz(), and sysclk_set_prescalers().
#define SYSCLK_PSDIV_128 7 /* !< Prescale CLKper4 by 128 */ |
Referenced by sysclk_get_rc_osc_hz(), sysclk_get_source_clock_hz(), and sysclk_set_prescalers().
#define SYSCLK_PSDIV_16 4 /* !< Prescale CLKper4 by 16 */ |
Referenced by sysclk_get_rc_osc_hz(), sysclk_get_source_clock_hz(), and sysclk_set_prescalers().
#define SYSCLK_PSDIV_2 1 /* !< Prescale CLKper4 by 2 */ |
Referenced by sysclk_get_rc_osc_hz(), sysclk_get_source_clock_hz(), and sysclk_set_prescalers().
#define SYSCLK_PSDIV_256 8 /* !< Prescale CLKper4 by 256 */ |
Referenced by sysclk_get_rc_osc_hz(), sysclk_get_source_clock_hz(), and sysclk_set_prescalers().
#define SYSCLK_PSDIV_32 5 /* !< Prescale CLKper4 by 32 */ |
Referenced by sysclk_get_rc_osc_hz(), sysclk_get_source_clock_hz(), and sysclk_set_prescalers().
#define SYSCLK_PSDIV_4 2 /* !< Prescale CLKper4 by 4 */ |
Referenced by sysclk_get_rc_osc_hz(), sysclk_get_source_clock_hz(), and sysclk_set_prescalers().
#define SYSCLK_PSDIV_64 6 /* !< Prescale CLKper4 by 64 */ |
Referenced by sysclk_get_rc_osc_hz(), sysclk_get_source_clock_hz(), and sysclk_set_prescalers().
#define SYSCLK_PSDIV_8 3 /* !< Prescale CLKper4 by 8 */ |
Referenced by sysclk_get_rc_osc_hz(), sysclk_get_source_clock_hz(), sysclk_init(), and sysclk_set_prescalers().
void sysclk_disable_module | ( | enum power_red_id | port, |
uint8_t | id | ||
) |
Disable the clock to peripheral id on port port.
port | ID of the port to which the module is connected (one of the power_red_id *definitions). |
id | The ID (bit mask) of the peripheral module to be disabled. |
References cpu_irq_restore(), and cpu_irq_save().
Referenced by sysclk_disable_peripheral_clock(), and sysclk_get_peripheral_bus_hz().
|
inlinestatic |
Disable a peripheral's clock from its base address.
Disables the clock to a peripheral, given its base address.
module | Pointer to the module's base address. |
References Assert, and sysclk_disable_module().
void sysclk_enable_module | ( | enum power_red_id | port, |
uint8_t | id | ||
) |
Enable the clock to peripheral id on port port.
port | ID of the port to which the module is connected (one of the power_red_id *definitions). |
id | The ID (bitmask) of the peripheral module to be disabled.* |
port | ID of the port to which the module is connected (one of the power_red_id *definitions). |
id | The ID (bitmask) of the peripheral module to be enabled. |
References cpu_irq_restore(), and cpu_irq_save().
Referenced by sysclk_enable_peripheral_clock().
|
inlinestatic |
Enable a peripherals clock from its base address.
Enables the clock to a peripheral, given its base address. If the peripheral has an associated clock on the HSB bus, this will be enabled also.
module | Pointer to the module's base address. |
References Assert, and sysclk_enable_module().
|
inlinestatic |
Return the current rate in Hz of the CPU clock.
References sysclk_get_source_clock_hz().
|
inlinestatic |
Return the current rate in Hz of the main system clock To know the clock value at what frequency the main clock is running.
References SYSCLK_SOURCE, SYSCLK_SRC_EXTERNAL, SYSCLK_SRC_RC128KHZ, SYSCLK_SRC_RC16MHZ, and SYSCLK_SRC_TRS16MHZ.
Referenced by sysclk_get_rc_osc_hz(), and sysclk_get_source_clock_hz().
|
inlinestatic |
Retrieves the current rate in Hz of the Peripheral Bus clock attached to the specified peripheral.
module | Pointer to the module's base address. |
References Assert, sysclk_disable_module(), and sysclk_get_source_clock_hz().
|
inlinestatic |
Return the current rate in Hz of the clock from internal oscillator.
References CONFIG_SYSCLK_PSDIV, sysclk_get_main_hz(), SYSCLK_PSDIV_1, SYSCLK_PSDIV_128, SYSCLK_PSDIV_16, SYSCLK_PSDIV_2, SYSCLK_PSDIV_256, SYSCLK_PSDIV_32, SYSCLK_PSDIV_4, SYSCLK_PSDIV_64, SYSCLK_PSDIV_8, SYSCLK_SOURCE, SYSCLK_SRC_RC128KHZ, and SYSCLK_SRC_RC16MHZ.
|
inlinestatic |
Return the current rate in Hz of source clock in Hz.
This clock always runs at the same rate as the CPU clock unless the divider is set.
References CONFIG_SYSCLK_PSDIV, sysclk_get_main_hz(), SYSCLK_PSDIV_1, SYSCLK_PSDIV_128, SYSCLK_PSDIV_16, SYSCLK_PSDIV_2, SYSCLK_PSDIV_256, SYSCLK_PSDIV_32, SYSCLK_PSDIV_4, SYSCLK_PSDIV_64, SYSCLK_PSDIV_8, SYSCLK_SOURCE, SYSCLK_SRC_RC128KHZ, and SYSCLK_SRC_RC16MHZ.
Referenced by sysclk_get_cpu_hz(), and sysclk_get_peripheral_bus_hz().
|
inlinestatic |
Check if the synchronous clock is enabled for a module.
port | ID of the port to which the module is connected (one of the SYSCLK_PORT_* definitions). |
id | The ID (bitmask) of the peripheral module to check (one of the SYSCLK_* module definitions). |
true | If the clock for module id on port is enabled. |
false | If the clock for module id on port is disabled. |
|
inlinestatic |
Set system clock prescaler configuration.
This function will change the system clock prescaler configuration to match the parameters.
psbcdiv | The prescaler settings (one of the SYSCLK_PSCDIV_* definitions). These determine the clkIO, clkADC and clkCPU frequencies. Note: Prescaler setting is not working with the brain dead un optimised code e.g. avr-gcc -00 |
References ASM, CONFIG_SYSCLK_PSDIV, cpu_irq_restore(), cpu_irq_save(), SYSCLK_PSDIV_1, SYSCLK_PSDIV_128, SYSCLK_PSDIV_16, SYSCLK_PSDIV_2, SYSCLK_PSDIV_256, SYSCLK_PSDIV_32, SYSCLK_PSDIV_4, SYSCLK_PSDIV_64, and SYSCLK_PSDIV_8.
Referenced by sysclk_init().