]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Rewrite spkmodem to use PIT for timing. Double the speed.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Thu, 17 Jan 2013 19:06:52 +0000 (20:06 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Thu, 17 Jan 2013 19:06:52 +0000 (20:06 +0100)
ChangeLog
grub-core/commands/setpci.c
grub-core/term/spkmodem.c
util/spkmodem-recv.c

index 9922c068fb84cbfeca82cf40d7e32877ed0fc70c..f8129ae7fe55f6456e05529918dfdd36122b1350 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 4eaba7c00de13529b44ebd3498c41494a8cd0b98..d5bc97d60b29dc1b9186f3c1de361e0fa8eb971c 100644 (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),
index 31dab65ab1cc0b9f890a3037f641ae5a091515e6..b6e7a049e9f1b03efee2ff919068279db4c7aa34 100644 (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;
 }
 
index cbec3af0e5f74832877ea3c9a573c79bcd889c15..4cc88b83a4996448827d95e4e1c4f37b9096ae60 100644 (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)