# CRM
[PLATFORM]

Clock and Reset module. More...

Collaboration diagram for CRM:

## Data Structures
struct | crm_env_tag
| CRM driver context structure. More...
struct | clk_config
| Clock configuration structure. More...
## Defines
#define | MDM_CONF_0_9 1
| This macro shall be set to one if the MDM is supporting confs 8 and 9 and to 0 otherwise.
#define | CRM_CLKCONF_UNDEFINED ((uint8_t)-1)
| Undefined value for the clock configuration.
#define | CLKOUT0 0x08
| Address of output0.
#define | CLKOUT1 0x0A
| Address of output1.
#define | CLKOUT2 0x0C
| Address of output2.
#define | CLKOUT3 0x0E
| Address of output3.
#define | CLKOUT4 0x10
| Address of output4.
#define | CLKOUT5 0x06
| Address of output5.
#define | CLKOUT6 0x12
| Address of output6.
#define | CLKOUTFB 0x14
| Address of feedback output.
#define | MMCM_REG1(mmcm, out)
| Address to configure clkreg1 reg for output `out` of mmcm `mmcm` note: use KARST_DYNCFGMMC_xxx defined assuming that FPGAA_DYNCFGMMC_xxx have the same values.
#define | MMCM_VCO_MULT(clk_ref_freq, vco_freq)
| Multiplier to apply to `clk_ref_freq` to get `vco_freq`.
#define | MMCM_VCO_DIV(vco_freq, target_freq)
| Divider to apply to `vco_freq` to get `target_freq`.
#define | MMCM_VCO_TO_NUM_DIV(vco_div) (((vco_div & 0x0FC0) >> 6) + (vco_div & 0x3F))
| Convert a VCO divider `vco_div` to its corresponding numeric value.
## Functions
void | crm_init (void)
| Initial clock settings (e.g.
uint8_t | crm_get_mac_freq (void)
| Return the frequency of the MAC core clock in case it would have been adjusted depending on the PHY properties.
uint32_t | crm_get_cpu_freq (void)
| Return the frequency of the CPU clock.
bool | crm_fe_160m (void)
| Indicate whether the RF front-end is configured at 160MHz or not.
void | crm_clk_set (uint8_t chan_type)
| Set the different clocks depending on the chosen channel bandwidth.
void | crm_mdm_reset (void)
| Reset the MODEM and the AGC.
static int | reg_poll (uint32_t reg, uint32_t val)
| Poll register until bits are set.
static void | udelay (uint32_t us)
| Active wait.
static void | crm_mmc_clk_set (uint32_t addr, uint16_t data)
| Configure one clock source.
static int | crm_clk_conf (uint8_t chan_type)
| Select clock configuration index.
## Variables
static struct crm_env_tag | crm_env
| CRM driver context.
static struct clk_config | clk_config [10]
| Table of all possible clock configurations.

## Detailed Description

Clock and Reset module.

## Define Documentation

#define MMCM_REG1 | ( | mmcm,
|  | out |  | ) |

Value:

    (KARST_DYNCFGMMC_WE_BIT |                   \
         (mmcm << KARST_DYNCFGMMC_SEL_LSB) |        \
         CLKOUT##out)

Address to configure clkreg1 reg for output `out` of mmcm `mmcm` note: use KARST_DYNCFGMMC_xxx defined assuming that FPGAA_DYNCFGMMC_xxx have the same values.

Definition at line 150 of file crm.c.

#define MMCM_VCO_DIV | ( | vco_freq,
|  | target_freq |  | ) |

Value:

    ((((vco_freq/target_freq) + 1) / 2) << 6 | \
         (((vco_freq/target_freq)) / 2) |          \
         0x1000)

Divider to apply to `vco_freq` to get `target_freq`.

Definition at line 162 of file crm.c.

#define MMCM_VCO_MULT | ( | clk_ref_freq,
|  | vco_freq |  | ) |

Value:

    ((((vco_freq/clk_ref_freq) + 1) / 2) << 6 |   \
         (((vco_freq/clk_ref_freq)) / 2) |            \
         0x1000)

