Main Page
Related Pages
Modules
Classes
Files
File List
File Members
kmain.c
Go to the documentation of this file.
1
6
/*
7
* The contents of this file are subject to the Mozilla Public License
8
* Version 1.0 (the "License"); you may not use this file except in
9
* compliance with the License. You may obtain a copy of the License at
10
* http://www.mozilla.org/MPL/
11
*
12
* Software distributed under the License is distributed on an "AS IS"
13
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
14
* License for the specific language governing rights and limitations
15
* under the License.
16
*
17
* The Original Code is legOS code, released October 17, 1999.
18
*
19
* The Initial Developer of the Original Code is Markus L. Noga.
20
* Portions created by Markus L. Noga are Copyright (C) 1999
21
* Markus L. Noga. All Rights Reserved.
22
*
23
* Contributor(s): Markus L. Noga <markus@noga.de>
24
* Kekoa Proudfoot <kekoa@graphics.stanford.edu>
25
* Lou Sortman <lou (at) sunsite (dot) unc (dot) edu>
26
*/
27
28
#include <
sys/mm.h
>
29
#include <
sys/time.h
>
30
#include <
sys/tm.h
>
31
#include <
sys/irq.h
>
32
#include <
sys/lcd.h
>
33
#include <
sys/dsensor.h
>
34
#include <
sys/dmotor.h
>
35
#include <
sys/dsound.h
>
36
#include <
sys/lnp.h
>
37
#include <
sys/lnp-logical.h
>
38
#include <
sys/program.h
>
39
#ifdef CONF_AUTOSHUTOFF
40
#include <
sys/timeout.h
>
41
#endif
42
#include <
rom/system.h
>
43
44
#include <
dbutton.h
>
45
46
#include <
string.h
>
47
#include <
conio.h
>
48
#include <
unistd.h
>
50
//
51
// Variables
52
//
54
56
58
unsigned
char
*
firmware_string
=
"Do you byte, when I knock?"
;
59
60
extern
char
__bss
;
61
extern
char
__bss_end
;
62
64
extern
char
__text_hi
,
__etext_hi
;
65
66
#if defined(CONF_DSOUND) && defined(CONF_ON_OFF_SOUND)
67
static
const
note_t
on_sound[]={{
PITCH_G4
, 1}, {
PITCH_G5
, 1}, {
PITCH_END
, 0}};
68
static
const
note_t
off_sound[]={{
PITCH_C4
, 1}, {
PITCH_C3
, 1}, {
PITCH_END
, 0}};
69
#endif
70
72
//
73
// Functions
74
//
76
77
extern
int
main
(
int
argc,
char
**argv);
78
79
#if defined(CONF_DSOUND) && defined(CONF_ON_OFF_SOUND)
80
static
void
onOffSound(
const
note_t
*snd) {
81
dsound_set_duration
(40);
82
dsound_play
(snd);
83
}
84
#endif
85
87
extern
inline
void
show_on
(
void
) {
88
cls
();
89
90
#ifdef CONF_ASCII
91
cputs
(
"ON"
);
92
#else
93
#ifdef CONF_CONIO
94
cputc_native_4
(0x38);
95
cputc_native_3
(0x3d);
96
cputc_native_2
(0x7c);
97
cputc_native_1
(0x7e);
98
cputc_native_0
(0x6d);
99
#else
100
lcd_digit
(1);
101
#endif
102
#endif
103
#ifndef CONF_LCD_REFRESH
104
lcd_refresh
();
105
#endif
106
#if defined(CONF_DSOUND) && defined(CONF_ON_OFF_SOUND)
107
onOffSound(on_sound);
108
#endif
109
delay
(250);
110
#if defined(CONF_DSOUND) && defined(CONF_ON_OFF_SOUND)
111
dsound_set_duration
(
DSOUND_DEFAULT_16th_ms
);
112
#endif
113
}
114
116
extern
inline
void
show_off
(
void
) {
117
cls
();
118
119
#ifdef CONF_ASCII
120
cputs
(
"OFF"
);
121
#else
122
#ifdef CONF_CONIO
123
cputc_native_4
(0x7e);
124
cputc_native_3
(0x1d);
125
cputc_native_2
(0x1d);
126
#else
127
lcd_digit
(0);
128
#endif
129
#endif
130
#ifndef CONF_LCD_REFRESH
131
lcd_refresh
();
132
#endif
133
#if defined(CONF_DSOUND) && defined(CONF_ON_OFF_SOUND)
134
onOffSound(off_sound);
135
#endif
136
}
137
138
140
142
void
kmain
(
void
) __attribute__((noreturn));
143
void
kmain
(
void
)
144
{
145
int
reset_after_shutdown=0;
146
#ifdef CONF_DKEY
147
int
c;
148
#endif
149
150
/* Install the text.hi segment in the correct place. The
151
* firmware loader puts it in the bss segment, we copy it
152
* to it's final location.
153
*/
154
memcpy
(&
__text_hi
, &
__bss
, &
__etext_hi
- &
__text_hi
);
155
156
reset_vector
=
rom_reset_vector
;
157
158
/* Turn off motor, since writing to hitext manipulates motors */
159
motor_controller
= 0;
160
161
memset
(&
__bss
, 0, &
__bss_end
- &
__bss
);
162
163
#ifdef CONF_MM
164
mm_init
();
165
#endif
166
167
while
(1) {
168
power_init
();
169
170
#ifdef CONF_AUTOSHUTOFF
171
shutoff_init
();
172
#endif
173
174
lcd_init
();
175
176
#ifdef CONF_DSOUND
177
dsound_init
();
178
#endif
179
#ifdef CONF_TIME
180
systime_init
();
181
#endif
182
#ifdef CONF_DSENSOR
183
ds_init
();
184
#endif
185
#ifdef CONF_DMOTOR
186
dm_init
();
187
#endif
188
#ifdef CONF_LNP
189
lnp_init
();
190
lnp_logical_init
();
191
#endif
192
#ifdef CONF_TM
193
tm_init
();
194
#endif
195
#ifdef CONF_PROGRAM
196
program_init
();
197
#endif
198
199
show_on
();
200
201
// wait till power key released
202
//
203
#ifdef CONF_DKEY
204
dkey_multi
=
KEY_ANY
;
205
while
((c=
dkey_multi
) &
KEY_ONOFF
);
206
#else
207
while
(
PRESSED
(
dbutton
(),
BUTTON_ONOFF
));
208
delay
(100);
209
#endif
210
211
cls
();
212
#ifndef CONF_PROGRAM
213
lcd_show
(
man_run
);
214
#ifndef CONF_LCD_REFRESH
215
lcd_refresh
();
216
#endif
217
#endif
218
219
// run app
220
//
221
#ifdef CONF_TM
222
# ifndef CONF_PROGRAM
223
execi
(&
main
,0,0,
PRIO_NORMAL
,
DEFAULT_STACK_SIZE
);
224
# endif
225
tm_start
();
226
#else
227
main
(0, (
void
*)0);
228
#endif
229
230
show_off
();
231
232
// ON/OFF + PROGRAM -> erase firmware
233
#ifdef CONF_DKEY
234
while
((c=
dkey_multi
) & KEY_ONOFF)
235
if
(c&
KEY_PRGM
)
236
reset_after_shutdown=1;
237
#else
238
while
(
PRESSED
(
dbutton
(),
BUTTON_ONOFF
))
239
if
(
PRESSED
(
dbutton
(),
BUTTON_PROGRAM
))
240
reset_after_shutdown=1;
241
#endif
242
243
#ifdef CONF_PROGRAM
244
program_shutdown
();
245
#endif
246
#ifdef CONF_LNP
247
lnp_logical_shutdown
();
248
#endif
249
#ifdef CONF_DMOTOR
250
dm_shutdown
();
251
#endif
252
#ifdef CONF_DSENSOR
253
ds_shutdown
();
254
#endif
255
#ifdef CONF_TIME
256
systime_shutdown
();
257
#endif
258
259
if
(reset_after_shutdown)
260
rom_reset
();
261
262
lcd_clear
();
263
lcd_power_off
();
264
265
power_off
();
266
}
267
}
brickOS
is released under the
Mozilla Public License
.
Original code copyright 1998-2005 by the authors.
Generated on Sat Mar 15 2014 11:28:21 for brickOS Kernel Developer by
1.8.1.2