Skip to content

Commit

Permalink
Increase COMM notice stack depth;
Browse files Browse the repository at this point in the history
Formalize filer return statuses.
  • Loading branch information
mpaperno committed Feb 8, 2016
1 parent 60344fa commit 600505e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/buildnum.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILDNUMBER 1883
#define BUILDNUMBER 1884
2 changes: 1 addition & 1 deletion src/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 22 additions & 18 deletions src/filer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/filer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 600505e

Please sign in to comment.