SingingCat 0
application
reboot.c
1#include "main-header.h"
2#include "baseinfo.h"
3#include "constants.h"
4#include "user_app_exe.h"
5
6void restart_app_at(void *app);
7
8void reboot(int num) {
9 user_app_disable();
10 constants_validate();
11 mculib_reset();
12}
13
14void reboot_hard() {
15 reboot(0);
16}
17void reboot_fast() {
18 reboot(1);
19}
20void reboot_immediately() {
21 reboot(2);
22}
23
24void avoid_watchdog(void) __attribute__((no_instrument_function));
25void avoid_watchdog(void) {
26 mculib_watchdog_avoid();
27}
28void restart_app(void) {
29 restart_app_at(get_app_header());
30 return;
31}
32
33void restart_app_adr(uint32_t address) {
34 if (address == 0) {
35 printf("Ignoring request to start app at adr 0\r\n");
36 return;
37 }
38 printf("Requested to start app at %p\r\n", address);
39 struct app_header *app = (struct app_header *)address;
40
41 if (app->magic != 0x53434657) {
42 printf("invalid magic (%p)\r\n", app->magic);
43 return;
44 }
45 void *p = (void *)app->entry;
46
47 printf("Starting app at %p\r\n", p);
48 restart_app_at(p);
49}
50
54void restart_app_at(void *app) {
55 printf("Starting app at %p\r\n", app);
56 mculib_disable_irq(MAIN_MCULIBHANDLE);
57
58#ifdef __unix__
59 printf("Restarting()\n");
60
61#else
62 uint32_t entry = (uint32_t)app;
63 asm volatile ("mov r5,#0;"
64 "mov pc,%0;"
65 : /* No "return" (output) variables */
66 : "r" (entry)
67 );
68#endif
69}