OSDN Git Service

Ticket #29299 Updated the uzume interface.
authorShinichiro Nakamura <shinta.main.jp@gmail.com>
Mon, 20 Aug 2012 17:45:35 +0000 (02:45 +0900)
committerShinichiro Nakamura <shinta.main.jp@gmail.com>
Mon, 20 Aug 2012 17:45:35 +0000 (02:45 +0900)
firm/bare_metal/main.c
firm/bare_metal/uzume.c
firm/bare_metal/uzume.h

index 1d1eb0e..1c3afc3 100644 (file)
@@ -5,10 +5,31 @@
  */
 
 #include "uzume.h"
+#include <string.h>
+#include <cdefBF592-A.h>
+
+/*
+ * See 'Blackfin GCC Built-in Functions'
+ */
+
+static void effect_through(
+        UZUME *p,
+        const int32_t *src, int32_t *des, int32_t count)
+{
+    memcpy(des, src, sizeof(int32_t) * count);
+}
+
+static void system_default(UZUME *p)
+{
+}
 
 int main(void)
 {
-    uzume_execute();
+    UZUME u;
+    uzume_init(&u);
+    uzume_set_effect(&u, effect_through);
+    uzume_set_system(&u, system_default);
+    uzume_execute(&u);
     return 0;
 }
 
index 68c4112..e404e1a 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * @file main.c
+ * @file uzume.c
  * @brief BlueTank ACB-BF592 Application Sample Codes.
  * @author Copyright(C) 2012 Shinichiro Nakamura
  */
@@ -13,6 +13,7 @@
 #include "led.h"
 #include "pff.h"
 #include "ssm2603.h"
+#include "uzume.h"
 
 #define SCLOCK_HZ           (100000000) /**< システムクロック(100MHz) */
 #define DMA_SAMPLE_SIZE     (256)       /**< 1回のサンプルサイズ */
@@ -21,7 +22,6 @@ typedef __attribute__((interrupt_handler)) void (*ex_handler_fn_gcc)(void);
 
 static void setup_pll(uint8_t mul_val, uint8_t div_val);
 static void __attribute__((interrupt_handler)) sport_rx_isr();
-static void audio_effect(const int32_t* src, int32_t* des, int32_t count);
 
 /**
  * SPORT受信バッファ(ダブルバッファ)
@@ -59,17 +59,6 @@ static void __attribute__((interrupt_handler)) sport_rx_isr()
     bufidx_dma_target = (bufidx_dma_target ^ 1) & 1;
 }
 
-/**
- * @brief オーディオ処理を実行する。
- *
- * @param src 処理元バッファ。
- * @param des 処理後バッファ。
- */
-static void audio_effect(const int32_t *src, int32_t *des, int32_t count)
-{
-    memcpy(des, src, sizeof(int32_t) * count);
-}
-
 static void vdsp_register_handler(interrupt_kind kind, ex_handler_fn_gcc fn)
 {
     uint32_t mask;
@@ -84,15 +73,17 @@ static void vdsp_register_handler(interrupt_kind kind, ex_handler_fn_gcc fn)
     sti(mask);
 }
 
-void uzume_execute(void)
+void uzume_init(UZUME *p)
 {
-    int32_t bufidx_dma_done;
     FATFS fatfs;
 #if 0
     DIR dir;
     FILINFO finfo;
 #endif
 
+    p->effect = NULL;
+    p->system = NULL;
+
     /*
      * PLLを設定する。
      */
@@ -213,6 +204,21 @@ void uzume_execute(void)
      * ミュートを解除する。
      */
     ssm2603_mute(false);
+}
+
+void uzume_set_effect(UZUME *p, UZUME_EFFECT_FUNC effect)
+{
+    p->effect = effect;
+}
+
+void uzume_set_system(UZUME *p, UZUME_SYSTEM_FUNC system)
+{
+    p->system = system;
+}
+
+void uzume_execute(UZUME *p)
+{
+    int32_t bufidx_dma_done;
 
     while (1) {
         asm("idle;");
@@ -226,12 +232,21 @@ void uzume_execute(void)
              * DMAが完了したバッファを使用してオーディオ処理を行なう。
              */
             bufidx_dma_done = bufidx_dma_target ^ 1;
-            audio_effect(sport_buffer_rx[bufidx_dma_done], sport_buffer_tx[bufidx_dma_done], DMA_SAMPLE_SIZE);
+            if (p->effect != NULL) {
+                p->effect(
+                        p,
+                        sport_buffer_rx[bufidx_dma_done],
+                        sport_buffer_tx[bufidx_dma_done],
+                        DMA_SAMPLE_SIZE);
+            }
             /*
              *
              */
             led_write(LedTargetR, 1);
         }
+        if (p->system != NULL) {
+            p->system(p);
+        }
     }
 }
 
index dd9d957..afe6b82 100644 (file)
@@ -1,7 +1,23 @@
+
 #ifndef UZUME_H
 #define UZUME_H
 
-void uzume_execute(void);
+#include <stdint.h>
+
+typedef struct UZUME UZUME;
+typedef void (*UZUME_EFFECT_FUNC)(UZUME *p,
+        const int32_t *src, int32_t *des, int32_t count);
+typedef void (*UZUME_SYSTEM_FUNC)(UZUME *p);
+
+struct UZUME {
+    UZUME_EFFECT_FUNC effect;
+    UZUME_SYSTEM_FUNC system;
+};
+
+void uzume_init(UZUME *p);
+void uzume_set_effect(UZUME *p, UZUME_EFFECT_FUNC effect);
+void uzume_set_system(UZUME *p, UZUME_SYSTEM_FUNC system);
+void uzume_execute(UZUME *p);
 
 #endif