mirror of
git://projects.qi-hardware.com/iris.git
synced 2025-04-21 12:27:27 +03:00
Make it work with new gcc version; use linker script to force entry code in page 0.
This commit is contained in:
@@ -1,54 +1,73 @@
|
||||
#pypp 0
|
||||
// vim: set filetype=cpp : //
|
||||
#include <iris.hh>
|
||||
#include <devices.hh>
|
||||
#include <ui.hh>
|
||||
|
||||
enum captypes:
|
||||
CONTROL = 1
|
||||
KBD
|
||||
INTERRUPT
|
||||
enum Ins:
|
||||
TOTAL_TIME
|
||||
START
|
||||
NUM_INS
|
||||
|
||||
enum Outs:
|
||||
CURRENT_TIME
|
||||
ALARM
|
||||
NUM_OUTS
|
||||
|
||||
typedef UI <NUM_INS, NUM_OUTS> ui_t
|
||||
static ui_t ui
|
||||
static ui_t::in <unsigned> total_time
|
||||
static ui_t::in_event do_start
|
||||
static ui_t::out <unsigned> current_time
|
||||
static ui_t::out_event do_alarm
|
||||
|
||||
static bool ticking
|
||||
|
||||
static void event (unsigned code):
|
||||
switch code:
|
||||
case TOTAL_TIME:
|
||||
break
|
||||
case START:
|
||||
current_time = total_time
|
||||
if !ticking:
|
||||
if !current_time:
|
||||
do_alarm ()
|
||||
else:
|
||||
ticking = true
|
||||
Iris::my_receiver.set_alarm (HZ)
|
||||
break
|
||||
default:
|
||||
Iris::panic (0, "invalid event for alarm clock")
|
||||
|
||||
Iris::Num start ():
|
||||
unsigned *screen = (unsigned *)0x40000000
|
||||
Iris::RTC rtc = Iris::my_parent.get_capability <Iris::RTC> ()
|
||||
Iris::Display display = Iris::my_parent.get_capability <Iris::Display> ()
|
||||
display.map_fb ((unsigned)screen)
|
||||
Iris::Font font = Iris::my_parent.get_capability <Iris::Font> ()
|
||||
font.set_display (display)
|
||||
Iris::Keyboard keyboard = Iris::my_parent.get_capability <Iris::Keyboard> ()
|
||||
Iris::Cap cap = Iris::my_receiver.create_capability (KBD)
|
||||
keyboard.set_cb (cap.copy ())
|
||||
Iris::free_cap (cap)
|
||||
Iris::Buzzer buzzer = Iris::my_parent.get_capability <Iris::Buzzer> ()
|
||||
Iris::Event self = Iris::my_receiver.create_capability (CONTROL)
|
||||
Iris::my_parent.provide_capability <Iris::Event> (self)
|
||||
cap = Iris::my_receiver.create_capability (INTERRUPT)
|
||||
ticking = false;
|
||||
Iris::Cap ui_cap = Iris::my_receiver.create_capability (0)
|
||||
ui.init (ui_cap.copy ());
|
||||
Iris::free_cap (ui_cap)
|
||||
total_time.init ()
|
||||
do_start.init ()
|
||||
current_time.init ()
|
||||
do_alarm.init ()
|
||||
ui.add_in (&total_time, TOTAL_TIME);
|
||||
ui.add_in (&do_start, START);
|
||||
ui.add_out (¤t_time, CURRENT_TIME);
|
||||
ui.add_out (&do_alarm, ALARM);
|
||||
Iris::my_parent.init_done ()
|
||||
|
||||
while true:
|
||||
Iris::wait ()
|
||||
switch Iris::recv.protected_data.l:
|
||||
case INTERRUPT:
|
||||
// RTC alarm interrupt.
|
||||
if Iris::recv.data[0].l == ~0:
|
||||
// Not a real interrupt, just an abort notification.
|
||||
continue
|
||||
font.printf ("alarm: RTC alarm interrupt\n")
|
||||
break
|
||||
case CONTROL:
|
||||
// Store callback
|
||||
font.printf ("alarm: control event\n")
|
||||
break
|
||||
case KBD:
|
||||
if Iris::recv.data[0].l & Iris::Keyboard::RELEASE:
|
||||
// Key release.
|
||||
Iris::poweroff ()
|
||||
case ~0:
|
||||
// alarm.
|
||||
if current_time:
|
||||
current_time = current_time - 1
|
||||
if !current_time:
|
||||
do_alarm ()
|
||||
ticking = false
|
||||
else:
|
||||
// Key press.
|
||||
unsigned time = rtc.get_time ()
|
||||
rtc.set_alarm (time + 5, cap)
|
||||
unsigned alarm = rtc.get_alarm ()
|
||||
unsigned enabled = Iris::recv.data[1].l
|
||||
font.printf ("Debug: %d %d %d\n", time, alarm, enabled)
|
||||
break
|
||||
default:
|
||||
Iris::panic (Iris::recv.protected_data.l, "invalid request for alarm")
|
||||
// TODO: use rtc for scheduling an event.
|
||||
Iris::my_receiver.set_alarm (HZ)
|
||||
continue
|
||||
case 0:
|
||||
// ui event.
|
||||
if !ui.event (&event):
|
||||
// Exit request.
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user