From 600505e598134cf8c8c7156e32586f3e76deb2c2 Mon Sep 17 00:00:00 2001 From: maxpaperno Date: Sun, 7 Feb 2016 21:02:29 -0500 Subject: [PATCH] Increase COMM notice stack depth; Formalize filer return statuses. --- src/buildnum.h | 2 +- src/comm.h | 2 +- src/filer.c | 40 ++++++++++++++++++++++------------------ src/filer.h | 13 +++++++++++++ 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/buildnum.h b/src/buildnum.h index e68922d6..532b3d51 100644 --- a/src/buildnum.h +++ b/src/buildnum.h @@ -1 +1 @@ -#define BUILDNUMBER 1883 +#define BUILDNUMBER 1884 diff --git a/src/comm.h b/src/comm.h index 157d6250..ceddba85 100644 --- a/src/comm.h +++ b/src/comm.h @@ -24,7 +24,7 @@ #define COMM_STACK_SIZE 336 // must be evenly divisible by 8 #define COMM_PRIORITY 40 -#define COMM_NOTICE_DEPTH 24 // must be power of 2 +#define COMM_NOTICE_DEPTH 36 // must be power of 2 #define COMM_NOTICE_LENGTH 64 #define COMM_LOG_BUF_SIZE 512 diff --git a/src/filer.c b/src/filer.c index 6298ed4f..5092bdea 100644 --- a/src/filer.c +++ b/src/filer.c @@ -40,7 +40,7 @@ static int32_t filerProcessWrite(filerFileStruct_t *f) { if (!f->open) { res = f_open(&f->fp, f->fileName, FA_CREATE_ALWAYS | FA_WRITE); if (res != FR_OK) - return -1; + return FILER_STATUS_ERR_OPEN; f->open = 1; } @@ -49,14 +49,14 @@ static int32_t filerProcessWrite(filerFileStruct_t *f) { res = f_lseek(&f->fp, f->seek); if (res != FR_OK) { f->open = 0; - return -1; + return FILER_STATUS_ERR_SEEK; } } res = f_write(&f->fp, f->buf, f->length, &bytes); if (res != FR_OK) { f->open = 0; - return -1; + return FILER_STATUS_ERR_WRITE; } return bytes; @@ -68,8 +68,12 @@ static int32_t filerProcessRead(filerFileStruct_t *f) { if (!f->open) { res = f_open(&f->fp, f->fileName, FA_OPEN_EXISTING | FA_READ); - if (res != FR_OK) - return -1; + if (res != FR_OK) { + if (res == FR_NO_FILE || res == FR_NO_PATH) + return FILER_STATUS_ERR_FNF; + else + return FILER_STATUS_ERR_OPEN; + } f->open = 1; } @@ -78,14 +82,14 @@ static int32_t filerProcessRead(filerFileStruct_t *f) { res = f_lseek(&f->fp, f->seek); if (res != FR_OK) { f->open = 0; - return -1; + return FILER_STATUS_ERR_SEEK; } } res = f_read(&f->fp, f->buf, f->length, &bytes); if (res != FR_OK) { f->open = 0; - return -1; + return FILER_STATUS_ERR_READ; } return bytes; @@ -95,13 +99,13 @@ static int32_t filerProcessSync(filerFileStruct_t *f) { uint32_t res; if (!f->open) { - return -1; + return FILER_STATUS_ERR_OPEN; } res = f_sync(&f->fp); if (res != FR_OK) { f->open = 0; - return -1; + return FILER_STATUS_ERR_SYNC; } return 0; @@ -116,7 +120,7 @@ static int32_t filerProcessStream(filerFileStruct_t *f, uint8_t final) { sprintf(filerData.buf, "%03d-%s.LOG", filerData.session, f->fileName); res = f_open(&f->fp, filerData.buf, FA_CREATE_ALWAYS | FA_WRITE); if (res != FR_OK) - return -1; + return FILER_STATUS_ERR_OPEN; f->open = 1; } @@ -132,7 +136,7 @@ static int32_t filerProcessStream(filerFileStruct_t *f, uint8_t final) { f->tail = (f->tail + bytes) % f->length; if (res != FR_OK) - return -1; + return FILER_STATUS_ERR_WRITE; } return bytes; @@ -147,9 +151,9 @@ static int32_t filerProcessClose(filerFileStruct_t *f) { } if (res != FR_OK) - return -1; + return FILER_STATUS_ERR_CLOSE; else - return 0; + return FILER_STATUS_OK; } static void filerProcessRequest(filerFileStruct_t *f) { @@ -369,13 +373,13 @@ int8_t filerGetHandle(char *fileName) { } // too many files open - return -1; + return FILER_STATUS_ERR_ALLOC; } int32_t filerReadWrite(filerFileStruct_t *f, void *buf, int32_t seek, uint32_t length, uint8_t function) { // handle allocated yet? if (!f->allocated || !filerData.initialized) - return -1; + return FILER_STATUS_ERR_INIT; f->buf = buf; f->function = function; @@ -404,7 +408,7 @@ int32_t filerSync(int8_t handle) { // handle allocated yet? if (!f->allocated) - return -1; + return FILER_STATUS_ERR_INIT; if (f->open) { f->function = FILER_FUNC_SYNC; @@ -422,7 +426,7 @@ int32_t filerClose(int8_t handle) { // handle allocated yet? if (!f->allocated) - return -1; + return FILER_STATUS_ERR_INIT; if (f->open) { f->function = FILER_FUNC_CLOSE; @@ -450,7 +454,7 @@ int32_t filerStream(int8_t handle, void *buf, uint32_t length) { // handle allocated yet? if (!f->allocated) - return -1; + return FILER_STATUS_ERR_INIT; f->function = FILER_FUNC_STREAM; f->buf = buf; diff --git a/src/filer.h b/src/filer.h index a88057eb..06a2f9b1 100644 --- a/src/filer.h +++ b/src/filer.h @@ -45,6 +45,19 @@ enum { FILER_STATE_MSC_ACTIVE }; +enum fileReturnStatus { + FILER_STATUS_ERR_CLOSE = -9, // error while closing an opened file + FILER_STATUS_ERR_SYNC = -8, // synch error on opened file + FILER_STATUS_ERR_WRITE = -7, // error writing to opened file + FILER_STATUS_ERR_READ = -6, // error reading from opened file + FILER_STATUS_ERR_SEEK = -5, // seek error on opened file + FILER_STATUS_ERR_OPEN = -4, // no file/could not open + FILER_STATUS_ERR_FNF = -3, // file/path not found + FILER_STATUS_ERR_ALLOC = -2, // could not allocate file handle, too many files open + FILER_STATUS_ERR_INIT = -1, // file system not initialized or resource not allocated + FILER_STATUS_OK = 0, // anything this or greater is OK (FR_OK equivalent) +}; + #define filerEnableMSC() {if (filerData.mscState == FILER_STATE_MSC_DISABLE) filerData.mscState = FILER_STATE_MSC_REQUEST;} #define filerEjectMSC() {filerData.mscState = FILER_STATE_MSC_EJECT;} #define filerGetMSCState() (filerData.mscState)