2009-07-21 13:17:52 +03:00
|
|
|
#pypp 0
|
|
|
|
// Iris: micro-kernel for a capability-based operating system.
|
|
|
|
// boot-programs/init.ccp: System boot manager.
|
|
|
|
// Copyright 2009 Bas Wijnen <wijnen@debian.org>
|
|
|
|
//
|
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
#include "devices.hh"
|
|
|
|
#include "iris.h"
|
|
|
|
|
|
|
|
static Capability kbd, tp, poweroff, powerbutton, battery, lockleds, pwm, lcd
|
|
|
|
|
|
|
|
enum type:
|
|
|
|
KBD = 0x10000
|
|
|
|
TP
|
|
|
|
POWERBUTTON
|
|
|
|
BATTERY
|
|
|
|
|
|
|
|
static void send (Capability c, unsigned d):
|
|
|
|
Capability n = receiver_create_capability (__my_receiver, d)
|
|
|
|
invoke_10 (c, cap_copy (n))
|
|
|
|
drop (n)
|
|
|
|
|
|
|
|
static void setup ():
|
|
|
|
unsigned state = 0
|
|
|
|
while true:
|
|
|
|
Message msg
|
|
|
|
wait (&msg)
|
|
|
|
switch msg.data[0]:
|
|
|
|
case INIT_SET_GPIO_0:
|
2009-07-25 23:00:32 +03:00
|
|
|
kdebug ("gpio 0\n")
|
2009-07-21 13:17:52 +03:00
|
|
|
kbd = msg.cap[0]
|
|
|
|
tp = msg.cap[1]
|
|
|
|
poweroff = msg.cap[2]
|
|
|
|
powerbutton = msg.cap[3]
|
|
|
|
++state
|
|
|
|
break
|
|
|
|
case INIT_SET_GPIO_1:
|
2009-07-25 23:00:32 +03:00
|
|
|
kdebug ("gpio 1\n")
|
2009-07-21 13:17:52 +03:00
|
|
|
battery = msg.cap[0]
|
|
|
|
lockleds = msg.cap[1]
|
|
|
|
pwm = msg.cap[2]
|
|
|
|
++state
|
|
|
|
break
|
|
|
|
case INIT_SET_LCD:
|
2009-07-25 23:00:32 +03:00
|
|
|
kdebug ("lcd\n")
|
2009-07-21 13:17:52 +03:00
|
|
|
lcd = msg.cap[0]
|
|
|
|
++state
|
|
|
|
break
|
|
|
|
if state == 3:
|
|
|
|
break
|
|
|
|
send (kbd, KBD)
|
|
|
|
send (tp, TP)
|
|
|
|
send (powerbutton, POWERBUTTON)
|
|
|
|
send (battery, BATTERY)
|
|
|
|
invoke_01 (pwm, 1)
|
|
|
|
|
|
|
|
int main ():
|
2009-07-25 23:00:32 +03:00
|
|
|
// Set up lcd first
|
2009-07-24 15:25:53 +03:00
|
|
|
schedule ()
|
2009-07-25 23:00:32 +03:00
|
|
|
kdebug ("start init\n")
|
2009-07-24 15:25:53 +03:00
|
|
|
setup ()
|
2009-07-25 23:00:32 +03:00
|
|
|
kdebug ("run init\n")
|
2009-07-21 13:17:52 +03:00
|
|
|
while true:
|
|
|
|
Message msg
|
|
|
|
wait (&msg)
|
|
|
|
switch msg.protected_data:
|
|
|
|
case KBD:
|
2009-07-25 01:54:12 +03:00
|
|
|
kdebug ("keyboard event: ")
|
|
|
|
kdebug_num (msg.data[0])
|
|
|
|
kdebug_char ('\n')
|
2009-07-21 13:17:52 +03:00
|
|
|
break
|
|
|
|
case TP:
|
2009-07-25 23:00:32 +03:00
|
|
|
unsigned leds = 0
|
|
|
|
if msg.data[0] & 1:
|
|
|
|
leds |= 0x1
|
|
|
|
else:
|
|
|
|
leds |= 0x4
|
|
|
|
if !(msg.data[0] & 0x10000):
|
|
|
|
leds |= 0x2
|
|
|
|
invoke_01 (lockleds, leds)
|
2009-07-21 13:17:52 +03:00
|
|
|
break
|
|
|
|
case POWERBUTTON:
|
2009-07-25 01:54:12 +03:00
|
|
|
kdebug ("powerbutton event\n")
|
2009-07-24 15:25:53 +03:00
|
|
|
break
|
2009-07-21 13:17:52 +03:00
|
|
|
case BATTERY:
|
2009-07-25 01:54:12 +03:00
|
|
|
kdebug ("battery event\n")
|
2009-07-21 13:17:52 +03:00
|
|
|
break
|