occs.c
来自「MC56F802BLDC 可以使用的算法 就是电机启动有点慢」· C语言 代码 · 共 98 行
C
98 行
/*******************************************************************************
*
* Motorola Inc.
* (c) Copyright 2000 Motorola Inc.
* ALL RIGHTS RESERVED.
*
********************************************************************************
*
*
* File Name: occs.c
*
* Description: Source file for On-chip Clock Synthesis (OCCS) driver.
*
*
* Modules Included:
*
* Notes:
*
*
*******************************************************************************/
#include "appconfig.h"
#include "types.h"
#include "periph.h"
#include "arch.h"
#include "occs.h"
#ifdef __cplusplus
extern "C" {
#endif
void occsInit(void)
{
#ifdef OCCS_CLKO_SELECT_REG
/* Set CLKO Select Register */
periphMemWrite(OCCS_CLKO_SELECT_REG, &ArchIO.Pll.SelectReg);
#endif
#ifdef OCCS_CONTROL_REG
/* Enable Lock Detector, Set ZCLOCK Source to Prescaler,
Let bit PRECS (Prescaler Clock Select) be as is */
if ((OCCS_CONTROL_REG & 0x0003) == OCCS_ZCLOCK_POSTSCALER)
{
periphMemWrite((OCCS_CONTROL_REG & OCCS_PRESCALER_CLOCK_SELECT) |
OCCS_LOCK_DETECTOR_BIT | OCCS_ZCLOCK_PRESCALER,
&ArchIO.Pll.ControlReg);
}
#endif
#ifdef OCCS_INTERNAL_OSC_REG
/* Set Internal Oscillator Control Register. Only for 801. */
periphMemWrite(OCCS_INTERNAL_OSC_REG, &ArchIO.Pll.InternalOscReg);
#endif
#ifdef OCCS_DIVIDE_BY_REG
/* Set Divide-by register */
periphMemWrite(OCCS_DIVIDE_BY_REG, &ArchIO.Pll.DivideReg);
#endif
#ifdef OCCS_CONTROL_REG
if ((OCCS_CONTROL_REG & 0x0003) == OCCS_ZCLOCK_POSTSCALER)
{
/* Wait until PLL is locked */
while (!periphBitTest(OCCS_STATUS_LOCK_1, &ArchIO.Pll.StatusReg))
;
}
/* ZCLOCK Source to Postscaler */
periphMemWrite(OCCS_CONTROL_REG, &ArchIO.Pll.ControlReg);
#endif
}
UInt32 occsGetIPBusFreq(UInt32 OscFreq)
{
UWord16 DivBy,
Prescaler,
Postscaler;
DivBy = periphMemRead(&ArchIO.Pll.DivideReg);
Prescaler = DivBy>>8;
Postscaler = Prescaler>>2;
DivBy &= 0x007F;
Prescaler &= 0x0003;
Postscaler &= 0x0003;
if (periphBitTest(0x0001, &ArchIO.Pll.ControlReg))
{ /* Prescaler Output */
return (OscFreq>>++Prescaler);
}
if (periphBitTest(0x0002, &ArchIO.Pll.ControlReg))
{ /* Postscaler Output */
return ((OscFreq * ++DivBy)>>(++Prescaler + ++Postscaler));
}
}
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?