Chip-specific system clock management functions.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
Macros | |
#define | ASM __asm__ |
#define | CONFIG_SYSCLK_PSDIV SYSCLK_PSDIV_8 |
#define | PRADC_bm 1 << PRADC |
#define | PRSPI_bm 1 << PRSPI |
#define | PRTIM0_bm 1 << PRTIM0 |
#define | PRTIM1_bm 1 << PRTIM1 |
#define | PRTIM2_bm 1 << PRTIM2 |
#define | PRTWI_bm 1 << PRTWI |
#define | PRUSART0_bm 1 << PRUSART0 |
#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 CONFIG_SYSCLK_PSDIV SYSCLK_PSDIV_8 |
Referenced by sysclk_get_rc_osc_hz(), sysclk_get_source_clock_hz(), sysclk_init(), and sysclk_set_prescalers().
#define PRADC_bm 1 << PRADC |
Referenced by sysclk_disable_peripheral_clock(), and sysclk_enable_peripheral_clock().
#define PRSPI_bm 1 << PRSPI |
Referenced by spi_master_init(), spi_slave_init(), sysclk_disable_peripheral_clock(), and sysclk_enable_peripheral_clock().
#define PRTIM0_bm 1 << PRTIM0 |
Referenced by sysclk_disable_peripheral_clock(), and sysclk_enable_peripheral_clock().
#define PRTIM1_bm 1 << PRTIM1 |
Referenced by sysclk_disable_peripheral_clock(), and sysclk_enable_peripheral_clock().
#define PRTIM2_bm 1 << PRTIM2 |
Referenced by sysclk_disable_peripheral_clock(), and sysclk_enable_peripheral_clock().
#define PRTWI_bm 1 << PRTWI |
#define PRUSART0_bm 1 << PRUSART0 |
#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, NULL, PRADC_bm, PRSPI_bm, PRTIM0_bm, PRTIM1_bm, PRTIM2_bm, PRTWI_bm, PRUSART0_bm, and sysclk_disable_module().
Referenced by get_temperature(), and tc_disable().
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 run_loopback_syncmode_test(), spi_master_init(), spi_slave_init(), sysclk_enable_peripheral_clock(), usart_enable_module_clock(), and usart_spi_init().
|
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, NULL, PRADC_bm, PRSPI_bm, PRTIM0_bm, PRTIM1_bm, PRTIM2_bm, PRTWI_bm, PRUSART0_bm, and sysclk_enable_module().
Referenced by adc_initialisation(), epd_spi_init(), get_temperature(), initialize_EPD_timer(), main(), PHY_Init(), PWM_start_toggle(), run_baudrate_set_test(), run_spi_transfer_test(), run_twi_master_recv_test(), run_twi_master_send_test(), sm_init(), tc_enable(), tfa_init(), timer2_initialisation(), trx_init(), twi_master_setup(), and twi_slave_setup().
|
inlinestatic |
Return the current rate in Hz of the CPU clock.
References sysclk_get_source_clock_hz().
Referenced by main(), run_baudrate_test(), run_spi_transfer_test(), run_twi_master_recv_test(), run_twi_master_send_test(), spi_master_setup_device(), and twi_master_setup().
|
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.
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, NULL, PRTWI_bm, sysclk_disable_module(), and sysclk_get_source_clock_hz().
Referenced by initialize_EPD_timer(), PWM_start_toggle(), and tmr_init().
|
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, and SYSCLK_PSDIV_8.
|
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, and SYSCLK_PSDIV_8.
Referenced by run_loopback_syncmode_test(), sysclk_get_cpu_hz(), sysclk_get_peripheral_bus_hz(), usart_init_rs232(), and usart_init_spi().
|
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().