/
main.c
331 lines (290 loc) · 8.81 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
* Flickernoise
* Copyright (C) 2010, 2011 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <bsp.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <resolv.h> /* those two head files for '_res.retry' */
#include <mtklib.h>
#include <rtems.h>
#include <bsp/milkymist_usbinput.h>
#include <bsp/milkymist_ac97.h>
#include <bsp/milkymist_pfpu.h>
#include <bsp/milkymist_tmu.h>
#include <bsp/milkymist_memcard.h>
#include <bsp/milkymist_flash.h>
#include <bsp/milkymist_dmx.h>
#include <bsp/milkymist_ir.h>
#include <bsp/milkymist_video.h>
#include <bsp/milkymist_midi.h>
#include <bsp/milkymist_versions.h>
#include <bsp/milkymist_gpio.h>
#include <bsp/milkymist_buttons.h>
#include <rtems/stackchk.h>
#include <rtems/shell.h>
#include <rtems/bdpart.h>
#include <rtems/rtems_bsdnet.h>
#include <rtems/ftpd.h>
#include <rtems/telnetd.h>
#include <yaffs/rtems_yaffs.h>
#include <curl/curl.h>
#include "yaffs.h"
#include "version.h"
#include "renderer/videoinreconf.h"
#include "renderer/renderer.h"
#include "shellext.h"
#include "sysconfig.h"
#include "fb.h"
#include "input.h"
#include "shortcuts.h"
#include "osc.h"
#include "gui/messagebox.h"
#include "gui/performance.h"
#include "gui/cp.h"
#include "gui/keyboard.h"
#include "gui/ir.h"
#include "gui/audio.h"
#include "gui/midi.h"
#include "gui/oscsettings.h"
#include "gui/dmxspy.h"
#include "gui/dmxdesk.h"
#include "gui/dmx.h"
#include "gui/videoin.h"
#include "gui/rsswall.h"
#include "gui/patcheditor.h"
#include "gui/firstpatch.h"
#include "gui/monitor.h"
#include "gui/filemanager.h"
#ifdef WITH_PDF
#include "gui/pdfreader.h"
#endif
#include "gui/sysettings.h"
#include "gui/shutdown.h"
#include "gui/about.h"
#include "gui/flash.h"
#include "gui/filedialog.h"
static rtems_task gui_task(rtems_task_argument argument)
{
init_fb_mtk(sysconfig_get_autostart_mode() == SC_AUTOSTART_FILE);
sysconfig_set_mtk_language();
sysconfig_set_mtk_wallpaper();
init_input();
input_add_callback(mtk_input);
init_shortcuts();
init_osc();
init_messagebox();
init_performance();
init_renderer();
init_cp();
init_keyboard();
init_ir();
init_audio();
init_midi();
init_oscsettings();
init_dmxspy();
init_dmxdesk();
init_dmx();
init_videoin();
init_rsswall();
init_patcheditor();
init_monitor();
init_firstpatch();
init_filemanager();
#ifdef WITH_PDF
init_pdfreader();
#endif
init_sysettings();
init_about();
init_flash();
init_shutdown();
cp_autostart();
if(sysconfig_is_rescue())
messagebox("Rescue mode", "You have booted in rescue mode.\n"
"Your system will function as usual, using back-up software.\n"
"From there, you can update the main software or perform\nother actions to fix the problem.\n");
/* FIXME: work around "black screen" bug in MTK */
mtk_cmd(1, "screen.refresh()");
input_eventloop();
}
static rtems_id gui_task_id;
/* Disable memory card automount as the driver is not ready for end users yet */
/*static void start_memcard()
{
rtems_status_code sc;
rtems_bdpart_format format;
rtems_bdpart_partition pt[RTEMS_BDPART_PARTITION_NUMBER_HINT];
size_t count;
count = RTEMS_BDPART_PARTITION_NUMBER_HINT;
sc = rtems_bdpart_read("/dev/memcard", &format, pt, &count);
if(sc != RTEMS_SUCCESSFUL)
return;
sc = rtems_bdpart_register("/dev/memcard", pt, count);
if(sc != RTEMS_SUCCESSFUL)
return;
mkdir("/memcard", 0777);
mount("/dev/memcard1", "/memcard", "dosfs", RTEMS_FILESYSTEM_READ_ONLY, "");
}*/
rtems_task Init(rtems_task_argument argument);
rtems_task Init(rtems_task_argument argument)
{
rtems_status_code sc;
sc = rtems_shell_init(
"SHLL",
RTEMS_MINIMUM_STACK_SIZE * 8,
1, /* We want it to work */
"/dev/console",
false,
false,
NULL
);
if(sc != RTEMS_SUCCESSFUL)
printf("Unable to start shell (error code %d)\n", sc);
/* FIXME:
* alarm() should work anyway in gethostbyname().(for TIMEOUT in libcurl)
* in the meantime we have a workaround,
* make sure the gethostbyname() finished in 15 seconds
*/
_res.retry = 2;
/* FIXME: can this be moved into the initialization table? */
memcard_register();
/*start_memcard();*/
mkdir("/ssd", 0777);
mount("/dev/flash5", "/ssd", "yaffs", RTEMS_FILESYSTEM_READ_WRITE, "");
init_version();
init_videoinreconf();
sysconfig_load();
rtems_bsdnet_initialize_network();
rtems_initialize_ftpd();
rtems_telnetd_initialize();
curl_global_init(CURL_GLOBAL_ALL);
sc = rtems_task_create(rtems_build_name('G', 'U', 'I', ' '), 9, 1024*1024,
RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
0, &gui_task_id);
assert(sc == RTEMS_SUCCESSFUL);
sc = rtems_task_start(gui_task_id, gui_task, 0);
assert(sc == RTEMS_SUCCESSFUL);
rtems_task_delete(RTEMS_SELF);
}
static struct rtems_ftpd_hook ftp_hooks[] = {
{NULL, NULL}
};
struct rtems_ftpd_configuration rtems_ftpd_configuration = {
20, /* FTPD task priority */
512*1024, /* Maximum hook 'file' size */
0, /* Use default port */
ftp_hooks, /* Local ftp hooks */
"/ssd/", /* Root */
3, /* Task count */
3600, /* Idle timeout */
0, /* Access */
sysconfig_login_check /* Login */
};
// FIXME: those functions should be exported by RTEMS
extern rtems_shell_env_t *rtems_shell_init_env(
rtems_shell_env_t *shell_env_p
);
extern void rtems_shell_env_free(
void *ptr
);
static void rtems_telnet_shell(char *pty_name, void *cmd_arg)
{
rtems_shell_env_t *shell_env;
shell_env = rtems_shell_init_env(NULL);
if(shell_env == NULL) {
printf("Unable to allocate shell environment");
return;
}
shell_env->devname = pty_name;
shell_env->taskname = pty_name;
shell_env->exit_shell = false;
shell_env->forever = false;
shell_env->echo = true;
shell_env->input = strdup("stdin");
shell_env->output = strdup("stdout");
shell_env->output_append = false;
shell_env->wake_on_end = RTEMS_INVALID_ID;
shell_env->login_check = sysconfig_login_check;
rtems_shell_main_loop(shell_env);
// shell_env is freed by rtems_shell_main_loop
// (using the "task variable" mechanism)
}
rtems_telnetd_config_table rtems_telnetd_config = {
.command = rtems_telnet_shell,
.arg = NULL,
.priority = 9,
.stack_size = 20 * RTEMS_MINIMUM_STACK_SIZE,
.login_check = NULL,
.keep_stdio = false
};
#define CONFIGURE_SHELL_COMMANDS_INIT
#define CONFIGURE_SHELL_COMMANDS_ALL
#define CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING
#define CONFIGURE_SHELL_USER_COMMANDS &shellext
#include <rtems/shellconfig.h>
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_FRAME_BUFFER_DRIVER
#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
FLASH_DRIVER_TABLE_ENTRY, \
USBINPUT_DRIVER_TABLE_ENTRY, \
AC97_DRIVER_TABLE_ENTRY, \
PFPU_DRIVER_TABLE_ENTRY, \
TMU_DRIVER_TABLE_ENTRY, \
DMX_DRIVER_TABLE_ENTRY, \
IR_DRIVER_TABLE_ENTRY, \
VIDEO_DRIVER_TABLE_ENTRY, \
MIDI_DRIVER_TABLE_ENTRY, \
VERSIONS_DRIVER_TABLE_ENTRY, \
GPIO_DRIVER_TABLE_ENTRY, \
BUTTONS_DRIVER_TABLE_ENTRY
#define CONFIGURE_MAXIMUM_DRIVERS 20
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_HAS_OWN_FILESYSTEM_TABLE
#include <rtems/imfs.h>
#include <rtems/dosfs.h>
#include <librtemsNfs.h>
const rtems_filesystem_table_t rtems_filesystem_table[] = {
{ RTEMS_FILESYSTEM_TYPE_IMFS, IMFS_initialize },
{ RTEMS_FILESYSTEM_TYPE_DOSFS, rtems_dosfs_initialize },
{ RTEMS_FILESYSTEM_TYPE_NFS, rtems_nfs_initialize },
{ RTEMS_FILESYSTEM_TYPE_YAFFS, yaffs_initialize },
{ NULL, NULL }
};
#define CONFIGURE_EXECUTIVE_RAM_SIZE (16*1024*1024)
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
#define CONFIGURE_MAXIMUM_PTYS 4
#define CONFIGURE_MAXIMUM_TASKS 32
#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 16
#define CONFIGURE_MAXIMUM_SEMAPHORES 32
#define CONFIGURE_TICKS_PER_TIMESLICE 3
#define CONFIGURE_MICROSECONDS_PER_TICK 10000
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT_TASK_STACK_SIZE (8*1024)
#define CONFIGURE_INIT_TASK_PRIORITY 100
#define CONFIGURE_INIT_TASK_ATTRIBUTES 0
#define CONFIGURE_INIT_TASK_INITIAL_MODES \
(RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR | \
RTEMS_INTERRUPT_LEVEL(0))
//#define CONFIGURE_MALLOC_STATISTICS
//#define CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY TRUE
//#define CONFIGURE_STACK_CHECKER_ENABLED
#define CONFIGURE_INIT
#include <rtems/confdefs.h>