You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/08/01 04:59:29 UTC

[12/16] incubator-mynewt-core git commit: os, cortex-M; keep using MSP as stack pointer until os_start(). This allows us to take interrupts during system init.

os, cortex-M; keep using MSP as stack pointer until os_start().
This allows us to take interrupts during system init.


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

Branch: refs/heads/sterly_refactor
Commit: 74793416a91452a5361103a95b06b2c81ffa12fc
Parents: 5092dc3
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Jul 29 13:32:48 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Sun Jul 31 21:58:57 2016 -0700

----------------------------------------------------------------------
 libs/os/include/os/arch/cortex_m0/os/os_arch.h | 12 +++----
 libs/os/include/os/arch/cortex_m4/os/os_arch.h | 12 +++----
 libs/os/src/arch/cortex_m0/m0/HAL_CM0.s        |  1 -
 libs/os/src/arch/cortex_m0/os_arch_arm.c       | 34 ++++++++++---------
 libs/os/src/arch/cortex_m4/m4/HAL_CM4.s        |  2 +-
 libs/os/src/arch/cortex_m4/os_arch_arm.c       | 36 ++++++++++++---------
 libs/os/src/os_priv.h                          |  3 +-
 7 files changed, 55 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74793416/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 e986702..1a83ba9 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
@@ -6,7 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
@@ -17,8 +17,8 @@
  * under the License.
  */
 
-#ifndef _OS_ARCH_ARM_H 
-#define _OS_ARCH_ARM_H 
+#ifndef _OS_ARCH_ARM_H
+#define _OS_ARCH_ARM_H
 
 #include <stdint.h>
 #include <mcu/cortex_m0.h>
@@ -48,7 +48,7 @@ typedef uint32_t os_stack_t;
     (OS_ALIGN((__nmemb), OS_STACK_ALIGNMENT))
 
 /* Enter a critical section, save processor state, and block interrupts */
-#define OS_ENTER_CRITICAL(__os_sr) (__os_sr = os_arch_save_sr()) 
+#define OS_ENTER_CRITICAL(__os_sr) (__os_sr = os_arch_save_sr())
 /* Exit a critical section, restore processor state and unblock interrupts */
 #define OS_EXIT_CRITICAL(__os_sr) (os_arch_restore_sr(__os_sr))
 #define OS_ASSERT_CRITICAL() (assert(os_arch_in_critical()))
@@ -63,7 +63,7 @@ void os_arch_init(void);
 uint32_t os_arch_start(void);
 os_error_t os_arch_os_init(void);
 os_error_t os_arch_os_start(void);
-void os_set_env(void);
+void os_set_env(os_stack_t *);
 void os_arch_init_task_stack(os_stack_t *sf);
 void os_default_irq_asm(void);
 
@@ -71,4 +71,4 @@ void os_default_irq_asm(void);
 void os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio);
 void os_bsp_ctx_sw(void);
 
-#endif /* _OS_ARCH_X86_H */ 
+#endif /* _OS_ARCH_ARM_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74793416/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 8c67f09..9e43a7a 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
@@ -6,7 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
@@ -17,8 +17,8 @@
  * under the License.
  */
 
-#ifndef _OS_ARCH_ARM_H 
-#define _OS_ARCH_ARM_H 
+#ifndef _OS_ARCH_ARM_H
+#define _OS_ARCH_ARM_H
 
 #include <stdint.h>
 #include "mcu/cortex_m4.h"
@@ -48,7 +48,7 @@ typedef uint32_t os_stack_t;
     (OS_ALIGN((__nmemb), OS_STACK_ALIGNMENT))
 
 /* Enter a critical section, save processor state, and block interrupts */
-#define OS_ENTER_CRITICAL(__os_sr) (__os_sr = os_arch_save_sr()) 
+#define OS_ENTER_CRITICAL(__os_sr) (__os_sr = os_arch_save_sr())
 /* Exit a critical section, restore processor state and unblock interrupts */
 #define OS_EXIT_CRITICAL(__os_sr) (os_arch_restore_sr(__os_sr))
 #define OS_ASSERT_CRITICAL() (assert(os_arch_in_critical()))
