You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2016/02/03 08:18:20 UTC

incubator-mynewt-larva git commit: Modify cortex-m0 os arch so that it calls the bsp to initialize the os time tick. Did not modify cortex-m4 code as of yet

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master f34359789 -> ce8a844a3


Modify cortex-m0 os arch so that it calls the bsp to initialize the os time tick. Did not modify cortex-m4 code as of yet


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/ce8a844a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/ce8a844a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/ce8a844a

Branch: refs/heads/master
Commit: ce8a844a3238f163dc3b21067e8d4c5e7bfbd81e
Parents: f343597
Author: wes3 <wi...@micosa.io>
Authored: Tue Feb 2 23:17:58 2016 -0800
Committer: wes3 <wi...@micosa.io>
Committed: Tue Feb 2 23:17:58 2016 -0800

----------------------------------------------------------------------
 hw/bsp/nrf51dk/src/os_bsp.c                    | 61 ++++++++++++++++++++
 hw/mcu/nordic/nrf51xxx/src/hal_system.c        | 64 ---------------------
 libs/os/include/os/arch/cortex_m0/os/os_arch.h |  2 +-
 libs/os/include/os/arch/cortex_m4/os/os_arch.h |  2 +-
 libs/os/src/arch/cortex_m0/os_arch_arm.c       | 31 +---------
 5 files changed, 64 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce8a844a/hw/bsp/nrf51dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/os_bsp.c b/hw/bsp/nrf51dk/src/os_bsp.c
index 54e9d04..3e28df3 100644
--- a/hw/bsp/nrf51dk/src/os_bsp.c
+++ b/hw/bsp/nrf51dk/src/os_bsp.c
@@ -14,6 +14,10 @@
  * limitations under the License.
  */
 #include <hal/flash_map.h>
+#include "bsp/cmsis_nvic.h"
+#include "mcu/nrf51.h"
+#include "mcu/nrf51_bitfields.h"
+#include "mcu/nrf51_hal.h"
 
 static struct flash_area bsp_flash_areas[] = {
 #if 0
@@ -78,3 +82,60 @@ os_bsp_init(void)
       sizeof(bsp_flash_areas) / sizeof(bsp_flash_areas[0]));
 
 }
+
+extern void timer_handler(void);
+static void
+rtc0_timer_handler(void)
+{
+    if (NRF_RTC0->EVENTS_TICK) {
+        NRF_RTC0->EVENTS_TICK = 0;
+        timer_handler();
+    }
+}
+
+void
+os_bsp_systick_init(uint32_t os_ticks_per_sec)
+{
+    uint32_t ctx;
+    uint32_t mask;
+    uint32_t pre_scaler;
+
+    /* Turn on the LFCLK */
+    NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_16MHz;
+    NRF_CLOCK->TASKS_LFCLKSTOP = 1;
+    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
+    NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal;
+    NRF_CLOCK->TASKS_LFCLKSTART = 1;
+
+    /* Wait here till started! */
+    mask = CLOCK_LFCLKSTAT_STATE_Msk | CLOCK_LFCLKSTAT_SRC_Xtal;
+    while (1) {
+        if (NRF_CLOCK->EVENTS_LFCLKSTARTED) {
+            if ((NRF_CLOCK->LFCLKSTAT & mask) == mask) {
+                break;
+            }
+        }
+    }
+
+    /* Is this exact frequency obtainable? */
+    pre_scaler = (32768 / os_ticks_per_sec) - 1;
+
+    /* disable interrupts */
+    __HAL_DISABLE_INTERRUPTS(ctx);
+
+    NRF_RTC0->TASKS_STOP = 1;
+    NRF_RTC0->EVENTS_TICK = 0;
+    NRF_RTC0->PRESCALER = pre_scaler;
+    NRF_RTC0->INTENCLR = 0xffffffff;
+    NRF_RTC0->TASKS_CLEAR = 1;
+
+    /* Set isr in vector table and enable interrupt */
+    NVIC_SetVector(RTC0_IRQn, (uint32_t)rtc0_timer_handler);
+    NVIC_EnableIRQ(RTC0_IRQn);
+
+    NRF_RTC0->INTENSET = RTC_INTENSET_TICK_Msk;
+    NRF_RTC0->TASKS_START = 1;
+
+    __HAL_ENABLE_INTERRUPTS(ctx);
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce8a844a/hw/mcu/nordic/nrf51xxx/src/hal_system.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_system.c b/hw/mcu/nordic/nrf51xxx/src/hal_system.c
index 3a01ca2..1ba0896 100644
--- a/hw/mcu/nordic/nrf51xxx/src/hal_system.c
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_system.c
@@ -16,12 +16,6 @@
 
 #include <mcu/cortex_m0.h>
 #include "hal/hal_system.h"
-/* XXX */
-#include "bsp/cmsis_nvic.h"
-#include "mcu/nrf51.h"
-#include "mcu/nrf51_bitfields.h"
-#include "mcu/nrf51_hal.h"
-/* XXX */
 
 void
 system_reset(void)
@@ -31,61 +25,3 @@ system_reset(void)
     }
 }
 
