cortexm_common/include/cpu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
30 #ifndef CPU_H
31 #define CPU_H
32 
33 #include <stdio.h>
34 
35 #include "irq.h"
36 #include "sched.h"
37 #include "thread.h"
38 #include "cpu_conf.h"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
51 #define STACK_CANARY_WORD (0xE7FEE7FEu)
52 
56 void cpu_init(void);
57 
61 void cortexm_init(void);
62 
66 static inline void cpu_print_last_instruction(void)
67 {
68  uint32_t *lr_ptr;
69  __asm__ __volatile__("mov %0, lr" : "=r"(lr_ptr));
70  printf("%p\n", (void*) lr_ptr);
71 }
72 
79 static inline void cortexm_sleep_until_event(void)
80 {
81  __WFE();
82 }
83 
89 static inline void cortexm_sleep(int deep)
90 {
91  if (deep) {
92  SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
93  }
94  else {
95  SCB->SCR &= ~(SCB_SCR_SLEEPDEEP_Msk);
96  }
97 
98  /* ensure that all memory accesses have completed and trigger sleeping */
99  __disable_irq();
100  __DSB();
101  __WFI();
102  __enable_irq();
103 }
104 
110 static inline void cortexm_isr_end(void)
111 {
113  thread_yield();
114  }
115 }
116 
117 #ifdef __cplusplus
118 }
119 #endif
120 
121 #endif /* CPU_H */
122 
static void __disable_irq(void)
Globally disable IRQs.
void thread_yield(void)
Lets current thread yield.
static void __enable_irq(void)
Globally enable IRQs.
Threading API.
volatile unsigned int sched_context_switch_request
Flag indicating whether a context switch is necessary after handling an interrupt.
static void cortexm_sleep_until_event(void)
Put the CPU into the 'wait for event' sleep mode.
Scheduler API definition.
static void cpu_print_last_instruction(void)
Prints the current content of the link register (lr)
static void cortexm_isr_end(void)
Trigger a conditional context scheduler run / context switch.
stdio.h wrapper for MSP430
static void cortexm_sleep(int deep)
Put the CPU into (deep) sleep mode, using the WFI instruction.
void cpu_init(void)
Initialization of the CPU.
void cortexm_init(void)
Initialize Cortex-M specific core parts of the CPU.
IRQ driver interface.