Pārlūkot izejas kodu

Fix some warnings and optimise for size

Looks like removing printf drops about 10kB.
Brian Starkey 1 gadu atpakaļ
vecāks
revīzija
9bdc2fded0
3 mainītis faili ar 26 papildinājumiem un 12 dzēšanām
  1. 1
    0
      CMakeLists.txt
  2. 16
    8
      main.c
  3. 9
    4
      tcp_comm.c

+ 1
- 0
CMakeLists.txt Parādīt failu

@@ -16,6 +16,7 @@ add_executable(picowota
16 16
 pico_enable_stdio_usb(picowota 1)
17 17
 
18 18
 pico_add_extra_outputs(picowota)
19
+set_target_properties(picowota PROPERTIES COMPILE_FLAGS "-Wall -Os")
19 20
 
20 21
 target_include_directories(picowota PRIVATE ${CMAKE_CURRENT_LIST_DIR})
21 22
 

+ 16
- 8
main.c Parādīt failu

@@ -27,6 +27,16 @@
27 27
 
28 28
 #include "tcp_comm.h"
29 29
 
30
+#ifdef DEBUG
31
+#include <stdio.h>
32
+#include "pico/stdio_usb.h"
33
+#define DBG_PRINTF_INIT() stdio_usb_init()
34
+#define DBG_PRINTF(...) printf(__VA_ARGS__)
35
+#else
36
+#define DBG_PRINTF_INIT() { }
37
+#define DBG_PRINTF(...) { }
38
+#endif
39
+
30 40
 extern const char *wifi_ssid;
31 41
 extern const char *wifi_pass;
32 42
 critical_section_t critical_section;
@@ -511,23 +521,21 @@ struct comm_command reboot_cmd = {
511 521
 
512 522
 int main()
513 523
 {
514
-	stdio_init_all();
515
-
516
-	sleep_ms(1000);
524
+	DBG_PRINTF_INIT();
517 525
 
518 526
 	if (cyw43_arch_init()) {
519
-		printf("failed to initialise\n");
527
+		DBG_PRINTF("failed to initialise\n");
520 528
 		return 1;
521 529
 	}
522 530
 
523 531
 	cyw43_arch_enable_sta_mode();
524 532
 
525
-	printf("Connecting to WiFi...\n");
533
+	DBG_PRINTF("Connecting to WiFi...\n");
526 534
 	if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid, wifi_pass, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
527
-		printf("failed to connect.\n");
535
+		DBG_PRINTF("failed to connect.\n");
528 536
 		return 1;
529 537
 	} else {
530
-		printf("Connected.\n");
538
+		DBG_PRINTF("Connected.\n");
531 539
 	}
532 540
 
533 541
 	critical_section_init(&critical_section);
@@ -550,7 +558,7 @@ int main()
550 558
 	for ( ; ; ) {
551 559
 		err_t err = tcp_comm_listen(tcp, TCP_PORT);
552 560
 		if (err != ERR_OK) {
553
-			printf("Failed to start server: %d\n", err);
561
+			DBG_PRINTF("Failed to start server: %d\n", err);
554 562
 			sleep_ms(1000);
555 563
 			continue;
556 564
 		}

+ 9
- 4
tcp_comm.c Parādīt failu

@@ -15,7 +15,13 @@
15 15
 
16 16
 #include "tcp_comm.h"
17 17
 
18
-#define DEBUG_printf printf
18
+#ifdef DEBUG
19
+#include <stdio.h>
20
+#define DEBUG_printf(...) printf(__VA_ARGS__)
21
+#else
22
+#define DEBUG_printf(...) { }
23
+#endif
24
+
19 25
 #define POLL_TIME_S 5
20 26
 
21 27
 #define COMM_MAX_NARG     5
@@ -94,6 +100,8 @@ static int tcp_comm_sync_begin(struct tcp_comm_ctx *ctx)
94 100
 {
95 101
 	ctx->conn_state = CONN_STATE_WAIT_FOR_SYNC;
96 102
 	ctx->rx_bytes_needed = sizeof(uint32_t);
103
+
104
+	return 0;
97 105
 }
98 106
 
99 107
 static int tcp_comm_sync_complete(struct tcp_comm_ctx *ctx)
@@ -159,8 +167,6 @@ static int tcp_comm_args_complete(struct tcp_comm_ctx *ctx)
159 167
 
160 168
 static int tcp_comm_data_begin(struct tcp_comm_ctx *ctx, uint32_t data_len)
161 169
 {
162
-	const struct comm_command *cmd = ctx->cmd;
163
-
164 170
 	ctx->conn_state = CONN_STATE_READ_DATA;
165 171
 	ctx->rx_bytes_needed = data_len;
166 172
 
@@ -168,7 +174,6 @@ static int tcp_comm_data_begin(struct tcp_comm_ctx *ctx, uint32_t data_len)
168 174
 		return tcp_comm_data_complete(ctx);
169 175
 	}
170 176
 
171
-
172 177
 	return 0;
173 178
 }
174 179
 

Notiek ielāde…
Atcelt
Saglabāt