#pypp 0 // Iris: micro-kernel for a capability-based operating system. // boot-programs/buzzer.ccp: Piezo buzzer driver. // 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 "devices.hh" #define ARCH #include "arch.hh" class DevBuzzer: static unsigned const pwm = 4 Iris::Cap event bool is_beeping public: DevBuzzer (): is_beeping = false tcu_stop_counter (pwm) tcu_select_extalclk (pwm) tcu_select_clk_div64 (pwm) tcu_enable_pwm_output (pwm) void stop (): if !is_beeping: return tcu_stop_counter (pwm) event.invoke () Iris::free_cap (event) is_beeping = false void beep (unsigned freq, unsigned ms, Iris::Cap cb): stop () event = cb unsigned full = JZ_EXTAL / 64 / freq tcu_set_full_data (pwm, full) tcu_set_half_data (pwm, full / 2) tcu_set_count (pwm, 0) tcu_start_counter (pwm) Iris::my_receiver.set_alarm (ms * HZ / 1000) is_beeping = true enum codes: BUZZER = 32 Iris::Num start (): map_tcu () DevBuzzer buzzer Iris::Buzzer dev = Iris::my_receiver.create_capability (BUZZER) Iris::my_parent.provide_capability (dev.copy ()) Iris::free_cap (dev) Iris::my_parent.init_done () while true: Iris::wait () if Iris::recv.protected_data.h == ~0: // Alarm. buzzer.stop () continue switch Iris::recv.protected_data.l: case BUZZER: // Buzzer device user request. switch Iris::recv.data[0].l: case Iris::Device::RESET: buzzer.stop () Iris::recv.reply.invoke () break case Iris::Buzzer::BEEP: // Volume is not used by this buzzer. Iris::Cap arg = Iris::get_arg () Iris::Cap reply = Iris::get_reply () buzzer.beep (Iris::recv.data[1].l, Iris::recv.data[1].h, arg) reply.invoke () Iris::free_cap (reply) break case Iris::Buzzer::STOP: buzzer.stop () Iris::recv.reply.invoke () break default: kdebug ("Buzzer: other\n") break break default: kdebug ("Buzzer: unknown num: ") kdebug_num (Iris::recv.protected_data.l) kdebug ("\n")