Root/
| 1 | #pypp 0 |
| 2 | // Iris: micro-kernel for a capability-based operating system. |
| 3 | // source/rtc.ccp: real-time clock driver. |
| 4 | // Copyright 2010 Bas Wijnen <wijnen@debian.org> |
| 5 | // |
| 6 | // This program is free software: you can redistribute it and/or modify |
| 7 | // it under the terms of the GNU General Public License as published by |
| 8 | // the Free Software Foundation, either version 3 of the License, or |
| 9 | // (at your option) any later version. |
| 10 | // |
| 11 | // This program is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | // |
| 16 | // You should have received a copy of the GNU General Public License |
| 17 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | |
| 19 | #include "devices.hh" |
| 20 | #define ARCH |
| 21 | #include "arch.hh" |
| 22 | |
| 23 | static Iris::Font font |
| 24 | |
| 25 | static void ready (): |
| 26 | while !rtc_write_ready (): |
| 27 | Iris::schedule () |
| 28 | |
| 29 | static unsigned get_second (): |
| 30 | ready () |
| 31 | unsigned ret = rtc_get_second () |
| 32 | unsigned r2 |
| 33 | while true: |
| 34 | ready () |
| 35 | r2 = rtc_get_second () |
| 36 | if ret == r2: |
| 37 | return ret |
| 38 | kdebug ("ret != r2\n") |
| 39 | ret = r2 |
| 40 | |
| 41 | Iris::Num start (): |
| 42 | map_cpm () |
| 43 | map_rtc () |
| 44 | cpm_start_rtc () |
| 45 | ready () |
| 46 | rtc_enabled () |
| 47 | if rtc_get_scratch_pattern () != 0xbeefface: |
| 48 | ready () |
| 49 | rtc_set_nc1Hz_val (RTC_CLOCK) |
| 50 | ready () |
| 51 | rtc_set_adjc_val (0) |
| 52 | ready () |
| 53 | rtc_set_second (0) |
| 54 | ready () |
| 55 | rtc_set_alarm_second (0) |
| 56 | ready () |
| 57 | rtc_set_scratch_pattern (0xbeefface) |
| 58 | ready () |
| 59 | rtc_disable_alarm () |
| 60 | ready () |
| 61 | rtc_clear_alarm_flag () |
| 62 | ready () |
| 63 | rtc_enable_alarm_irq () |
| 64 | ready () |
| 65 | rtc_disable_1Hz_irq () |
| 66 | ready () |
| 67 | rtc_set_hwfcr_val (0x1e0) |
| 68 | ready () |
| 69 | rtc_set_hrcr_val (0xfe0) |
| 70 | ready () |
| 71 | rtc_disable_alarm_wakeup () |
| 72 | Iris::RTC self = Iris::my_receiver.create_capability (1) |
| 73 | Iris::my_parent.provide_capability <Iris::RTC> (self.copy ()) |
| 74 | Iris::free_cap (self) |
| 75 | Iris::my_parent.init_done () |
| 76 | bool have_interrupt = false |
| 77 | Iris::Cap interrupt |
| 78 | while true: |
| 79 | Iris::wait () |
| 80 | if Iris::recv.protected_data.l == 0: |
| 81 | // Interrupt. |
| 82 | ready () |
| 83 | rtc_disable_alarm () |
| 84 | ready () |
| 85 | rtc_disable_alarm_wakeup () |
| 86 | if have_interrupt: |
| 87 | interrupt.invoke (0) |
| 88 | Iris::free_cap (interrupt) |
| 89 | have_interrupt = false |
| 90 | continue |
| 91 | switch Iris::recv.data[0].l: |
| 92 | case Iris::RTC::SETUP: |
| 93 | ready () |
| 94 | rtc_set_nc1Hz_val (Iris::recv.data[1].l) |
| 95 | ready () |
| 96 | rtc_set_adjc_val (Iris::recv.data[1].h) |
| 97 | Iris::recv.reply.invoke () |
| 98 | break |
| 99 | case Iris::RTC::GET_TIME: |
| 100 | ready () |
| 101 | Iris::recv.reply.invoke (rtc_get_second ()) |
| 102 | Iris::recv.reply.invoke (0) |
| 103 | break |
| 104 | case Iris::RTC::SET_TIME: |
| 105 | ready () |
| 106 | rtc_set_second (Iris::recv.data[1].l) |
| 107 | Iris::recv.reply.invoke () |
| 108 | break |
| 109 | case Iris::RTC::GET_ALARM: |
| 110 | ready () |
| 111 | Iris::recv.reply.invoke (rtc_get_alarm_second (), rtc_alarm_is_enabled ()) |
| 112 | Iris::recv.reply.invoke (0) |
| 113 | break |
| 114 | case Iris::RTC::UNSET_ALARM: |
| 115 | Iris::Cap reply = Iris::get_reply () |
| 116 | if have_interrupt: |
| 117 | have_interrupt = false |
| 118 | interrupt.invoke (~0) |
| 119 | Iris::free_cap (interrupt) |
| 120 | Iris::unregister_interrupt (IRQ_RTC) |
| 121 | ready () |
| 122 | rtc_disable_alarm () |
| 123 | ready () |
| 124 | rtc_disable_alarm_wakeup () |
| 125 | reply.invoke () |
| 126 | Iris::free_cap (reply) |
| 127 | case Iris::RTC::SET_ALARM: |
| 128 | Iris::Cap reply = Iris::get_reply () |
| 129 | Iris::Cap arg = Iris::get_arg () |
| 130 | unsigned alarm = Iris::recv.data[1].l |
| 131 | if have_interrupt: |
| 132 | Iris::debug ("not registering irq\n") |
| 133 | interrupt.invoke (~0) |
| 134 | Iris::free_cap (interrupt) |
| 135 | else: |
| 136 | Iris::debug ("registering irq\n") |
| 137 | Iris::register_interrupt (IRQ_RTC) |
| 138 | interrupt = arg |
| 139 | have_interrupt = true |
| 140 | ready () |
| 141 | rtc_set_alarm_second (alarm) |
| 142 | ready () |
| 143 | rtc_clear_alarm_flag () |
| 144 | ready () |
| 145 | rtc_enable_alarm () |
| 146 | ready () |
| 147 | rtc_enable_alarm_wakeup () |
| 148 | reply.invoke () |
| 149 | Iris::free_cap (reply) |
| 150 | break |
| 151 | default: |
| 152 | Iris::panic (Iris::recv.data[0].l, "invalid rtc request") |
| 153 | return 0 |
| 154 |
Branches:
master
