Skip to content

Commit 600505e

Browse files
committed
Increase COMM notice stack depth;
Formalize filer return statuses.
1 parent 60344fa commit 600505e

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

src/buildnum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define BUILDNUMBER 1883
1+
#define BUILDNUMBER 1884

src/comm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#define COMM_STACK_SIZE 336 // must be evenly divisible by 8
2626
#define COMM_PRIORITY 40
27-
#define COMM_NOTICE_DEPTH 24 // must be power of 2
27+
#define COMM_NOTICE_DEPTH 36 // must be power of 2
2828
#define COMM_NOTICE_LENGTH 64
2929

3030
#define COMM_LOG_BUF_SIZE 512

src/filer.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int32_t filerProcessWrite(filerFileStruct_t *f) {
4040
if (!f->open) {
4141
res = f_open(&f->fp, f->fileName, FA_CREATE_ALWAYS | FA_WRITE);
4242
if (res != FR_OK)
43-
return -1;
43+
return FILER_STATUS_ERR_OPEN;
4444

4545
f->open = 1;
4646
}
@@ -49,14 +49,14 @@ static int32_t filerProcessWrite(filerFileStruct_t *f) {
4949
res = f_lseek(&f->fp, f->seek);
5050
if (res != FR_OK) {
5151
f->open = 0;
52-
return -1;
52+
return FILER_STATUS_ERR_SEEK;
5353
}
5454
}
5555

5656
res = f_write(&f->fp, f->buf, f->length, &bytes);
5757
if (res != FR_OK) {
5858
f->open = 0;
59-
return -1;
59+
return FILER_STATUS_ERR_WRITE;
6060
}
6161

6262
return bytes;
@@ -68,8 +68,12 @@ static int32_t filerProcessRead(filerFileStruct_t *f) {
6868

6969
if (!f->open) {
7070
res = f_open(&f->fp, f->fileName, FA_OPEN_EXISTING | FA_READ);
71-
if (res != FR_OK)
72-
return -1;
71+
if (res != FR_OK) {
72+
if (res == FR_NO_FILE || res == FR_NO_PATH)
73+
return FILER_STATUS_ERR_FNF;
74+
else
75+
return FILER_STATUS_ERR_OPEN;
76+
}
7377

7478
f->open = 1;
7579
}
@@ -78,14 +82,14 @@ static int32_t filerProcessRead(filerFileStruct_t *f) {
7882
res = f_lseek(&f->fp, f->seek);
7983
if (res != FR_OK) {
8084
f->open = 0;
81-
return -1;
85+
return FILER_STATUS_ERR_SEEK;
8286
}
8387
}
8488

8589
res = f_read(&f->fp, f->buf, f->length, &bytes);
8690
if (res != FR_OK) {
8791
f->open = 0;
88-
return -1;
92+
return FILER_STATUS_ERR_READ;
8993
}
9094

9195
return bytes;
@@ -95,13 +99,13 @@ static int32_t filerProcessSync(filerFileStruct_t *f) {
9599
uint32_t res;
96100

97101
if (!f->open) {
98-
return -1;
102+
return FILER_STATUS_ERR_OPEN;
99103
}
100104

101105
res = f_sync(&f->fp);
102106
if (res != FR_OK) {
103107
f->open = 0;
104-
return -1;
108+
return FILER_STATUS_ERR_SYNC;
105109
}
106110

107111
return 0;
@@ -116,7 +120,7 @@ static int32_t filerProcessStream(filerFileStruct_t *f, uint8_t final) {
116120
sprintf(filerData.buf, "%03d-%s.LOG", filerData.session, f->fileName);
117121
res = f_open(&f->fp, filerData.buf, FA_CREATE_ALWAYS | FA_WRITE);
118122
if (res != FR_OK)
119-
return -1;
123+
return FILER_STATUS_ERR_OPEN;
120124

121125
f->open = 1;
122126
}
@@ -132,7 +136,7 @@ static int32_t filerProcessStream(filerFileStruct_t *f, uint8_t final) {
132136
f->tail = (f->tail + bytes) % f->length;
133137

134138
if (res != FR_OK)
135-
return -1;
139+
return FILER_STATUS_ERR_WRITE;
136140
}
137141

138142
return bytes;
@@ -147,9 +151,9 @@ static int32_t filerProcessClose(filerFileStruct_t *f) {
147151
}
148152

149153
if (res != FR_OK)
150-
return -1;
154+
return FILER_STATUS_ERR_CLOSE;
151155
else
152-
return 0;
156+
return FILER_STATUS_OK;
153157
}
154158

155159
static void filerProcessRequest(filerFileStruct_t *f) {
@@ -369,13 +373,13 @@ int8_t filerGetHandle(char *fileName) {
369373
}
370374

371375
// too many files open
372-
return -1;
376+
return FILER_STATUS_ERR_ALLOC;
373377
}
374378

375379
int32_t filerReadWrite(filerFileStruct_t *f, void *buf, int32_t seek, uint32_t length, uint8_t function) {
376380
// handle allocated yet?
377381
if (!f->allocated || !filerData.initialized)
378-
return -1;
382+
return FILER_STATUS_ERR_INIT;
379383

380384
f->buf = buf;
381385
f->function = function;
@@ -404,7 +408,7 @@ int32_t filerSync(int8_t handle) {
404408

405409
// handle allocated yet?
406410
if (!f->allocated)
407-
return -1;
411+
return FILER_STATUS_ERR_INIT;
408412

409413
if (f->open) {
410414
f->function = FILER_FUNC_SYNC;
@@ -422,7 +426,7 @@ int32_t filerClose(int8_t handle) {
422426

423427
// handle allocated yet?
424428
if (!f->allocated)
425-
return -1;
429+
return FILER_STATUS_ERR_INIT;
426430

427431
if (f->open) {
428432
f->function = FILER_FUNC_CLOSE;
@@ -450,7 +454,7 @@ int32_t filerStream(int8_t handle, void *buf, uint32_t length) {
450454

451455
// handle allocated yet?
452456
if (!f->allocated)
453-
return -1;
457+
return FILER_STATUS_ERR_INIT;
454458

455459
f->function = FILER_FUNC_STREAM;
456460
f->buf = buf;

src/filer.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ enum {
4545
FILER_STATE_MSC_ACTIVE
4646
};
4747

48+
enum fileReturnStatus {
49+
FILER_STATUS_ERR_CLOSE = -9, // error while closing an opened file
50+
FILER_STATUS_ERR_SYNC = -8, // synch error on opened file
51+
FILER_STATUS_ERR_WRITE = -7, // error writing to opened file
52+
FILER_STATUS_ERR_READ = -6, // error reading from opened file
53+
FILER_STATUS_ERR_SEEK = -5, // seek error on opened file
54+
FILER_STATUS_ERR_OPEN = -4, // no file/could not open
55+
FILER_STATUS_ERR_FNF = -3, // file/path not found
56+
FILER_STATUS_ERR_ALLOC = -2, // could not allocate file handle, too many files open
57+
FILER_STATUS_ERR_INIT = -1, // file system not initialized or resource not allocated
58+
FILER_STATUS_OK = 0, // anything this or greater is OK (FR_OK equivalent)
59+
};
60+
4861
#define filerEnableMSC() {if (filerData.mscState == FILER_STATE_MSC_DISABLE) filerData.mscState = FILER_STATE_MSC_REQUEST;}
4962
#define filerEjectMSC() {filerData.mscState = FILER_STATE_MSC_EJECT;}
5063
#define filerGetMSCState() (filerData.mscState)

0 commit comments

Comments
 (0)