Ver código fonte

put networking functions into weak symbols

Thomas Buck 5 meses atrás
pai
commit
4abdeee20f
3 arquivos alterados com 46 adições e 31 exclusões
  1. 7
    1
      CMakeLists.txt
  2. 1
    0
      LICENSE
  3. 38
    30
      main.c

+ 7
- 1
CMakeLists.txt Ver arquivo

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

+ 1
- 0
LICENSE Ver arquivo

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

564
 	return !gpio_get(BOOTLOADER_ENTRY_PIN) || wd_says_so;
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
 #if PICOWOTA_WIFI_AP == 1
600
 #if PICOWOTA_WIFI_AP == 1
570
 	dhcp_server_deinit(&dhcp_server);
601
 	dhcp_server_deinit(&dhcp_server);
593
 
624
 
594
 	queue_init(&event_queue, sizeof(struct event), EVENT_QUEUE_LENGTH);
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
 	critical_section_init(&critical_section);
632
 	critical_section_init(&critical_section);
625
 
633
 
626
 	const struct comm_command *cmds[] = {
634
 	const struct comm_command *cmds[] = {
655
 				break;
663
 				break;
656
 			case EVENT_TYPE_REBOOT:
664
 			case EVENT_TYPE_REBOOT:
657
 				tcp_comm_server_close(tcp);
665
 				tcp_comm_server_close(tcp);
658
-				network_deinit();
666
+				picowota_network_deinit();
659
 				picowota_reboot(ev.reboot.to_bootloader);
667
 				picowota_reboot(ev.reboot.to_bootloader);
660
 				/* Should never get here */
668
 				/* Should never get here */
661
 				break;
669
 				break;
662
 			case EVENT_TYPE_GO:
670
 			case EVENT_TYPE_GO:
663
 				tcp_comm_server_close(tcp);
671
 				tcp_comm_server_close(tcp);
664
-				network_deinit();
672
+				picowota_network_deinit();
665
 				disable_interrupts();
673
 				disable_interrupts();
666
 				reset_peripherals();
674
 				reset_peripherals();
667
 				jump_to_vtor(ev.go.vtor);
675
 				jump_to_vtor(ev.go.vtor);
674
 		sleep_ms(5);
682
 		sleep_ms(5);
675
 	}
683
 	}
676
 
684
 
677
-	network_deinit();
685
+	picowota_network_deinit();
678
 	return 0;
686
 	return 0;
679
 }
687
 }

Carregando…
Cancelar
Salvar