This group contains functions and definitions related to configuring and enabling/disabling on-chip PLLs.
A PLL will take an input signal (the source), optionally divide the frequency by a configurable divider, and then multiply the frequency by a configurable multiplier.
Some devices don't support input dividers; specifying any other divisor than 1 on these devices will result in an assertion failure. Other devices may have various restrictions to the frequency range of the input and output signals.
The following example shows how to configure and enable PLL0 using the default parameters specified using the configuration symbols listed above.
To configure, enable PLL0 using the default parameters and to disable a specific feature like Wide Bandwidth Mode (a UC3A3-specific PLL option.), you can use this initialization process.
When the last function call returns, PLL0 is ready to be used as the main system clock source.
Each PLL has a set of default parameters determined by the following configuration symbols in the application's configuration file:
These configuration symbols determine the result of calling pll_config_defaults() and pll_get_default_rate().
Data Structures | |
struct | pll_config |
Hardware-specific representation of PLL configuration. More... | |
Macros | |
#define | PLL_TIMEOUT_MS div_ceil(1000 * (PLL_MAX_STARTUP_CYCLES * 2), OSC_SLOW_MIN_HZ) |
Number of milliseconds to wait for PLL lock. More... | |
Enumerations | |
enum | pll_source { PLL_SRC_OSC0 = 0, PLL_SRC_OSC1 = 1, PLL_NR_SOURCES } |
PLL clock source. More... | |
Chip-specific PLL characteristics | |
#define | PLL_MAX_STARTUP_CYCLES ((1 << AVR32_PM_PLL0_PLLCOUNT_SIZE) - 1) |
Maximum PLL startup time in number of slow clock cycles. More... | |
#define | NR_PLLS 2 |
Number of on-chip PLLs. More... | |
#define | PLL_MIN_HZ 40000000 |
Minimum frequency that the PLL can generate. More... | |
#define | PLL_MAX_HZ 240000000 |
Maximum frequency that the PLL can generate. More... | |
PLL configuration | |
static void | pll_config_set_option (struct pll_config *cfg, unsigned int option) |
Set the PLL option bit option in the configuration cfg. More... | |
static void | pll_config_clear_option (struct pll_config *cfg, unsigned int option) |
Clear the PLL option bit option in the configuration cfg. More... | |
static void | pll_config_init (struct pll_config *cfg, enum pll_source src, unsigned int div, unsigned int mul) |
The PLL options PLL_OPT_VCO_RANGE_LOW and PLL_OPT_OUTPUT_DIV will be set automatically based on the calculated target frequency. More... | |
static void | pll_config_read (struct pll_config *cfg, unsigned int pll_id) |
Read the currently active configuration of pll_id. More... | |
static void | pll_config_write (const struct pll_config *cfg, unsigned int pll_id) |
Activate the configuration cfg on pll_id. More... | |
#define | pll_config_defaults(cfg, pll_id) |
Initialize PLL configuration using default parameters. More... | |
#define | pll_get_default_rate(pll_id) |
Get the default rate in Hz of pll_id. More... | |
Interaction with the PLL hardware | |
static int | pll_wait_for_lock (unsigned int pll_id) |
Wait for PLL pll_id to become locked. More... | |
static void | pll_enable (const struct pll_config *cfg, unsigned int pll_id) |
Activate the configuration cfg and enable PLL pll_id. More... | |
static void | pll_disable (unsigned int pll_id) |
Disable the PLL identified by pll_id. More... | |
static bool | pll_is_locked (unsigned int pll_id) |
Determine whether the PLL is locked or not. More... | |
static void | pll_enable_source (enum pll_source src) |
Enable the source of the pll. More... | |
static void | pll_enable_config_defaults (unsigned int pll_id) |
Enable the pll with the default configuration. More... | |
Chip-specific PLL options | |
#define | PLL_NR_OPTIONS AVR32_PM_PLL0_PLLOPT_SIZE |
Number of PLL option bits. More... | |
#define | PLL_OPT_VCO_RANGE_LOW 0 |
VCO frequency range is 80-180 MHz (160-240 MHz if unset). More... | |
#define | PLL_OPT_OUTPUT_DIV 1 |
Divide output frequency by two. More... | |
#define | PLL_OPT_WBM_DISABLE 2 |
Disable wide-bandwidth mode. More... | |
#define | PLL_VCO_LOW_THRESHOLD |
The threshold under which to set the PLL_OPT_VCO_RANGE_LOW option. More... | |
#define NR_PLLS 2 |
Number of on-chip PLLs.
Referenced by pll_config_read(), pll_config_write(), pll_disable(), pll_enable(), pll_is_locked(), and pll_wait_for_lock().
#define pll_config_defaults | ( | cfg, | |
pll_id | |||
) |
Initialize PLL configuration using default parameters.
After this function returns, cfg will contain a configuration which will make the PLL run at (CONFIG_PLLx_MUL / CONFIG_PLLx_DIV) times the frequency of CONFIG_PLLx_SOURCE.
cfg | The PLL configuration to be initialized. |
pll_id | Use defaults for this PLL. |
#define pll_get_default_rate | ( | pll_id | ) |
Get the default rate in Hz of pll_id.
Referenced by sysclk_get_main_hz().
#define PLL_MAX_HZ 240000000 |
Maximum frequency that the PLL can generate.
Referenced by pll_config_init().
#define PLL_MAX_STARTUP_CYCLES ((1 << AVR32_PM_PLL0_PLLCOUNT_SIZE) - 1) |
Maximum PLL startup time in number of slow clock cycles.
Referenced by pll_config_init().
#define PLL_MIN_HZ 40000000 |
Minimum frequency that the PLL can generate.
Referenced by pll_config_init().
#define PLL_NR_OPTIONS AVR32_PM_PLL0_PLLOPT_SIZE |
Number of PLL option bits.
Number of PLL options.
Referenced by pll_config_clear_option(), and pll_config_set_option().
#define PLL_OPT_OUTPUT_DIV 1 |
Divide output frequency by two.
Referenced by pll_config_init().
#define PLL_OPT_VCO_RANGE_LOW 0 |
VCO frequency range is 80-180 MHz (160-240 MHz if unset).
Referenced by pll_config_init().
#define PLL_OPT_WBM_DISABLE 2 |
Disable wide-bandwidth mode.
#define PLL_TIMEOUT_MS div_ceil(1000 * (PLL_MAX_STARTUP_CYCLES * 2), OSC_SLOW_MIN_HZ) |
Number of milliseconds to wait for PLL lock.
#define PLL_VCO_LOW_THRESHOLD |
The threshold under which to set the PLL_OPT_VCO_RANGE_LOW option.
Referenced by pll_config_init().
enum pll_source |
|
inlinestatic |
Clear the PLL option bit option in the configuration cfg.
cfg | The PLL configuration to be changed. |
option | The PLL option bit to be cleared. |
References Assert, pll_config::ctrl, and PLL_NR_OPTIONS.
|
inlinestatic |
The PLL options PLL_OPT_VCO_RANGE_LOW and PLL_OPT_OUTPUT_DIV will be set automatically based on the calculated target frequency.
Initialize PLL configuration from standard parameters.
cfg | The PLL configuration to be initialized. |
src | The oscillator to be used as input to the PLL. |
div | PLL input divider. |
mul | PLL loop divider (i.e. multiplier). |
References Assert, pll_config::ctrl, osc_get_rate(), pll_config_set_option(), PLL_MAX_HZ, PLL_MAX_STARTUP_CYCLES, PLL_MIN_HZ, PLL_NR_SOURCES, PLL_OPT_OUTPUT_DIV, PLL_OPT_VCO_RANGE_LOW, and PLL_VCO_LOW_THRESHOLD.
Referenced by pll_enable_config_defaults().
|
inlinestatic |
Read the currently active configuration of pll_id.
cfg | The configuration object into which to store the currently active configuration. |
pll_id | The ID of the PLL to be accessed. |
References Assert, pll_config::ctrl, and NR_PLLS.
|
inlinestatic |
Set the PLL option bit option in the configuration cfg.
cfg | The PLL configuration to be changed. |
option | The PLL option bit to be set. |
References Assert, pll_config::ctrl, and PLL_NR_OPTIONS.
Referenced by pll_config_init().
|
inlinestatic |
Activate the configuration cfg on pll_id.
cfg | The configuration object representing the PLL configuration to be activated. |
pll_id | The ID of the PLL to be updated. |
References Assert, pll_config::ctrl, and NR_PLLS.
|
inlinestatic |
Disable the PLL identified by pll_id.
After this function is called, the PLL identified by pll_id will be disabled. The PLL configuration stored in hardware may be affected by this, so if the caller needs to restore the same configuration later, it should either do a pll_config_read() before disabling the PLL, or remember the last configuration written to the PLL.
pll_id | The ID of the PLL to be disabled. |
|
inlinestatic |
Activate the configuration cfg and enable PLL pll_id.
cfg | The PLL configuration to be activated. |
pll_id | The ID of the PLL to be enabled. |
References Assert, pll_config::ctrl, and NR_PLLS.
Referenced by pll_enable_config_defaults().
|
inlinestatic |
Enable the pll with the default configuration.
PLL is enabled, if the PLL is not already locked.
pll_id | The ID of the PLL to enable. |
References Assert, CONFIG_PLL0_DIV, CONFIG_PLL0_MUL, CONFIG_PLL0_SOURCE, CONFIG_PLL1_DIV, CONFIG_PLL1_MUL, CONFIG_PLL1_SOURCE, pll_config_init(), pll_enable(), pll_enable_source(), and pll_is_locked().
Referenced by genclk_enable_source(), and sysclk_init().
|
inlinestatic |
Enable the source of the pll.
The source is enabled, if the source is not already running.
src | The ID of the PLL source to enable. |
References Assert, osc_enable(), OSC_ID_OSC0, OSC_ID_OSC1, osc_is_ready(), osc_wait_ready(), PLL_SRC_OSC0, and PLL_SRC_OSC1.
Referenced by pll_enable_config_defaults().
|
inlinestatic |
Determine whether the PLL is locked or not.
pll_id | The ID of the PLL to check. |
true | The PLL is locked and ready to use as a clock source |
false | The PLL is not yet locked, or has not been enabled. |
References Assert, and NR_PLLS.
Referenced by pll_enable_config_defaults(), and pll_wait_for_lock().
|
inlinestatic |
Wait for PLL pll_id to become locked.
pll_id | The ID of the PLL to wait for. |
STATUS_OK | The PLL is now locked. |
ERR_TIMEOUT | Timed out waiting for PLL to become locked. |
References Assert, NR_PLLS, and pll_is_locked().