RTEMS  5.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
187 void atsam_power_handler_sleep_mode(
188  const atsam_power_control *controls,
189  atsam_power_state state
190 );
191 
198 #define ATSAM_POWER_PERIPHERAL(f, l) \
199  { \
200  .handler = atsam_power_handler_peripheral, \
201  .data = { .peripherals = { .first = f, .last = l } } \
202  }
203 
204 #define ATSAM_POWER_HANDLER(h, a) \
205  { \
206  .handler = h, \
207  .data = { .arg = a } \
208  }
209 
210 #define ATSAM_POWER_CLOCK_DRIVER \
211  { .handler = atsam_power_handler_clock_driver }
212 
213 #define ATSAM_POWER_SLEEP_MODE \
214  { .handler = atsam_power_handler_sleep_mode }
215 
221 typedef struct {
225  uint8_t interval;
226 } atsam_power_data_rtc_driver;
227 
235 #define ATSAM_POWER_RTC_DRIVER(a) \
236  { \
237  .handler = atsam_power_handler_rtc_driver, \
238  .data = { .arg = a } \
239  }
240 
241 #ifdef __cplusplus
242 }
243 #endif /* __cplusplus */
244 
245 #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.