Skip to content

Class hal::lpc40::clock

ClassList > hal > lpc40 > clock

Allows user code to manipulate and retrieve the various system clocks speeds.

  • #include <clock.hpp>

Classes

Type Name
struct configuration
Clock configuration object.

Public Types

Type Name
enum uint32_t flash_configuration
enum uint8_t spifi_clock_source
spifi clock options
enum uint8_t usb_clock_source
USB oscillator source constants (not used)
enum uint8_t usb_divider
USB Clock divider constants.

Public Static Attributes

Type Name
constexpr uint32_t default_peripheral_divider = = 4
The default clock divider for the peripheral clock.
constexpr hertz irc_frequency = = 12'000'000.0f
The frequency of the internal RC clock and the clock frequency at startup.

Public Functions

Type Name
configuration & config ()
Get the clock config object.
hertz get_frequency (peripheral p_peripheral)
Get the operating frequency of the peripheral.
status reconfigure_clocks ()
Apply the clock configuration to hardware.

Public Static Functions

Type Name
clock & get ()
Get system clock object.
status maximum (hertz p_external_crystal_frequency)
Set the lpc40xx MCU to the maximum clock speed (120MHz) possible.

Public Types Documentation

enum flash_configuration

enum hal::lpc40::clock::flash_configuration {
    clock1 = 0b0000 << 12,
    clock2 = 0b0001 << 12,
    clock3 = 0b0010 << 12,
    clock4 = 0b0011 << 12,
    clock5 = 0b0100 << 12,
    clock6 = 0b0101 << 12
};

Defines the codes for the flash access clock cycles required based on the CPU clocks speed.

enum spifi_clock_source

enum hal::lpc40::clock::spifi_clock_source {
    system_clock = 0b00,
    pll0 = 0b01,
    pll1 = 0b10
};

enum usb_clock_source

enum hal::lpc40::clock::usb_clock_source {
    system_clock = 0b00,
    pll0 = 0b01,
    pll1 = 0b10
};

enum usb_divider

enum hal::lpc40::clock::usb_divider {
    divide_by1 = 0,
    divide_by2,
    divide_by3,
    divide_by4
};

Public Static Attributes Documentation

variable default_peripheral_divider

constexpr uint32_t hal::lpc40::clock::default_peripheral_divider;

variable irc_frequency

constexpr hertz hal::lpc40::clock::irc_frequency;

Public Functions Documentation

function config

Get the clock config object.

configuration & hal::lpc40::clock::config () 

Returns:

configuration& - reference to configuration object

function get_frequency

Get the operating frequency of the peripheral.

hertz hal::lpc40::clock::get_frequency (
    peripheral p_peripheral
) 

Parameters:

  • p_peripheral - id of the peripheral

Returns:

frequency - operating frequency of the peripheral

function reconfigure_clocks

Apply the clock configuration to hardware.

status hal::lpc40::clock::reconfigure_clocks () 

TODO(#65): explain the set of errors in better detail

Returns:

status - success or failure calculations could not be reached.

Public Static Functions Documentation

function get

Get system clock object.

static clock & hal::lpc40::clock::get () 

All peripherals and application code should use this function and clock objects. Additional clock objects should not created outside of unit tests. Doing so will result in multiple objects with shared state.

Returns:

clock& - return the system clock object

function maximum

Set the lpc40xx MCU to the maximum clock speed (120MHz) possible.

static status hal::lpc40::clock::maximum (
    hertz p_external_crystal_frequency
) 

This function REQUIRES an external crystal to be used.

  • CPU clock speed set to 120MHz
  • USB clock speed set to 120MHz
  • Peripheral clock set to 120MHZ
  • SPIFI clock set to 120MHz
  • PLL0 is set to 120MHz and used for everything
  • PLL1 is disabled and not used

Parameters:

  • p_external_crystal_frequency - frequency of the crystal connected to the XTAL1 & XTAL2

Returns:

status - whether or not the function failed to set the clock speed to the maximum.


The documentation for this class was generated from the following file libraries/include/libhal-lpc40/clock.hpp