From 6b1c52b304002677697a3f83d20448452c2061cd Mon Sep 17 00:00:00 2001 From: Shinichiro Nakamura Date: Tue, 17 Jul 2012 05:09:35 +0900 Subject: [PATCH] Separated the file I/O control. --- firm/sample/sample1/os/Makefile | 7 ++-- firm/sample/sample1/os/kozos.h | 1 + firm/sample/sample1/os/main.c | 2 + firm/sample/sample1/os/task.h | 5 ++- firm/sample/sample1/os/task_fileio.c | 75 ++++++++++++++++++++++++++++++++++++ firm/sample/sample1/os/task_fileio.h | 7 ++++ firm/sample/sample1/os/task_input.c | 56 +-------------------------- 7 files changed, 93 insertions(+), 60 deletions(-) create mode 100644 firm/sample/sample1/os/task_fileio.c create mode 100644 firm/sample/sample1/os/task_fileio.h diff --git a/firm/sample/sample1/os/Makefile b/firm/sample/sample1/os/Makefile index f90a69c..b56b22f 100644 --- a/firm/sample/sample1/os/Makefile +++ b/firm/sample/sample1/os/Makefile @@ -28,11 +28,12 @@ OBJS += vs1011e.o OBJS += spi.o spreg.o # Tasks -OBJS += task_input.o -OBJS += task_command.o -OBJS += task_display.o OBJS += task_audio.o +OBJS += task_display.o +OBJS += task_fileio.o OBJS += task_system.o +OBJS += task_input.o +OBJS += task_command.o # Kernel OBJS += kozos.o syscall.o memory.o diff --git a/firm/sample/sample1/os/kozos.h b/firm/sample/sample1/os/kozos.h index 90ac31d..25c7270 100644 --- a/firm/sample/sample1/os/kozos.h +++ b/firm/sample/sample1/os/kozos.h @@ -41,6 +41,7 @@ void kz_srvcall(kz_syscall_type_t type, kz_syscall_param_t *param); extern kz_thread_id_t tskid_audio; extern kz_thread_id_t tskid_display; +extern kz_thread_id_t tskid_fileio; extern kz_thread_id_t tskid_system; extern kz_thread_id_t tskid_input; extern kz_thread_id_t tskid_command; diff --git a/firm/sample/sample1/os/main.c b/firm/sample/sample1/os/main.c index dbc3b3d..470a05e 100644 --- a/firm/sample/sample1/os/main.c +++ b/firm/sample/sample1/os/main.c @@ -5,6 +5,7 @@ kz_thread_id_t tskid_audio; kz_thread_id_t tskid_display; +kz_thread_id_t tskid_fileio; kz_thread_id_t tskid_system; kz_thread_id_t tskid_input; kz_thread_id_t tskid_command; @@ -26,6 +27,7 @@ static int start_threads(int argc, char *argv[]) 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); + tskid_fileio = kz_run(task_fileio, "tFileIO", 8, 0x800, 0, NULL); kz_chpri(15); /* Í¥Àè½ç°Ì¤ò²¼¤²¤Æ¡¤¥¢¥¤¥É¥ë¥¹¥ì¥Ã¥É¤Ë°Ü¹Ô¤¹¤ë */ INTR_ENABLE; /* ³ä¹þ¤ßÍ­¸ú¤Ë¤¹¤ë */ diff --git a/firm/sample/sample1/os/task.h b/firm/sample/sample1/os/task.h index c77f0d0..ddbaff2 100644 --- a/firm/sample/sample1/os/task.h +++ b/firm/sample/sample1/os/task.h @@ -1,10 +1,11 @@ #ifndef TASK_H #define TASK_H -#include "task_input.h" -#include "task_command.h" #include "task_audio.h" #include "task_display.h" +#include "task_fileio.h" #include "task_system.h" +#include "task_input.h" +#include "task_command.h" #endif diff --git a/firm/sample/sample1/os/task_fileio.c b/firm/sample/sample1/os/task_fileio.c new file mode 100644 index 0000000..aab4a16 --- /dev/null +++ b/firm/sample/sample1/os/task_fileio.c @@ -0,0 +1,75 @@ +#include "defines.h" +#include "kozos.h" +#include "lib.h" +#include "intr.h" +#include "portconf.h" +#include "pff.h" + +#define VS1011E_CHK_DREQ() (((*PORTCONF_P4DR) & PORTCONF_P4BIT_VSDREQ) ? 0 : 1) + +static FATFS fatfs; +static DIR dir; +static FILINFO filinfo; + +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)) { + while (VS1011E_CHK_DREQ()) { + kz_wait(); + } + } + 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_fileio(int argc, char *argv[]) +{ + 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; + } + } + } + } + } + } + + return 0; +} + diff --git a/firm/sample/sample1/os/task_fileio.h b/firm/sample/sample1/os/task_fileio.h new file mode 100644 index 0000000..96c4ee8 --- /dev/null +++ b/firm/sample/sample1/os/task_fileio.h @@ -0,0 +1,7 @@ + +#ifndef TASK_FILEIO_H +#define TASK_FILEIO_H + +int task_fileio(int argc, char *argv[]); + +#endif diff --git a/firm/sample/sample1/os/task_input.c b/firm/sample/sample1/os/task_input.c index bdbfdf0..45b8fc9 100644 --- a/firm/sample/sample1/os/task_input.c +++ b/firm/sample/sample1/os/task_input.c @@ -6,7 +6,6 @@ #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) @@ -72,9 +71,6 @@ 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) { @@ -141,39 +137,6 @@ 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[]) { /* @@ -195,24 +158,7 @@ int task_input(int argc, char *argv[]) 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; - } - } - } - } - } + kz_sleep(); } return 0; -- 2.11.0