-
Notifications
You must be signed in to change notification settings - Fork 0
/
sleep.c
60 lines (53 loc) · 863 Bytes
/
sleep.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
/*
* sleep.c
*
* Created on: 2014-1-1
* Author: twd2
*/
#include "sleep.h"
volatile short is_delay=0;
volatile short is_sleep=0;
volatile int sleep_deadline=0;
void sleep_delay_us(long n)
{
if(n<=62) return;
is_delay=1;
is_sleep=0;
TACCTL0 = CCIE;
TACCR0 = (long long)((double)n*ACLK_F/1000000.0-1);
TACTL = TASSEL_1 + ID_0 + MC_1; //ACLK, DIV 0, Up.
_EINT();
LPM0;
}
void sleep_second(int n)
{
if (n<=0) return;
is_delay=0;
is_sleep=1;
sleep_deadline=n;
TACCTL0 = CCIE;
TACCR0 = ACLK_F-1;
TACTL = TASSEL_1 + ID_0 + MC_1; //ACLK, DIV 0, Up.
_EINT();
LPM3;
}
#pragma vector = TIMERA0_VECTOR
__interrupt void sleep_TA_ISR(void)
{
if (is_sleep)
{
--sleep_deadline;
if(sleep_deadline<=0)
{
is_sleep=0;
sleep_disableTA();
LPM3_EXIT;
}
}
else if (is_delay)
{
is_delay=0;
sleep_disableTA();
LPM0_EXIT;
}
}