1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-07-16 04:15:21 +03:00
iris/boot-programs/thread0.ccp

81 lines
2.6 KiB
Plaintext
Raw Normal View History

2009-05-22 23:48:49 +03:00
#pypp 0
2009-06-01 15:26:42 +03:00
// Iris: micro-kernel for a capability-based operating system.
// thread0.ccp: Testing userspace thread.
// 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 "iris.h"
2009-05-22 23:48:49 +03:00
2009-06-01 20:22:11 +03:00
// GPIO pins for the keyboard: Rows =
// Rows = 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 125
// Cols = 0, 1, 2, 3, 4, 5, 6, 7
// Rows: 60...6f; 7d
// Nicely aligned to a port: use cols as output; rows as input.
// Map memory from b0010000, which is really 10010000 in kseg1.
#define D(n) (*(volatile unsigned *)(0x00 + 0x30 * n + address))
#define DI(n) (*(volatile unsigned *)(0x04 + 0x30 * n + address))
#define AL(n) (*(volatile unsigned *)(0x10 + 0x30 * n + address))
#define AU(n) (*(volatile unsigned *)(0x14 + 0x30 * n + address))
#define IE(n) (*(volatile unsigned *)(0x20 + 0x30 * n + address))
void event (bool release, unsigned col, unsigned row):
debug_set_led ((col & 1) | (row & 2) | (release ? 4 : 0))
2009-05-22 23:48:49 +03:00
int main ():
2009-06-01 20:22:11 +03:00
// map memory
Capability page = memory_create_page (__my_memory)
alloc_physical (page, 0x10010000, 0)
unsigned const address = 0x00010000
memory_map (__my_memory, page, address)
// Disable all interrupts.
IE (3) &= ~0x2000ffff
IE (0) &= ~0x000000ff
// Set all to GPIO
AL (3) = 0
AU (3) &= ~0x0c000000
AL (0) &= ~0x0000ffff
// Set all to input
DI (3) |= 0x2000ffff
DI (0) |= 0x000000ff
unsigned keys[2][8]
for unsigned i = 0; i < 8; ++i:
keys[1][i] = 0x2000ffff
2009-05-22 23:48:49 +03:00
while true:
2009-06-01 20:22:11 +03:00
// read keyboard
for unsigned col = 0; col < 8; ++col:
// set col to output, all others to input
DI (0) = (DI (0) & ~0x000000ff) | (1 << col)
// read input
keys[0][col] = D (3) & ~0x2000ffff
// Generate events
if keys[0][col] == keys[1][col]:
continue
unsigned bit, b
for bit = 1, b = 0; bit < 0x10000; bit <<= 1, ++b:
if (keys[0][col] ^ keys[1][col]) & bit:
event (keys[0][col] & bit, col, b)
if (keys[0][col] ^ keys[1][col]) & 0x20000000:
// Not really bit 16, but it's easier to handle.
event (keys[0][col] & 0x20000000, col, 16)
schedule ()