Kaynağa Gözat

Move reboot functionality to a separate library

This will be required for including into apps, so break it out.
Brian Starkey 1 yıl önce
ebeveyn
işleme
ac21d218d6

+ 3
- 0
CMakeLists.txt Dosyayı Görüntüle

@@ -20,6 +20,8 @@ set_target_properties(picowota PROPERTIES COMPILE_FLAGS "-Wall -Os")
20 20
 
21 21
 target_include_directories(picowota PRIVATE ${CMAKE_CURRENT_LIST_DIR})
22 22
 
23
+add_subdirectory(picowota_reboot)
24
+
23 25
 target_link_libraries(picowota
24 26
 	cmsis_core
25 27
 	hardware_dma
@@ -30,4 +32,5 @@ target_link_libraries(picowota
30 32
 	pico_stdlib
31 33
 	pico_sync
32 34
 	pico_util
35
+	picowota_reboot
33 36
 )

+ 5
- 21
main.c Dosyayı Görüntüle

@@ -28,6 +28,8 @@
28 28
 
29 29
 #include "tcp_comm.h"
30 30
 
31
+#include "picowota/reboot.h"
32
+
31 33
 #ifdef DEBUG
32 34
 #include <stdio.h>
33 35
 #include "pico/stdio_usb.h"
@@ -64,7 +66,6 @@ struct event {
64 66
 };
65 67
 
66 68
 #define BOOTLOADER_ENTRY_PIN 15
67
-#define BOOTLOADER_ENTRY_MAGIC 0xb105f00d
68 69
 
69 70
 #define TCP_PORT 4242
70 71
 
@@ -501,23 +502,6 @@ const struct comm_command info_cmd = {
501 502
 	.handle = &handle_info,
502 503
 };
503 504
 
504
-static void do_reboot(bool to_bootloader)
505
-{
506
-	hw_clear_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS);
507
-	if (to_bootloader) {
508
-		watchdog_hw->scratch[5] = BOOTLOADER_ENTRY_MAGIC;
509
-		watchdog_hw->scratch[6] = ~BOOTLOADER_ENTRY_MAGIC;
510
-	} else {
511
-		watchdog_hw->scratch[5] = 0;
512
-		watchdog_hw->scratch[6] = 0;
513
-	}
514
-	watchdog_reboot(0, 0, 0);
515
-	while (1) {
516
-		tight_loop_contents();
517
-		asm("");
518
-	}
519
-}
520
-
521 505
 static uint32_t size_reboot(uint32_t *args_in, uint32_t *data_len_out, uint32_t *resp_data_len_out)
522 506
 {
523 507
 	*data_len_out = 0;
@@ -554,8 +538,8 @@ struct comm_command reboot_cmd = {
554 538
 
555 539
 static bool should_stay_in_bootloader()
556 540
 {
557
-	bool wd_says_so = (watchdog_hw->scratch[5] == BOOTLOADER_ENTRY_MAGIC) &&
558
-		(watchdog_hw->scratch[6] == ~BOOTLOADER_ENTRY_MAGIC);
541
+	bool wd_says_so = (watchdog_hw->scratch[5] == PICOWOTA_BOOTLOADER_ENTRY_MAGIC) &&
542
+		(watchdog_hw->scratch[6] == ~PICOWOTA_BOOTLOADER_ENTRY_MAGIC);
559 543
 
560 544
 	return !gpio_get(BOOTLOADER_ENTRY_PIN) || wd_says_so;
561 545
 }
@@ -633,7 +617,7 @@ int main()
633 617
 			case EVENT_TYPE_REBOOT:
634 618
 				tcp_comm_server_close(tcp);
635 619
 				cyw43_arch_deinit();
636
-				do_reboot(ev.reboot.to_bootloader);
620
+				picowota_reboot(ev.reboot.to_bootloader);
637 621
 				/* Should never get here */
638 622
 				break;
639 623
 			case EVENT_TYPE_GO:

+ 13
- 0
picowota_reboot/CMakeLists.txt Dosyayı Görüntüle

@@ -0,0 +1,13 @@
1
+add_library(picowota_reboot INTERFACE)
2
+
3
+target_include_directories(picowota_reboot INTERFACE
4
+	${CMAKE_CURRENT_LIST_DIR}/include
5
+)
6
+
7
+target_sources(picowota_reboot INTERFACE
8
+	${CMAKE_CURRENT_LIST_DIR}/reboot.c
9
+)
10
+
11
+target_link_libraries(picowota_reboot INTERFACE
12
+	hardware_structs
13
+)

+ 16
- 0
picowota_reboot/include/picowota/reboot.h Dosyayı Görüntüle

@@ -0,0 +1,16 @@
1
+/**
2
+ * Copyright (c) 2022 Brian Starkey <stark3y@gmail.com>
3
+ *
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+
7
+#ifndef __PICOWOTA_REBOOT_H__
8
+#define __PICOWOTA_REBOOT_H__
9
+
10
+#include <stdbool.h>
11
+
12
+#define PICOWOTA_BOOTLOADER_ENTRY_MAGIC 0xb105f00d
13
+
14
+void picowota_reboot(bool to_bootloader);
15
+
16
+#endif /* __PICOWOTA_REBOOT_H__ */

+ 28
- 0
picowota_reboot/reboot.c Dosyayı Görüntüle

@@ -0,0 +1,28 @@
1
+/**
2
+ * Copyright (c) 2022 Brian Starkey <stark3y@gmail.com>
3
+ *
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+
7
+#include "RP2040.h"
8
+#include "hardware/structs/watchdog.h"
9
+#include "hardware/watchdog.h"
10
+
11
+#include "picowota/reboot.h"
12
+
13
+void picowota_reboot(bool to_bootloader)
14
+{
15
+	hw_clear_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS);
16
+	if (to_bootloader) {
17
+		watchdog_hw->scratch[5] = PICOWOTA_BOOTLOADER_ENTRY_MAGIC;
18
+		watchdog_hw->scratch[6] = ~PICOWOTA_BOOTLOADER_ENTRY_MAGIC;
19
+	} else {
20
+		watchdog_hw->scratch[5] = 0;
21
+		watchdog_hw->scratch[6] = 0;
22
+	}
23
+	watchdog_reboot(0, 0, 0);
24
+	while (1) {
25
+		tight_loop_contents();
26
+		asm("");
27
+	}
28
+}

Loading…
İptal
Kaydet