OSDN Git Service

Separated the file I/O control.
authorShinichiro Nakamura <shinta.main.jp@gmail.com>
Mon, 16 Jul 2012 20:09:35 +0000 (05:09 +0900)
committerShinichiro Nakamura <shinta.main.jp@gmail.com>
Mon, 16 Jul 2012 20:09:35 +0000 (05:09 +0900)
firm/sample/sample1/os/Makefile
firm/sample/sample1/os/kozos.h
firm/sample/sample1/os/main.c
firm/sample/sample1/os/task.h
firm/sample/sample1/os/task_fileio.c [new file with mode: 0644]
firm/sample/sample1/os/task_fileio.h [new file with mode: 0644]
firm/sample/sample1/os/task_input.c

index f90a69c..b56b22f 100644 (file)
@@ -28,11 +28,12 @@ OBJS += vs1011e.o
 OBJS += spi.o spreg.o
 
 # Tasks
-OBJS += task_input.o
-OBJS += task_command.o
-OBJS += task_display.o
 OBJS += task_audio.o
+OBJS += task_display.o
+OBJS += task_fileio.o
 OBJS += task_system.o
+OBJS += task_input.o
+OBJS += task_command.o
 
 # Kernel
 OBJS += kozos.o syscall.o memory.o
index 90ac31d..25c7270 100644 (file)
@@ -41,6 +41,7 @@ void kz_srvcall(kz_syscall_type_t type, kz_syscall_param_t *param);
 
 extern kz_thread_id_t tskid_audio;
 extern kz_thread_id_t tskid_display;
+extern kz_thread_id_t tskid_fileio;
 extern kz_thread_id_t tskid_system;
 extern kz_thread_id_t tskid_input;
 extern kz_thread_id_t tskid_command;
index dbc3b3d..470a05e 100644 (file)
@@ -5,6 +5,7 @@
 
 kz_thread_id_t tskid_audio;
 kz_thread_id_t tskid_display;
+kz_thread_id_t tskid_fileio;
 kz_thread_id_t tskid_system;
 kz_thread_id_t tskid_input;
 kz_thread_id_t tskid_command;
@@ -26,6 +27,7 @@ static int start_threads(int argc, char *argv[])
   tskid_system  = kz_run(task_system,   "tSystem",   5, 0x800, 0, NULL);
   tskid_input   = kz_run(task_input,    "tInput",    6, 0x800, 0, NULL);
   tskid_command = kz_run(task_command,  "tCommand",  7, 0x800, 0, NULL);
+  tskid_fileio  = kz_run(task_fileio,   "tFileIO",   8, 0x800, 0, NULL);
 
   kz_chpri(15); /* Í¥Àè½ç°Ì¤ò²¼¤²¤Æ¡¤¥¢¥¤¥É¥ë¥¹¥ì¥Ã¥É¤Ë°Ü¹Ô¤¹¤ë */
   INTR_ENABLE; /* ³ä¹þ¤ßÍ­¸ú¤Ë¤¹¤ë */
index c77f0d0..ddbaff2 100644 (file)
@@ -1,10 +1,11 @@
 #ifndef TASK_H
 #define TASK_H
 
-#include "task_input.h"
-#include "task_command.h"
 #include "task_audio.h"
 #include "task_display.h"
+#include "task_fileio.h"
 #include "task_system.h"
+#include "task_input.h"
+#include "task_command.h"
 
 #endif
