OSDN Git Service

Added audio play test codes.
authorShinichiro Nakamura <shinta.main.jp@gmail.com>
Sat, 14 Jul 2012 03:03:16 +0000 (12:03 +0900)
committerShinichiro Nakamura <shinta.main.jp@gmail.com>
Sat, 14 Jul 2012 03:03:16 +0000 (12:03 +0900)
firm/sample/sample1/bootload/main.c
firm/sample/sample1/os/kozos.h
firm/sample/sample1/os/ld.scr
firm/sample/sample1/os/main.c
firm/sample/sample1/os/memory.c
firm/sample/sample1/os/task_audio.c
firm/sample/sample1/os/task_input.c

index 8b4e739..79bd1cb 100644 (file)
@@ -107,7 +107,7 @@ static int init(void)
 
   led_write(Led1, LedOff);
   led_write(Led2, LedOff);
-  vs1011e_volume_write(0x10, 0x10);
+  vs1011e_volume_write(0x02, 0x02);
 
   return 0;
 }
index e36eefa..9109d9e 100644 (file)
@@ -8,8 +8,10 @@
 #include "task.h"
 
 /* ¥·¥¹¥Æ¥à¡¦¥³¡¼¥ë */
-kz_thread_id_t kz_run(kz_func_t func, char *name, int priority, int stacksize,
-                     int argc, char *argv[]);
+kz_thread_id_t kz_run(
+        kz_func_t func, char *name,
+        int priority, int stacksize,
+        int argc, char *argv[]);
 void kz_exit(void);
 int kz_wait(void);
 int kz_sleep(void);
@@ -29,8 +31,10 @@ int kx_kmfree(void *p);
 int kx_send(kz_msgbox_id_t id, int size, char *p);
 
 /* ¥é¥¤¥Ö¥é¥ê´Ø¿ô */
-void kz_start(kz_func_t func, char *name, int priority, int stacksize,
-             int argc, char *argv[]);
+void kz_start(
+        kz_func_t func, char *name,
+        int priority, int stacksize,
+        int argc, char *argv[]);
 void kz_sysdown(void);
 void kz_syscall(kz_syscall_type_t type, kz_syscall_param_t *param);
 void kz_srvcall(kz_syscall_type_t type, kz_syscall_param_t *param);
index f1a2f15..792e49e 100644 (file)
@@ -33,6 +33,7 @@ SECTIONS
                *(.strings)
                *(.rodata)
                *(.rodata.*)
+                . = ALIGN(4);
                _erodata = . ;
        } > ram
 
index 51f2c74..d884ebf 100644 (file)
@@ -6,12 +6,12 @@
 /* ¥·¥¹¥Æ¥à¡¦¥¿¥¹¥¯¤È¥æ¡¼¥¶¡¦¥¿¥¹¥¯¤Îµ¯Æ° */
 static int start_threads(int argc, char *argv[])
 {
-  kz_run(driver_console,    "dConsole",      1, 0x200, 0, NULL);
-  kz_run(driver_timer,      "dTimer",        2, 0x200, 0, NULL);
-  kz_run(task_display,      "tDisplay",      5, 0x400, 0, NULL);
-  kz_run(task_audio,        "tAudio",        6, 0x400, 0, NULL);
-  kz_run(task_command,      "tCommand",      7, 0x400, 0, NULL);
-  kz_run(task_input,        "tInput",        8, 0x400, 0, NULL);
+  kz_run(driver_console,    "dConsole",  1, 0x200, 0, NULL);
+  kz_run(driver_timer,      "dTimer",    2, 0x200, 0, NULL);
+  kz_run(task_audio,        "tAudio",    5, 0x800, 0, NULL);
+  kz_run(task_display,      "tDisplay",  6, 0x800, 0, NULL);
+  kz_run(task_input,        "tInput",   10, 0x800, 0, NULL);
+  kz_run(task_command,      "tCommand", 12, 0x800, 0, NULL);
 
   kz_chpri(15); /* Í¥Àè½ç°Ì¤ò²¼¤²¤Æ¡¤¥¢¥¤¥É¥ë¥¹¥ì¥Ã¥É¤Ë°Ü¹Ô¤¹¤ë */
   INTR_ENABLE; /* ³ä¹þ¤ßÍ­¸ú¤Ë¤¹¤ë */
@@ -34,3 +34,4 @@ int main(void)
 
   return 0;
 }
+
index 75925d0..d817134 100644 (file)
@@ -21,7 +21,13 @@ typedef struct _kzmem_pool {
 
 /* ¥á¥â¥ê¡¦¥×¡¼¥ë¤ÎÄêµÁ(¸Ä¡¹¤Î¥µ¥¤¥º¤È¸Ä¿ô) */
 static kzmem_pool pool[] = {
-  { 16, 8, NULL }, { 32, 8, NULL }, { 64, 4, NULL },
+  {    8, 8, NULL },
+  {   16, 8, NULL },
+  {   32, 8, NULL },
+  {   64, 8, NULL },
+  {  128, 4, NULL },
+  {  256, 4, NULL },
+  { 1024, 4, NULL },
 };
 
 #define MEMORY_AREA_NUM (sizeof(pool) / sizeof(*pool))
index 8ca2731..0534427 100644 (file)
@@ -1,6 +1,7 @@
 #include "task_audio.h"
 #include "vs1011e.h"
 #include "kozos.h"
+#include "pff.h"
 
 #define AUDIO_CMD_PULSE  'p'
 
@@ -31,11 +32,51 @@ static int audio_cmdproc(char *p)
   return 0;
 }
 
