source: rtems/bsps/arm/atsam/start/power.c @ ba619b7f

Last change on this file since ba619b7f was ba619b7f, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 21:38:20

bsps/arm/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
3 *
4 * The license and distribution terms for this file may be
5 * found in the file LICENSE in this distribution or at
6 * http://www.rtems.org/license/LICENSE.
7 */
8
9#include <bsp.h>
10#include <bsp/power.h>
11#include <bsp/irq.h>
12
13#include <libchip/chip.h>
14
15void atsam_power_change_state(
16    const atsam_power_control *controls,
17    size_t n,
18    atsam_power_state state
19)
20{
21        size_t i;
22
23        switch (state) {
24                case ATSAM_POWER_ON:
25                        for (i = n; i > 0; --i) {
26                                const atsam_power_control *c;
27
28                                c = &controls[i - 1];
29                                (*c->handler)(c, state);
30                        }
31
32                        break;
33                case ATSAM_POWER_INIT:
34                case ATSAM_POWER_OFF:
35                        for (i = 0; i < n; ++i) {
36                                const atsam_power_control *c;
37
38                                c = &controls[i];
39                                (*c->handler)(c, state);
40                        }
41
42                        break;
43                default:
44                        break;
45        }
46}
47
48void atsam_power_handler_peripheral(
49    const atsam_power_control *control,
50    atsam_power_state state
51)
52{
53        uint32_t id;
54        uint32_t end;
55
56        id = control->data.peripherals.first;
57        end = control->data.peripherals.last + 1;
58
59        switch (state) {
60                case ATSAM_POWER_ON:
61                        while (id != end) {
62                                PMC_EnablePeripheral(id);
63                                ++id;
64                        }
65                        break;
66                case ATSAM_POWER_OFF:
67                        while (id != end) {
68                                PMC_DisablePeripheral(id);
69                                ++id;
70                        }
71                        break;
72                default:
73                        break;
74        }
75}
76
77void atsam_power_handler_sleep_mode(const atsam_power_control *control, atsam_power_state state)
78{
79        (void) control;
80
81        switch (state) {
82                case ATSAM_POWER_OFF:
83                        /* Enable Low Power Mode in the Fast Startup Mode Register */
84                        PMC->PMC_FSMR &= (uint32_t)~PMC_FSMR_LPM;
85                        /* Do not set deep sleep, but "normal" sleep */
86                        SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
87
88                        __asm__ volatile ("wfi");
89                        break;
90                default:
91                        break;
92        }
93}
Note: See TracBrowser for help on using the repository browser.