mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 10:58:49 +08:00
Replace callse to ioctl() in the OS to file_ioctl()
This commit is contained in:
parent
5a0c6547d9
commit
a83b6d990b
6 changed files with 71 additions and 73 deletions
|
@ -91,7 +91,7 @@ static struct binfmt_s g_builtin_binfmt =
|
||||||
static int builtin_loadbinary(struct binary_s *binp)
|
static int builtin_loadbinary(struct binary_s *binp)
|
||||||
{
|
{
|
||||||
FAR const char *filename;
|
FAR const char *filename;
|
||||||
FAR const struct builtin_s *b;
|
FAR const struct builtin_s *builtin;
|
||||||
int fd;
|
int fd;
|
||||||
int index;
|
int index;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -138,10 +138,10 @@ static int builtin_loadbinary(struct binary_s *binp)
|
||||||
* the priority. That is a bug and needs to be fixed.
|
* the priority. That is a bug and needs to be fixed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
b = builtin_for_index(index);
|
builtin = builtin_for_index(index);
|
||||||
binp->entrypt = b->main;
|
binp->entrypt = builtin->main;
|
||||||
binp->stacksize = b->stacksize;
|
binp->stacksize = builtin->stacksize;
|
||||||
binp->priority = b->priority;
|
binp->priority = builtin->priority;
|
||||||
close(fd);
|
close(fd);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* configs/nucleo-144/src/stm32_bbsram.c
|
* configs/nucleo-144/src/stm32_bbsram.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2016m, 2018 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2016, 2018 Gregory Nutt. All rights reserved.
|
||||||
* Author: David Sidrane <david_s5@nscdg.com>
|
* Author: David Sidrane <david_s5@nscdg.com>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -291,29 +291,25 @@ static uint8_t g_sdata[STM32F7_BBSRAM_SIZE];
|
||||||
|
|
||||||
static int hardfault_get_desc(struct bbsramd_s *desc)
|
static int hardfault_get_desc(struct bbsramd_s *desc)
|
||||||
{
|
{
|
||||||
int ret = -ENOENT;
|
FAR struct file filestruct;
|
||||||
int fd = nx_open(HARDFAULT_PATH, O_RDONLY);
|
int ret;
|
||||||
int rv;
|
|
||||||
|
|
||||||
if (fd < 0)
|
ret = file_open(&filestruct, HARDFAULT_PATH, O_RDONLY);
|
||||||
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_INFO, "stm32 bbsram: Failed to open Fault Log file [%s] "
|
syslog(LOG_INFO, "stm32 bbsram: Failed to open Fault Log file [%s] "
|
||||||
"(%d)\n", HARDFAULT_PATH, fd);
|
"(%d)\n", HARDFAULT_PATH, ret);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = -EIO;
|
ret = file_ioctl(&filestruct, STM32F7_BBSRAM_GETDESC_IOCTL,
|
||||||
rv = ioctl(fd, STM32F7_BBSRAM_GETDESC_IOCTL,
|
(unsigned long)((uintptr_t)desc));
|
||||||
(unsigned long)((uintptr_t)desc));
|
(void)file_close_detached(&filestruct);
|
||||||
|
|
||||||
if (rv >= 0)
|
if (ret < 0)
|
||||||
{
|
|
||||||
ret = fd;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
syslog(LOG_INFO, "stm32 bbsram: Failed to get Fault Log descriptor "
|
syslog(LOG_INFO, "stm32 bbsram: Failed to get Fault Log descriptor "
|
||||||
"(%d)\n", rv);
|
"(%d)\n", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +348,6 @@ int stm32_bbsram_int(void)
|
||||||
struct tm tt;
|
struct tm tt;
|
||||||
time_t time_sec;
|
time_t time_sec;
|
||||||
|
|
||||||
|
|
||||||
/* Using Battery Backed Up SRAM */
|
/* Using Battery Backed Up SRAM */
|
||||||
|
|
||||||
stm32_bbsraminitialize(BBSRAM_PATH, filesizes);
|
stm32_bbsraminitialize(BBSRAM_PATH, filesizes);
|
||||||
|
@ -380,7 +375,6 @@ int stm32_bbsram_int(void)
|
||||||
syslog(LOG_INFO, "Fault Logged on %s - Valid\n", buf);
|
syslog(LOG_INFO, "Fault Logged on %s - Valid\n", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(rv);
|
|
||||||
rv = unlink(HARDFAULT_PATH);
|
rv = unlink(HARDFAULT_PATH);
|
||||||
if (rv < 0)
|
if (rv < 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -166,28 +166,27 @@ static const uint32_t g_pinlist[ADC1_NCHANNELS] =
|
||||||
|
|
||||||
int stm32l4_adc_measure_voltages(uint32_t *vrefint, uint32_t *vbat, uint32_t *vext)
|
int stm32l4_adc_measure_voltages(uint32_t *vrefint, uint32_t *vbat, uint32_t *vext)
|
||||||
{
|
{
|
||||||
|
FAR struct file filestruct;
|
||||||
ssize_t nbytes;
|
ssize_t nbytes;
|
||||||
struct adc_msg_s sample[ADC1_NCHANNELS] = { 0 };
|
struct adc_msg_s sample[ADC1_NCHANNELS] = { 0 };
|
||||||
int nsamples;
|
int nsamples;
|
||||||
int ret;
|
int ret;
|
||||||
int fd;
|
|
||||||
|
|
||||||
fd = nx_open("/dev/adc0", O_RDONLY);
|
ret = file_open(&filestruct, "/dev/adc0", O_RDONLY);
|
||||||
if (fd < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
aerr("ERROR: Cannot open ADC converter\n");
|
aerr("ERROR: Cannot open ADC converter\n");
|
||||||
ret = fd;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ioctl(fd, ANIOC_TRIGGER, 0);
|
ret = file_ioctl(&filestruct, ANIOC_TRIGGER, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
aerr("ERROR: Cannot trigger ADC conversion\n");
|
aerr("ERROR: Cannot trigger ADC conversion\n");
|
||||||
goto out_close;
|
goto out_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbytes = nx_read(fd, sample, sizeof(sample));
|
nbytes = file_read(&filestruct, sample, sizeof(sample));
|
||||||
if (nbytes < 0)
|
if (nbytes < 0)
|
||||||
{
|
{
|
||||||
if (nbytes != -EINTR)
|
if (nbytes != -EINTR)
|
||||||
|
@ -268,7 +267,8 @@ int stm32l4_adc_measure_voltages(uint32_t *vrefint, uint32_t *vbat, uint32_t *ve
|
||||||
}
|
}
|
||||||
|
|
||||||
out_close:
|
out_close:
|
||||||
close(fd);
|
file_close_detached(&filestruct);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,23 +65,21 @@
|
||||||
|
|
||||||
static int wdog_daemon(int argc, char *argv[])
|
static int wdog_daemon(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd;
|
FAR struct file filestruct;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Open watchdog device */
|
/* Open watchdog device */
|
||||||
|
|
||||||
fd = nx_open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY);
|
ret = file_open(&filestruct, CONFIG_WATCHDOG_DEVPATH, O_RDONLY);
|
||||||
|
if (ret < 0)
|
||||||
if (fd < 0)
|
|
||||||
{
|
{
|
||||||
wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, fd);
|
wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, ret);
|
||||||
return fd;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start watchdog timer */
|
/* Start watchdog timer */
|
||||||
|
|
||||||
ret = ioctl(fd, WDIOC_START, 0);
|
ret = file_ioctl(&filestruct, WDIOC_START, 0);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
wderr("ERROR: ioctl(WDIOC_START) failed: %d\n", errno);
|
wderr("ERROR: ioctl(WDIOC_START) failed: %d\n", errno);
|
||||||
|
@ -94,8 +92,7 @@ static int wdog_daemon(int argc, char *argv[])
|
||||||
|
|
||||||
/* Send keep alive ioctl */
|
/* Send keep alive ioctl */
|
||||||
|
|
||||||
ret = ioctl(fd, WDIOC_KEEPALIVE, 0);
|
ret = file_ioctl(&filestruct, WDIOC_KEEPALIVE, 0);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
wderr("ERROR: ioctl(WDIOC_KEEPALIVE) failed: %d\n", errno);
|
wderr("ERROR: ioctl(WDIOC_KEEPALIVE) failed: %d\n", errno);
|
||||||
|
@ -104,9 +101,9 @@ static int wdog_daemon(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
exit_close_dev:
|
exit_close_dev:
|
||||||
|
|
||||||
/* Close watchdog device and exit. */
|
/* Close watchdog device and exit. */
|
||||||
close(fd);
|
|
||||||
|
file_close_detached(&filestruct);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,30 +121,31 @@ exit_close_dev:
|
||||||
|
|
||||||
int photon_watchdog_initialize(void)
|
int photon_watchdog_initialize(void)
|
||||||
{
|
{
|
||||||
int fd;
|
FAR struct file filestruct;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
/* Open the watchdog device */
|
/* Open the watchdog device */
|
||||||
|
|
||||||
fd = nx_open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY);
|
ret = file_open(&filestruct, CONFIG_WATCHDOG_DEVPATH, O_RDONLY);
|
||||||
if (fd < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, fd);
|
wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, ret);
|
||||||
return fd;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the watchdog timeout */
|
/* Set the watchdog timeout */
|
||||||
|
|
||||||
#ifdef CONFIG_PHOTON_IWDG
|
#ifdef CONFIG_PHOTON_IWDG
|
||||||
wdinfo("Timeout = %d.\n", CONFIG_PHOTON_IWDG_TIMEOUT);
|
wdinfo("Timeout = %d.\n", CONFIG_PHOTON_IWDG_TIMEOUT);
|
||||||
ret = ioctl(fd, WDIOC_SETTIMEOUT, (unsigned long)CONFIG_PHOTON_IWDG_TIMEOUT);
|
ret = ioctl(&filestruct, WDIOC_SETTIMEOUT,
|
||||||
|
(unsigned long)CONFIG_PHOTON_IWDG_TIMEOUT);
|
||||||
#else
|
#else
|
||||||
# error "No watchdog configured"
|
# error "No watchdog configured"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Close watchdog as it is not needed here anymore */
|
/* Close watchdog as it is not needed here anymore */
|
||||||
|
|
||||||
close(fd);
|
(void)file_close_detached(&filestruct);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
@ -157,7 +155,7 @@ int photon_watchdog_initialize(void)
|
||||||
|
|
||||||
#if defined(CONFIG_PHOTON_WDG_THREAD)
|
#if defined(CONFIG_PHOTON_WDG_THREAD)
|
||||||
|
|
||||||
/* Spawn wdog deamon thread */
|
/* Spawn wdog daemon thread */
|
||||||
|
|
||||||
int taskid = kthread_create(CONFIG_PHOTON_WDG_THREAD_NAME,
|
int taskid = kthread_create(CONFIG_PHOTON_WDG_THREAD_NAME,
|
||||||
CONFIG_PHOTON_WDG_THREAD_PRIORITY,
|
CONFIG_PHOTON_WDG_THREAD_PRIORITY,
|
||||||
|
|
|
@ -93,23 +93,23 @@
|
||||||
#if defined(CONFIG_WDT_THREAD)
|
#if defined(CONFIG_WDT_THREAD)
|
||||||
static int wdog_daemon(int argc, char *argv[])
|
static int wdog_daemon(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd;
|
FAR struct file filestruct;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Open the watchdog device for reading */
|
/* Open the watchdog device for reading */
|
||||||
|
|
||||||
wdinfo("Opening.\n");
|
wdinfo("Opening.\n");
|
||||||
fd = nx_open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY);
|
ret = file_open(&filestruct, CONFIG_WATCHDOG_DEVPATH, O_RDONLY);
|
||||||
if (fd < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, fd);
|
wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, ret);
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start the watchdog timer. */
|
/* Start the watchdog timer. */
|
||||||
|
|
||||||
wdinfo("Starting.\n");
|
wdinfo("Starting.\n");
|
||||||
ret = ioctl(fd, WDIOC_START, 0);
|
ret = file_ioctl(&filestruct, WDIOC_START, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
wderr("ERROR: ioctl(WDIOC_START) failed: %d\n", errno);
|
wderr("ERROR: ioctl(WDIOC_START) failed: %d\n", errno);
|
||||||
|
@ -122,7 +122,7 @@ static int wdog_daemon(int argc, char *argv[])
|
||||||
nxsig_usleep((CONFIG_WDT_THREAD_INTERVAL)*1000);
|
nxsig_usleep((CONFIG_WDT_THREAD_INTERVAL)*1000);
|
||||||
|
|
||||||
wdinfo("ping\n");
|
wdinfo("ping\n");
|
||||||
ret = ioctl(fd, WDIOC_KEEPALIVE, 0);
|
ret = file_ioctl(&filestruct, WDIOC_KEEPALIVE, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
wderr("ERROR: ioctl(WDIOC_KEEPALIVE) failed: %d\n", errno);
|
wderr("ERROR: ioctl(WDIOC_KEEPALIVE) failed: %d\n", errno);
|
||||||
|
@ -131,9 +131,9 @@ static int wdog_daemon(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
errout_with_dev:
|
errout_with_dev:
|
||||||
close(fd);
|
file_close_detached(&filestruct);
|
||||||
errout:
|
errout:
|
||||||
return ERROR;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -150,28 +150,32 @@ errout:
|
||||||
int sam_watchdog_initialize(void)
|
int sam_watchdog_initialize(void)
|
||||||
{
|
{
|
||||||
#if (defined(CONFIG_SAM34_WDT) && !defined(CONFIG_WDT_DISABLE_ON_RESET))
|
#if (defined(CONFIG_SAM34_WDT) && !defined(CONFIG_WDT_DISABLE_ON_RESET))
|
||||||
int fd;
|
FAR struct file filestruct;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Initialize tha register the watchdog timer device */
|
/* Initialize tha register the watchdog timer device */
|
||||||
|
|
||||||
wdinfo("Initializing Watchdog driver...\n");
|
wdinfo("Initializing Watchdog driver...\n");
|
||||||
|
|
||||||
sam_wdtinitialize(CONFIG_WATCHDOG_DEVPATH);
|
sam_wdtinitialize(CONFIG_WATCHDOG_DEVPATH);
|
||||||
|
|
||||||
/* Open the watchdog device */
|
/* Open the watchdog device */
|
||||||
|
|
||||||
wdinfo("Opening.\n");
|
wdinfo("Opening.\n");
|
||||||
fd = nx_open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY);
|
|
||||||
if (fd < 0)
|
ret = file_open(&filestruct, CONFIG_WATCHDOG_DEVPATH, O_RDONLY);
|
||||||
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, fd);
|
wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, ret);
|
||||||
goto fd;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the watchdog timeout */
|
/* Set the watchdog timeout */
|
||||||
|
|
||||||
wdinfo("Timeout = %d.\n", CONFIG_WDT_TIMEOUT);
|
wdinfo("Timeout = %d.\n", CONFIG_WDT_TIMEOUT);
|
||||||
ret = ioctl(fd, WDIOC_SETTIMEOUT, (unsigned long)CONFIG_WDT_TIMEOUT);
|
|
||||||
|
ret = file_ioctl(&filestruct, WDIOC_SETTIMEOUT,
|
||||||
|
(unsigned long)CONFIG_WDT_TIMEOUT);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
wderr("ERROR: ioctl(WDIOC_SETTIMEOUT) failed: %d\n", errno);
|
wderr("ERROR: ioctl(WDIOC_SETTIMEOUT) failed: %d\n", errno);
|
||||||
|
@ -181,7 +185,8 @@ int sam_watchdog_initialize(void)
|
||||||
/* Set the watchdog minimum time */
|
/* Set the watchdog minimum time */
|
||||||
|
|
||||||
wdinfo("MinTime = %d.\n", CONFIG_WDT_MINTIME);
|
wdinfo("MinTime = %d.\n", CONFIG_WDT_MINTIME);
|
||||||
ret = ioctl(fd, WDIOC_MINTIME, (unsigned long)CONFIG_WDT_MINTIME);
|
ret = file_ioctl(&filestruct, WDIOC_MINTIME,
|
||||||
|
(unsigned long)CONFIG_WDT_MINTIME);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
wderr("ERROR: ioctl(WDIOC_MINTIME) failed: %d\n", errno);
|
wderr("ERROR: ioctl(WDIOC_MINTIME) failed: %d\n", errno);
|
||||||
|
@ -205,9 +210,9 @@ int sam_watchdog_initialize(void)
|
||||||
#endif
|
#endif
|
||||||
return OK;
|
return OK;
|
||||||
errout_with_dev:
|
errout_with_dev:
|
||||||
close(fd);
|
file_close_detached(&filestruct);
|
||||||
errout:
|
errout:
|
||||||
return ERROR;
|
return ret;
|
||||||
#else
|
#else
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
int bchdev_unregister(FAR const char *chardev)
|
int bchdev_unregister(FAR const char *chardev)
|
||||||
{
|
{
|
||||||
FAR struct bchlib_s *bch;
|
FAR struct bchlib_s *bch;
|
||||||
int fd;
|
FAR struct file *filestruct;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
|
@ -87,19 +87,20 @@ int bchdev_unregister(FAR const char *chardev)
|
||||||
|
|
||||||
/* Open the character driver associated with chardev */
|
/* Open the character driver associated with chardev */
|
||||||
|
|
||||||
fd = nx_open(chardev, O_RDONLY);
|
ret = file_open(&filestruct, chardev, O_RDONLY);
|
||||||
if (fd < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
_err("ERROR: Failed to open %s: %d\n", chardev, fd);
|
_err("ERROR: Failed to open %s: %d\n", chardev, ret);
|
||||||
return fd;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a reference to the internal data structure. On success, we
|
/* Get a reference to the internal data structure. On success, we
|
||||||
* will hold a reference count on the state structure.
|
* will hold a reference count on the state structure.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = ioctl(fd, DIOC_GETPRIV, (unsigned long)((uintptr_t)&bch));
|
ret = file_ioctl(&filestruct, DIOC_GETPRIV,
|
||||||
(void)close(fd);
|
(unsigned long)((uintptr_t)&bch));
|
||||||
|
(void)file_close_detached(&filestruct);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue