summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/fiio/system-fiio.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/fiio/system-fiio.c')
-rw-r--r--firmware/target/hosted/fiio/system-fiio.c205
1 files changed, 205 insertions, 0 deletions
diff --git a/firmware/target/hosted/fiio/system-fiio.c b/firmware/target/hosted/fiio/system-fiio.c
new file mode 100644
index 0000000000..5e638989a1
--- /dev/null
+++ b/firmware/target/hosted/fiio/system-fiio.c
@@ -0,0 +1,205 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 Marcin Bukat
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <unistd.h>
22#include <signal.h>
23#include <string.h>
24#include <ucontext.h>
25#include <backtrace.h>
26
27#include "system.h"
28#include "mv.h"
29#include "font.h"
30#include "power.h"
31#include "button.h"
32#include "backlight-target.h"
33#include "lcd.h"
34
35#include "panic.h"
36#include <fcntl.h>
37#include <sys/ioctl.h>
38
39/* to make thread-internal.h happy */
40uintptr_t *stackbegin;
41uintptr_t *stackend;
42
43static void sig_handler(int sig, siginfo_t *siginfo, void *context)
44{
45 /* safe guard variable - we call backtrace() only on first
46 * UIE call. This prevent endless loop if backtrace() touches
47 * memory regions which cause abort
48 */
49 static bool triggered = false;
50
51 lcd_set_backdrop(NULL);
52 lcd_set_drawmode(DRMODE_SOLID);
53 lcd_set_foreground(LCD_BLACK);
54 lcd_set_background(LCD_WHITE);
55 unsigned line = 0;
56
57 lcd_setfont(FONT_SYSFIXED);
58 lcd_set_viewport(NULL);
59 lcd_clear_display();
60
61 /* get context info */
62 ucontext_t *uc = (ucontext_t *)context;
63 unsigned long pc = uc->uc_mcontext.pc;
64 unsigned long sp = uc->uc_mcontext.gregs[29];
65
66 lcd_putsf(0, line++, "%s at %08x", strsignal(sig), pc);
67
68 if(sig == SIGILL || sig == SIGFPE || sig == SIGSEGV || sig == SIGBUS || sig == SIGTRAP)
69 lcd_putsf(0, line++, "address 0x%08x", siginfo->si_addr);
70
71 if(!triggered)
72 {
73 triggered = true;
74 rb_backtrace(pc, sp, &line);
75 }
76
77#ifdef ROCKBOX_HAS_LOGF
78 lcd_putsf(0, line++, "logf:");
79 logf_panic_dump(&line);
80#endif
81
82 lcd_update();
83
84 system_exception_wait(); /* If this returns, try to reboot */
85
86 backlight_hw_off();
87 system_reboot();
88 while (1); /* halt */
89}
90
91static int axp_hw;
92
93void power_off(void)
94{
95 backlight_hw_off();
96
97 axp_hw = open("/dev/axp173", O_RDWR);
98 if(axp_hw < 0)
99 panicf("Cannot open '/dev/axp173'");
100
101 if(ioctl(axp_hw, 0x20003323, 0) < 0)
102 {
103 panicf("Call AXP173_SHUTDOWN fail");
104 }
105
106 close(axp_hw);
107}
108
109void system_init(void)
110{
111 int *s;
112 /* fake stack, to make thread-internal.h happy */
113 stackbegin = stackend = (uintptr_t*)&s;
114 /* catch some signals for easier debugging */
115 struct sigaction sa;
116 sigfillset(&sa.sa_mask);
117 sa.sa_flags = SA_SIGINFO;
118 sa.sa_sigaction = &sig_handler;
119 sigaction(SIGILL, &sa, NULL);
120 sigaction(SIGABRT, &sa, NULL);
121 sigaction(SIGFPE, &sa, NULL);
122 sigaction(SIGSEGV, &sa, NULL);
123 sigaction(SIGPIPE, &sa, NULL);
124 sigaction(SIGTERM, &sa, NULL);
125 sigaction(SIGBUS, &sa, NULL);
126 sigaction(SIGTERM, &sa, NULL);
127}
128
129void system_reboot(void)
130{
131 backlight_hw_off();
132 system("/sbin/reboot");
133 while (1); /* halt */
134}
135
136void system_exception_wait(void)
137{
138 backlight_hw_on();
139 backlight_hw_brightness(DEFAULT_BRIGHTNESS_SETTING);
140 /* wait until button press and release */
141 while(button_read_device() != 0) {}
142 while(button_read_device() == 0) {}
143 while(button_read_device() != 0) {}
144 while(button_read_device() == 0) {}
145}
146
147bool hostfs_removable(IF_MD_NONVOID(int drive))
148{
149#ifdef HAVE_MULTIDRIVE
150 if (drive > 0) /* Active LOW */
151 return true;
152 else
153#endif
154 return false; /* internal: always present */
155}
156
157bool hostfs_present(IF_MD_NONVOID(int drive))
158{
159#ifdef HAVE_MULTIDRIVE
160 if (drive > 0) /* Active LOW */
161 return true; //FIXME
162 else
163#endif
164 return true; /* internal: always present */
165}
166
167#ifdef HAVE_MULTIDRIVE
168int volume_drive(int drive)
169{
170 return drive;
171}
172#endif /* HAVE_MULTIDRIVE */
173
174#ifdef CONFIG_STORAGE_MULTI
175int hostfs_driver_type(int drive)
176{
177 return drive > 0 ? STORAGE_SD_NUM : STORAGE_HOSTFS_NUM;
178}
179#endif /* CONFIG_STORAGE_MULTI */
180
181int hostfs_init(void)
182{
183 return 0;
184}
185
186int hostfs_flush(void)
187{
188 sync();
189 return 0;
190}
191
192#ifdef HAVE_HOTSWAP
193bool volume_removable(int volume)
194{
195 /* don't support more than one partition yet, so volume == drive */
196 return hostfs_removable(volume);
197}
198
199bool volume_present(int volume)
200{
201 /* don't support more than one partition yet, so volume == drive */
202 return hostfs_present(volume);
203}
204#endif
205