diff --git a/firm/sample/sample1/os/task_fileio.c b/firm/sample/sample1/os/task_fileio.c
new file mode 100644 (file)
index 0000000..aab4a16
--- /dev/null
@@ -0,0 +1,75 @@
+#include "defines.h"
+#include "kozos.h"
+#include "lib.h"
+#include "intr.h"
+#include "portconf.h"
+#include "pff.h"
+
+#define VS1011E_CHK_DREQ()  (((*PORTCONF_P4DR) & PORTCONF_P4BIT_VSDREQ) ? 0 : 1)
+
+static FATFS fatfs;
+static DIR dir;
+static FILINFO filinfo;
+
+static int readfunc(void *buf, int siz)
+{
+    WORD cnt;
+    pf_read(buf, siz, &cnt);
+    return cnt;
+}
+
+static int play(const char *filename)
+{
+    FRESULT r = pf_open(filename);
+    if (r != FR_OK) {
+        return 1;
+    }
+    while (audio_play(readfunc)) {
+        while (VS1011E_CHK_DREQ()) {
+            kz_wait();
+        }
+    }
+    return 0;
+}
+
+static int is_music_file(const char *filename)
+{
+    int len = strlen(filename);
+    if (len < 4) {
+        return 0;
+    }
+    if (strcmp(filename + len - 4, ".MP3") == 0) {
+        return 1;
+    }
+    if (strcmp(filename + len - 4, ".WAV") == 0) {
+        return 1;
+    }
+    return 0;
+}
+
+int task_fileio(int argc, char *argv[])
+{
+  while (1) {
+      if (pf_mount(&fatfs)) {
+          continue;
+      }
+      while (1) {
+          if (pf_opendir(&dir, "")) {
+              break;
+          }
+          while (!pf_readdir(&dir, &filinfo) && filinfo.fname[0]) {
+              if (!(filinfo.fattrib & (AM_DIR | AM_HID))) {
+                  if (is_music_file(filinfo.fname)) {
+                      display_draw_text(40, 4, filinfo.fname);
+                      if (play(filinfo.fname)) {
+                          break;
+                      }
+                  }
+              }
+          }
+      }
+  }
+
+  return 0;
+}
+
diff --git a/firm/sample/sample1/os/task_fileio.h b/firm/sample/sample1/os/task_fileio.h
new file mode 100644 (file)
index 0000000..96c4ee8
--- /dev/null
@@ -0,0 +1,7 @@
+
+#ifndef TASK_FILEIO_H
+#define TASK_FILEIO_H
+
+int task_fileio(int argc, char *argv[]);
+
+#endif
index bdbfdf0..45b8fc9 100644 (file)
@@ -6,7 +6,6 @@
 #include "re.h"
 #include "intr.h"
 #include "portconf.h"
-#include "pff.h"
 
 #define H8_3069F_ISCR       ((volatile uint8 *)0xFEE014)
 #define H8_3069F_IER        ((volatile uint8 *)0xFEE015)
@@ -72,9 +71,6 @@ static ir_state_t irs = WaitLeader;
 static uint8 data[MAX_BIT_COUNT / 8];
 static uint16 bitcnt = 0;
 static uint16 prev = 0, curr = 0;
-static FATFS fatfs;
-static DIR dir;
-static FILINFO filinfo;
 
 static void remocon_intr_edge(void)
 {
@@ -141,39 +137,6 @@ static void encoder_intr_tovf(void)
   }
 }
 
-static int readfunc(void *buf, int siz)
-{
-    WORD cnt;
-    pf_read(buf, siz, &cnt);
-    return cnt;
-}
-
-static int play(const char *filename)
-{
-    FRESULT r = pf_open(filename);
-    if (r != FR_OK) {
-        return 1;
-    }
-    while (audio_play(readfunc)) {
-    }
-    return 0;
-}
-
-static int is_music_file(const char *filename)
-{
-    int len = strlen(filename);
-    if (len < 4) {
-        return 0;
-    }
-    if (strcmp(filename + len - 4, ".MP3") == 0) {
-        return 1;
-    }
-    if (strcmp(filename + len - 4, ".WAV") == 0) {
-        return 1;
-    }
-    return 0;
-}
-
 int task_input(int argc, char *argv[])
 {
   /*
@@ -195,24 +158,7 @@ int task_input(int argc, char *argv[])
   audio_volume(250, 250);
 
   while (1) {
-      if (pf_mount(&fatfs)) {
-          continue;
-      }
-      while (1) {
-          if (pf_opendir(&dir, "")) {
-              break;
-          }
-          while (!pf_readdir(&dir, &filinfo) && filinfo.fname[0]) {
-              if (!(filinfo.fattrib & (AM_DIR | AM_HID))) {
-                  if (is_music_file(filinfo.fname)) {
-                      display_draw_text(40, 4, filinfo.fname);
-                      if (play(filinfo.fname)) {
-                          break;
-                      }
-                  }
-              }
-          }
-      }
+    kz_sleep();
   }
 
   return 0;