Rewrite spkmodem to use PIT for timing. Double the speed.

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-01-17 20:06:52 +01:00
parent 7d462559da
commit 17334a6b6a
4 changed files with 61 additions and 26 deletions

View file

@ -1,3 +1,7 @@
2013-01-17 Vladimir Serbinenko <phcoder@gmail.com>
Rewrite spkmodem to use PIT for timing. Double the speed.
2013-01-16 Vladimir Serbinenko <phcoder@gmail.com>
Add new command pcidump.

View file

@ -129,7 +129,7 @@ grub_setpci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
if (!write_mask)
{
grub_printf (_("Register %x of %d:%d.%d is %x\n"), regaddr,
grub_printf (_("Register %x of %x:%02x.%x is %x\n"), regaddr,
grub_pci_get_bus (dev),
grub_pci_get_device (dev),
grub_pci_get_function (dev),

View file

@ -30,30 +30,66 @@ GRUB_MOD_LICENSE ("GPLv3+");
extern struct grub_terminfo_output_state grub_spkmodem_terminfo_output;
static void
make_tone (grub_uint16_t freq_count, unsigned int duration)
{
/* 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 (freq_count & 0xff, GRUB_PIT_COUNTER_2); /* LSB */
grub_outb ((freq_count >> 8) & 0xff, GRUB_PIT_COUNTER_2); /* MSB */
/* Start speaker. */
grub_outb (grub_inb (GRUB_PIT_SPEAKER_PORT)
| GRUB_PIT_SPK_TMR2 | GRUB_PIT_SPK_DATA,
GRUB_PIT_SPEAKER_PORT);
for (; duration; duration--)
{
unsigned short counter, previous_counter = 0xffff;
while (1)
{
counter = grub_inb (GRUB_PIT_COUNTER_2);
counter |= ((grub_uint16_t) grub_inb (GRUB_PIT_COUNTER_2)) << 8;
if (counter > previous_counter)
{
previous_counter = counter;
break;
}
previous_counter = counter;
}
}
}
static int inited;
static void
put (struct grub_term_output *term __attribute__ ((unused)), const int c)
{
int i;
if (!inited)
{
make_tone (GRUB_SPEAKER_PIT_FREQUENCY / 50, 20);
inited = 1;
}
for (i = 7; i >= 0; i--)
{
if ((c >> i) & 1)
grub_speaker_beep_on (2000);
make_tone (GRUB_SPEAKER_PIT_FREQUENCY / 2000, 20);
else
grub_speaker_beep_on (4000);
grub_millisleep (10);
grub_speaker_beep_on (1000);
grub_millisleep (10);
make_tone (GRUB_SPEAKER_PIT_FREQUENCY / 4000, 40);
make_tone (GRUB_SPEAKER_PIT_FREQUENCY / 1000, 10);
}
grub_speaker_beep_on (50);
make_tone (GRUB_SPEAKER_PIT_FREQUENCY / 50, 0);
}
static grub_err_t
grub_spkmodem_init_output (struct grub_term_output *term)
{
grub_speaker_beep_on (50);
grub_millisleep (50);
grub_terminfo_output_init (term);
return 0;
@ -63,6 +99,7 @@ static grub_err_t
grub_spkmodem_fini_output (struct grub_term_output *term __attribute__ ((unused)))
{
grub_speaker_beep_off ();
inited = 0;
return 0;
}

View file

@ -5,19 +5,13 @@
/* Compilation: gcc -o spkmodem-recv spkmodem-recv */
/* Usage: parecord --channels=1 --rate=48000 --format=s16le | ./spkmodem-recv */
#define RATE 48000
#define SAMPLES_PER_TRAME 480
#define AMPLITUDE_THRESHOLD 100000
#define FREQ_SEP_MIN 15
#define FREQ_SEP_NOM 20
#define FREQ_SEP_MAX 25
#define FREQ_DATA_MIN 10
#define FREQ_DATA_THRESHOLD 60
#define FREQ_DATA_MAX 120
#define AMPLITUDE_SAMPLES 2 * SAMPLES_PER_TRAME
#define THRESHOLD 1000
#define SAMPLES_PER_TRAME 240
#define FREQ_SEP_MIN 6
#define FREQ_SEP_MAX 15
#define FREQ_DATA_MIN 15
#define FREQ_DATA_THRESHOLD 25
#define FREQ_DATA_MAX 60
#define THRESHOLD 500
#define DEBUG 0
@ -67,14 +61,14 @@ main ()
c = 0;
lp = 0;
}
if (f2 > 12 && f2 < 25
&& f1 > 5 && f1 < 120)
if (f2 > FREQ_SEP_MIN && f2 < FREQ_SEP_MAX
&& f1 > FREQ_DATA_MIN && f1 < FREQ_DATA_MAX)
{
#if DEBUG
printf ("%d %d %d @%d\n", f1, f2, FREQ_DATA_THRESHOLD,
ftell (stdin) - sizeof (trame));
#endif
if (f1 < 60)
if (f1 < FREQ_DATA_THRESHOLD)
c |= (1 << bitn);
bitn--;
if (bitn < 0)