audio: add the base audio code and hooks
authorAlan Cox <alan@linux.intel.com>
Tue, 31 Mar 2015 21:51:11 +0000 (22:51 +0100)
committerAlan Cox <alan@linux.intel.com>
Tue, 31 Mar 2015 21:51:11 +0000 (22:51 +0100)
Kernel/audio.c [new file with mode: 0644]
Kernel/devsys.c
Kernel/process.c

diff --git a/Kernel/audio.c b/Kernel/audio.c
new file mode 100644 (file)
index 0000000..9e6bf03
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *     FUZIX audio core support
+ */
+
+#include <kernel.h>
+#include <kdata.h>
+#include <printf.h>
+#include <audio.h>
+
+#ifdef CONFIG_AUDIO
+
+struct sound sound;
+
+int audio_ioctl(uarg_t op, void *val)
+{
+  uint8_t i;
+
+  if ((op >> 8) != 0x02)
+    return -EINVAL;
+  switch(op) {
+    case AUDIOC_GETINFO:
+      return uput(&audio_info, val, sizeof(audio_info));
+    case AUDIOC_STOP:
+      for (i = 0; i < audio_info.channels;i++)
+        devaudio_stop(i);
+      return 0;
+    case AUDIOC_WAIT:
+      for (i = 0; i < audio_info.channels;i++)
+        devaudio_wait(i);
+      return 0;
+    case AUDIOC_PLAY:
+      if (uget(&sound, val, sizeof(sound)) == -1)
+        return -1;
+      if (sound.channel > audio_info.channels) {
+        udata.u_error = ERANGE;
+        return -1;
+      }
+      if (sound.flags & SND_WAIT)
+        if (devaudio_wait(sound.channel))
+          return -1;
+      return devaudio_play();
+    default:
+      return devaudio_ioctl(op, val);
+  }
+}
+
+void audio_tick(void)
+{
+  /* For now no core processing */
+  devaudio_tick();
+}
+
+/* TODO: read/write for DSP devices */
+
+#endif
index c2fcc25..89e4e68 100644 (file)
@@ -2,6 +2,7 @@
 #include <version.h>
 #include <kdata.h>
 #include <devsys.h>
+#include <audio.h>
 
 /*
  *     System devices:
@@ -10,6 +11,7 @@
  *     Minor   1       mem
  *     Minor   2       zero
  *     Minor   3       proc
+ *     Minor   64      audio
  *
  *     Use Minor 128+ for platform specific devices
  */
@@ -72,6 +74,10 @@ int sys_write(uint8_t minor, uint8_t rawflag, uint8_t flag)
 
 int sys_ioctl(uint8_t minor, uarg_t request, char *data)
 {
+#ifdef CONFIG_AUDIO
+       if (minor == 64)
+               return audio_ioctl(request, data);
+#endif
        if (minor != 3) {
           udata.u_error = ENOTTY;
          return -1;
index 493c348..ffcce80 100644 (file)
@@ -5,6 +5,7 @@
 #include <kernel.h>
 #include <kdata.h>
 #include <printf.h>
+#include <audio.h>
 
 /* psleep() puts a process to sleep on the given event.  If another
  * process is runnable, it switches out the current one and starts the
@@ -350,6 +351,9 @@ void timer_interrupt(void)
                        }
                }
                updatetod();
+#ifdef CONFIG_AUDIO
+               audio_tick();
+#endif
        }
 #ifndef CONFIG_SINGLETASK
        /* Check run time of current process */