Statistics
| Branch: | Tag: | Revision:

amiro-os / devices / PowerManagement / exti.cpp @ 9090cc7e

History | View | Annotate | Download (2.934 KB)

1 58fe0e0b Thomas Schöpping
#include <ch.hpp>
2
#include <hal.h>
3
4
#include <board.h>
5
6
#include "exti.hpp"
7
8
volatile uint32_t shutdown_now = 0x00000000u;
9
volatile uint32_t pathdc_change = 0x00000000u;
10
11
EXTConfig extcfg = {
12
13
  {
14
    /* channel 0 */
15
    {
16
      /* mode */ EXT_CH_MODE_DISABLED,
17
      /* cb   */ NULL,
18
    },
19
    /* channel 1 */
20
    {
21
      /* mode */ EXT_CH_MODE_DISABLED,
22
      /* cb   */ NULL,
23
    },
24
    /* channel 2 */
25
    {
26
      /* mode */ EXT_CH_MODE_DISABLED,
27
      /* cb   */ NULL,
28
    },
29
    /* channel 3 */
30
    {
31
      /* mode */ EXT_CH_MODE_DISABLED,
32
      /* cb   */ NULL,
33
    },
34
    /* channel 4 */
35
    {
36
      /* mode */ EXT_CH_MODE_DISABLED,
37
      /* cb   */ NULL,
38
    },
39
    /* channel 5 */
40
    {
41
      /* mode */ EXT_CH_MODE_DISABLED,
42
      /* cb   */ NULL,
43
    },
44
    /* channel 6 */
45
    {
46
      /* mode */ EXT_CH_MODE_DISABLED,
47
      /* cb   */ NULL,
48
    },
49
    /* channel 7 */
50
    {
51
      /* mode */ EXT_CH_MODE_DISABLED,
52
      /* cb   */ NULL,
53
    },
54
    /* channel 8 */
55
    {
56
      /* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_AUTOSTART | EXT_CH_MODE_BOTH_EDGES,
57
      /* cb   */ pathdc_cb,
58
    },
59
    /* channel 9 */
60
    {
61
      /* mode */ EXT_CH_MODE_DISABLED,
62
      /* cb   */ NULL,
63
    },
64
    /* channel A */
65
    {
66
      /* mode */ EXT_CH_MODE_DISABLED,
67
      /* cb   */ NULL,
68
    },
69
    /* channel B */
70
    {
71
      /* mode */ EXT_CH_MODE_DISABLED,
72
      /* cb   */ NULL,
73
    },
74
    /* channel C */
75
    {
76
      /* mode */ EXT_CH_MODE_DISABLED,
77
      /* cb   */ NULL,
78
    },
79
    /* channel D */
80
    {
81
      /* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_AUTOSTART | EXT_CH_MODE_FALLING_EDGE,
82
      /* cb   */ power_down_cb,
83
    },
84
    /* channel E */
85
    {
86
      /* mode */ EXT_CH_MODE_DISABLED,
87
      /* cb   */ NULL,
88
    },
89
    /* channel F */
90
    {
91
      /* mode */ EXT_CH_MODE_DISABLED,
92
      /* cb   */ NULL,
93
    },
94
    /* channel 10 */
95
    {
96
      /* mode */ EXT_CH_MODE_DISABLED,
97
      /* cb   */ NULL,
98
    },
99
    /* channel 11 */
100
    {
101
      /* mode */ EXT_CH_MODE_DISABLED,
102
      /* cb   */ NULL,
103
    },
104
    /* channel 12 */
105
    {
106
      /* mode */ EXT_CH_MODE_DISABLED,
107
      /* cb   */ NULL,
108
    },
109
    /* channel 13 */
110
    {
111
      /* mode */ EXT_CH_MODE_DISABLED,
112
      /* cb   */ NULL,
113
    },
114
    /* channel 14 */
115
    {
116
      /* mode */ EXT_CH_MODE_DISABLED,
117
      /* cb   */ NULL,
118
    },
119
    /* channel 15 */
120
    {
121
      /* mode */ EXT_CH_MODE_DISABLED,
122
      /* cb   */ NULL,
123
    },
124
    /* channel 16 */
125
    {
126
      /* mode */ EXT_CH_MODE_DISABLED,
127
      /* cb   */ NULL,
128
    },
129
  }
130
};
131
132
void power_down_cb(EXTDriver *extp, expchannel_t channel) {
133
134
  (void) extp;
135
  (void) channel;
136
  // make sure we don't accidentally power down when somebody tries to wake us
137
  if (!palReadPad(GPIOC, GPIOC_SYS_PD_N))
138
    palWritePad(GPIOC, GPIOC_SYS_INT_N, PAL_LOW); // indicate that the module needs some time to shut down
139
    shutdown_now = 5; // = SHUTDOWN_HANDLE_REQUEST in main.cpp
140
}
141
142
void pathdc_cb(EXTDriver *extp, expchannel_t channel) {
143
144
  (void) extp;
145
  (void) channel;
146
147
  pathdc_change = ~0u;
148
149
}