[rtems commit] bsps: Shared ARMv7-M clock driver

Sebastian Huber sebh at rtems.org
Sat Mar 24 19:21:50 UTC 2012


Module:    rtems
Branch:    master
Commit:    34c6151754f2e9ed03e66058047fa2c627a60f3f
Changeset: http://git.rtems.org/rtems/commit/?id=34c6151754f2e9ed03e66058047fa2c627a60f3f

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Sat Mar 24 20:14:27 2012 +0100

bsps: Shared ARMv7-M clock driver

---

 c/src/lib/libbsp/arm/lm3s69xx/Makefile.am          |    4 +-
 c/src/lib/libbsp/arm/lpc24xx/Makefile.am           |    3 +-
 c/src/lib/libbsp/arm/lpc24xx/include/bsp.h         |    2 +
 .../armv7m/clock/armv7m-clock-config.c}            |   44 +++++++++++++++----
 .../libbsp/arm/shared/lpc/clock/lpc-clock-config.c |    8 +++-
 5 files changed, 47 insertions(+), 14 deletions(-)

diff --git a/c/src/lib/libbsp/arm/lm3s69xx/Makefile.am b/c/src/lib/libbsp/arm/lm3s69xx/Makefile.am
index a68056a..6ad98d6 100644
--- a/c/src/lib/libbsp/arm/lm3s69xx/Makefile.am
+++ b/c/src/lib/libbsp/arm/lm3s69xx/Makefile.am
@@ -97,8 +97,8 @@ libbsp_a_SOURCES += console/console-config.c
 libbsp_a_SOURCES += console/uart.c
 
 # Clock
-libbsp_a_SOURCES += clock/clock-config.c \
-	../../../shared/clockdrv_shell.h
+libbsp_a_SOURCES += ../../shared/clockdrv_shell.h
+libbsp_a_SOURCES += ../shared/armv7m/clock/armv7m-clock-config.c
 
 # Timer
 libbsp_a_SOURCES += timer/timer.c
diff --git a/c/src/lib/libbsp/arm/lpc24xx/Makefile.am b/c/src/lib/libbsp/arm/lpc24xx/Makefile.am
index e64fd56..1a69af0 100644
--- a/c/src/lib/libbsp/arm/lpc24xx/Makefile.am
+++ b/c/src/lib/libbsp/arm/lpc24xx/Makefile.am
@@ -121,8 +121,9 @@ libbsp_a_SOURCES += ../../shared/console.c \
     ../../shared/console_control.c
 
 # Clock
-libbsp_a_SOURCES += ../shared/lpc/clock/lpc-clock-config.c
 libbsp_a_SOURCES += ../../shared/clockdrv_shell.h
+libbsp_a_SOURCES += ../shared/lpc/clock/lpc-clock-config.c
+libbsp_a_SOURCES += ../shared/armv7m/clock/armv7m-clock-config.c
 
 # RTC
 libbsp_a_SOURCES += ../../shared/tod.c \
