mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-11-17 01:24:39 +02:00
154 lines
3.9 KiB
COBOL
154 lines
3.9 KiB
COBOL
#pypp 0
|
|
// Iris: micro-kernel for a capability-based operating system.
|
|
// source/rtc.ccp: real-time clock driver.
|
|
// Copyright 2010 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"
|
|
#define ARCH
|
|
#include "arch.hh"
|
|
|
|
static Iris::Font font
|
|
|
|
static void ready ():
|
|
while !rtc_write_ready ():
|
|
Iris::schedule ()
|
|
|
|
static unsigned get_second ():
|
|
ready ()
|
|
unsigned ret = rtc_get_second ()
|
|
unsigned r2
|
|
while true:
|
|
ready ()
|
|
r2 = rtc_get_second ()
|
|
if ret == r2:
|
|
return ret
|
|
kdebug ("ret != r2\n")
|
|
ret = r2
|
|
|
|
Iris::Num start ():
|
|
map_cpm ()
|
|
map_rtc ()
|
|
cpm_start_rtc ()
|
|
ready ()
|
|
rtc_enabled ()
|
|
if rtc_get_scratch_pattern () != 0xbeefface:
|
|
ready ()
|
|
rtc_set_nc1Hz_val (RTC_CLOCK)
|
|
ready ()
|
|
rtc_set_adjc_val (0)
|
|
ready ()
|
|
rtc_set_second (0)
|
|
ready ()
|
|
rtc_set_alarm_second (0)
|
|
ready ()
|
|
rtc_set_scratch_pattern (0xbeefface)
|
|
ready ()
|
|
rtc_disable_alarm ()
|
|
ready ()
|
|
rtc_clear_alarm_flag ()
|
|
ready ()
|
|
rtc_enable_alarm_irq ()
|
|
ready ()
|
|
rtc_disable_1Hz_irq ()
|
|
ready ()
|
|
rtc_set_hwfcr_val (0x1e0)
|
|
ready ()
|
|
rtc_set_hrcr_val (0xfe0)
|
|
ready ()
|
|
rtc_disable_alarm_wakeup ()
|
|
Iris::RTC self = Iris::my_receiver.create_capability (1)
|
|
Iris::my_parent.provide_capability <Iris::RTC> (self.copy ())
|
|
Iris::free_cap (self)
|
|
Iris::my_parent.init_done ()
|
|
bool have_interrupt = false
|
|
Iris::Cap interrupt
|
|
while true:
|
|
Iris::wait ()
|
|
if Iris::recv.protected_data.l == 0:
|
|
// Interrupt.
|
|
ready ()
|
|
rtc_disable_alarm ()
|
|
ready ()
|
|
rtc_disable_alarm_wakeup ()
|
|
if have_interrupt:
|
|
interrupt.invoke (0)
|
|
Iris::free_cap (interrupt)
|
|
have_interrupt = false
|
|
continue
|
|
switch Iris::recv.data[0].l:
|
|
case Iris::RTC::SETUP:
|
|
ready ()
|
|
rtc_set_nc1Hz_val (Iris::recv.data[1].l)
|
|
ready ()
|
|
rtc_set_adjc_val (Iris::recv.data[1].h)
|
|
Iris::recv.reply.invoke ()
|
|
break
|
|
case Iris::RTC::GET_TIME:
|
|
ready ()
|
|
Iris::recv.reply.invoke (rtc_get_second ())
|
|
Iris::recv.reply.invoke (0)
|
|
break
|
|
case Iris::RTC::SET_TIME:
|
|
ready ()
|
|
rtc_set_second (Iris::recv.data[1].l)
|
|
Iris::recv.reply.invoke ()
|
|
break
|
|
case Iris::RTC::GET_ALARM:
|
|
ready ()
|
|
Iris::recv.reply.invoke (rtc_get_alarm_second (), rtc_alarm_is_enabled ())
|
|
Iris::recv.reply.invoke (0)
|
|
break
|
|
case Iris::RTC::UNSET_ALARM:
|
|
Iris::Cap reply = Iris::get_reply ()
|
|
if have_interrupt:
|
|
have_interrupt = false
|
|
interrupt.invoke (~0)
|
|
Iris::free_cap (interrupt)
|
|
Iris::unregister_interrupt (IRQ_RTC)
|
|
ready ()
|
|
rtc_disable_alarm ()
|
|
ready ()
|
|
rtc_disable_alarm_wakeup ()
|
|
reply.invoke ()
|
|
Iris::free_cap (reply)
|
|
case Iris::RTC::SET_ALARM:
|
|
Iris::Cap reply = Iris::get_reply ()
|
|
Iris::Cap arg = Iris::get_arg ()
|
|
unsigned alarm = Iris::recv.data[1].l
|
|
if have_interrupt:
|
|
Iris::debug ("not registering irq\n")
|
|
interrupt.invoke (~0)
|
|
Iris::free_cap (interrupt)
|
|
else:
|
|
Iris::debug ("registering irq\n")
|
|
Iris::register_interrupt (IRQ_RTC)
|
|
interrupt = arg
|
|
have_interrupt = true
|
|
ready ()
|
|
rtc_set_alarm_second (alarm)
|
|
ready ()
|
|
rtc_clear_alarm_flag ()
|
|
ready ()
|
|
rtc_enable_alarm ()
|
|
ready ()
|
|
rtc_enable_alarm_wakeup ()
|
|
reply.invoke ()
|
|
Iris::free_cap (reply)
|
|
break
|
|
default:
|
|
Iris::panic (Iris::recv.data[0].l, "invalid rtc request")
|
|
return 0
|