@@ -63,7 +63,7 @@ void os_arch_init(void);
 uint32_t os_arch_start(void);
 os_error_t os_arch_os_init(void);
 os_error_t os_arch_os_start(void);
-void os_set_env(void);
+void os_set_env(os_stack_t *);
 void os_arch_init_task_stack(os_stack_t *sf);
 void os_default_irq_asm(void);
 
@@ -72,4 +72,4 @@ void os_bsp_systick_init(uint32_t os_tick_per_sec, int prio);
 void os_bsp_idle(os_time_t ticks);
 void os_bsp_ctx_sw(void);
 
-#endif /* _OS_ARCH_X86_H */ 
+#endif /* _OS_ARCH_ARM_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74793416/libs/os/src/arch/cortex_m0/m0/HAL_CM0.s
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/m0/HAL_CM0.s b/libs/os/src/arch/cortex_m0/m0/HAL_CM0.s
index 03d7957..de7d46c 100644
--- a/libs/os/src/arch/cortex_m0/m0/HAL_CM0.s
+++ b/libs/os/src/arch/cortex_m0/m0/HAL_CM0.s
@@ -52,7 +52,6 @@ os_set_env:
         .fnstart
         .cantunwind
 
-        MOV     R0,SP           /* Copy MSP to PSP */
         MSR     PSP,R0
         LDR     R0,=os_flags
         LDRB    R0,[R0]

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74793416/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 40b9254..ef1be4d 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -6,7 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
@@ -23,6 +23,8 @@
 #include <hal/hal_os_tick.h>
 #include <bsp/cmsis_nvic.h>
 
+#include "os_priv.h"
+
 /*
  * From HAL_CM0.s
  */
@@ -223,13 +225,6 @@ os_arch_os_init(void)
         /* Set the SVC interrupt to priority 0 (highest configurable) */
         NVIC_SetPriority(SVCall_IRQn, SVC_PRIO);
 
