summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/get-system-clock.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2012-01-23 11:19:22 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-01-23 11:19:22 +0100
commita762dc2a49fad0e7797806fefd34d144b6d998b2 (patch)
tree3f21a6ba6320a3a89581a3d1e2be5162bb8a904f /c/src/lib/libbsp/powerpc/mpc55xxevb/startup/get-system-clock.c
parentGoogle C++ Testing Framework 1.6.0. (diff)
downloadrtems-a762dc2a49fad0e7797806fefd34d144b6d998b2.tar.bz2
Support for MPC5643L.
Rework of the start sequence to reduce the amount assembler code and to support configuration tables which may be provided by the application.
Diffstat (limited to 'c/src/lib/libbsp/powerpc/mpc55xxevb/startup/get-system-clock.c')
-rw-r--r--c/src/lib/libbsp/powerpc/mpc55xxevb/startup/get-system-clock.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/get-system-clock.c b/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/get-system-clock.c
new file mode 100644
index 0000000000..5e0c608d41
--- /dev/null
+++ b/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/get-system-clock.c
@@ -0,0 +1,85 @@
+/**
+ * @file
+ *
+ * @ingroup mpc55xx
+ *
+ * @brief System clock calculation.
+ */
+
+/*
+ * Copyright (c) 2008-2011 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <bsp.h>
+#include <bsp/start.h>
+#include <bsp/mpc55xx-config.h>
+
+uint32_t mpc55xx_get_system_clock(void)
+{
+ uint32_t system_clock = 0;
+
+ #ifdef MPC55XX_HAS_FMPLL
+ volatile struct FMPLL_tag *fmpll = &FMPLL;
+ union FMPLL_SYNSR_tag synsr = { .R = fmpll->SYNSR.R };
+ uint32_t reference_clock = MPC55XX_FMPLL_REF_CLOCK;
+ bool pll_clock_mode = synsr.B.MODE != 0;
+ bool crystal_or_external_reference_mode = synsr.B.PLLSEL != 0;
+
+ if (pll_clock_mode) {
+ if (crystal_or_external_reference_mode) {
+ union FMPLL_SYNCR_tag syncr = { .R = fmpll->SYNCR.R };
+ uint32_t prediv = syncr.B.PREDIV;
+ uint32_t mfd = syncr.B.MFD;
+ uint32_t rfd = syncr.B.RFD;
+
+ system_clock = ((reference_clock * (mfd + 4)) >> rfd) / (prediv + 1);
+ } else {
+ system_clock = 2 * reference_clock;
+ }
+ } else {
+ system_clock = reference_clock;
+ }
+ #endif
+
+ #ifdef MPC55XX_HAS_FMPLL_ENHANCED
+ volatile struct FMPLL_tag *fmpll = &FMPLL;
+ union FMPLL_ESYNCR1_tag esyncr1 = { .R = fmpll->ESYNCR1.R };
+ uint32_t reference_clock = MPC55XX_FMPLL_REF_CLOCK;
+ bool normal_mode = (esyncr1.B.CLKCFG & 0x4U) != 0;
+
+ if (normal_mode) {
+ union FMPLL_ESYNCR2_tag esyncr2 = { .R = fmpll->ESYNCR2.R };
+ uint32_t eprediv = esyncr1.B.EPREDIV;
+ uint32_t emfd = esyncr1.B.EMFD;
+ uint32_t erfd = esyncr2.B.ERFD;
+
+ system_clock = (reference_clock * (emfd + 16))
+ / ((erfd + 1) * (eprediv + 1));
+ } else {
+ system_clock = reference_clock;
+ }
+ #endif
+
+ #ifdef MPC55XX_HAS_MODE_CONTROL
+ /* FIXME: Assumes normal mode and external oscillator */
+ PLLD_CR_32B_tag cr = { . R = CGM.FMPLL [0].CR.R };
+ uint32_t xosc = MPC55XX_FMPLL_REF_CLOCK;
+ uint32_t ldf = cr.B.NDIV;
+ uint32_t idf = cr.B.IDF + 1;
+ uint32_t odf = 2U << cr.B.ODF;
+
+ system_clock = (xosc * ldf) / (idf * odf);
+ #endif
+
+ return system_clock;
+}