aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAtsushi Saitoh <lynxeyed@xj9.so-net.ne.jp>2012-04-01 09:22:26 +0900
committerAtsushi Saitoh <lynxeyed@xj9.so-net.ne.jp>2012-04-01 09:22:26 +0900
commit6807f9123c9f8154c755c343d03a864fac31acdb (patch)
treeeb9f65607bba2be77495c5d264821b74e039f116 /src
parent5132c4d706fa38c271050d581a5700bc279bfe2a (diff)
fixed clocking error
Diffstat (limited to 'src')
-rwxr-xr-xsrc/core/system_LPC11xx.cpp8
-rwxr-xr-xsrc/user_application.cpp122
2 files changed, 121 insertions, 9 deletions
diff --git a/src/core/system_LPC11xx.cpp b/src/core/system_LPC11xx.cpp
index 4d8d275..5a291c5 100755
--- a/src/core/system_LPC11xx.cpp
+++ b/src/core/system_LPC11xx.cpp
@@ -125,14 +125,14 @@
#define SYSOSCCTRL_Val 0x00000000
#define WDTOSC_SETUP 0
#define WDTOSCCTRL_Val 0x000000A0
-//#define SYSPLLCLKSEL_Val 0x00000001
-#define SYSPLLCLKSEL_Val 0x00000000 // for Mary-MB
+#define SYSPLLCLKSEL_Val 0x00000001
+//#define SYSPLLCLKSEL_Val 0x00000000 // for NON EXTCLK
#define SYSPLL_SETUP 1
#define SYSPLLCTRL_Val 0x00000023
#define MAINCLKSEL_Val 0x00000003
#define SYSAHBCLKDIV_Val 0x00000001
-//#define AHBCLKCTRL_Val 0x0001005F
-#define AHBCLKCTRL_Val 0x0001FFFF // for Mary-MB
+#define AHBCLKCTRL_Val 0x0001005F
+//#define AHBCLKCTRL_Val 0x0001FFFF // for NON EXTCLK
#define SSP0CLKDIV_Val 0x00000001
#define UARTCLKDIV_Val 0x00000001
#define SSP1CLKDIV_Val 0x00000001
diff --git a/src/user_application.cpp b/src/user_application.cpp
index c46b077..d2a4cda 100755
--- a/src/user_application.cpp
+++ b/src/user_application.cpp
@@ -1,13 +1,125 @@
#include <libmary.h>
+#include <SD.h>
+#include <SPI1.h>
+
+#define LRCLK 6 // LRCLK(BU9480F) -> D6(eXodusino)
+#define AudioBufRow 256 // length of proc_r
+volatile uint16_t empty_c = 0; // Column
+volatile uint16_t proc_r = 0; // Row
+uint16_t AudioBuf[2][AudioBufRow]; //AudioBuf[empty_c][proc_r]
+bool dac_semp; // オーディオバッファ書き込み完了フラグ true:完了, false:まだ
+
+
+uint16_t br;
+FRESULT rc;
+
+void readSound(void)
+{
+ volatile int16_t i=0,j=0;
+ while(1){
+ if(i != empty_c)
+ {
+ if(j >= AudioBufRow - 1)
+ {
+ i = empty_c; // DACが使用してない(使い終わった)バッファを選択
+ j = 0;
+ }
+ }
+
+ if (j < AudioBufRow - 1)
+ {
+ rc = pf_read(AudioBuf[i], sizeof(uint16_t)*256, &br); // Read a chunk of file
+ if (rc || !br)break;
+
+ j = j + 256;
+
+ }
+ if(j >= AudioBufRow - 1)
+ { // 音声バッファは満タン?(DACがリードしてもOK?)
+ dac_semp = true;
+ }
+ }
+}
+
+
+void playSound(void)
+{
+ static uint16_t i,j; // AudioBuf[j][i]
+ uint16_t k;
+ if(i >= AudioBufRow - 1)
+ {
+ if(dac_semp) // empty_cカラムは書き込み完了?(=true?)
+ {
+ i = 0;
+ empty_c =(empty_c == 1)?0:1; // DACが使い終えたバッファをempty_cとする
+ j = (empty_c == 1)?0:1; // decode()関数がデータを貯めているバッファに切り替え
+ dac_semp = false; // empty_cは空なのでfalse
+
+ }else
+ { // 書き込み完了してない?
+ return;
+ }
+ }
+ //DACへデータ送信
+ k =(AudioBuf[j][i++]);
+ digitalWrite(LRCLK,HIGH);
+ SPI1.transfer(k);
+
+ k =(AudioBuf[j][i++]);
+ digitalWrite(LRCLK,LOW);
+ SPI1.transfer(k);
+
+ return;
+}
void setup()
{
- Serial.begin(9600); // XBeeの初期化
- Serial.println("Start");
+ // XBeeの初期化
+ Serial.begin(9600);
+
+ //BU9480Fの初期化
+ pinMode(LRCLK,OUTPUT);
+ SPI1.setBitLength(16);
+ SPI1.setClockDivider(SPI_CLOCK_DIV2);
+ SPI1.begin();
+
+ // SDCard初期化のtry&catch
+ if (!SDFile.begin())
+ {
+ Serial.println("Cannot detect SDCard") ;
+ return ;
+ }
+
+ Serial.println("card initialized.") ;
+ rc = SDFile.open("test.wav") ;
+
+ if (rc)
+ {
+ // ファイルオープン失敗
+ Serial.println("Failed to open...") ;
+ SDFile.close() ;
+ while(1); // 動作停止
+ }
+
}
-void loop()
+void loop(void)
{
- delay(1000);
- Serial.println(millis()/1000,DEC);
+ Serial.println("Start...");
+ attachMicroseconds(playSound,20000);
+ detachMicroseconds();
+ delayMicroseconds(1000000);
+ Serial.println("play start");
+ // 45マイクロ秒ごと=22.05kHzごとにplaySound()をコールする
+ attachMicroseconds(playSound,45);
+ readSound();
+
+ SDFile.close() ; // ファイルをクローズ
+ detachMicroseconds(); // 割り込みを停止
+
+ Serial.println(""); //改行
+ Serial.println("play end.");
+ while(1);
+
}
+