Clock Manager API Reference#

The Clock Manager provides seven main API categories for comprehensive clock management:

API Category

Description

Initialization

Core initialization functions for oscillators, clock tree setup, and runtime initialization enabling comprehensive clock management capabilities

Frequency and Precision Query

Runtime frequency and precision retrieval for oscillators and clock branches enabling accurate timing calculations and peripheral configuration

Bus Clock Control

Peripheral bus clock enable/disable functions for power management and register access control with support for on-demand clock activation

Oscillator Calibration

Advanced calibration functions for HFXO, LFXO, and RC oscillators supporting runtime tuning and temperature compensation with precision control

Clock Export

GPIO clock output functionality for external timing signals and debugging with configurable clock sources and dividers

RCO Calibration

Hardware-supported RCO calibration process for runtime oscillator tuning using high-precision reference clocks with automated calibration cycles

Advanced Clock Management

Specialized functions for SYSCLK control, external flash clock management, and advanced timing features for runtime clock manipulation

The following table lists all the functions in each API category for a quick reference by function names.

Category

Functions

Initialization

sl_clock_manager_init(), sl_clock_manager_runtime_init()

Frequency and Precision Query

sl_clock_manager_get_oscillator_frequency(), sl_clock_manager_get_oscillator_precision(), sl_clock_manager_get_clock_branch_frequency(), sl_clock_manager_get_clock_branch_precision()

Bus Clock Control

sl_clock_manager_enable_bus_clock(), sl_clock_manager_disable_bus_clock()

Oscillator Calibration

sl_clock_manager_set_rc_oscillator_calibration(), sl_clock_manager_get_rc_oscillator_calibration(), sl_clock_manager_set_hfxo_calibration(), sl_clock_manager_get_hfxo_calibration(), slx_clock_manager_hfxo_set_ctune(), slx_clock_manager_hfxo_get_ctune(), slx_clock_manager_hfxo_calibrate_ctune(), sl_clock_manager_set_lfxo_calibration(), sl_clock_manager_get_lfxo_calibration()

Clock Export

sl_clock_manager_set_gpio_clock_output()

RCO Calibration

sl_clock_manager_configure_rco_calibration(), sl_clock_manager_start_rco_calibration(), sl_clock_manager_stop_rco_calibration(), sl_clock_manager_wait_rco_calibration(), sl_clock_manager_get_rco_calibration_count()

Advanced Clock Management

sl_clock_manager_set_ext_flash_clk(), sl_clock_manager_get_ext_flash_clk(), slx_clock_manager_set_sysclk_source(), sl_clock_manager_get_sysclk_source(), sl_clock_manager_wait_usbpll()

The following sub-sections cover the most frequently used APIs for typical applications. For a complete API documentation of all functions not described in the sub-sections below, refer to the Clock Manager API documentation.

Frequency and Precision Query APIs#

Clock Branch Frequency Query#

sl_clock_manager_get_clock_branch_frequency#

sl_status_t sl_clock_manager_get_clock_branch_frequency(sl_clock_branch_t clock_branch, uint32_t *frequency);

Description: Retrieves the frequency of a clock branch that supplies peripheral modules

Parameters:

  • clock_branch: Clock branch to query (use sl_device_peripheral_get_clock_branch() to get branch for specific peripheral)

  • frequency: Pointer to store the frequency value in Hz

Return Values:

  • SL_STATUS_OK: Success

  • SL_STATUS_NULL_POINTER: frequency parameter is NULL

  • SL_STATUS_INVALID_PARAMETER: Invalid clock branch specified

Example Usage:

#include "sl_clock_manager.h"
#include "sl_device_peripheral.h"

void query_peripheral_clock(void) {
  sl_status_t status;
  uint32_t frequency;
  sl_clock_branch_t clock_branch;
  
  // Get clock branch for TIMER0 peripheral.
  clock_branch = sl_device_peripheral_get_clock_branch(SL_PERIPHERAL_TIMER0);
  
  // Query the frequency of that clock branch.
  status = sl_clock_manager_get_clock_branch_frequency(clock_branch, &frequency);
  if (status == SL_STATUS_OK) {
    printf("TIMER0 clock frequency: %lu Hz\n", frequency);

    // Use frequency for precise timing calculations.
  }
}

Oscillator Frequency Query#

sl_clock_manager_get_oscillator_frequency#

sl_status_t sl_clock_manager_get_oscillator_frequency(sl_oscillator_t oscillator, uint32_t *frequency);

Description: Retrieves the frequency of a specific oscillator

Parameters:

  • oscillator: Oscillator to query (e.g., SL_OSCILLATOR_HFXO, SL_OSCILLATOR_HFRCODPLL)

  • frequency: Pointer to store the frequency value in Hz

Return Values:

  • SL_STATUS_OK: Success

  • SL_STATUS_NULL_POINTER: frequency parameter is NULL

  • SL_STATUS_INVALID_PARAMETER: Invalid oscillator specified

Example Usage:

#include "sl_clock_manager.h"

void query_hfxo_frequency(void) {
  sl_status_t status;
  uint32_t frequency;
  
  status = sl_clock_manager_get_oscillator_frequency(SL_OSCILLATOR_HFXO, &frequency);
  if (status == SL_STATUS_OK) {
    printf("HFXO frequency: %lu Hz\n", frequency);
  }
}

Bus Clock Control APIs#

sl_clock_manager_enable_bus_clock / sl_clock_manager_disable_bus_clock#

sl_status_t sl_clock_manager_enable_bus_clock(sl_bus_clock_t module_bus_clock);
sl_status_t sl_clock_manager_disable_bus_clock(sl_bus_clock_t module_bus_clock);

Description: Enables or disables the bus clock for a peripheral module

Parameters:

  • module_bus_clock: Bus clock identifier for the peripheral (e.g., SL_BUS_CLOCK_GPIO, SL_BUS_CLOCK_TIMER0)

Return Values:

  • SL_STATUS_OK: Success

  • SL_STATUS_INVALID_PARAMETER: Invalid bus clock specified

Example Usage:

#include "sl_clock_manager.h"

void enable_peripheral_access(void) {
  sl_status_t status;
  
  // Enable GPIO bus clock before accessing GPIO registers.
  status = sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_GPIO);
  if (status == SL_STATUS_OK) {
    // Safe to access GPIO registers now.
    // ... GPIO configuration and operations ...
    
    // Disable bus clock to save power when done.
    sl_clock_manager_disable_bus_clock(SL_BUS_CLOCK_GPIO);
  }
}

Additional APIs#

For complete API documentation including oscillator calibration, clock export, RCO calibration, and advanced clock management functions, refer to the Clock Manager API documentation and the Extended API Examples section.