summaryrefslogtreecommitdiff
path: root/firmware/test
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test')
-rw-r--r--firmware/test/i2s/Makefile9
-rw-r--r--firmware/test/i2s/i2stest.c107
-rw-r--r--firmware/test/test.c12
-rw-r--r--firmware/test/test.h6
4 files changed, 120 insertions, 14 deletions
diff --git a/firmware/test/i2s/Makefile b/firmware/test/i2s/Makefile
index ed7860c..c6673a9 100644
--- a/firmware/test/i2s/Makefile
+++ b/firmware/test/i2s/Makefile
@@ -27,7 +27,7 @@ RM = rm
# Flags
CFLAGS = -W -Wall -Werror -O0 --std=gnu99 -fgnu89-inline -mcpu=cortex-m3 -mthumb
CFLAGS += -ffunction-sections -fdata-sections
-CFLAGS += -I${DRV}
+CFLAGS += -I${DRV} -I${LPC}
ASFLAGS =
LDFLAGS = --gc-sections
@@ -43,6 +43,8 @@ CSRCS = \
${LPC}/system_LPC17xx.c \
${LPC}/startup_LPC17xx.c \
${DRV}/led.c \
+ ${DRV}/cli.c \
+ ${DRV}/uart.c \
${DRV}/i2s.c \
../test.c
@@ -97,6 +99,9 @@ flash: $(EXECNAME)
openocd -f ../../openocd.cfg \
-c 'flash write_image erase $(PROJ).bin' \
-c 'verify_image $(PROJ).bin' \
- -c 'reset run'
+ -c 'reset run' || (sleep 1; openocd -f ../../openocd.cfg \
+ -c 'flash write_image erase $(PROJ).bin' \
+ -c 'verify_image $(PROJ).bin' \
+ -c 'reset run')
-include $(CSRCS:.c=.d)
diff --git a/firmware/test/i2s/i2stest.c b/firmware/test/i2s/i2stest.c
index 31f5c20..8a2c598 100644
--- a/firmware/test/i2s/i2stest.c
+++ b/firmware/test/i2s/i2stest.c
@@ -26,35 +26,120 @@
*/
#include <i2s.h>
#include <led.h>
+#include <LPC17xx.h>
+
+#include <cli.h>
#include "../test.h"
+#include "../../src/sample.h"
+unsigned int size = sizeof(samples) / sizeof(short);
+
+static uint32_t cnt = 0;
+static int num = 0;
+
+#if 1
+void I2S_IRQHandler (void)
+{
+ num = 8 - i2s_get_state_tx_level();
+
+ for(int i = 0; i < num; i++) {
+ i2s_write_pcm_16_stereo(samples[cnt % size] * 10,
+ samples[cnt % size] * 10);
+ //if((cnt % 24000) == 0) led_toggle();
+ //i2s_write_pcm_16_stereo(cnt, cnt);
+ // if(cnt > (1<<16)) cnt = 0;
+ cnt++;
+ }
+
+ /*
+ uint32_t RxCount = 0;
+
+ if ( LPC_I2S->I2SSTATE & 0x01 )
+ {
+ RxCount = (LPC_I2S->I2SSTATE >> 8) & 0xFF;
+ if ( (RxCount != RXFIFO_EMPTY) && !I2SRXDone )
+ {
+ while ( RxCount > 0 )
+ {
+ if ( I2SReadLength == BUFSIZE )
+ {
+ LPC_I2S->I2SDAI |= ((0x01 << 3) | (0x01 << 4));
+ LPC_I2S->I2SIRQ &= ~(0x01 << 0); // Disable RX
+ I2SRXDone = 1;
+ break;
+ }
+ else
+ {
+ I2SRXBuffer[I2SReadLength++] = LPC_I2S->I2SRXFIFO;
+ }
+ RxCount--;
+ }
+ }
+ }
+ return;
+*/
+}
+#endif
+
int main (void)
{
led_init();
-
+ cli_init();
+ /*
// From: tools/clkcalc 48000 16 2
- int pclkdiv = 1;
- int bitrate = 24;
- int x = 96;
- int y = 125;
+ int pclkdiv = 8;
+ int bitrate = 3;
+ int x = 57;
+ int y = 59;
+ // err = 16.949153 bits/second
int bitwidth = 16;
int channels = 2;
int res = i2s_init(pclkdiv, bitrate, x, y, bitwidth, channels);
+ */
+ int res = i2s_clkcalc_init(48000, 16, 2);
if(res) error();
+ // BUG? 4pin mode = 0 works for some reason...?
+ i2s_set_tx_mode_control(CLK_TX_SRC, 0, 1);
+
+ // i2s_tx_reset_fifo();
+ /*
+ // Set up IRQ
+ uint32_t *i2sirq = (uint32_t*)0x400A801C;
+ // *i2sirq &= ~(0b1111 << 16); // Reset tx irq depth
+ int depth = 4;
+ *i2sirq |= ((depth & 0b1111) << 16); // Set tx irq depth
+ *i2sirq |= 0b1 << 1; // Enable IRQ, pg. 479 table 412
+
+ NVIC_EnableIRQ(I2S_IRQn); // I2S_IRQn = 27;
+ */
i2s_tx_start();
- // success();
+ cli_printf("loop...\n");
- int16_t s = 0;
+ // int32_t *fifo = (int32_t*)0x400A8008;
while(1) {
- //while(i2s_get_state_tx_level() < 3) {}
- i2s_write_pcm_16_stereo(s, s);
- if((s % 2) == 0) led_toggle();
- s++;
+ while(i2s_get_state_tx_level() > 7) {}
+ // i2s_write_pcm_16_stereo(cnt, cnt);
+ // *fifo = cnt;
+
+ // *fifo = (cnt / 40) | (cnt / 40) << 16;
+ if(cnt < size) {
+ i2s_write_pcm_16_stereo((samples[cnt] - 485) * 10,
+ (samples[cnt] - 485) * 10);
+ } else {
+ // repeat last sample
+ i2s_write_pcm_16_stereo(0, 0);
+ }
+
+ if(cnt > size * 10) cnt = 0;
+
+ // if(cnt > 64000) cnt = 0;
+ cnt++;
}
+
}
diff --git a/firmware/test/test.c b/firmware/test/test.c
index 8671c5e..00cfac5 100644
--- a/firmware/test/test.c
+++ b/firmware/test/test.c
@@ -30,7 +30,7 @@
volatile int temp;
-static void delay(int del)
+void delay(int del)
{
int i;
for(i = 0; i < del; i++) {
@@ -48,6 +48,16 @@ static void blink(int t)
}
}
+void number(int num)
+{
+ int i;
+ for(i = 0; i < num * 2; i++) {
+ led_toggle();
+ delay(1 << 20);
+ }
+ delay(1 << 23);
+}
+
void error()
{
blink(17);
diff --git a/firmware/test/test.h b/firmware/test/test.h
index 9ab8484..adc4e2f 100644
--- a/firmware/test/test.h
+++ b/firmware/test/test.h
@@ -30,4 +30,10 @@
void error();
void success();
+void delay(int loop);
+/**
+ * Flash number, then pause
+ */
+void number(int num);
+
#endif/*__PEDAL2METAL_TEST_H__*/