-        /*
-         * Set the os environment. This will set stack pointers and, based
-         * on the contents of os_flags, will determine if the tasks run in
-         * priviliged or un-privileged mode.
-         */
-        os_set_env();
-
         /* Check if privileged or not */
         if ((__get_CONTROL() & 1) == 0) {
             os_arch_init();
@@ -273,17 +268,26 @@ static inline void svc_os_arch_start(void)
 }
 
 /**
- * Start the OS. First check to see if we are running with the correct stack 
- * pointer set (PSP) and privilege mode (PRIV). 
- * 
- * 
- * @return os_error_t 
+ * Start the OS. First check to see if we are running with the correct stack
+ * pointer set (PSP) and privilege mode (PRIV).
+ *
+ * @return os_error_t
  */
 os_error_t
 os_arch_os_start(void)
 {
     os_error_t err;
 
+    /*
+     * Set the os environment. This will set stack pointers and, based
+     * on the contents of os_flags, will determine if the tasks run in
+     * priviliged or un-privileged mode.
+     *
+     * We switch to using "empty" part of idle task's stack until
+     * the svc_os_arch_start() executes SVC, and we will never return.
+     */
+    os_set_env(g_idle_task.t_stackptr - 1);
+
     err = OS_ERR_IN_ISR;
     if (__get_IPSR() == 0) {
         /*
@@ -304,7 +308,7 @@ os_arch_os_start(void)
             err = OS_ERR_PRIV;
             break;
         case 0x02:
-            /* 
+            /*
              * We are running in Privileged Thread mode w/SP = PSP but we
              * are supposed to be un-privileged.
              */
@@ -313,7 +317,7 @@ os_arch_os_start(void)
             }
             break;
         case 0x03:
-            /* 
+            /*
              * We are running in Unprivileged Thread mode w/SP = PSP but we
              * are supposed to be privileged.
              */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74793416/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s b/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
index c9ae103..9c6ab52 100755
--- a/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
+++ b/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
@@ -52,7 +52,6 @@ os_set_env:
         .fnstart
         .cantunwind
 
-        MOV     R0,SP           /* Copy MSP to PSP */
         MSR     PSP,R0
         LDR     R0,=os_flags
         LDRB    R0,[R0]
@@ -63,6 +62,7 @@ os_set_env:
 
         .fnend
         .size   os_set_env, .-os_set_env
+
 /*--------------------------- os_set_env ------------------------------------*/
 
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74793416/libs/os/src/arch/cortex_m4/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_arch_arm.c b/libs/os/src/arch/cortex_m4/os_arch_arm.c
index 2bd084a..184170f 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -6,7 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
@@ -23,6 +23,8 @@
 #include <hal/hal_os_tick.h>
 #include <bsp/cmsis_nvic.h>
 
+#include "os_priv.h"
+
 /* Initial program status register */
 #define INITIAL_xPSR    0x01000000
 
@@ -217,13 +219,6 @@ os_arch_os_init(void)
         /* Set the SVC interrupt to priority 0 (highest configurable) */
         NVIC_SetPriority(SVCall_IRQn, SVC_PRIO);
 
-        /*
-         * Set the os environment. This will set stack pointers and, based
-         * on the contents of os_flags, will determine if the tasks run in
-         * priviliged or un-privileged mode.
-         */
-        os_set_env();
-
         /* Check if privileged or not */
         if ((__get_CONTROL() & 1) == 0) {
             os_arch_init();
@@ -267,17 +262,28 @@ static inline void svc_os_arch_start(void)
 }
 
 /**
- * Start the OS. First check to see if we are running with the correct stack 
- * pointer set (PSP) and privilege mode (PRIV). 
- * 
- * 
- * @return os_error_t 
+ * Start the OS. First check to see if we are running with the correct stack
+ * pointer set (PSP) and privilege mode (PRIV).
+ *
+ *
+ * @return os_error_t
  */
 os_error_t
 os_arch_os_start(void)
 {
     os_error_t err;
 
+    /*
+     * Set the os environment. This will set stack pointers and, based
+     * on the contents of os_flags, will determine if the tasks run in
+     * privileged or un-privileged mode.
+     *
+     * We switch to using "empty" part of idle task's stack until
+     * the svc_os_arch_start() executes SVC, and we will never return.
+     */
+     */
+    os_set_env(g_idle_task.t_stackptr - 1);
+
     err = OS_ERR_IN_ISR;
     if (__get_IPSR() == 0) {
         /*
@@ -298,7 +304,7 @@ os_arch_os_start(void)
             err = OS_ERR_PRIV;
             break;
         case 0x02:
-            /* 
+            /*
              * We are running in Privileged Thread mode w/SP = PSP but we
              * are supposed to be un-privileged.
              */
@@ -307,7 +313,7 @@ os_arch_os_start(void)
             }
             break;
         case 0x03:
-            /* 
+            /*
              * We are running in Unprivileged Thread mode w/SP = PSP but we
              * are supposed to be privileged.
              */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74793416/libs/os/src/os_priv.h
----------------------------------------------------------------------
diff --git a/libs/os/src/os_priv.h b/libs/os/src/os_priv.h
index ddc656b..b5c8f65 100644
--- a/libs/os/src/os_priv.h
+++ b/libs/os/src/os_priv.h
@@ -6,7 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
@@ -26,6 +26,7 @@ TAILQ_HEAD(os_task_list, os_task);
 TAILQ_HEAD(os_callout_list, os_callout);
 STAILQ_HEAD(os_task_stailq, os_task);
 
+extern struct os_task g_idle_task;
 extern struct os_task_list g_os_run_list;
 extern struct os_task_list g_os_sleep_list;
 extern struct os_task_stailq g_os_task_list;