forked from nuttx/nuttx-update
noteram:support binary read mode
Signed-off-by: zhangwenjian <zhangwenjian@xiaomi.com>
This commit is contained in:
parent
1fde78ddc6
commit
7a3c50b3db
2 changed files with 78 additions and 19 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -453,30 +454,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)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Parse notes into text format */
|
||||
|
||||
ret = noteram_dump_one(note, (FAR struct lib_outstream_s *)&stream,
|
||||
ctx);
|
||||
}
|
||||
while (ret == 0);
|
||||
else
|
||||
{
|
||||
lib_memoutstream(&stream, buffer, buflen);
|
||||
|
||||
do
|
||||
{
|
||||
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));
|
||||
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);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -539,6 +549,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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
/****************************************************************************
|
||||
|
|
Loading…
Reference in a new issue