Multiplier to apply to `clk_ref_freq` to get `vco_freq`.

Definition at line 156 of file crm.c.

Referenced by crm_clk_set().

## Function Documentation

static int crm_clk_conf | ( | uint8_t | chan_type | ) | `[static]`

Select clock configuration index.

Parameters:

  `[in]` | chan_type | Channel bandwidth

Returns:
  the clock configuration to apply for the selected bandwidth

Definition at line 487 of file crm.c.

References ASSERT_ERR, PHY_CHNL_BW_20, PHY_CHNL_BW_40, PHY_CHNL_BW_80, and phy_vht_supported().

Referenced by crm_clk_set(), and crm_init().

void crm_clk_set | ( | uint8_t | chan_type | ) |

Set the different clocks depending on the chosen channel bandwidth.

Parameters:

  `[in]` | chan_type | Channel bandwidth

Definition at line 552 of file crm.c.

References clk_config::bd_div, crm_env_tag::clk_conf, crm_clk_conf(), crm_env, crm_mmc_clk_set(), clk_config::fe_div, MMCM_VCO_MULT, clk_config::phy_div, reg_poll(), and udelay().

Referenced by phy_hw_set_channel().

bool crm_fe_160m | ( | void |  | ) |

Indicate whether the RF front-end is configured at 160MHz or not.

Returns:
  true if configured at 160MHz, false otherwise

Definition at line 630 of file crm.c.

References crm_env_tag::clk_conf, CRM_CLKCONF_UNDEFINED, crm_env, and clk_config::fe_div.

uint32_t crm_get_cpu_freq | ( | void |  | ) |

Return the frequency of the CPU clock.

Returns:
  The CPU clock frequency in Hz

Definition at line 645 of file crm.c.

References crm_env_tag::cpu_freq, and crm_env.

uint8_t crm_get_mac_freq | ( | void |  | ) |

Return the frequency of the MAC core clock in case it would have been adjusted depending on the PHY properties.

Returns:
  The MAC core clock frequency in MHz

Definition at line 640 of file crm.c.

References crm_env, and crm_env_tag::mac_freq.

void crm_init | ( | void |  | ) |

Initial clock settings (e.g.

MPIF and MAC core clock value depending on the PHY capabilities)

Definition at line 585 of file crm.c.

References crm_env_tag::clk_conf, crm_env_tag::cpu_freq, crm_clk_conf(), CRM_CLKCONF_UNDEFINED, crm_env, crm_mmc_clk_set(), clk_config::mac, clk_config::mac_config::mac_div, crm_env_tag::mac_freq, and clk_config::mpif.

void crm_mdm_reset | ( | void |  | ) |

Reset the MODEM and the AGC.

Definition at line 650 of file crm.c.

References udelay().

Referenced by mdm_init(), mdm_set_channel(), and phy_rc_isr().

static void crm_mmc_clk_set | ( | uint32_t | addr,
|  | uint16_t | data |
| ) |  |  | `[static]`

Configure one clock source.

Parameters:

  `[in]` | addr | Address of the register
  `[in]` | data | Value to apply

Definition at line 458 of file crm.c.

References reg_poll().

Referenced by crm_clk_set(), and crm_init().

static int reg_poll | ( | uint32_t | reg,
|  | uint32_t | val |
| ) |  |  | `[static]`

Poll register until bits are set.

Parameters:

  `[in]` | reg | Register to poll
  `[in]` | val | Bits to wait

Returns:
  0 if bits are set in register, and !=0 otherwise

Definition at line 76 of file crm.c.

References D_ERR, D_PHY, dbg, and REG_PL_RD.

Referenced by crm_clk_set(), and crm_mmc_clk_set().

static void udelay | ( | uint32_t | us | ) | `[inline, static]`

Active wait.

Parameters:

  `[in]` | us | Waiting duration (in us)

Definition at line 97 of file crm.c.

Referenced by crm_clk_set(), and crm_mdm_reset().