+int8 readfunc(uint8 * buf, const uint16 len)
+{
+    WORD cnt;
+    pf_read(buf, len, &cnt);
+    return cnt;
+}
+
+static int play(const char *filename)
+{
+    FRESULT r = pf_open("splash.mp3");
+    if (r != FR_OK) {
+        return 1;
+    }
+    vs1011e_play(readfunc);
+    return 0;
+}
+
 int task_audio(int argc, char *argv[])
 {
   int size;
   char *p;
 
+  FATFS fatfs;
+  DIR dir;
+  FILINFO filinfo;
+
+  vs1011e_volume_write(0x02, 0x02);
+  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 (play(filinfo.fname)) {
+                      break;
+                  }
+              }
+          }
+      }
+  }
+
   while (1) {
     kz_recv(MSGBOX_ID_AUDIO, &size, &p);
     audio_cmdproc(p);
@@ -43,3 +84,4 @@ int task_audio(int argc, char *argv[])
 
   return 0;
 }
+
index 807ffb8..a0638c4 100644 (file)
 
 #define MAX_BIT_COUNT (64)
 
+#define TCNT_COUNT_START()  (*H8_3069F_TSTR |= (1 << 0))
+#define TCNT_COUNT_STOP()   (*H8_3069F_TSTR &= ~(1 << 0))
+#define TCNT_COUNT_VALUE()  (((*H8_3069F_16TCNT0H) << 8) | ((*H8_3069F_16TCNT0L) << 0))
+#define TCNT_COUNT_RESET()  \
+  do { \
+    *H8_3069F_16TCNT0H = 0; \
+    *H8_3069F_16TCNT0L = 0; \
+  } while (0)
+
+#define TCR0_SETUP()        (*H8_3069F_16TCR0 = 0x03)
+#define TMRINT_ENABLE()     (*H8_3069F_TISRC |= (1 << 4))
+#define TMRINT_FLAG_CLEAR() (*H8_3069F_TISRC &= ~(1 << 0))
+#define IRQ4_ENABLE() \
+  do { \
+    (*H8_3069F_ISCR |= (1 << 4)); \
+    (*H8_3069F_IER |= (1 << 4)); \
+  } while (0)
+
 typedef enum {
   WaitLeader,
   FoundLeader,
@@ -35,7 +53,8 @@ static void remocon_intr_edge(void)
 {
   switch (irs) {
     case WaitLeader:
-      *H8_3069F_TSTR |= (1 << 0);
+      TCNT_COUNT_RESET();
+      TCNT_COUNT_START();
       bitcnt = 0;
       tmrovf = 0;
       irs = FoundLeader;
@@ -48,9 +67,7 @@ static void remocon_intr_edge(void)
         if ((bitcnt % 8) == 0) {
           data[bitcnt / 8] = 0;
         }
-        uint16 tmrval =
-          ((*H8_3069F_16TCNT0H) << 8) |
-          ((*H8_3069F_16TCNT0L) << 0);
+        uint16 tmrval = TCNT_COUNT_VALUE();
         if (tmrval > 0x1077) {
           data[bitcnt / 8] |= (1 << (bitcnt % 8));
         }
@@ -61,20 +78,21 @@ static void remocon_intr_edge(void)
       }
       break;
     case Received:
-      *H8_3069F_TSTR &= ~(1 << 0);
+      TCNT_COUNT_STOP();
       break;
     default:
+      TCNT_COUNT_STOP();
       break;
   }
-  *H8_3069F_16TCNT0H = 0;
-  *H8_3069F_16TCNT0L = 0;
+  TCNT_COUNT_RESET();
 }
 
 static void remocon_intr_tovf(void)
 {
-  *H8_3069F_TISRC &= ~(1 << 0);
+  TMRINT_FLAG_CLEAR();
   tmrovf = 1;
-  *H8_3069F_TSTR &= ~(1 << 0);
+  irs = WaitLeader;
+  TCNT_COUNT_STOP();
 }
 
 int task_input(int argc, char *argv[])
@@ -84,15 +102,11 @@ int task_input(int argc, char *argv[])
   /*
    * Setup.
    */
-#if 0
   kz_setintr(SOFTVEC_TYPE_IR_EDGE, remocon_intr_edge);
   kz_setintr(SOFTVEC_TYPE_IR_TOVF, remocon_intr_tovf);
-  *H8_3069F_ISCR |= (1 << 4);
-  *H8_3069F_IER |= (1 << 4);
-
-  *H8_3069F_TISRC |= (1 << 4);
-  *H8_3069F_16TCR0 = 0x03;
-#endif
+  TCR0_SETUP();
+  TMRINT_ENABLE();
+  IRQ4_ENABLE();
 
   /*
    * Display clear
@@ -129,8 +143,8 @@ int task_input(int argc, char *argv[])
 
       display_draw_box(nx + 20, ny, nx + 20, ny + 16, 0);
       display_draw_logo(nx, ny, 0);
+      display_led_toggle(3);
     }
-    display_led_toggle(3);
 
     if (tmrovf) {
       if (bitcnt == 32) {
@@ -150,7 +164,6 @@ int task_input(int argc, char *argv[])
       }
       bitcnt = 0;
       tmrovf = 0;
-      irs = WaitLeader;
     }
   }