浏览代码

Rework the makefile and optimize the code for flash space

Bernd Gottschlag 5 年前
父节点
当前提交
3a21aef881

+ 1
- 0
weather-sensor/firmware/.gitignore 查看文件

1
 main
1
 main
2
 *.hex
2
 *.hex
3
+*.o
3
 
4
 
4
 
5
 
5
 *.swp
6
 *.swp

+ 2
- 0
weather-sensor/firmware/bme280_interface.c 查看文件

1
 #include <avr/io.h>
1
 #include <avr/io.h>
2
 #include <util/delay.h>
2
 #include <util/delay.h>
3
+#include <string.h>
3
 
4
 
4
 #include "spi.h"
5
 #include "spi.h"
5
 #include "bme280.h"
6
 #include "bme280.h"
58
 /* Get one measurement in forced mode */
59
 /* Get one measurement in forced mode */
59
 void BME280_Get_Measurement(struct bme280_data * data)
60
 void BME280_Get_Measurement(struct bme280_data * data)
60
 {
61
 {
62
+	memset(data, 0, sizeof(struct bme280_data));
61
 	bme280_set_sensor_mode(BME280_FORCED_MODE, &deviceStructure);
63
 	bme280_set_sensor_mode(BME280_FORCED_MODE, &deviceStructure);
62
 	deviceStructure.delay_ms(req_delay);
64
 	deviceStructure.delay_ms(req_delay);
63
 	bme280_get_sensor_data(BME280_ALL, data, &deviceStructure);
65
 	bme280_get_sensor_data(BME280_ALL, data, &deviceStructure);

+ 12
- 2
weather-sensor/firmware/makefile 查看文件

1
+CFLAGS = -DF_CPU=1000000UL -D BME280_32BIT_ENABLE -I BME280_driver -mmcu=atmega88p -Os -flto -Wall -Wextra -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
2
+DEPS = spi.h nrf24l01.h nrf24l01_definitions.h bme280_interface.h BME280_driver/bme280.h led.h pin_programming.h crc.h encryption.h
3
+
1
 all: main.hex
4
 all: main.hex
2
 
5
 
3
 clean:
6
 clean:
4
 	rm -f main.hex
7
 	rm -f main.hex
5
 	rm -f main
8
 	rm -f main
9
+	rm -f obj/*.o
6
 
10
 
7
 flash: main.hex
11
 flash: main.hex
8
 	sudo avrdude -c buspirate -b 115200 -P /dev/ttyUSB1 -p m88p -v -U flash:w:main.hex
12
 	sudo avrdude -c buspirate -b 115200 -P /dev/ttyUSB1 -p m88p -v -U flash:w:main.hex
9
 
13
 
10
-main: main.c spi.c spi.h nrf24l01.c nrf24l01.h nrf24l01_definitions.h bme280_interface.c bme280_interface.h BME280_driver/bme280.c BME280_driver/bme280.h led.h pin_programming.c pin_programming.h crc.c crc.h
11
-	avr-gcc main.c spi.c nrf24l01.c bme280_interface.c BME280_driver/bme280.c pin_programming.c crc.c -I BME280_driver -o main -mmcu=atmega88p -Os -Wall -Wextra -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -DF_CPU=1000000UL -D BME280_32BIT_ENABLE
14
+obj/%.o: %.c $(DEPS)
15
+	avr-gcc -c $< -o $@ $(CFLAGS)
16
+
17
+obj/%.o: BME280_driver/%.c $(DEPS)
18
+	avr-gcc -c $< -o $@ $(CFLAGS)
19
+
20
+main: obj/main.o obj/spi.o obj/nrf24l01.o obj/bme280_interface.o obj/bme280.o obj/pin_programming.o obj/crc.o obj/encryption.o
21
+	avr-gcc $^ -o $@ $(CFLAGS)
12
 
22
 
13
 main.hex: main
23
 main.hex: main
14
 	avr-objcopy -O ihex -R .eeprom main main.hex
24
 	avr-objcopy -O ihex -R .eeprom main main.hex

+ 25
- 73
weather-sensor/firmware/nrf24l01.c 查看文件

19
 void Print_Register_Contents(uint8_t address);
19
 void Print_Register_Contents(uint8_t address);
20
 void Send_TX_Flush_Command(void);
20
 void Send_TX_Flush_Command(void);
21
 
21
 
22
+static void Write_Two_Bytes(uint8_t byte1, uint8_t byte2);
23
+static void Write_Byte_And_Buffer(uint8_t byte, uint8_t * buffer, uint8_t length);
24
+
22
 /* Startup and initial configuration of the NRF24L01 */
25
 /* Startup and initial configuration of the NRF24L01 */
23
 void Initialize_NRF24L01(void)
26
 void Initialize_NRF24L01(void)
24
 {
27
 {
168
 	return;
171
 	return;
169
 }
172
 }
170
 
173
 
171
-void Print_Register_Contents(uint8_t address)
172
-{
173
-	uint8_t registerContent[5];
174
-	uint8_t lengthRead;
175
-	char registerContentString[30];
176
-
177
-
178
-	lengthRead = Read_NRF_Register(address, registerContent);
179
-
180
-	registerContentString[0] = '\0';
181
-	for (uint8_t i = 0; i < lengthRead; i++)
182
-	{
183
-		sprintf(registerContentString, "%s0x%x ", registerContentString, registerContent[i]);
184
-	}
185
-}
186
-
187
-
188
-
189
-
190
-/* Send a message:
191
- * - Set PRIM_RX = 0 and add one message to the TX-FIFO
192
- * - Set CE=1 for more than 10 us
193
- * - The NRF takes 130 us to enter the TX Mode
194
- * - An Interrupt is generated once the 
195
- * - 
196
- */
197
-
198
-
199
-/* Set the NRF to RX Mode */
200
-
201
-/* Disable the RX Mode */
202
-
203
-
204
-
205
-
206
 uint8_t Read_NRF_Status_Register(void)
174
 uint8_t Read_NRF_Status_Register(void)
207
 {
175
 {
208
 	uint8_t registerContents;
176
 	uint8_t registerContents;
213
 	return registerContents;
181
 	return registerContents;
214
 }
182
 }
215
 
183
 
184
+
185
+/* TODO: rewrite the read register function if it is needed (remove the read operations for the 5-byte registers)*/
186
+#if 0
216
 uint8_t Read_NRF_Register(uint8_t address, uint8_t * registerContents)
187
 uint8_t Read_NRF_Register(uint8_t address, uint8_t * registerContents)
217
 {
188
 {
218
 	/* TODO: simplify this function, as the registers with more than one byte are accessed with other functions */
189
 	/* TODO: simplify this function, as the registers with more than one byte are accessed with other functions */
247
 	return numberOfBytes;
218
 	return numberOfBytes;
248
 }
219
 }
249
 
220
 
221
+#endif
222
+
250
 void Write_NRF_Register(uint8_t address, uint8_t registerContents)
223
 void Write_NRF_Register(uint8_t address, uint8_t registerContents)
251
 {
224
 {
252
-	/* First write the write command with the address */
253
-	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
254
-
255
-	SPI_Transfer_Byte(address | 0x20);
256
-
257
-	/* Write the data byte */
258
-	SPI_Transfer_Byte(registerContents);
259
-
260
-	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
225
+	Write_Two_Bytes(address | 0x20, registerContents);
261
 }
226
 }
262
 
227
 
263
-// TODO: clean up functions
264
 void Send_Activate_Command(void)
228
 void Send_Activate_Command(void)
265
 {
229
 {
266
-	/* First write the write command with the address */
230
+	Write_Two_Bytes(0x50, 0x73);
231
+}
232
+
233
+static void Write_Two_Bytes(uint8_t byte1, uint8_t byte2)
234
+{
267
 	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
235
 	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
268
-	SPI_Transfer_Byte(0x50);
269
 
236
 
270
-	/* Write the data byte */
271
-	SPI_Transfer_Byte(0x73);
237
+	SPI_Transfer_Byte(byte1);
238
+	SPI_Transfer_Byte(byte2);
272
 
239
 
273
 	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
240
 	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
274
 }
241
 }
287
 
254
 
288
 void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer)
255
 void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer)