-/* XXX*/
-extern void timer_handler(void);
-
-static void
-rtc0_timer_handler(void)
-{
-    if (NRF_RTC0->EVENTS_TICK) {
-        NRF_RTC0->EVENTS_TICK = 0;
-        timer_handler();
-    }
-}
-
-void
-system_os_tick_init(uint32_t os_ticks_per_sec)
-{
-    uint32_t ctx;
-    uint32_t mask;
-    uint32_t pre_scaler;
-
-    /* Turn on the LFCLK */
-    NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_16MHz;
-    NRF_CLOCK->TASKS_LFCLKSTOP = 1;
-    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
-    NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal;
-    NRF_CLOCK->TASKS_LFCLKSTART = 1;
-
-    /* Wait here till started! */
-    mask = CLOCK_LFCLKSTAT_STATE_Msk | CLOCK_LFCLKSTAT_SRC_Xtal;
-    while (1) {
-        if (NRF_CLOCK->EVENTS_LFCLKSTARTED) {
-            if ((NRF_CLOCK->LFCLKSTAT & mask) == mask) {
-                break;
-            }
-        }
-    }
-
-    /* Is this exact frequency obtainable? */
-    pre_scaler = (32768 / os_ticks_per_sec) - 1;
-
-    /* disable interrupts */
-    __HAL_DISABLE_INTERRUPTS(ctx);
-
-    NRF_RTC0->TASKS_STOP = 1;
-    NRF_RTC0->EVENTS_TICK = 0;
-    NRF_RTC0->PRESCALER = pre_scaler;
-    NRF_RTC0->INTENCLR = 0xffffffff;
-    NRF_RTC0->TASKS_CLEAR = 1;
-
-    /* Set isr in vector table and enable interrupt */
-    NVIC_SetVector(RTC0_IRQn, (uint32_t)rtc0_timer_handler);
-    NVIC_EnableIRQ(RTC0_IRQn);
-
-    NRF_RTC0->INTENSET = RTC_INTENSET_TICK_Msk;
-    NRF_RTC0->TASKS_START = 1;
-
-    __HAL_ENABLE_INTERRUPTS(ctx);
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce8a844a/libs/os/include/os/arch/cortex_m0/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m0/os/os_arch.h b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
index 4ddd768..992e9f3 100755
--- a/libs/os/include/os/arch/cortex_m0/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
@@ -67,7 +67,7 @@ void os_arch_init_task_stack(os_stack_t *sf);
 void os_default_irq_asm(void);
 
 /* External function prototypes supplied by BSP */
-void os_bsp_systick_init(uint32_t os_tick_usecs);
+void os_bsp_systick_init(uint32_t os_ticks_per_sec);
 void os_bsp_init(void);
 void os_bsp_ctx_sw(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce8a844a/libs/os/include/os/arch/cortex_m4/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m4/os/os_arch.h b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
index 1f92c72..3bb1cb7 100755
--- a/libs/os/include/os/arch/cortex_m4/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
@@ -67,7 +67,7 @@ void os_arch_init_task_stack(os_stack_t *sf);
 void os_default_irq_asm(void);
 
 /* External function prototypes supplied by BSP */
-void os_bsp_systick_init(uint32_t os_tick_usecs);
+void os_bsp_systick_init(uint32_t os_tick_per_sec);
 void os_bsp_init(void);
 void os_bsp_ctx_sw(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce8a844a/libs/os/src/arch/cortex_m0/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/os_arch_arm.c b/libs/os/src/arch/cortex_m0/os_arch_arm.c
index 8f4753a..fabd0fd 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -230,35 +230,6 @@ os_arch_os_init(void)
     return err;
 }
 
-/**
- * os systick init
- *
- * Initializes systick for the MCU
- *
- * @param os_tick_usecs The number of microseconds in an os time tick
- */
-static void
-os_systick_init(uint32_t os_tick_usecs)
-{
-    /* XXX */
-#if 0
-    uint32_t reload_val;
-
-    reload_val = (((uint64_t)SystemCoreClock * os_tick_usecs) / 1000000) - 1;
-
-    /* Set the system time ticker up */
-    SysTick->LOAD = reload_val;
-    SysTick->VAL = 0;
-    SysTick->CTRL = 0x0007;
-
-    /* Set the system tick priority */
-    NVIC_SetPriority(SysTick_IRQn, SYSTICK_PRIO);
-#else
-    system_os_tick_init(1024);
-#endif
-
-}
-
 uint32_t
 os_arch_start(void)
 {
@@ -272,7 +243,7 @@ os_arch_start(void)
     __set_PSP((uint32_t)t->t_stackptr + offsetof(struct stack_frame, r0));
 
     /* Intitialize and start system clock timer */
-    os_systick_init(1000000 / OS_TICKS_PER_SEC);
+    os_bsp_systick_init(OS_TICKS_PER_SEC);
 
     /* Mark the OS as started, right before we run our first task */
     g_os_started = 1;