-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw.h
135 lines (116 loc) · 3.19 KB
/
hw.h
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
#ifndef HW_H_
#define HW_H_
#define PSEL0_ADC P1SEL0
#define PSEL1_ADC P1SEL1
#define BIT_ADC_VSOL BIT1
#define BIT_ADC_VBAT BIT2
#define POUT_VEN P1OUT
#define PDIR_VEN P1DIR
#define BIT_VEN_GPS BIT5
#define BIT_VEN_RF BIT4
#define POUT_I2C P1OUT
#define PDIR_I2C P1DIR
#define PSEL0_I2C P1SEL0
#define PSEL1_I2C P1SEL1
#define BIT_I2C_SCL BIT7
#define BIT_I2C_SDA BIT6
#define POUT_UART P2OUT
#define PDIR_UART P2DIR
#define PSEL0_UART P2SEL0
#define PSEL1_UART P2SEL1
#define BIT_UART_TXD BIT0
#define BIT_UART_RXD BIT1
#define POUT_1PPS P2OUT
#define PDIR_1PPS P2DIR
#define BIT_1PPS BIT2
#define POUT_CLKIN PJOUT
#define PIN_CLKIN PJIN
#define PDIR_CLKIN PJDIR
#define PSEL0_CLKIN PJSEL0
#define PSEL1_CLKIN PJSEL1
#define BIT_CLKIN BIT4
#define POUT_UNUSED1 P1OUT
#define PDIR_UNUSED1 P1DIR
#define BIT_UNUSED1_A BIT0
#define BIT_UNUSED1_B BIT3
#define POUT_UNUSED2 P2OUT
#define PDIR_UNUSED2 P2DIR
#define BIT_UNUSED2_A BIT3
#define BIT_UNUSED2_B BIT4
#define BIT_UNUSED2_C BIT5
#define BIT_UNUSED2_D BIT6
#define BIT_UNUSED2_E BIT7
typedef enum {MODULE_DISABLE, MODULE_ENABLE} hw_module_state;
/*
* hw_init()
*
* Initializes the necessary functionality for low power operation:
* * DCO is ACLK and MCLK, SMCLK is XT1
* * unused pins are output, tied to GND
* * hardware enable pins are output, tied to Vcc (disable voltages)
* * UART and I2C pins are output, tied to GND
* * ADC pins are input, routed to ADC
* * 1PPS input is output, tied to GND
*/
void hw_init(void);
/*
* hw_watchdog_feed()
*
* Resets the watchdog timer
*/
void hw_watchdog_feed(void);
/*
* hw_gps_config()
*
* Enables GPS and corresponding peripherals:
* * UART and 1PPS pins are initialized
* * Power MOSFET on
* * UART is configured and released from reset
*
* Disables GPS and corresponding peripherals:
* * UART is put into reset
* * Power MOSFET off
* * UART and 1PPS pins are deinitalized
*/
void hw_gps_config(hw_module_state state);
/*
* hw_rf_config()
*
* Enables RF section and corresponding peripherals:
* * I2C Pins are initialized
* * Power MOSFET on
* * I2C is configured and released from reset
* * XT1 and Timer B are initialized
*
* Disables RF section and correspondig peripherals:
* * XT1 and Timer B are deinitialied
* * I2C is put into reset
* * Power MOSFET off
* * I2C pins are deinitialized
*/
void hw_rf_config(hw_module_state state);
/*
* hw_enter_low_power_mode()
*
* Enters low power consumption operating mode.
*
* The CPU will be woken up by the heartbeat timer if the global
* ISR_FLAG_WAKE_CPU flag is set. There is no other way to leave this mode.
*/
void hw_enter_low_power_mode(void);
/*
* hw_reset_wspr_baud_timer()
*
* Aligns the WSPR baud rate timer to the call time. This will cause an
* interrupt to occur right after this function is called, setting the
* corresponding ISR flag.
*/
void hw_reset_wspr_baud_timer(void);
#define hw_delay_us(x) __delay_cycles(2*x)
/*
* hw_delay_ms()
*
* Coarse delay routine.
*/
void hw_delay_ms(uint16_t ms);
#endif