-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwkup_det.c
executable file
·103 lines (99 loc) · 1.59 KB
/
wkup_det.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
#include "MQ6812.h"
#include "iApp.h"
#include "FlashFunction.h"
#include "protocol.h"
#include "wkup_det.h"
extern uchar cur_dev_sta;
extern uchar pre_dev_sta;
extern uchar nxt_dev_sta;
uchar wkup_back_in_cnt = 0;
uchar wkup_back_out_cnt = 0;
uchar wkup_front_in_cnt = 0;
uchar wkup_front_out_cnt = 0;
uchar usb_adp_in_flag = 0;
uchar wkup_back_flag = 0;
uchar wkup_front_flag = 0;
void WKUP_Detect(void)
{
if(WKUP_BACK==1)
{
wkup_back_in_cnt++;
}
else
{
wkup_back_out_cnt++;
}
if(WKUP_FRONT==1)
{
wkup_front_in_cnt++;
}
else
{
wkup_front_out_cnt++;
}
if(wkup_back_in_cnt>10)
{
wkup_back_flag = 1;
wkup_back_in_cnt=0;
wkup_back_out_cnt=0;
}
if(wkup_back_out_cnt>10)
{
wkup_back_flag = 1;
wkup_back_in_cnt=0;
wkup_back_out_cnt=0;
}
if(wkup_front_in_cnt>10)
{
if(wkup_front_out_cnt>6)
{
usb_adp_in_flag =1;
wkup_front_in_cnt=0;
wkup_front_out_cnt=0;
}
else
{
usb_adp_in_flag =0;
wkup_front_flag=1;
wkup_front_in_cnt=0;
wkup_front_out_cnt=0;
}
}
if(wkup_front_out_cnt>9)
{
if(wkup_front_in_cnt ==0)
{
wkup_front_flag=0;
wkup_front_in_cnt=0;
wkup_front_out_cnt=0;
}
}
WKUP_Update_Device_State();
}
void WKUP_Update_Device_State(void)
{
if(wkup_back_flag==1)
{
nxt_dev_sta |= 0x04;
}
else
{
nxt_dev_sta &= 0xfb;
}
if(wkup_front_flag==1)
{
nxt_dev_sta |= 0x08;
}
else
{
nxt_dev_sta &= 0xf7;
}
if(usb_adp_in_flag==1)
{
nxt_dev_sta |= 0x10;
}
else
{
nxt_dev_sta &= 0xef;
}
}