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 
59 #define PROVIDES_PM_SET_LOWEST
60 
64 void cpu_init(void);
65 
69 void cortexm_init(void);
70 
74 static inline void cpu_print_last_instruction(void)
75 {
76  uint32_t *lr_ptr;
77  __asm__ __volatile__("mov %0, lr" : "=r"(lr_ptr));
78  printf("%p\n", (void*) lr_ptr);
79 }
80 
87 static inline void cortexm_sleep_until_event(void)
88 {
89  __WFE();
90 }
91 
97 static inline void cortexm_sleep(int deep)
98 {
99  if (deep) {
100  SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk);
101  }
102  else {
103  SCB->SCR &= ~(SCB_SCR_SLEEPDEEP_Msk);
104  }
105 
106  /* ensure that all memory accesses have completed and trigger sleeping */
107  unsigned state = irq_disable();
108  __DSB();
109  __WFI();
110  irq_restore(state);
111 }
112 
118 static inline void cortexm_isr_end(void)
119 {
121  thread_yield();
122  }
123 }
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif /* CPU_H */
130 
void irq_restore(unsigned state)
This function restores the IRQ disable bit in the status register to the value contained within passe...
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 &#39;wait for event&#39; 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.
void thread_yield(void)
Lets current thread yield.
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.
unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.
IRQ driver interface.