diff --git a/drivers/note/noteram_driver.c b/drivers/note/noteram_driver.c index 98fdb5b3353df..f084d45faf038 100644 --- a/drivers/note/noteram_driver.c +++ b/drivers/note/noteram_driver.c @@ -101,6 +101,7 @@ struct noteram_dump_cpu_context_s struct noteram_dump_context_s { struct noteram_dump_cpu_context_s cpu[NCPUS]; + unsigned int mode; }; /**************************************************************************** @@ -450,30 +451,39 @@ static ssize_t noteram_read(FAR struct file *filep, FAR char *buffer, FAR struct noteram_driver_s *drv = filep->f_inode->i_private; FAR struct lib_memoutstream_s stream; ssize_t ret; + irqstate_t flags; - lib_memoutstream(&stream, buffer, buflen); - - do + if (ctx->mode == NOTERAM_MODE_READ_BINARY) { - irqstate_t flags; - uint8_t note[256]; - - /* Get the next note (removing it from the buffer) */ - flags = spin_lock_irqsave_wo_note(&drv->lock); - ret = noteram_get(drv, note, sizeof(note)); + ret = noteram_get(drv, (FAR uint8_t *)buffer, buflen); spin_unlock_irqrestore_wo_note(&drv->lock, flags); - if (ret <= 0) + } + else + { + lib_memoutstream(&stream, buffer, buflen); + + do { - return ret; - } + uint8_t note[256]; - /* Parse notes into text format */ + /* Get the next note (removing it from the buffer) */ - ret = noteram_dump_one(note, (FAR struct lib_outstream_s *)&stream, - ctx); + flags = spin_lock_irqsave_wo_note(&drv->lock); + ret = noteram_get(drv, note, sizeof(note)); + spin_unlock_irqrestore_wo_note(&drv->lock, flags); + if (ret <= 0) + { + return ret; + } + + /* Parse notes into text format */ + + ret = noteram_dump_one(note, (FAR struct lib_outstream_s *)&stream, + ctx); + } + while (ret == 0); } - while (ret == 0); return ret; } @@ -536,6 +546,44 @@ static int noteram_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } break; + /* NOTERAM_GETREADMODE + * - Get read mode + * Argument: A writable pointer to unsigned int + */ + + case NOTERAM_GETREADMODE: + if (arg == 0) + { + ret = -EINVAL; + } + else + { + FAR struct noteram_dump_context_s *ctx = filep->f_priv; + + *(FAR unsigned int *)arg = ctx->mode; + ret = OK; + } + break; + + /* NOTERAM_SETREADMODE + * - Set read mode + * Argument: A read-only pointer to unsigned int + */ + + case NOTERAM_SETREADMODE: + if (arg == 0) + { + ret = -EINVAL; + } + else + { + FAR struct noteram_dump_context_s *ctx = filep->f_priv; + + ctx->mode = *(FAR unsigned int *)arg; + ret = OK; + } + break; + default: break; } diff --git a/include/nuttx/note/noteram_driver.h b/include/nuttx/note/noteram_driver.h index 1aae20d016104..fe85e984c8f26 100644 --- a/include/nuttx/note/noteram_driver.h +++ b/include/nuttx/note/noteram_driver.h @@ -48,12 +48,20 @@ * NOTERAM_SETMODE * - Set overwrite mode * Argument: A read-only pointer to unsigned int + * NOTERAM_GETREADMODE + * - Get read mode + * Argument: A writable pointer to unsigned int + * NOTERAM_SETREADMODE + * - Set read mode + * Argument: A read-only pointer to unsigned int */ #ifdef CONFIG_DRIVERS_NOTERAM #define NOTERAM_CLEAR _NOTERAMIOC(0x01) #define NOTERAM_GETMODE _NOTERAMIOC(0x02) #define NOTERAM_SETMODE _NOTERAMIOC(0x03) +#define NOTERAM_GETREADMODE _NOTERAMIOC(0x04) +#define NOTERAM_SETREADMODE _NOTERAMIOC(0x05) #endif /* Overwrite mode definitions */ @@ -62,6 +70,9 @@ #define NOTERAM_MODE_OVERWRITE_DISABLE 0 #define NOTERAM_MODE_OVERWRITE_ENABLE 1 #define NOTERAM_MODE_OVERWRITE_OVERFLOW 2 + +#define NOTERAM_MODE_READ_ASCII 0 +#define NOTERAM_MODE_READ_BINARY 1 #endif /****************************************************************************