/
mahatma.c
115 lines (101 loc) · 2.7 KB
/
mahatma.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
/*
* main program entry point
*
* Copyright (c) 2009 Openmoko Inc.
*
* Authors Daniel Mack <daniel@caiaq.de>
* Christopher Hall <hsw@openmoko.com>
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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/>.
*/
/* wikilib and guilib includes */
#include <guilib.h>
#include <wikilib.h>
#include <input.h>
#include <stdlib.h>
#include <malloc-simple.h>
#include <tff.h>
#include <regs.h>
#include <profile.h>
#include <tick.h>
#include <suspend.h>
#include <analog.h>
#include <temperature.h>
#include <file-io.h>
/* local includes */
#include "msg-output.h"
#include "serial.h"
#include "traps.h"
#include "gui.h"
#include "msg.h"
#include "touchscreen.h"
#include "gpio.h"
#include "gui.h"
#define VERSION "0.4"
static FATFS fatfs;
__attribute ((noreturn))
int main(void)
{
// set the initial stack and data pointers
asm volatile (
"\txld.w\t%r15, __MAIN_STACK\n"
"\tld.w\t%sp, %r15\n"
"\txld.w\t%r15, __dp\n"
"\tld.w\t%r4, 0\n"
"\tld.w\t%psr, %r4\n"
);
// critical first initialisation
Suspend_initialise(); // set up clocks so must be first
traps_init(); // set up vectors so must be second
// other high priority initialisation
Tick_initialise();
Analog_initialise();
Temperature_initialise();
msg_init();
// start of normal initialisation
// anything below here can use debug outputs
msg(MSG_INFO, "Starting\n");
// initialise remainder of I/O
gpio_init();
touchscreen_init();
fb_init();
// set up memory manager before remaining initialisation
malloc_init_simple();
if (f_mount(0, &fatfs) != FR_OK)
msg(MSG_INFO, "unable to mount FAT filesystem!\n");
wikilib_init();
//guilib_init();
profile_init();
// initialisation complete
msg(MSG_INFO, "Mahatma super slim kernel v%s\n", VERSION);
int fd = wl_open("version.txt", WL_O_RDONLY);
if (fd >= 0) {
msg(MSG_INFO, "Display version.txt\n");
for (;;) {
char c;
size_t len = wl_read(fd, &c, 1);
if (len <= 0) {
break;
}
msg(MSG_INFO, "%c", c);
}
wl_close(fd);
} else {
msg(MSG_INFO, "Missing version.txt\n");
}
// the next function will loop forever and call wl_input_wait()
for (;;) {
wikilib_run();
}
}