#pypp 0 // Iris: micro-kernel for a capability-based operating system. // mips/test.ccp: Telling the user things with LEDs. // 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 "../kernel.hh" #define REG32(addr) *((volatile unsigned int *)(addr)) #define GPIO_BASE 0xB0010000 #define __gpio_port_data(p) ( REG_GPIO_GPDR(p) ) #define GPIO_GPSLR(n) (GPIO_BASE + (0x10 + (n)*0x30)) #define GPIO_GPSUR(n) (GPIO_BASE + (0x14 + (n)*0x30)) #define GPIO_GPFLR(n) (GPIO_BASE + (0x18 + (n)*0x30)) #define GPIO_GPFUR(n) (GPIO_BASE + (0x1c + (n)*0x30)) #define GPIO_GPDR(n) (GPIO_BASE + (0x00 + (n)*0x30)) #define REG_GPIO_GPSLR(n) REG32(GPIO_GPSLR((n))) #define REG_GPIO_GPSUR(n) REG32(GPIO_GPSUR((n))) #define REG_GPIO_GPFLR(n) REG32(GPIO_GPFLR((n))) #define REG_GPIO_GPFUR(n) REG32(GPIO_GPFUR((n))) #define REG_GPIO_GPDR(n) REG32(GPIO_GPDR((n))) static void __gpio_port_as_gpiofn (unsigned p, unsigned o, unsigned fn): unsigned int tmp if o < 16: tmp = REG_GPIO_GPSLR(p) tmp &= ~(3 << ((o) << 1)) REG_GPIO_GPSLR(p) = tmp tmp = REG_GPIO_GPFLR(p) tmp &= ~(3 << ((o) << 1)) tmp |= fn << ((o) << 1) REG_GPIO_GPFLR(p) = tmp else: tmp = REG_GPIO_GPSUR(p) tmp &= ~(3 << (((o) - 16) << 1)) REG_GPIO_GPSUR(p) = tmp tmp = REG_GPIO_GPFUR(p) tmp &= ~(3 << (((o) - 16) << 1)) tmp |= fn << (((o) - 16) << 1) REG_GPIO_GPFUR(p) = tmp static void __gpio_port_as_output (unsigned p, unsigned o): __gpio_port_as_gpiofn (p, o, 1) static void __gpio_port_as_input (unsigned p, unsigned o): __gpio_port_as_gpiofn (p, o, 0) static void __gpio_as_output (unsigned n): __gpio_port_as_output(n / 32, n % 32) static void __gpio_as_input (unsigned n): __gpio_port_as_input(n / 32, n % 32) static void __gpio_set_pin (unsigned n): __gpio_port_data (n / 32) |= (1 << (n % 32)) static void __gpio_clear_pin (unsigned n): __gpio_port_data (n / 32) &= ~(1 << (n % 32)) #define CAPSLOCKLED_IO 27 #define NUMLOCKLED_IO 86 #define NETWORK_IO 9 #define LIGHT 105 void dbg_led (bool one, bool two, bool three): __gpio_as_output (CAPSLOCKLED_IO) __gpio_as_output (NUMLOCKLED_IO) __gpio_as_output (NETWORK_IO) if one: __gpio_clear_pin (NUMLOCKLED_IO) else: __gpio_set_pin (NUMLOCKLED_IO) if two: __gpio_clear_pin (CAPSLOCKLED_IO) else: __gpio_set_pin (CAPSLOCKLED_IO) if three: __gpio_clear_pin (NETWORK_IO) else: __gpio_set_pin (NETWORK_IO) void dbg_sleep (unsigned ms): for unsigned i = 0; i < 2673 * ms; ++i: __gpio_as_output (CAPSLOCKLED_IO) void dbg_send (unsigned code, unsigned bits): for int i = bits - 1; i >= 0; --i: bool on = code & (1 << i) dbg_led (false, false, false) dbg_sleep (200) if on: dbg_led (true, false, false) else: dbg_led (false, true, false) dbg_sleep (400) dbg_led (false, false, false) dbg_sleep (200) dbg_led (true, true, false) dbg_sleep (500) dbg_led (false, false, false) dbg_sleep (500)