-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.h
189 lines (169 loc) · 5.62 KB
/
user.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* Copyright (c) 2014 Graham Murphy <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/******************************************************************************/
/* User Level #define Macros */
/******************************************************************************/
/* Baud rate - 19200 is probably the maximum */
#define BAUD 9200
#define SERIAL_BIT_TIME 1000000/BAUD
#define SERIAL_US_A_BIT SERIAL_BIT_TIME-15 // Using XC8 in free mode, 15uS
// is how long the loop takes once.
/* Microcontroller Freqs*/
#define _XTAL_FREQ 8000000L
/* I/O Pins */
#define SDI RB7
#define SCK RB6
#define nSEL RC5
#define nIRQ RA2
#define FSK RC4
#define BTN RB4 // Button
#define INP RC3 // Input
#define LED RC6 // LED
#define SENS RC3 // Sensor
/******************************************************************************/
/* User Function Prototypes */
/******************************************************************************/
/**
* Set Oscillator speed high or low
* @param speed 0 - 31KHz (low speed), >0 - 8MHz (high speed)
*/
void ConfigureOscillator(uint8_t speed);
/**
* Transmit data
* @param TxBuff 8 byte data buffer containing data to transmit
*/
void TXData(uint8_t *TxBuff);
/**
* Generate a new address and write it to EEPROM and data buffer
* @param txBuff 8 byte buffer that address will be written to.
* @param type type of sensor
* @return new 12bit sensor address
*/
uint16_t GenAddr(uint8_t *txBuff, bool type );
/**
* Retreive store address from EEPROM and return it in buffer
* @param txBuff 8 byte buffer that address will be written to.
* @return 12bit sensor address
*/
uint16_t GetAddr(uint8_t *TxBuff);
/**
* Generates new address and transmits pairing request
* @param txBuff 8 byte buffer
* @param mType sensor type
* @param ipu Impulses per unit
*/
void doPair(uint8_t *txBuff, uint8_t mType, uint32_t ipu);
/**
* Send out txBuff 30 times with pairing flag set.
* @param txBuff
*/
void PairTX(uint8_t *txBuff);
/**
* Set up peripherals and I/O ports
*/
void InitApp(void); // I/O and Peripheral Initialization
/**
* Configure radio parameters.
*/
void InitRadio(void); // Inits radio settings
/**
* Power up TX stages.
*/
void StartTX(void);
/**
* Power down TX stages.
*/
void StopTX(void); // Power down TX
/**
* Send control messages to radio.
* @param tosend message to send to radio
*/
void SendCTRL( unsigned int tosend);
/**
* Send a byte with manchester encoding.
* @param data byte to send
*/
void SendManFSK( unsigned char data);
/**
* Send a byte as is (without manchester encoding).
* @param data byte to send
*/
void SendFSK(unsigned char data);
/**
* Send a bit for FSK.
* @param data bit to send
*/
void Sendbit(unsigned char data);
/**
* Wait for radio to finish sending bit.
*/
void WaitFSK(void);
/**
* Write data to EEPROM at address
* @param address address to write to
* @param data data to write
*/
void EEPROM_putc(uint8_t address, uint8_t data); // Write to EEPROM
/**
* Read data from EEPROM at address
* @param address address to read from
* @return byte in EEPROM
*/
uint8_t EEPROM_getc(uint8_t address); // Read from EEPROM
/**
* SoftUSART character output
* @param chr byte to write to serial port
*/
void _Soft_USART_Write(uint8_t chr);
/**
* SoftUSART HEX output
* @param data byte to convert to hex to write to serial port
*/
void _Soft_USART_Write_Hex(unsigned char data);
/**
* SoftUSART write string
* @param s string to write to serial port
*/
void _Soft_USART_Writes(const char * s);
/******************************************************************************/
/* User Structures */
/******************************************************************************/
typedef union {
struct {
/** high nibble of 12bit device address */
unsigned int address_high :4;
unsigned int :2;
unsigned int data_sensor :1;
/** pairing mode indicator */
unsigned int pair_request :1;
/** low byte of 12bit device address */
unsigned int address_low :8;
unsigned int :8;
/** type of sensor
2 = electricity
3 = gas
4 = water
*/
unsigned int sensor_type :8;
/** MSB of 32 impulse value */
unsigned int value_high :8;
unsigned int value_midh :8;
unsigned int value_midl :8;
/** LSB of 32 impulse value */
unsigned int value_low :8;
};
/** unsigned char representation of data packet*/
unsigned char bytes[8];
} DataPacket_t;