diff --git a/c/src/lib/libbsp/arm/lpc24xx/include/bsp.h b/c/src/lib/libbsp/arm/lpc24xx/include/bsp.h
index cd63737..62ab748 100644
--- a/c/src/lib/libbsp/arm/lpc24xx/include/bsp.h
+++ b/c/src/lib/libbsp/arm/lpc24xx/include/bsp.h
@@ -43,6 +43,8 @@ extern "C" {
 
 #define LPC24XX_MPU_REGION_COUNT 8
 
+#define BSP_ARMV7M_SYSTICK_FREQUENCY LPC24XX_CCLK
+
 #ifndef ASM
 
 struct rtems_bsdnet_ifconfig;
diff --git a/c/src/lib/libbsp/arm/lm3s69xx/clock/clock-config.c b/c/src/lib/libbsp/arm/shared/armv7m/clock/armv7m-clock-config.c
similarity index 66%
rename from c/src/lib/libbsp/arm/lm3s69xx/clock/clock-config.c
rename to c/src/lib/libbsp/arm/shared/armv7m/clock/armv7m-clock-config.c
index 909fcee..82fefce 100644
--- a/c/src/lib/libbsp/arm/lm3s69xx/clock/clock-config.c
+++ b/c/src/lib/libbsp/arm/shared/armv7m/clock/armv7m-clock-config.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 Sebastian Huber.  All rights reserved.
+ * Copyright (c) 2011-2012 Sebastian Huber.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Obere Lagerstr. 30
@@ -10,17 +10,27 @@
  * 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.
- *
- * $Id$
  */
 
 #include <rtems.h>
 #include <rtems/score/armv7m.h>
 
-/* This is defined in ../../../shared/clockdrv_shell.h */
+#include <bsp.h>
+
+#ifdef ARM_MULTILIB_ARCH_V7M
+
+/* This is defined in clockdrv_shell.h */
 rtems_isr Clock_isr(rtems_vector_number vector);
 
-static uint64_t _ARMV7M_Systick_factor;
+#define _ARMV7M_Systick_get_factor(freq) \
+  ((1000000000ULL << 32) / (freq))
+
+#ifdef BSP_ARMV7M_SYSTICK_FREQUENCY
+  #define _ARMV7M_Systick_factor \
+    _ARMV7M_Systick_get_factor(BSP_ARMV7M_SYSTICK_FREQUENCY)
+#else
+  static uint64_t _ARMV7M_Systick_factor;
+#endif
 
 static void _ARMV7M_Systick_at_tick(void)
 {
@@ -39,6 +49,10 @@ static void _ARMV7M_Systick_handler(void)
 
 static void _ARMV7M_Systick_handler_install(void)
 {
+  _ARMV7M_Set_exception_priority(
+    ARMV7M_VECTOR_SYSTICK,
+    ARMV7M_EXCEPTION_PRIORITY_LOWEST
+  );
   _ARMV7M_Set_exception_handler(
     ARMV7M_VECTOR_SYSTICK,
     _ARMV7M_Systick_handler
@@ -48,15 +62,23 @@ static void _ARMV7M_Systick_handler_install(void)
 static void _ARMV7M_Systick_initialize(void)
 {
   volatile ARMV7M_Systick *systick = _ARMV7M_Systick;
-  uint64_t frequency = ARMV7M_SYSTICK_CALIB_TENMS_GET(systick->calib) * 100ULL;
+  #ifdef BSP_ARMV7M_SYSTICK_FREQUENCY
+    uint64_t freq = BSP_ARMV7M_SYSTICK_FREQUENCY;
+  #else
+    uint64_t freq = ARMV7M_SYSTICK_CALIB_TENMS_GET(systick->calib) * 100ULL;
+  #endif
   uint64_t us_per_tick = rtems_configuration_get_microseconds_per_tick();
-  uint64_t interval = (frequency * us_per_tick) / 1000000ULL;
+  uint64_t interval = (freq * us_per_tick) / 1000000ULL;
 
-  _ARMV7M_Systick_factor = (1000000000ULL << 32) / frequency;
+  #ifndef BSP_ARMV7M_SYSTICK_FREQUENCY
+    _ARMV7M_Systick_factor = _ARMV7M_Systick_get_factor(freq);
+  #endif
 
   systick->rvr = (uint32_t) interval;
   systick->cvr = 0;
-  systick->csr = ARMV7M_SYSTICK_CSR_TICKINT | ARMV7M_SYSTICK_CSR_ENABLE;
+  systick->csr = ARMV7M_SYSTICK_CSR_ENABLE
+    | ARMV7M_SYSTICK_CSR_TICKINT
+    | ARMV7M_SYSTICK_CSR_CLKSOURCE;
 }
 
 static void _ARMV7M_Systick_cleanup(void)
@@ -99,4 +121,6 @@ static uint32_t _ARMV7M_Systick_nanoseconds_since_last_tick(void)
   _ARMV7M_Systick_nanoseconds_since_last_tick
 
 /* Include shared source clock driver code */
-#include "../../../shared/clockdrv_shell.h"
+#include "../../../../shared/clockdrv_shell.h"
+
+#endif /* ARM_MULTILIB_ARCH_V7M */
diff --git a/c/src/lib/libbsp/arm/shared/lpc/clock/lpc-clock-config.c b/c/src/lib/libbsp/arm/shared/lpc/clock/lpc-clock-config.c
index e0a521f..f09ebb9 100644
--- a/c/src/lib/libbsp/arm/shared/lpc/clock/lpc-clock-config.c
+++ b/c/src/lib/libbsp/arm/shared/lpc/clock/lpc-clock-config.c
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (c) 2009-2011 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Obere Lagerstr. 30
@@ -20,9 +20,13 @@
  * http://www.rtems.com/license/LICENSE.
  */
 
+#include <rtems.h>
+
 #include <bsp/lpc-clock-config.h>
 #include <bsp/lpc-timer.h>
 
+#ifdef ARM_MULTILIB_ARCH_V4
+
 /* This is defined in ../../../shared/clockdrv_shell.h */
 rtems_isr Clock_isr(rtems_vector_number vector);
 
@@ -127,3 +131,5 @@ static uint32_t lpc_clock_nanoseconds_since_last_tick(void)
 
 /* Include shared source clock driver code */
 #include "../../../../shared/clockdrv_shell.h"
+
+#endif /* ARM_MULTILIB_ARCH_V4 */




More information about the vc mailing list