From 203cca184cf7449336ea8bd33563b5d350981058 Mon Sep 17 00:00:00 2001 From: Tifer King Date: Fri, 25 Apr 2025 05:33:36 +0800 Subject: [PATCH] Fix some bugs --- LMK_ClockTree.c | 20 ++++++++++++++------ LMK_ClockTree.h | 19 +++++++++++-------- LMK_Preset.h | 6 +++--- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/LMK_ClockTree.c b/LMK_ClockTree.c index 05127d5..8ba165e 100644 --- a/LMK_ClockTree.c +++ b/LMK_ClockTree.c @@ -16,9 +16,9 @@ __weak int LMK_CalPLL1CommonRate(LMK_Simple *SimpleConfig) __weak int LMK_CalPLL2CommonRate(LMK_Simple *SimpleConfig) { + u8 i; u64 PLL2CommonRate; u64 ChMaxRate; - u64 VCORate; u64 RootDiv; ChMaxRate = 0; for(i = 0; i < 7; i++) @@ -52,7 +52,7 @@ __weak int LMK_CalPLL2CommonRate(LMK_Simple *SimpleConfig) { return LMK_FAILURE; } - PLL2CommonRate = GreatestCommonDivisor(VCORate, SimpleConfig->VCOXClockRate * 2) / 2; + PLL2CommonRate = GreatestCommonDivisor(SimpleConfig->Generated.VCORate / 2, SimpleConfig->VCOXClockRate); LMK_AssertInValid(PLL2CommonRate); SimpleConfig->Generated.PLL2CommonRate = PLL2CommonRate; return LMK_SUCCESS; @@ -66,9 +66,9 @@ __weak int LMK_CalRegister(LMK_Simple *SimpleConfig) LMK_AssertZero(SimpleConfig->Generated.PLL2CommonRate); SimpleConfig->Generated.SYSREF_DIV = SimpleConfig->Generated.VCORate / SimpleConfig->SYSREFRate; - SimpleConfig->Generated.CLKin_R = SimpleConfig->Generated.RefClockRate / SimpleConfig->Generated.PLL1CommonRate; - SimpleConfig->Generated.PLL1_N = SimpleConfig->Generated.VCOXClockRate / SimpleConfig->Generated.PLL1CommonRate; - SimpleConfig->Generated.PLL2_R = SimpleConfig->Generated.VCOXClockRate / SimpleConfig->Generated.PLL2CommonRate; + SimpleConfig->Generated.CLKin_R = SimpleConfig->RefClockRate / SimpleConfig->Generated.PLL1CommonRate; + SimpleConfig->Generated.PLL1_N = SimpleConfig->VCOXClockRate / SimpleConfig->Generated.PLL1CommonRate; + SimpleConfig->Generated.PLL2_R = SimpleConfig->VCOXClockRate / SimpleConfig->Generated.PLL2CommonRate; SimpleConfig->Generated.PLL2_N = SimpleConfig->Generated.VCORate / SimpleConfig->Generated.PLL2CommonRate / 2; for(i = 0; i < 7; i++) { @@ -77,7 +77,7 @@ __weak int LMK_CalRegister(LMK_Simple *SimpleConfig) return LMK_SUCCESS; } -__weak int LMK_ConfigSetRegister(LMK_Config *DevConfig, LMK_Simple *SimpleConfig) +int LMK_ConfigInitRegister(LMK_Config *DevConfig) { int i; // Fixed Register Set @@ -292,6 +292,13 @@ __weak int LMK_ConfigSetRegister(LMK_Config *DevConfig, LMK_Simple *SimpleConfig return LMK_SUCCESS; } +__weak int LMK_ConfigSetRegister(LMK_Config *DevConfig, LMK_Simple *SimpleConfig) +{ + UNUSED(DevConfig); + UNUSED(SimpleConfig); + return LMK_SUCCESS; +} + __weak int LMK_ConfigPreset(LMK_Config *DevConfig, LMK_Simple *SimpleConfig) { UNUSED(DevConfig); @@ -312,6 +319,7 @@ __weak int LMK_ConfigMake(LMK_Config *DevConfig, LMK_Simple *SimpleConfig) LMK_AssertFailure(LMK_CalPLL1CommonRate(SimpleConfig)); LMK_AssertFailure(LMK_CalPLL2CommonRate(SimpleConfig)); LMK_AssertFailure(LMK_CalRegister(SimpleConfig)); + LMK_AssertFailure(LMK_ConfigInitRegister(DevConfig)); LMK_AssertFailure(LMK_ConfigSetRegister(DevConfig, SimpleConfig)); LMK_AssertFailure(LMK_ConfigPreset(DevConfig, SimpleConfig)); LMK_AssertFailure(LMK_ConfigCustomize(DevConfig, SimpleConfig)); diff --git a/LMK_ClockTree.h b/LMK_ClockTree.h index 2b037d7..7030afa 100644 --- a/LMK_ClockTree.h +++ b/LMK_ClockTree.h @@ -311,26 +311,29 @@ typedef struct LMK_Config_Simple_Type { void *InterfaceInst; //Unit Hz; - u64 RefClockRate = 0; - u64 VCOXClockRate = 0; - u64 DClockRate[7] = {0}; - u64 SYSREFRate = 0; + u64 RefClockRate; + u64 VCOXClockRate; + u64 DClockRate[7]; + u64 SYSREFRate; //Generated config LMK_Generated Generated; } LMK_Simple; - +int LMK_CalPLL1CommonRate(LMK_Simple *SimpleConfig); +int LMK_CalPLL2CommonRate(LMK_Simple *SimpleConfig); +int LMK_CalRegister(LMK_Simple *SimpleConfig); +int LMK_ConfigInitRegister(LMK_Config *DevConfig); +int LMK_ConfigSetRegister(LMK_Config *DevConfig, LMK_Simple *SimpleConfig); +int LMK_ConfigPreset(LMK_Config *DevConfig, LMK_Simple *SimpleConfig); +int LMK_ConfigCustomize(LMK_Config *DevConfig, LMK_Simple *SimpleConfig); int LMK_ConfigMake(LMK_Config *DevConfig, LMK_Simple *SimpleConfig); -int LMK_ConfigCustomize(LMK_Config *DevConfig); int LMK_Init(LMK_Config *DevConfig); int LMK_StatusRead(LMK_Config *DevConfig); int LMK_RegLock(LMK_Config *DevConfig); int LMK_RegUnlock(LMK_Config *DevConfig); - int LMK_WriteReg(LMK_Config *DevConfig, u16 RegisterAddress, u8 Value); int LMK_ReadReg(LMK_Config *DevConfig, u16 RegisterAddress, u8 *Value); - #endif /* SRC_LMK_CLOCKTREE_H_ */ diff --git a/LMK_Preset.h b/LMK_Preset.h index 3acbc00..9caf85c 100644 --- a/LMK_Preset.h +++ b/LMK_Preset.h @@ -10,10 +10,10 @@ #include "LMK_ClockTree.h" -#define LMK_PRESET_NONE -//#define LMK_PRESET_IW_RFSOC_2T2R_INTERNAL +//#define LMK_PRESET_NONE +#define LMK_PRESET_IW_RFSOC_2T2R_INTERNAL //#define LMK_PRESET_IW_RFSOC_2T2R_EXTERNAL int LMK_ConfigPreset(LMK_Config *DevConfig, LMK_Simple *SimpleConfig); -#endif /* SRC_LMK_PRESET_H_ */ \ No newline at end of file +#endif /* SRC_LMK_PRESET_H_ */