1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-17 09:31:32 +02:00
iris/boot-programs/init.ccp
2009-09-06 11:04:09 +02:00

93 lines
2.5 KiB
COBOL

#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"
static Keyboard kbd, tp
static Display lcd
static Kernel::Cap lockleds, pwm
// Event types.
enum type:
KBD = 0x10000
TP
static void setup ():
unsigned state = 0
Kernel::recv.arg = Kernel::alloc_cap ()
while true:
Kernel::wait ()
switch Kernel::recv.data[0].value ():
case INIT_SET_GPIO:
kdebug ("gpio\n")
Kernel::Caps caps = Kernel::get_arg ()
Kernel::Cap reply = Kernel::get_reply ()
unsigned gpio_slot = caps.use ()
kbd = Kernel::Cap (gpio_slot, 0)
tp = Kernel::Cap (gpio_slot, 1)
lockleds = Kernel::Cap (gpio_slot, 2)
pwm = Kernel::Cap (gpio_slot, 3)
reply.invoke ()
Kernel::free_cap (reply)
++state
break
case INIT_SET_LCD:
kdebug ("lcd\n")
lcd = Kernel::get_arg ()
Kernel::recv.reply.invoke ()
++state
break
if state == 2:
break
Kernel::schedule ()
kdebug ("init registering keyboard\n")
Kernel::Cap kc = Kernel::my_receiver.create_capability (KBD)
kbd.set_cb (kc)
Kernel::Cap tc = Kernel::my_receiver.create_capability (TP)
tp.set_cb (tc)
pwm.call (1)
char const *decode_kbd = "0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*() T\n[],.-=/\\;|`'UDLREIKBPFZMS{}CA\":"
Kernel::Num start ():
// Set up lcd first
Kernel::schedule ()
kdebug ("start init\n")
setup ()
kdebug ("run init\n")
while true:
Kernel::wait ()
switch Kernel::recv.protected_data.value ():
case KBD:
unsigned code = Kernel::recv.data[0].l
if code & Keyboard::RELEASE:
break
kdebug_char (decode_kbd[code])
break
case TP:
unsigned leds = 0
if Kernel::recv.data[0].l & 1:
leds |= 0x1
else:
leds |= 0x4
if !(Kernel::recv.data[0].l & Keyboard::RELEASE):
leds |= 0x2
lockleds.call (leds)
break