1
2 /**
3 * \file
4 *
5 * \brief SAM Power manager
6 *
7 * Copyright (C) 2014-2016 Atmel Corporation. All rights reserved.
8 *
9 * \asf_license_start
10 *
11 * \page License
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above copyright notice,
20 * this list of conditions and the following disclaimer in the documentation
21 * and/or other materials provided with the distribution.
22 *
23 * 3. The name of Atmel may not be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * 4. This software may only be redistributed and used in connection with an
27 * Atmel microcontroller product.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
32 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
33 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 *
41 * \asf_license_stop
42 *
43 */
44
45 #include <hpl_sleep.h>
46 #include <hpl_init.h>
47
48 /**
49 * \brief Set the sleep mode for the device
50 */
_set_sleep_mode(const uint8_t mode)51 int32_t _set_sleep_mode(const uint8_t mode)
52 {
53 switch (mode) {
54 case 2:
55 case 4:
56 case 5:
57 case 6:
58 hri_pm_write_SLEEPCFG_SLEEPMODE_bf(PM, mode);
59 break;
60 default:
61 return ERR_INVALID_ARG;
62 }
63
64 return ERR_NONE;
65 }
66
67 /**
68 * \brief Set performance level
69 */
_set_performance_level(const uint8_t level)70 void _set_performance_level(const uint8_t level)
71 {
72 hri_pm_clear_INTFLAG_reg(PM, 0xFF);
73 if (hri_pm_get_PLCFG_PLSEL_bf(PM, PM_PLCFG_PLSEL_Msk) != level) {
74 hri_pm_write_PLCFG_PLSEL_bf(PM, level);
75 }
76 while (!hri_pm_read_INTFLAG_reg(PM))
77 ;
78 }
79