Skip to content

Commit cad59dd

Browse files
committed
Implement FIFO_FLAG_INIT, cherry pick to 4.0
1 parent ab43881 commit cad59dd

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

include/device/fifo.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,15 @@ typedef union {
1616
u32 atomic_access; // read head and tail in one operation
1717
} fifo_atomic_position_t;
1818

19-
typedef struct MCU_PACK {
19+
typedef struct {
2020
volatile fifo_atomic_position_t atomic_position; // 4 bytes
2121
devfs_transfer_handler_t transfer_handler; // 8 bytes
2222
volatile u32 o_flags; // 4 bytes
2323
} fifo_state_t;
2424

25-
/*! \brief FIFO Configuration
26-
* \details This structure defines the static FIFO configuration.
27-
*
28-
*/
2925
typedef struct MCU_PACK {
30-
u32 size /*! \brief The size of the buffer (only size-1 is usable) */;
31-
char *buffer /*! \brief A pointer to the buffer */;
26+
u32 size;
27+
char *buffer;
3228
} fifo_config_t;
3329

3430
int fifo_open(const devfs_handle_t *handle) MCU_ROOT_EXEC_CODE;

src/device/fifo.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2011-2021 Tyler Gilbert and Stratify Labs, Inc; see LICENSE.md
22

3-
43
#include <errno.h>
54
#include <fcntl.h>
65
#include <stddef.h>
@@ -247,9 +246,17 @@ int fifo_close(const devfs_handle_t *handle) {
247246
return fifo_close_local(config, state);
248247
}
249248

250-
int fifo_open_local(const fifo_config_t *config, fifo_state_t *state) { return 0; }
249+
int fifo_open_local(const fifo_config_t *config, fifo_state_t *state) {
250+
MCU_UNUSED_ARGUMENT(config);
251+
MCU_UNUSED_ARGUMENT(state);
252+
return 0;
253+
}
251254

252-
int fifo_close_local(const fifo_config_t *config, fifo_state_t *state) { return 0; }
255+
int fifo_close_local(const fifo_config_t *config, fifo_state_t *state) {
256+
MCU_UNUSED_ARGUMENT(config);
257+
MCU_UNUSED_ARGUMENT(state);
258+
return 0;
259+
}
253260

254261
int fifo_ioctl_local(
255262
const fifo_config_t *config,
@@ -288,6 +295,14 @@ int fifo_ioctl_local(
288295
fifo_data_transmitted(config, state); // something might be waiting to write the fifo
289296
return 0;
290297
case I_FIFO_SETATTR:
298+
299+
if( attr->o_flags & FIFO_FLAG_INIT ){
300+
state->transfer_handler.read = NULL;
301+
state->transfer_handler.write = NULL;
302+
fifo_flush(state);
303+
fifo_data_transmitted(config, state); // something might be waiting to write the fifo
304+
}
305+
291306
if (attr->o_flags & FIFO_FLAG_SET_WRITEBLOCK) {
292307
if (attr->o_flags & FIFO_FLAG_IS_OVERFLOW) {
293308
fifo_set_writeblock(state, 0);
@@ -301,6 +316,7 @@ int fifo_ioctl_local(
301316
fifo_data_transmitted(config, state); // something might be waiting to write the
302317
// fifo
303318
}
319+
304320
return 0;
305321
}
306322
return SYSFS_SET_RETURN(EINVAL);

0 commit comments

Comments
 (0)