RTEMS  5.1
power.h
1 /*
2  * Copyright (c) 2016 embedded brains GmbH. All rights reserved.
3  *
4  * embedded brains GmbH
5  * Dornierstr. 4
6  * 82178 Puchheim
7  * Germany
8  * <rtems@embedded-brains.de>
9  *
10  * The license and distribution terms for this file may be
11  * found in the file LICENSE in this distribution or at
12  * http://www.rtems.org/license/LICENSE.
13  */
14 
15 #ifndef LIBBSP_ARM_ATSAM_POWER_H
16 #define LIBBSP_ARM_ATSAM_POWER_H
17 
18 #include <sys/types.h>
19 
20 #include <stdint.h>
21 
22 #ifdef __cplusplus
23 extern "C"{
24 #endif /* __cplusplus */
25 
29 typedef enum {
33  ATSAM_POWER_INIT,
37  ATSAM_POWER_ON,
41  ATSAM_POWER_OFF
42 } atsam_power_state;
43 
47 typedef struct atsam_power_control {
51  void (*handler)(
52  const struct atsam_power_control *control,
53  atsam_power_state state
54  );
58  union {
59  void *arg;
60  struct {
61  uint8_t first;
62  uint8_t last;
63  } peripherals;
64  } data;
66 
124 void atsam_power_change_state(
125  const atsam_power_control *controls,
126  size_t n,
127  atsam_power_state state
128 );
129 
141 void atsam_power_handler_peripheral(
142  const atsam_power_control *controls,
143  atsam_power_state state
144 );
145 
157 void atsam_power_handler_clock_driver(
158  const atsam_power_control *controls,
159  atsam_power_state state
160 );
161 
174 void atsam_power_handler_rtc_driver(
175  const atsam_power_control *controls,
176  atsam_power_state state
177 );
178 
184 void atsam_power_handler_sleep_mode(
185  const atsam_power_control *controls,
186  atsam_power_state state
187 );
188 
196 void atsam_power_handler_wait_mode(
197  const atsam_power_control *controls,
198  atsam_power_state state
199 );
200 
207 #define ATSAM_POWER_PERIPHERAL(f, l) \
208  { \
209  .handler = atsam_power_handler_peripheral, \
210  .data = { .peripherals = { .first = f, .last = l } } \
211  }
212 
213 #define ATSAM_POWER_HANDLER(h, a) \
214  { \
215  .handler = h, \
216  .data = { .arg = a } \
217  }
218 
219 #define ATSAM_POWER_CLOCK_DRIVER \
220  { .handler = atsam_power_handler_clock_driver }
221 
222 #define ATSAM_POWER_SLEEP_MODE \
223  { .handler = atsam_power_handler_sleep_mode }
224 
225 #define ATSAM_POWER_WAIT_MODE \
226  { .handler = atsam_power_handler_wait_mode }
227 
233 typedef struct {
239  uint32_t interval;
240 } atsam_power_data_rtc_driver;
241 
249 #define ATSAM_POWER_RTC_DRIVER(a) \
250  { \
251  .handler = atsam_power_handler_rtc_driver, \
252  .data = { .arg = a } \
253  }
254 
255 #ifdef __cplusplus
256 }
257 #endif /* __cplusplus */
258 
259 #endif /* LIBBSP_ARM_ATSAM_POWER_H */
Control structure for power control handling.
Definition: power.h:47
Definition: intercom.c:74
void(* handler)(const struct atsam_power_control *control, atsam_power_state state)
Data pointer to the handler with its desired state.
Definition: power.h:51
union atsam_power_control::@7 data
Data chunk that is used by the handler.