289
 {
256
 {
290
-	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
291
-
292
-	/* Issue the write command: */
293
-	SPI_Transfer_Byte(0xA0);
294
-
295
-	/* Write the data bytes */
296
-	for (uint8_t i = 0; i < length; i++)
297
-	{
298
-		SPI_Transfer_Byte(buffer[i]);
299
-	}
300
-
301
-	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
257
+	Write_Byte_And_Buffer(0xA0, buffer, length);
302
 }
258
 }
303
 
259
 
304
 void Set_TX_Address(uint8_t * txAddress, uint8_t length)
260
 void Set_TX_Address(uint8_t * txAddress, uint8_t length)
305
 {
261
 {
306
-	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
307
-
308
-	SPI_Transfer_Byte(TX_ADDR_ADDRESS | 0x20);
309
-	/* Write the data byte */
310
-	for (uint8_t i = 0; i < length; i ++)
311
-	{
312
-		SPI_Transfer_Byte(txAddress[i]);
313
-	}
314
-
315
-	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
262
+	Write_Byte_And_Buffer(TX_ADDR_ADDRESS | 0x20, txAddress, length);
316
 }
263
 }
317
 
264
 
318
 void Set_RX_P0_Address(uint8_t * rxAddress, uint8_t length)
265
 void Set_RX_P0_Address(uint8_t * rxAddress, uint8_t length)
266
+{
267
+	Write_Byte_And_Buffer(RX_ADDR_P0_ADDRESS | 0x20, rxAddress, length);
268
+}
269
+
270
+static void Write_Byte_And_Buffer(uint8_t byte, uint8_t * buffer, uint8_t length)
319
 {
271
 {
320
 	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
272
 	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
321
 
273
 
322
-	SPI_Transfer_Byte(RX_ADDR_P0_ADDRESS | 0x20);
274
+	SPI_Transfer_Byte(byte);
323
 
275
 
324
 	/* Write the data byte */
276
 	/* Write the data byte */
325
 	for (uint8_t i = 0; i < length; i ++)
277
 	for (uint8_t i = 0; i < length; i ++)
326
 	{
278
 	{
327
-		SPI_Transfer_Byte(rxAddress[i]);
279
+		SPI_Transfer_Byte(buffer[i]);
328
 	}
280
 	}
329
 
281
 
330
 	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
282
 	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);

+ 0
- 1
weather-sensor/firmware/nrf24l01.h 查看文件

70
 		} values;
70
 		} values;
71
 		uint8_t buffer[PACKET_BUFFER_LENGTH];
71
 		uint8_t buffer[PACKET_BUFFER_LENGTH];
72
 	}payload;
72
 	}payload;
73
-	//uint8_t buffer[PACKET_BUFFER_LENGTH];
74
 	uint16_t crc;
73
 	uint16_t crc;
75
 } PACKET;
74
 } PACKET;
76
 
75
 

+ 0
- 0
weather-sensor/firmware/obj/.keep 查看文件


正在加载...
取消
保存