From 756360b2098721496e7362ea7a7b3f75b6f719e0 Mon Sep 17 00:00:00 2001 From: Shinichiro Nakamura Date: Mon, 16 Jul 2012 20:15:16 +0900 Subject: [PATCH] Changed IPC structure for playing mp3 file. --- firm/sample/sample1/os/main.c | 8 ++-- firm/sample/sample1/os/memory.c | 18 ++++---- firm/sample/sample1/os/task_input.c | 65 +++++++++++++++++++++++++-- firm/sample/sample1/os/task_system.c | 86 ++---------------------------------- 4 files changed, 78 insertions(+), 99 deletions(-) diff --git a/firm/sample/sample1/os/main.c b/firm/sample/sample1/os/main.c index a4e0dbf..dbc3b3d 100644 --- a/firm/sample/sample1/os/main.c +++ b/firm/sample/sample1/os/main.c @@ -22,10 +22,10 @@ static int start_threads(int argc, char *argv[]) * Tasks */ tskid_audio = kz_run(task_audio, "tAudio", 3, 0x800, 0, NULL); - tskid_display = kz_run(task_display, "tDisplay", 3, 0x800, 0, NULL); - tskid_system = kz_run(task_system, "tSystem", 4, 0x800, 0, NULL); - tskid_input = kz_run(task_input, "tInput", 4, 0x800, 0, NULL); - tskid_command = kz_run(task_command, "tCommand", 4, 0x800, 0, NULL); + tskid_display = kz_run(task_display, "tDisplay", 4, 0x800, 0, NULL); + 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); kz_chpri(15); /* Í¥Àè½ç°Ì¤ò²¼¤²¤Æ¡¤¥¢¥¤¥É¥ë¥¹¥ì¥Ã¥É¤Ë°Ü¹Ô¤¹¤ë */ INTR_ENABLE; /* ³ä¹þ¤ßÍ­¸ú¤Ë¤¹¤ë */ diff --git a/firm/sample/sample1/os/memory.c b/firm/sample/sample1/os/memory.c index 869fdb2..fff9cc7 100644 --- a/firm/sample/sample1/os/memory.c +++ b/firm/sample/sample1/os/memory.c @@ -21,15 +21,15 @@ typedef struct _kzmem_pool { /* ¥á¥â¥ê¡¦¥×¡¼¥ë¤ÎÄêµÁ(¸Ä¡¹¤Î¥µ¥¤¥º¤È¸Ä¿ô) */ static kzmem_pool pool[] = { - { 8, 8, NULL }, - { 16, 8, NULL }, - { 32, 8, NULL }, - { 64, 8, NULL }, - { 128, 8, NULL }, - { 256, 8, NULL }, - { 512, 8, NULL }, - { 1024, 8, NULL }, - { 2048, 8, NULL }, + { 8, 16, NULL }, + { 16, 16, NULL }, + { 32, 16, NULL }, + { 64, 16, NULL }, + { 128, 16, NULL }, + { 256, 16, NULL }, + { 512, 16, NULL }, + { 1024, 16, NULL }, + { 2048, 16, NULL }, }; #define MEMORY_AREA_NUM (sizeof(pool) / sizeof(*pool)) diff --git a/firm/sample/sample1/os/task_input.c b/firm/sample/sample1/os/task_input.c index 65b2bf1..bdbfdf0 100644 --- a/firm/sample/sample1/os/task_input.c +++ b/firm/sample/sample1/os/task_input.c @@ -5,6 +5,8 @@ #include "sw.h" #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) @@ -57,6 +59,8 @@ #define TCR1_INTR_ENABLE() (*H8_3069F_TISRC |= (1 << 5)) #define TCR1_FLAG_CLEAR() (*H8_3069F_TISRC &= ~(1 << 1)) +#define VS1011E_CHK_DREQ() (((*PORTCONF_P4DR) & PORTCONF_P4BIT_VSDREQ) ? 0 : 1) + typedef enum { WaitLeader, FoundLeader, @@ -68,6 +72,9 @@ 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) { @@ -114,6 +121,7 @@ static void remocon_intr_tovf(void) static void encoder_intr_tovf(void) { TCR1_FLAG_CLEAR(); + /* * $B%m!<%?%j!<%(%s%3!<%@F~NO=hM}(B */ @@ -133,6 +141,39 @@ 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[]) { /* @@ -151,11 +192,27 @@ int task_input(int argc, char *argv[]) IRQ4_ENABLE(); + audio_volume(250, 250); + while (1) { - /* - * - */ - kz_wait(); + 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_system.c b/firm/sample/sample1/os/task_system.c index d909c96..ca69c67 100644 --- a/firm/sample/sample1/os/task_system.c +++ b/firm/sample/sample1/os/task_system.c @@ -2,16 +2,12 @@ #include "task_system.h" #include "task_audio.h" #include "task_display.h" -#include "pff.h" #include "kozos.h" #include "lib.h" #define SYSTEM_CMD_INPUT 'i' #define SYSTEM_CMD_REMOTE 'r' -FATFS fatfs; -DIR dir; -FILINFO filinfo; int nx = 40, ny = 12; int system_input_from_isr(int left, int right, int sw) @@ -40,13 +36,6 @@ int system_remote_from_isr(char *signal, int siz) return 0; } -static int readfunc(void *buf, int siz) -{ - WORD cnt; - pf_read(buf, siz, &cnt); - return cnt; -} - static int system_cmdproc(char *p) { int cmd = p[0]; @@ -58,6 +47,8 @@ static int system_cmdproc(char *p) nx--; display_draw_box(nx + 20, ny, nx + 20, ny + 16, 0); display_draw_logo(nx, ny, 0); + display_led_write(1, 0); + display_led_toggle(0); } } if (p[2]) { @@ -65,6 +56,8 @@ static int system_cmdproc(char *p) nx++; display_draw_box(nx + 20, ny, nx + 20, ny + 16, 0); display_draw_logo(nx, ny, 0); + display_led_write(0, 0); + display_led_toggle(1); } } if (p[3]) { puts("S"); } @@ -86,78 +79,8 @@ static int system_cmdproc(char *p) return 0; } -static int play(const char *filename) -{ - FRESULT r = pf_open(filename); - if (r != FR_OK) { - return 1; - } - int cnt = 0; - while (audio_play(readfunc)) { - if (((cnt++) % 32) == 0) { - display_draw_progressbar( - 5, 20, 121 - 5, 25, - 0, 100, fatfs.fptr * 100 / fatfs.fsize); - } - { - int size; - char *p; - kz_recv(MSGBOX_ID_SYSTEM, &size, &p); - system_cmdproc(p); - } - } - display_draw_progressbar( - 5, 20, 121 - 5, 25, - 0, 100, fatfs.fptr * 100 / fatfs.fsize); - 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_system(int argc, char *argv[]) { -#if 0 - display_clear(); - display_draw_logo( 0, 0, 2); - display_draw_box(0, 0, 121, 31, 1); - display_draw_text(40, 4, "KOZOS EXPBRD #00"); - - 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; - } - } - } - } - } - } -#else display_clear(); display_draw_logo( 0, 0, 2); display_draw_box(0, 0, 121, 31, 1); @@ -170,7 +93,6 @@ int task_system(int argc, char *argv[]) kz_recv(MSGBOX_ID_SYSTEM, &size, &p); system_cmdproc(p); } -#endif return 0; } -- 2.11.0