summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/file.c16
-rw-r--r--firmware/export/mpeg.h5
-rw-r--r--firmware/mpeg.c39
3 files changed, 56 insertions, 4 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 46af790bf7..01279d4421 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -348,8 +348,13 @@ static int flush_cache(int fd)
348 348
349 rc = fat_readwrite(&(file->fatfile), 1, 349 rc = fat_readwrite(&(file->fatfile), 1,
350 file->cache, true ); 350 file->cache, true );
351 if ( rc < 0 ) 351
352 if ( rc < 0 ) {
353 if(file->fatfile.eof)
354 errno = ENOSPC;
355
352 return rc * 10 - 2; 356 return rc * 10 - 2;
357 }
353 358
354 file->dirty = false; 359 file->dirty = false;
355 360
@@ -418,14 +423,19 @@ static int readwrite(int fd, void* buf, int count, bool write)
418 return rc * 10 - 3; 423 return rc * 10 - 3;
419 } 424 }
420 425
421 /* read whole sectors right into the supplied buffer */ 426 /* read/write whole sectors right into/from the supplied buffer */
422 sectors = count / SECTOR_SIZE; 427 sectors = count / SECTOR_SIZE;
423 if ( sectors ) { 428 if ( sectors ) {
424 int rc = fat_readwrite(&(file->fatfile), sectors, buf+nread, write ); 429 int rc = fat_readwrite(&(file->fatfile), sectors, buf+nread, write );
425 if ( rc < 0 ) { 430 if ( rc < 0 ) {
426 DEBUGF("Failed read/writing %d sectors\n",sectors); 431 DEBUGF("Failed read/writing %d sectors\n",sectors);
427 errno = EIO; 432 errno = EIO;
428 file->fileoffset += nread; 433 if(write && file->fatfile.eof) {
434 DEBUGF("No space left on device\n");
435 errno = ENOSPC;
436 } else {
437 file->fileoffset += nread;
438 }
429 file->cacheoffset = -1; 439 file->cacheoffset = -1;
430 return nread ? nread : rc * 10 - 4; 440 return nread ? nread : rc * 10 - 4;
431 } 441 }
diff --git a/firmware/export/mpeg.h b/firmware/export/mpeg.h
index d939567f3d..dda93f811d 100644
--- a/firmware/export/mpeg.h
+++ b/firmware/export/mpeg.h
@@ -95,6 +95,8 @@ unsigned long mpeg_num_recorded_bytes(void);
95#endif 95#endif
96void mpeg_get_debugdata(struct mpeg_debug *dbgdata); 96void mpeg_get_debugdata(struct mpeg_debug *dbgdata);
97void mpeg_set_buffer_margin(int seconds); 97void mpeg_set_buffer_margin(int seconds);
98unsigned int mpeg_error(void);
99void mpeg_error_clear(void);
98 100
99#define SOUND_VOLUME 0 101#define SOUND_VOLUME 0
100#define SOUND_BASS 1 102#define SOUND_BASS 1
@@ -120,5 +122,8 @@ void mpeg_set_buffer_margin(int seconds);
120#define MPEG_STATUS_PLAY 1 122#define MPEG_STATUS_PLAY 1
121#define MPEG_STATUS_PAUSE 2 123#define MPEG_STATUS_PAUSE 2
122#define MPEG_STATUS_RECORD 4 124#define MPEG_STATUS_RECORD 4
125#define MPEG_STATUS_ERROR 8
126
127#define MPEGERR_DISK_FULL 1
123 128
124#endif 129#endif
diff --git a/firmware/mpeg.c b/firmware/mpeg.c
index 6872ee171b..11f7e60f16 100644
--- a/firmware/mpeg.c
+++ b/firmware/mpeg.c
@@ -26,6 +26,7 @@
26#include "string.h" 26#include "string.h"
27#include <kernel.h> 27#include <kernel.h>
28#include "thread.h" 28#include "thread.h"
29#include "errno.h"
29#include "mp3data.h" 30#include "mp3data.h"
30#include "buffer.h" 31#include "buffer.h"
31#ifndef SIMULATOR 32#ifndef SIMULATOR
@@ -356,6 +357,8 @@ static void set_elapsed(struct mp3entry* id3)
356 357
357static bool paused; /* playback is paused */ 358static bool paused; /* playback is paused */
358 359
360static unsigned int mpeg_errno;
361
359#ifdef SIMULATOR 362#ifdef SIMULATOR
360static bool is_playing = false; 363static bool is_playing = false;
361static bool playing = false; 364static bool playing = false;
@@ -1952,7 +1955,20 @@ static void mpeg_thread(void)
1952 writelen); 1955 writelen);
1953 1956
1954 if(rc < 0) 1957 if(rc < 0)
1955 panicf("rec wrt: %d", rc); 1958 {
1959 if(errno == ENOSPC)
1960 {
1961 mpeg_errno = MPEGERR_DISK_FULL;
1962 demand_irq_enable(false);
1963 stop_recording();
1964 queue_post(&mpeg_queue, MPEG_STOP_DONE, 0);
1965 break;
1966 }
1967 else
1968 {
1969 panicf("rec wrt: %d", rc);
1970 }
1971 }
1956 1972
1957 rc = flush(mpeg_file); 1973 rc = flush(mpeg_file);
1958 if(rc < 0) 1974 if(rc < 0)
@@ -2224,6 +2240,8 @@ static void init_playback(void)
2224 2240
2225void mpeg_record(char *filename) 2241void mpeg_record(char *filename)
2226{ 2242{
2243 mpeg_errno = 0;
2244
2227 strncpy(recording_filename, filename, MAX_PATH - 1); 2245 strncpy(recording_filename, filename, MAX_PATH - 1);
2228 recording_filename[MAX_PATH - 1] = 0; 2246 recording_filename[MAX_PATH - 1] = 0;
2229 2247
@@ -2330,6 +2348,8 @@ void mpeg_play(int offset)
2330 2348
2331 queue_post(&mpeg_queue, MPEG_PLAY, (void*)offset); 2349 queue_post(&mpeg_queue, MPEG_PLAY, (void*)offset);
2332#endif 2350#endif
2351
2352 mpeg_errno = 0;
2333} 2353}
2334 2354
2335void mpeg_stop(void) 2355void mpeg_stop(void)
@@ -2343,6 +2363,7 @@ void mpeg_stop(void)
2343 is_playing = false; 2363 is_playing = false;
2344 playing = false; 2364 playing = false;
2345#endif 2365#endif
2366
2346} 2367}
2347 2368
2348void mpeg_pause(void) 2369void mpeg_pause(void)
@@ -2452,9 +2473,23 @@ int mpeg_status(void)
2452 if(is_recording) 2473 if(is_recording)
2453 ret |= MPEG_STATUS_RECORD; 2474 ret |= MPEG_STATUS_RECORD;
2454#endif 2475#endif
2476
2477 if(mpeg_errno)
2478 ret |= MPEG_STATUS_ERROR;
2479
2455 return ret; 2480 return ret;
2456} 2481}
2457 2482
2483unsigned int mpeg_error(void)
2484{
2485 return mpeg_errno;
2486}
2487
2488void mpeg_error_clear(void)
2489{
2490 mpeg_errno = 0;
2491}
2492
2458#ifndef SIMULATOR 2493#ifndef SIMULATOR
2459#ifdef HAVE_MAS3507D 2494#ifdef HAVE_MAS3507D
2460int current_left_volume = 0; /* all values in tenth of dB */ 2495int current_left_volume = 0; /* all values in tenth of dB */
@@ -2919,6 +2954,8 @@ static void mpeg_thread(void)
2919void mpeg_init(int volume, int bass, int treble, int balance, int loudness, 2954void mpeg_init(int volume, int bass, int treble, int balance, int loudness,
2920 int bass_boost, int avc, int channel_config) 2955 int bass_boost, int avc, int channel_config)
2921{ 2956{
2957 mpeg_errno = 0;
2958
2922#ifdef SIMULATOR 2959#ifdef SIMULATOR
2923 volume = bass = treble = balance = loudness 2960 volume = bass = treble = balance = loudness
2924 = bass_boost = avc = channel_config; 2961 = bass_boost = avc = channel_config;