#pypp 0 // Iris: micro-kernel for a capability-based operating system. // boot-programs/init.ccp: System boot manager. // Copyright 2009 Bas Wijnen // // 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 . #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: kdebug ("gpio 0\n") kbd = msg.cap[0] tp = msg.cap[1] poweroff = msg.cap[2] powerbutton = msg.cap[3] ++state break case INIT_SET_GPIO_1: kdebug ("gpio 1\n") battery = msg.cap[0] lockleds = msg.cap[1] pwm = msg.cap[2] ++state break case INIT_SET_LCD: kdebug ("lcd\n") 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 (): // Set up lcd first schedule () kdebug ("start init\n") setup () kdebug ("run init\n") while true: Message msg wait (&msg) switch msg.protected_data: case KBD: kdebug ("keyboard event: ") kdebug_num (msg.data[0]) kdebug_char ('\n') break case TP: unsigned leds = 0 if msg.data[0] & 1: leds |= 0x1 else: leds |= 0x4 if !(msg.data[0] & 0x10000): leds |= 0x2 invoke_01 (lockleds, leds) break case POWERBUTTON: kdebug ("powerbutton event\n") break case BATTERY: kdebug ("battery event\n") break