1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-17 09:50:37 +02:00
iris/boot-programs/init.ccp

102 lines
2.9 KiB
Plaintext
Raw Normal View History

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.hh"
2009-09-07 00:34:50 +03:00
#include "init.hh"
2009-07-21 13:17:52 +03:00
static Keyboard kbd, tp
static Display lcd
2009-09-06 12:04:09 +03:00
static Kernel::Cap lockleds, pwm
2009-07-21 13:17:52 +03:00
// Event types.
2009-07-21 13:17:52 +03:00
enum type:
KBD = 0x10000
TP
static void setup ():
unsigned state = 0
2009-09-07 00:34:50 +03:00
Kernel::Caps my_caps = Kernel::my_memory.create_caps (4 + 1)
unsigned my_slot = my_caps.use ()
unsigned slot = Kernel::alloc_slot ()
2009-07-21 13:17:52 +03:00
while true:
2009-09-06 12:04:09 +03:00
Kernel::wait ()
2009-09-07 00:34:50 +03:00
Kernel::Cap reply = Kernel::get_reply ()
Kernel::Caps caps = Kernel::get_arg ()
2009-09-06 12:04:09 +03:00
switch Kernel::recv.data[0].value ():
2009-09-07 00:34:50 +03:00
case Init::REGISTER_GPIO:
caps.use (slot)
for unsigned i = 0; i < 4; ++i:
my_caps.set (i, Kernel::Cap (slot, i).copy ())
kbd = Kernel::Cap (my_slot, 0)
tp = Kernel::Cap (my_slot, 1)
lockleds = Kernel::Cap (my_slot, 2)
pwm = Kernel::Cap (my_slot, 3)
2009-07-21 13:17:52 +03:00
break
2009-09-07 00:34:50 +03:00
case Init::REGISTER_LCD:
caps.use (slot)
my_caps.set (4, Kernel::Cap (slot, 0).copy ())
lcd = Kernel::Cap (my_slot, 4)
2009-07-21 13:17:52 +03:00
break
2009-09-07 00:34:50 +03:00
default:
kdebug ("unknown setup request for init\n")
continue
reply.invoke ()
Kernel::free_cap (caps)
Kernel::free_cap (reply)
if ++state == 2:
2009-07-21 13:17:52 +03:00
break
2009-09-07 00:34:50 +03:00
Kernel::free_cap (my_caps)
Kernel::free_slot (slot)
2009-09-06 12:04:09 +03:00
Kernel::schedule ()
Kernel::Cap kc = Kernel::my_receiver.create_capability (KBD)
2009-08-24 22:02:35 +03:00
kbd.set_cb (kc)
2009-09-06 12:04:09 +03:00
Kernel::Cap tc = Kernel::my_receiver.create_capability (TP)
2009-08-24 22:02:35 +03:00
tp.set_cb (tc)
pwm.call (1)
2009-07-21 13:17:52 +03:00
char const *decode_kbd = "0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*() T\n[],.-=/\\;|`'UDLREIKBPFZMS{}CA\":"
2009-09-06 12:04:09 +03:00
Kernel::Num start ():
2009-09-30 00:48:33 +03:00
kdebug ("init started\n")
2009-07-24 15:25:53 +03:00
setup ()
2009-09-30 00:48:33 +03:00
kdebug ("init set up\n")
2009-07-21 13:17:52 +03:00
while true:
2009-09-30 00:48:33 +03:00
kdebug ("init waiting\n")
2009-09-06 12:04:09 +03:00
Kernel::wait ()
2009-09-30 00:48:33 +03:00
kdebug ("init done waiting\n")
2009-09-06 12:04:09 +03:00
switch Kernel::recv.protected_data.value ():
2009-07-21 13:17:52 +03:00
case KBD:
2009-09-06 12:04:09 +03:00
unsigned code = Kernel::recv.data[0].l
if code & Keyboard::RELEASE:
break
kdebug_char (decode_kbd[code])
if code == 0:
Kernel::Caps ().print (~0)
2009-07-21 13:17:52 +03:00
break
case TP:
2009-07-25 23:00:32 +03:00
unsigned leds = 0
2009-09-06 12:04:09 +03:00
if Kernel::recv.data[0].l & 1:
2009-07-25 23:00:32 +03:00
leds |= 0x1
else:
leds |= 0x4
2009-09-06 12:04:09 +03:00
if !(Kernel::recv.data[0].l & Keyboard::RELEASE):
2009-07-25 23:00:32 +03:00
leds |= 0x2
2009-08-24 22:02:35 +03:00
lockleds.call (leds)
2009-07-21 13:17:52 +03:00
break