Enumerations | Functions

Clock control (hal_clk)
[nRF24LE1 HAL]


The clock to the MCU is sourced from either an on-chip RC oscillator or an external crystal oscillator. This module contains functions for selecting clock source and clock frequency.

Enumerations

enum  hal_clk_input_t { HAL_CLK_XOSC16_OR_RCOSC16 = 0, HAL_CLK_PAD_XC1 = 1 }
enum  hal_clk_source_t { HAL_CLK_XOSC16M_AND_RCOSC16M = 0, HAL_CLK_RCOSC16M = 1, HAL_CLK_XOSC16M = 2 }
enum  hal_clk_freq_t {
  HAL_CLK_16MHZ = 0, HAL_CLK_8MHZ = 1, HAL_CLK_4MHZ = 2, HAL_CLK_2MHZ = 3,
  HAL_CLK_1MHZ = 4, HAL_CLK_500KHZ = 5, HAL_CLK_250KHZ = 6, HAL_CLK_125KHZ = 7
}
enum  hal_clklf_source_t {
  HAL_CLKLF_XOSC32K = 0, HAL_CLKLF_RCOSC32K = 1, HAL_CLKLF_XOSC16M_SYNTH = 2, HAL_CLKLF_PAD_XC1 = 3,
  HAL_CLKLF_DIG_IO_RAIL = 4, HAL_CLKLF_NONE = 7
}

Functions

void hal_clk_regret_xosc16m_on (_Bool on)
void hal_clk_set_input (hal_clk_input_t input)
void hal_clk_set_16m_source (hal_clk_source_t source)
hal_clk_source_t hal_clk_get_16m_source (void)
void hal_clk_set_freq (hal_clk_freq_t freq)
_Bool hal_clklf_phase (void)
_Bool hal_clklf_ready (void)
void hal_clklf_set_source (hal_clklf_source_t source)

Enumeration Type Documentation

An enum describing the possible system clock inputs.

Enumerator:
HAL_CLK_XOSC16_OR_RCOSC16 
HAL_CLK_PAD_XC1 

Definition at line 34 of file hal_clk.h.

An enum used for selecting which 16MHz clocks to run.

Enumerator:
HAL_CLK_XOSC16M_AND_RCOSC16M 
HAL_CLK_RCOSC16M 
HAL_CLK_XOSC16M 

Definition at line 43 of file hal_clk.h.

An enum describing the possible internal (system) clock frequencies.

Enumerator:
HAL_CLK_16MHZ 
HAL_CLK_8MHZ 
HAL_CLK_4MHZ 
HAL_CLK_2MHZ 
HAL_CLK_1MHZ 
HAL_CLK_500KHZ 
HAL_CLK_250KHZ 
HAL_CLK_125KHZ 

Definition at line 53 of file hal_clk.h.

An enum describing the possible 32khz clock (clklf) sources.

Enumerator:
HAL_CLKLF_XOSC32K 
HAL_CLKLF_RCOSC32K 
HAL_CLKLF_XOSC16M_SYNTH 
HAL_CLKLF_PAD_XC1 
HAL_CLKLF_DIG_IO_RAIL 
HAL_CLKLF_NONE 

Definition at line 68 of file hal_clk.h.


Function Documentation

void hal_clk_regret_xosc16m_on ( _Bool  on )

Function selecting whether XOSC16 should run during register retention power down mode.

Parameters:
onBoolean value. True = on, false = off.

Definition at line 22 of file hal_clk.c.

{
  if(on)
  {
    CLKCTRL = (CLKCTRL | 0x80U) & (uint8_t)~0x08U;   // & ~0x08 to prevent writing 1 to this bit
  }
  else
  {
    CLKCTRL = CLKCTRL & (uint8_t)~0x88U;            // & ~0x08 to prevent writing 1 to this bit
  }
}
void hal_clk_set_input ( hal_clk_input_t  input )

Function selecting the main source for the 16MHz system clock.

Parameters:
inputselects the clock source.

  • HAL_CLK_XOSC16_OR_RCOSC16
  • HAL_CLK_PAD_XC1

Definition at line 34 of file hal_clk.c.

{
  CLKCTRL = (CLKCTRL & (uint8_t)~0x48U) | ((input & 0x01U) << 6);
}
void hal_clk_set_16m_source ( hal_clk_source_t  source )

Function selecting the 16Mhz clock to be used. For this function to have any effect the main source for the 16MHz clock must be either XOSC16 or RCOSC16. See hal_clk_set_input().

Parameters:
sourceselects the 16M clock to be used.

  • HAL_CLK_XOSC16M_AND_RCOSC16M. Here, the source will be automatically be switched to XOSC16M when possible (ready).
  • HAL_CLK_RCOSC16M_ONLY
  • HAL_CLK_XCOSC16M_ONLY

Definition at line 39 of file hal_clk.c.

{
  CLKCTRL = (CLKCTRL & (uint8_t)~0x38U) | ((source & 0x03U) << 4);
}
hal_clk_source_t hal_clk_get_16m_source ( void   )

Function returning the source for the 16MHz clock. For this function to have any effect the main source for the 16MHz clock must be either XOSC16 or RCOSC16. See hal_clk_set_input().

Note:
If you are using nRF24LE1 rev A you must change the SFR that is used to CLKCTRL

Definition at line 44 of file hal_clk.c.

{
  hal_clk_source_t clock_source;
  if(CLKLFCTRL & (uint8_t)0x08U)
  {
    clock_source = HAL_CLK_XOSC16M;
  }
  else
  {
    clock_source = HAL_CLK_RCOSC16M;
  }

  return clock_source;
}
void hal_clk_set_freq ( hal_clk_freq_t  freq )

Function for setting the internal system clock frequency. The system clock source is always 16MHz. This function configures the system clock prescaler.

Parameters:
freqselects the internal clock to be used.

  • HAL_CLK_16MHZ
  • HAL_CLK_8MHZ
  • HAL_CLK_4MHZ
  • HAL_CLK_2MHZ
  • HAL_CLK_1MHZ
  • HAL_CLK_500KHZ
  • HAL_CLK_250KHZ
  • HAL_CLK_125KHZ

Definition at line 59 of file hal_clk.c.

{
  CLKCTRL = ((CLKCTRL & (uint8_t)~0x0FU) | ((uint8_t)freq & 0x07U)); // & ~0x08 to prevent writing 1 to this bit
}
_Bool hal_clklf_phase ( void   )

Read the CLKLF (phase).

Definition at line 64 of file hal_clk.c.

{
  return (bool)(CLKLFCTRL & 0x80U);
}
_Bool hal_clklf_ready ( void   )

Checks if the 32kHz clock is ready to be used.

Definition at line 69 of file hal_clk.c.

{
  return (bool)(CLKLFCTRL & 0x40U);
}
void hal_clklf_set_source ( hal_clklf_source_t  source )

Function for setting the source for the 32KHz clock (clklf / RTC).

Parameters:
sourceselects the 32KHz clock source.

  • HAL_CLKLF_XOSC32K
  • HAL_CLKLF_RCOSC32K
  • HAL_CLKLF_XOSC16M_SYNTH
  • HAL_CLKLF_PAD_XC1
  • HAL_CLKLF_DIG_IO_RAIL

Definition at line 74 of file hal_clk.c.

{
  CLKLFCTRL = (uint8_t)(CLKLFCTRL & (uint8_t)~0x07U) | (uint8_t)((uint8_t)source & (uint8_t)0x07U);
}