nuttx/drivers/note/notectl_driver.c

218 lines
6.6 KiB
C

/****************************************************************************
* drivers/note/notectl_driver.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <errno.h>
#include <nuttx/fs/fs.h>
#include "note_driver.h"
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static int notectl_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
/****************************************************************************
* Private Data
****************************************************************************/
static const struct file_operations g_notectl_fops =
{
NULL, /* open */
NULL, /* close */
NULL, /* read */
NULL, /* write */
NULL, /* seek */
notectl_ioctl, /* ioctl */
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: notectl_ioctl
****************************************************************************/
static int notectl_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
int ret = -ENOSYS;
if (arg == 0)
{
return -EINVAL;
}
/* Handle the ioctl commands */
switch (cmd)
{
/* NOTE_GETFILTERMODE
* - Get note filter mode
* Argument: A writable pointer to struct note_filter_mode_s
*/
case NOTE_GETFILTER:
{
FAR struct note_filter_named_mode_s *mode =
(FAR struct note_filter_named_mode_s *)arg;
note_filter_mode(mode, NULL);
return OK;
}
/* NOTE_SETFILTERMODE
* - Set note filter mode
* Argument: A read-only pointer to struct note_filter_mode_s
*/
case NOTE_SETFILTER:
{
FAR struct note_filter_named_mode_s *mode =
(FAR struct note_filter_named_mode_s *)arg;
note_filter_mode(NULL, mode);
return OK;
}
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
/* NOTE_GETSYSCALLFILTER
* - Get syscall filter setting
* Argument: A writable pointer to struct note_filter_syscall_s
*/
case NOTE_GETSYSCALLFILTER:
{
FAR struct note_filter_named_syscall_s *filter;
filter = (FAR struct note_filter_named_syscall_s *)arg;
note_filter_syscall(filter, NULL);
return OK;
}
/* NOTE_SETSYSCALLFILTER
* - Set syscall filter setting
* Argument: A read-only pointer to struct note_filter_syscall_s
*/
case NOTE_SETSYSCALLFILTER:
{
FAR struct note_filter_named_syscall_s *filter;
filter = (FAR struct note_filter_named_syscall_s *)arg;
note_filter_syscall(NULL, filter);
return OK;
}
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
/* NOTE_GETIRQFILTER
* - Get IRQ filter setting
* Argument: A writable pointer to struct note_filter_irq_s
*/
case NOTE_GETIRQFILTER:
{
FAR struct note_filter_named_irq_s *filter;
filter = (FAR struct note_filter_named_irq_s *)arg;
note_filter_irq(filter, NULL);
return OK;
}
/* NOTE_SETIRQFILTER
* - Set IRQ filter setting
* Argument: A read-only pointer to struct
* note_filter_irq_s
*/
case NOTE_SETIRQFILTER:
{
FAR struct note_filter_named_irq_s *filter;
filter = (FAR struct note_filter_named_irq_s *)arg;
note_filter_irq(NULL, filter);
return OK;
}
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
/* NOTE_GETTAGFILTER
* - Get tag filter setting
* Argument: A writable pointer to struct note_filter_tag_s
*/
case NOTE_GETTAGFILTER:
{
FAR struct note_filter_named_tag_s *filter;
filter = (FAR struct note_filter_named_tag_s *)arg;
note_filter_tag(filter, NULL);
return OK;
}
/* NOTE_SETTAGFILTER
* - Set tag filter setting
* Argument: A read-only pointer to struct note_filter_tag_s
*/
case NOTE_SETTAGFILTER:
{
FAR struct note_filter_named_tag_s *filter;
filter = (FAR struct note_filter_named_tag_s *)arg;
note_filter_tag(NULL, filter);
return OK;
}
#endif
default:
break;
}
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: notectl_register
*
* Description:
* Register a driver at /dev/notectl that can be used by an application to
* control the note filter.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero on success. A negated errno value is returned on a failure.
*
****************************************************************************/
int notectl_register(void)
{
return register_driver("/dev/notectl", &g_notectl_fops, 0666, NULL);
}