2021-11-26 04:13:58 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/clk/clk.h
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __DRIVER_CLK_CLK_H
|
|
|
|
#define __DRIVER_CLK_CLK_H
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <strings.h>
|
2023-02-01 14:41:12 +01:00
|
|
|
#include <sys/param.h>
|
2024-06-21 09:47:59 +02:00
|
|
|
|
2023-10-10 03:50:35 +02:00
|
|
|
#include <nuttx/bits.h>
|
2024-06-21 09:47:59 +02:00
|
|
|
#include <nuttx/lib/math32.h>
|
2021-11-26 04:13:58 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_CLK
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define MASK(width) (BIT(width) - 1)
|
|
|
|
#define MULT_ROUND_UP(r, m) ((r) * (m) + (m) - 1)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Inline Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void clk_write(uint32_t reg, uint32_t value)
|
|
|
|
{
|
2024-06-20 04:44:56 +02:00
|
|
|
*((volatile uint32_t *)(uintptr_t)reg) = value;
|
2021-11-26 04:13:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t clk_read(uint32_t reg)
|
|
|
|
{
|
2024-06-20 04:44:56 +02:00
|
|
|
return *((volatile uint32_t *)(uintptr_t)reg);
|
2021-11-26 04:13:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t gcd(uint32_t a, uint32_t b)
|
|
|
|
{
|
|
|
|
uint32_t r;
|
|
|
|
uint32_t tmp;
|
|
|
|
|
|
|
|
if (a < b)
|
|
|
|
{
|
|
|
|
tmp = a;
|
|
|
|
a = b;
|
|
|
|
b = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!b)
|
|
|
|
{
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((r = a % b) != 0)
|
|
|
|
{
|
|
|
|
a = b;
|
|
|
|
b = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t roundup_double(double n)
|
|
|
|
{
|
|
|
|
uint32_t intn = (uint32_t)n;
|
|
|
|
if (n == (double)intn)
|
|
|
|
{
|
|
|
|
return intn;
|
|
|
|
}
|
|
|
|
|
|
|
|
return intn + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_CLK */
|
|
|
|
#endif /* __DRIVER_CLK_CLK_H */
|