-
Notifications
You must be signed in to change notification settings - Fork 0
/
awu.c
53 lines (48 loc) · 1.03 KB
/
awu.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
#include <iostm8s103f3.h>
#include <intrinsics.h>
#include <stdint.h>
#include "dispatcher.h"
#include "awu.h"
static uint8_t awu_timeout;
static uint8_t awu_timeout_event;
#pragma vector = AWU_vector
__interrupt void awu_vector_isr(void)
{
// I think that this would read register to clear interrupt ????
uint8_t v = AWU_CSR1;
ADD_EVENT(EVENT_AWU);
}
uint8_t awu_handle_event(uint8_t e)
{
if (e == EVENT_AWU)
{
if (awu_timeout)
{
awu_timeout--;
if (awu_timeout == 0)
ADD_EVENT(awu_timeout_event);
}
return 1;
}
else
return 0;
}
void awu_set(uint8_t apr, uint8_t tbr, uint8_t csr)
{
AWU_APR = apr;
AWU_TBR = tbr;
AWU_CSR1 = csr;
}
void set_awu_timeout(uint8_t seconds, uint8_t event)
{
if (seconds)
{
awu_timeout = seconds;
awu_timeout_event = event;
awu_set(62, 12, MASK_AWU_CSR1_AWUEN);
}
else
{
awu_set(62, 0, 0);
}
}