View of xos/drivers/beep.c


XOS | Parent Directory | View | Download

/* Copyright (C) 2008  Emmanuel Varoquaux
 
   This file is part of XOS.
 
   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/>. */
 
/* Pour emettre un bip, on utilise conjointement le compteur 2 du 8253 PIT et
 * le speaker du 8255 PPI. */
 
#include <alarm.h>
#include <alarm_struct.h>
#include <asm.h>
 
static struct alarm_struct beep_alarm;
 
/* start_beep() emet un nouveau bip a chaque appel, meme si un bip est deja en
 * cours. */
static void start_beep()
{
  int intr;
 
  disable_intr(intr);
  outbp(0xb6, 0x43);             /* commande : ecriture de deux octets */
  outbp(0x37, 0x42);             /* frequence : 0x637 (750 Hz) */
  outb(0x06, 0x42);
  outbp(inbp(0x61) | 0x3, 0x61); /* compteur 2 */
  alarm_set(&beep_alarm, 125);   /* duree : 1/8 seconde */
  restore_intr(intr);
}
 
static void stop_beep()
{
  outb(inbp(0x61) & 0xfc, 0x61);
}
 
void beep_init()
{
  alarm_init(&beep_alarm, stop_beep);
}
 
void beep()
{
  start_beep();
}