Browse Source

put networking functions into weak symbols

Thomas Buck 4 months ago
parent
commit
4abdeee20f
3 changed files with 46 additions and 31 deletions
  1. 7
    1
      CMakeLists.txt
  2. 1
    0
      LICENSE
  3. 38
    30
      main.c

+ 7
- 1
CMakeLists.txt View File

@@ -37,6 +37,7 @@ add_executable(picowota
37 37
 	main.c
38 38
 	tcp_comm.c
39 39
 	dhcpserver/dhcpserver.c
40
+	${PICOWOTA_ADDITIONAL_SOURCES}
40 41
 )
41 42
 
42 43
 function(target_cl_options option)
@@ -54,7 +55,9 @@ pico_add_extra_outputs(picowota)
54 55
 
55 56
 target_include_directories(picowota PRIVATE
56 57
 	${CMAKE_CURRENT_LIST_DIR} # Needed so that lwip can find lwipopts.h
57
-	${CMAKE_CURRENT_LIST_DIR}/dhcpserver)
58
+	${CMAKE_CURRENT_LIST_DIR}/dhcpserver
59
+	${PICOWOTA_ADDITIONAL_INCLUDES}
60
+)
58 61
 
59 62
 pico_enable_stdio_usb(picowota 1)
60 63
 
@@ -71,6 +74,7 @@ target_link_libraries(picowota
71 74
 	pico_sync
72 75
 	pico_util
73 76
 	picowota_reboot
77
+	${PICOWOTA_ADDITIONAL_LIBS}
74 78
 )
75 79
 
76 80
 # Retrieves build variables from the environment if present
@@ -101,6 +105,8 @@ endif ()
101 105
 target_compile_definitions(picowota PUBLIC PICOWOTA_WIFI_SSID=${PICOWOTA_WIFI_SSID})
102 106
 target_compile_definitions(picowota PUBLIC PICOWOTA_WIFI_PASS=${PICOWOTA_WIFI_PASS})
103 107
 
108
+target_compile_definitions(picowota PUBLIC PICOWOTA)
109
+
104 110
 # Use the WiFi AP mode upon request
105 111
 if (PICOWOTA_WIFI_AP)
106 112
 	target_compile_definitions(picowota PUBLIC PICOWOTA_WIFI_AP=1)

+ 1
- 0
LICENSE View File

@@ -1,4 +1,5 @@
1 1
 Copyright 2022 Brian Starkey <stark3y@gmail.com>
2
+Copyright 2023 Thomas Buck <thomas@xythobuz.de>
2 3
 
3 4
 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4 5
 

+ 38
- 30
main.c View File

@@ -564,7 +564,38 @@ static bool should_stay_in_bootloader()
564 564
 	return !gpio_get(BOOTLOADER_ENTRY_PIN) || wd_says_so;
565 565
 }
566 566
 
567
-static void network_deinit()
567
+int __attribute__((weak)) picowota_network_init()
568
+{
569
+	if (cyw43_arch_init()) {
570
+		DBG_PRINTF("failed to initialise\n");
571
+		return 1;
572
+	}
573
+
574
+#if PICOWOTA_WIFI_AP == 1
575
+	cyw43_arch_enable_ap_mode(wifi_ssid, wifi_pass, CYW43_AUTH_WPA2_AES_PSK);
576
+	DBG_PRINTF("Enabled the WiFi AP.\n");
577
+
578
+	ip4_addr_t gw, mask;
579
+	IP4_ADDR(&gw, 192, 168, 4, 1);
580
+	IP4_ADDR(&mask, 255, 255, 255, 0);
581
+
582
+	dhcp_server_init(&dhcp_server, &gw, &mask);
583
+	DBG_PRINTF("Started the DHCP server.\n");
584
+#else
585
+	cyw43_arch_enable_sta_mode();
586
+
587
+	DBG_PRINTF("Connecting to WiFi...\n");
588
+	if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid, wifi_pass, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
589
+		DBG_PRINTF("failed to connect.\n");
590
+		return 1;
591
+	} else {
592
+		DBG_PRINTF("Connected.\n");
593
+	}
594
+#endif
595
+	return 0;
596
+}
597
+
598
+void __attribute__((weak)) picowota_network_deinit()
568 599
 {
569 600
 #if PICOWOTA_WIFI_AP == 1
570 601
 	dhcp_server_deinit(&dhcp_server);
@@ -593,34 +624,11 @@ int main()
593 624
 
594 625
 	queue_init(&event_queue, sizeof(struct event), EVENT_QUEUE_LENGTH);
595 626
 
596
-	if (cyw43_arch_init()) {
597
-		DBG_PRINTF("failed to initialise\n");
598
-		return 1;
627
+	int n = picowota_network_init();
628
+	if (n != 0) {
629
+		return n;
599 630
 	}
600 631
 
601
-#if PICOWOTA_WIFI_AP == 1
602
-	cyw43_arch_enable_ap_mode(wifi_ssid, wifi_pass, CYW43_AUTH_WPA2_AES_PSK);
603
-	DBG_PRINTF("Enabled the WiFi AP.\n");
604
-
605
-	ip4_addr_t gw, mask;
606
-	IP4_ADDR(&gw, 192, 168, 4, 1);
607
-	IP4_ADDR(&mask, 255, 255, 255, 0);
608
-
609
-	dhcp_server_t dhcp_server;
610
-	dhcp_server_init(&dhcp_server, &gw, &mask);
611
-	DBG_PRINTF("Started the DHCP server.\n");
612
-#else
613
-	cyw43_arch_enable_sta_mode();
614
-
615
-	DBG_PRINTF("Connecting to WiFi...\n");
616
-	if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid, wifi_pass, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
617
-		DBG_PRINTF("failed to connect.\n");
618
-		return 1;
619
-	} else {
620
-		DBG_PRINTF("Connected.\n");
621
-	}
622
-#endif
623
-
624 632
 	critical_section_init(&critical_section);
625 633
 
626 634
 	const struct comm_command *cmds[] = {
@@ -655,13 +663,13 @@ int main()
655 663
 				break;
656 664
 			case EVENT_TYPE_REBOOT:
657 665
 				tcp_comm_server_close(tcp);
658
-				network_deinit();
666
+				picowota_network_deinit();
659 667
 				picowota_reboot(ev.reboot.to_bootloader);
660 668
 				/* Should never get here */
661 669
 				break;
662 670
 			case EVENT_TYPE_GO:
663 671
 				tcp_comm_server_close(tcp);
664
-				network_deinit();
672
+				picowota_network_deinit();
665 673
 				disable_interrupts();
666 674
 				reset_peripherals();
667 675
 				jump_to_vtor(ev.go.vtor);
@@ -674,6 +682,6 @@ int main()
674 682
 		sleep_ms(5);
675 683
 	}
676 684
 
677
-	network_deinit();
685
+	picowota_network_deinit();
678 686
 	return 0;
679 687
 }

Loading…
Cancel
Save