rt-thread-official/libcpu/arm/sep4020/clk.c

109 lines
2.0 KiB
C
Raw Normal View History

2013-01-08 21:05:02 +08:00
/*
2021-03-27 17:51:56 +08:00
* Copyright (c) 2006-2021, RT-Thread Development Team
2013-01-08 21:05:02 +08:00
*
* SPDX-License-Identifier: Apache-2.0
2013-01-08 21:05:02 +08:00
*
* Change Logs:
* Date Author Notes
* 2010-03-20 zchong first version
*/
#include <rtthread.h>
#include "sep4020.h"
2021-03-27 17:51:56 +08:00
#define CLK_IN 4000000 /* Fin = 4.00MHz */
#define SYSCLK 72000000 /* system clock we want */
#define CLK_ESRAM 0
#define CLK_LCDC 1
#define CLK_PWM 2
#define CLK_DMAC 3
#define CLK_EMI 4
#define CLK_MMCSD 5
#define CLK_SSI 7
#define CLK_UART0 8
#define CLK_UART1 9
#define CLK_UART2 10
#define CLK_UART3 11
#define CLK_USB 12
#define CLK_MAC 13
#define CLK_SMC 14
#define CLK_I2C 15
#define CLK_GPT 16
2013-01-08 21:05:02 +08:00
static void rt_hw_set_system_clock(void)
{
2021-03-27 17:51:56 +08:00
rt_uint8_t pv;
/* pv value*/
pv = SYSCLK/2/CLK_IN;
/* go to normal mode*/
*(RP)PMU_PMDR = 0x01;
/* set the clock */
*(RP)PMU_PMCR = 0x4000 | pv;
/* trige configurate*/
*(RP)PMU_PMCR = 0xc000 | pv;
2013-01-08 21:05:02 +08:00
}
static void rt_hw_set_usb_clock(void)
{
2021-03-27 17:51:56 +08:00
/* set the clock */
*(RP)PMU_PUCR = 0x000c;
/* trige configurate*/
*(RP)PMU_PMCR = 0x800c;
2013-01-08 21:05:02 +08:00
}
/**
* @brief System Clock Configuration
*/
void rt_hw_clock_init(void)
{
2021-03-27 17:51:56 +08:00
/* set system clock */
rt_hw_set_system_clock();
/* set usb clock */
rt_hw_set_usb_clock();
2013-01-08 21:05:02 +08:00
}
/**
* @brief Get system clock
*/
rt_uint32_t rt_hw_get_clock(void)
{
2021-03-27 17:51:56 +08:00
rt_uint32_t val;
rt_uint8_t pv, pd, npd;
/* get PMCR value */
val =*(RP) PMU_PMCR;
/* get NPD */
npd = (val >> 14) & 0x01;
/* get PD */
pd = (val >> 10) & 0x0f;
/* get PV */
pv = val & 0x7f;
/* caculate the system clock */
if(npd)
val = 2 * CLK_IN * pv;
else
val = CLK_IN * pv / (pd + 1);
2013-01-08 21:05:02 +08:00
return(val);
}
/**
* @brief Enable module clock
*/
void rt_hw_enable_module_clock(rt_uint8_t module)
{
}
/**
* @brief Disable module clock
*/
void rt_hw_disable_module_clock(rt_uint8_t module)
{
}