pm.c
2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2015 Saurabh Singh
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup cpu_samd21
* @ingroup drivers_periph_pm
* @{
*
* @file
* @brief Implementation of the kernels power management interface
*
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
* @author Saurabh Singh <saurabh@cezy.co>
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include "periph/pm.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
enum system_sleepmode {
/**
* Idle 0 mode.
* Potential Wake Up sources: Synchronous(APB, AHB), asynchronous.
*/
SYSTEM_SLEEPMODE_IDLE_0,
/**
* Idle 1 mode.
* Potential Wake Up sources: Synchronous (APB), asynchronous
*/
SYSTEM_SLEEPMODE_IDLE_1,
/**
* Idle 2 mode.
* Potential Wake Up sources: Asynchronous
*/
SYSTEM_SLEEPMODE_IDLE_2,
/**
* Standby mode.
* Potential Wake Up sources: Asynchronous
*/
SYSTEM_SLEEPMODE_STANDBY,
};
void pm_set(unsigned mode)
{
int deep = 0;
switch (mode) {
case 0:
/* Standby Mode
* Potential Wake Up sources: asynchronous
*/
deep = 1;
break;
case 1:
/* Sleep mode Idle 2
* Potential Wake Up sources: asynchronous
*/
PM->SLEEP.reg = SYSTEM_SLEEPMODE_IDLE_2;
break;
case 2:
/* Sleep mode Idle 1
* Potential Wake Up sources: Synchronous (APB), asynchronous
*/
PM->SLEEP.reg = SYSTEM_SLEEPMODE_IDLE_1;
break;
case 3:
/* Sleep mode Idle 0
* Potential Wake Up sources: Synchronous (APB, AHB), asynchronous
*/
PM->SLEEP.reg = SYSTEM_SLEEPMODE_IDLE_0;
break;
}
cortexm_sleep(deep);
}