Skip to content

Commit

Permalink
noteram:support binary read mode
Browse files Browse the repository at this point in the history
Signed-off-by: zhangwenjian <[email protected]>
  • Loading branch information
zhangwenjian111 authored and Gary-Hobson committed Oct 11, 2024
1 parent 343c442 commit 88999b5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 16 deletions.
80 changes: 64 additions & 16 deletions drivers/note/noteram_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/****************************************************************************
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions include/nuttx/note/noteram_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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

/****************************************************************************
Expand Down

0 comments on commit 88999b5

Please sign in to comment.