Paparazzi UAS  v6.0_unstable-92-g17422e4-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mcu_arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 AggieAir, A Remote Sensing Unmanned Aerial System for Scientific Applications
3  * Utah State University, http://aggieair.usu.edu/
4  *
5  * Michal Podhradsky (michal.podhradsky@aggiemail.usu.edu)
6  * Calvin Coopmans (c.r.coopmans@ieee.org)
7  *
8  *
9  * This file is part of paparazzi.
10  *
11  * paparazzi is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2, or (at your option)
14  * any later version.
15  *
16  * paparazzi is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with paparazzi; see the file COPYING. If not, write to
23  * the Free Software Foundation, 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  */
31 #ifndef CHIBIOS_MCU_ARCH_H
32 #define CHIBIOS_MCU_ARCH_H
33 
34 #include "std.h"
35 
36 extern void mcu_arch_init(void);
37 
38 #if USE_HARD_FAULT_RECOVERY
39 extern bool recovering_from_hard_fault;
40 #endif
41 
42 #include <ch.h>
43 
52 static inline void mcu_deep_sleep(void)
53 {
54 #if defined STM32F4
55  /* clear PDDS and LPDS bits */
56  PWR->CR &= ~(PWR_CR_PDDS | PWR_CR_LPDS);
57  /* set LPDS and clear */
58  PWR->CR |= (PWR_CR_LPDS | PWR_CR_CSBF | PWR_CR_CWUF);
59 #elif defined STM32F7
60  /* clear PDDS and LPDS bits */
61  PWR->CR1 &= ~(PWR_CR1_PDDS | PWR_CR1_LPDS);
62  /* set LPDS and clear */
63  PWR->CR1 |= (PWR_CR1_LPDS | PWR_CR1_CSBF);
64 #endif
65 
66  /* Setup the deepsleep mask */
67  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
68 
69  __disable_irq();
70 
71  __SEV();
72  __WFE();
73  __WFE();
74 
75  __enable_irq();
76 
77  /* clear the deepsleep mask */
78  SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
79 }
80 
83 static inline void mcu_reset(void)
84 {
85  NVIC_SystemReset();
86 }
87 
91 extern void mcu_periph_energy_save(void);
92 
93 #endif /* CHIBIOS_MCU_ARCH_H */
void mcu_periph_energy_save(void)
Call board specific energy saving Can be necessary for closing on power off.
Definition: mcu_arch.c:154
static void __enable_irq(void)
Definition: i2c_arch.c:67
static void __disable_irq(void)
Definition: i2c_arch.c:66
void mcu_arch_init(void)
Definition: mcu_arch.c:109
static void mcu_reset(void)
Request a software reset of the MCU.
Definition: mcu_arch.h:83
static void mcu_deep_sleep(void)
Put MCU into deep sleep mode.
Definition: mcu_arch.h:52