forked from Chunzhi-Lin/mcu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard_power_impl.c
172 lines (147 loc) · 3.48 KB
/
board_power_impl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <chip.h>
#include <common.h>
#include <pin.h>
#include <power.h>
#include <project.h>
#include <stdbool.h>
#include <tick.h>
#include <timer.h>
#define PRESS_VALUE 1
#define FORCE_POWEROFF_PRESS_TIME 2000
#define WARM_POWEROFF_PRESS_TIME 500
#define POWERON_PRESS_TIME 200
#define FORCE_REBOOT_PRESS_TIME 2000
#define WARM_REBOOT_PRESS_TIME 500
bool is_evb_power_key_on(void)
{
if (gpio_get(MCU_PS_ON_PORT, MCU_PS_ON_PIN) == 1)
return true;
return false;
}
// static bool is_power_button_pressed(void)
// {
// if (gpio_get(POWER_KEY_PORT, POWER_KEY_PIN) == PRESS_VALUE)
// return true;
// return false;
// }
// static bool is_reset_button_pressed(void)
// {
// if (gpio_get(RESET_KEY_PORT, RESET_KEY_PIN) == PRESS_VALUE)
// return true;
// return false;
// }
// void milkv_warm_poweroff(void)
// {
// gpio_set(LINK_GPIO22_PORT, LINK_GPIO22_PIN);
// timer_mdelay(150);
// gpio_clear(LINK_GPIO22_PORT, LINK_GPIO22_PIN);
// }
// void milkv_warm_reboot(void)
// {
// gpio_set(LINK_GPIO23_PORT, LINK_GPIO23_PIN);
// timer_mdelay(150);
// gpio_clear(LINK_GPIO23_PORT, LINK_GPIO23_PIN);
// }
// static void milkv_power_button_control(void)
// {
// uint16_t press_time, curren_time, last_time;
// curren_time = last_time = tick_get();
// while (is_power_button_pressed()) {
// curren_time = tick_get();
// if(curren_time - last_time > FORCE_POWEROFF_PRESS_TIME)
// break;
// }
// press_time = curren_time - last_time;
// if (power_status() == true) {
// if (press_time > FORCE_POWEROFF_PRESS_TIME) {
// power_off();
// while (is_power_button_pressed())
// ;
// } else if (press_time > WARM_POWEROFF_PRESS_TIME)
// milkv_warm_poweroff();
// } else {
// if (press_time > POWERON_PRESS_TIME)
// power_on();
// }
// }
// static void milkv_reset_button_control(void)
// {
// uint16_t press_time, curren_time, last_time;
// curren_time = last_time = tick_get();
// while ((power_status() == true) && is_reset_button_pressed()) {
// curren_time = tick_get();
// if (curren_time - last_time > FORCE_REBOOT_PRESS_TIME)
// break;
// }
// press_time = curren_time - last_time;
// if (press_time > FORCE_REBOOT_PRESS_TIME) {
// power_off();
// timer_mdelay(50);
// power_on();
// } else if (press_time > WARM_REBOOT_PRESS_TIME)
// milkv_warm_reboot();
// }
static void evb_power_control(void)
{
if (is_evb_power_key_on() == true) {
if (power_status() == false) {
while(gpio_get(PWR_OK_C_PORT, PWR_OK_C_PIN) == 1){
timer_udelay(1000);
}
timer_udelay(10000);
power_on();
}
}
if (is_evb_power_key_on() == false) {
if (power_status() == true)
power_off();
}
}
// void milkv_auto_power_on(void)
// {
// if (get_board_type() == MILKV_PIONEER) {
// /* Wait for 12V to be stable */
// timer_mdelay(1000);
// /* power on automatically after ATX powered */
// power_on();
// }
// }
void board_power_control(void)
{
switch (get_board_type()) {
case BM1690EVB:
evb_power_control();
break;
default:
break;
}
}
// int milkv_atx_ctl_on(void)
// {
// if (get_board_type() == MILKV_PIONEER)
// gpio_set(MCU_ATX_ON_PORT, MCU_ATX_ON_PIN);
// return 0;
// }
// void milkv_atx_ctl_off(void)
// {
// if (get_board_type() == MILKV_PIONEER)
// gpio_clear(MCU_ATX_ON_PORT, MCU_ATX_ON_PIN);
// }
int sys_rst_assert_on(void)
{
chip_enable();
return 0;
}
void sys_rst_assert_off(void)
{
}
int sys_rst_deassert_on(void)
{
chip_disable();
return 0;
}
void sys_rst_deassert_off(void)
{
/* reset chip firstly when power off */
chip_disable();
}