File: speaker.h

package info (click to toggle)
grub2 2.14-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 81,540 kB
  • sloc: ansic: 550,889; asm: 68,074; sh: 9,818; cpp: 2,095; makefile: 1,916; python: 1,546; sed: 450; lex: 393; yacc: 268; awk: 85; lisp: 54; perl: 31
file content (47 lines) | stat: -rw-r--r-- 1,142 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef GRUB_SPEAKER_HEADER
#define GRUB_SPEAKER_HEADER 1

#include <grub/cpu/io.h>
#include <grub/i386/pit.h>

/* The frequency of the PIT clock.  */
#define GRUB_SPEAKER_PIT_FREQUENCY		0x1234dd

static inline void
grub_speaker_beep_off (void)
{
  unsigned char status;

  status = grub_inb (GRUB_PIT_SPEAKER_PORT);
  grub_outb (status & ~(GRUB_PIT_SPK_TMR2 | GRUB_PIT_SPK_DATA),
	     GRUB_PIT_SPEAKER_PORT);
}

static inline void
grub_speaker_beep_on (grub_uint16_t pitch)
{
  unsigned char status;
  unsigned int counter;

  if (pitch < 20)
    pitch = 20;
  else if (pitch > 20000)
    pitch = 20000;

  counter = GRUB_SPEAKER_PIT_FREQUENCY / pitch;

  /* Program timer 2.  */
  grub_outb (GRUB_PIT_CTRL_SELECT_2
	     | GRUB_PIT_CTRL_READLOAD_WORD
	     | GRUB_PIT_CTRL_SQUAREWAVE_GEN
	     | GRUB_PIT_CTRL_COUNT_BINARY, GRUB_PIT_CTRL);
  grub_outb (counter & 0xff, GRUB_PIT_COUNTER_2);		/* LSB */
  grub_outb ((counter >> 8) & 0xff, GRUB_PIT_COUNTER_2);	/* MSB */

  /* Start speaker.  */
  status = grub_inb (GRUB_PIT_SPEAKER_PORT);
  grub_outb (status | GRUB_PIT_SPK_TMR2 | GRUB_PIT_SPK_DATA,
	     GRUB_PIT_SPEAKER_PORT);
}

#endif