Replace callse to ioctl() in the OS to file_ioctl()
This commit is contained in:
parent
5a0c6547d9
commit
a83b6d990b
@ -91,7 +91,7 @@ static struct binfmt_s g_builtin_binfmt =
|
||||
static int builtin_loadbinary(struct binary_s *binp)
|
||||
{
|
||||
FAR const char *filename;
|
||||
FAR const struct builtin_s *b;
|
||||
FAR const struct builtin_s *builtin;
|
||||
int fd;
|
||||
int index;
|
||||
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.
|
||||
*/
|
||||
|
||||
b = builtin_for_index(index);
|
||||
binp->entrypt = b->main;
|
||||
binp->stacksize = b->stacksize;
|
||||
binp->priority = b->priority;
|
||||
builtin = builtin_for_index(index);
|
||||
binp->entrypt = builtin->main;
|
||||
binp->stacksize = builtin->stacksize;
|
||||
binp->priority = builtin->priority;
|
||||
close(fd);
|
||||
return OK;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* 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>
|
||||
*
|
||||
* 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)
|
||||
{
|
||||
int ret = -ENOENT;
|
||||
int fd = nx_open(HARDFAULT_PATH, O_RDONLY);
|
||||
int rv;
|
||||
FAR struct file filestruct;
|
||||
int ret;
|
||||
|
||||
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] "
|
||||
"(%d)\n", HARDFAULT_PATH, fd);
|
||||
"(%d)\n", HARDFAULT_PATH, ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -EIO;
|
||||
rv = ioctl(fd, STM32F7_BBSRAM_GETDESC_IOCTL,
|
||||
ret = file_ioctl(&filestruct, STM32F7_BBSRAM_GETDESC_IOCTL,
|
||||
(unsigned long)((uintptr_t)desc));
|
||||
(void)file_close_detached(&filestruct);
|
||||
|
||||
if (rv >= 0)
|
||||
{
|
||||
ret = fd;
|
||||
}
|
||||
else
|
||||
if (ret < 0)
|
||||
{
|
||||
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;
|
||||
time_t time_sec;
|
||||
|
||||
|
||||
/* Using Battery Backed Up SRAM */
|
||||
|
||||
stm32_bbsraminitialize(BBSRAM_PATH, filesizes);
|
||||
@ -380,7 +375,6 @@ int stm32_bbsram_int(void)
|
||||
syslog(LOG_INFO, "Fault Logged on %s - Valid\n", buf);
|
||||
}
|
||||
|
||||
close(rv);
|
||||
rv = unlink(HARDFAULT_PATH);
|
||||
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)
|
||||
{
|
||||
FAR struct file filestruct;
|
||||
ssize_t nbytes;
|
||||
struct adc_msg_s sample[ADC1_NCHANNELS] = { 0 };
|
||||
int nsamples;
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
fd = nx_open("/dev/adc0", O_RDONLY);
|
||||
if (fd < 0)
|
||||
ret = file_open(&filestruct, "/dev/adc0", O_RDONLY);
|
||||
if (ret < 0)
|
||||
{
|
||||
aerr("ERROR: Cannot open ADC converter\n");
|
||||
ret = fd;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = ioctl(fd, ANIOC_TRIGGER, 0);
|
||||
ret = file_ioctl(&filestruct, ANIOC_TRIGGER, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
aerr("ERROR: Cannot trigger ADC conversion\n");
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
nbytes = nx_read(fd, sample, sizeof(sample));
|
||||
nbytes = file_read(&filestruct, sample, sizeof(sample));
|
||||
if (nbytes < 0)
|
||||
{
|
||||
if (nbytes != -EINTR)
|
||||
@ -268,7 +267,8 @@ int stm32l4_adc_measure_voltages(uint32_t *vrefint, uint32_t *vbat, uint32_t *ve
|
||||
}
|
||||
|
||||
out_close:
|
||||
close(fd);
|
||||
file_close_detached(&filestruct);
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
@ -65,23 +65,21 @@
|
||||
|
||||
static int wdog_daemon(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
FAR struct file filestruct;
|
||||
int ret;
|
||||
|
||||
/* Open watchdog device */
|
||||
|
||||
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);
|
||||
return fd;
|
||||
wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Start watchdog timer */
|
||||
|
||||
ret = ioctl(fd, WDIOC_START, 0);
|
||||
|
||||
ret = file_ioctl(&filestruct, WDIOC_START, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
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 */
|
||||
|
||||
ret = ioctl(fd, WDIOC_KEEPALIVE, 0);
|
||||
|
||||
ret = file_ioctl(&filestruct, WDIOC_KEEPALIVE, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
wderr("ERROR: ioctl(WDIOC_KEEPALIVE) failed: %d\n", errno);
|
||||
@ -104,9 +101,9 @@ static int wdog_daemon(int argc, char *argv[])
|
||||
}
|
||||
|
||||
exit_close_dev:
|
||||
|
||||
/* Close watchdog device and exit. */
|
||||
close(fd);
|
||||
|
||||
file_close_detached(&filestruct);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -124,30 +121,31 @@ exit_close_dev:
|
||||
|
||||
int photon_watchdog_initialize(void)
|
||||
{
|
||||
int fd;
|
||||
FAR struct file filestruct;
|
||||
int ret = 0;
|
||||
|
||||
/* Open the watchdog device */
|
||||
|
||||
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);
|
||||
return fd;
|
||||
wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Set the watchdog timeout */
|
||||
|
||||
#ifdef CONFIG_PHOTON_IWDG
|
||||
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
|
||||
# error "No watchdog configured"
|
||||
#endif
|
||||
|
||||
/* Close watchdog as it is not needed here anymore */
|
||||
|
||||
close(fd);
|
||||
(void)file_close_detached(&filestruct);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -157,7 +155,7 @@ int photon_watchdog_initialize(void)
|
||||
|
||||
#if defined(CONFIG_PHOTON_WDG_THREAD)
|
||||
|
||||
/* Spawn wdog deamon thread */
|
||||
/* Spawn wdog daemon thread */
|
||||
|
||||
int taskid = kthread_create(CONFIG_PHOTON_WDG_THREAD_NAME,
|
||||
CONFIG_PHOTON_WDG_THREAD_PRIORITY,
|
||||
|
@ -93,23 +93,23 @@
|
||||
#if defined(CONFIG_WDT_THREAD)
|
||||
static int wdog_daemon(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
FAR struct file filestruct;
|
||||
int ret;
|
||||
|
||||
/* Open the watchdog device for reading */
|
||||
|
||||
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 errout;
|
||||
}
|
||||
|
||||
/* Start the watchdog timer. */
|
||||
|
||||
wdinfo("Starting.\n");
|
||||
ret = ioctl(fd, WDIOC_START, 0);
|
||||
ret = file_ioctl(&filestruct, WDIOC_START, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
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);
|
||||
|
||||
wdinfo("ping\n");
|
||||
ret = ioctl(fd, WDIOC_KEEPALIVE, 0);
|
||||
ret = file_ioctl(&filestruct, WDIOC_KEEPALIVE, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
wderr("ERROR: ioctl(WDIOC_KEEPALIVE) failed: %d\n", errno);
|
||||
@ -131,9 +131,9 @@ static int wdog_daemon(int argc, char *argv[])
|
||||
}
|
||||
|
||||
errout_with_dev:
|
||||
close(fd);
|
||||
file_close_detached(&filestruct);
|
||||
errout:
|
||||
return ERROR;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -150,28 +150,32 @@ errout:
|
||||
int sam_watchdog_initialize(void)
|
||||
{
|
||||
#if (defined(CONFIG_SAM34_WDT) && !defined(CONFIG_WDT_DISABLE_ON_RESET))
|
||||
int fd;
|
||||
FAR struct file filestruct;
|
||||
int ret;
|
||||
|
||||
/* Initialize tha register the watchdog timer device */
|
||||
|
||||
wdinfo("Initializing Watchdog driver...\n");
|
||||
|
||||
sam_wdtinitialize(CONFIG_WATCHDOG_DEVPATH);
|
||||
|
||||
/* Open the watchdog device */
|
||||
|
||||
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);
|
||||
goto fd;
|
||||
wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Set the watchdog 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)
|
||||
{
|
||||
wderr("ERROR: ioctl(WDIOC_SETTIMEOUT) failed: %d\n", errno);
|
||||
@ -181,7 +185,8 @@ int sam_watchdog_initialize(void)
|
||||
/* Set the watchdog minimum time */
|
||||
|
||||
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)
|
||||
{
|
||||
wderr("ERROR: ioctl(WDIOC_MINTIME) failed: %d\n", errno);
|
||||
@ -205,9 +210,9 @@ int sam_watchdog_initialize(void)
|
||||
#endif
|
||||
return OK;
|
||||
errout_with_dev:
|
||||
close(fd);
|
||||
file_close_detached(&filestruct);
|
||||
errout:
|
||||
return ERROR;
|
||||
return ret;
|
||||
#else
|
||||
return -ENODEV;
|
||||
#endif
|
||||
|
@ -73,7 +73,7 @@
|
||||
int bchdev_unregister(FAR const char *chardev)
|
||||
{
|
||||
FAR struct bchlib_s *bch;
|
||||
int fd;
|
||||
FAR struct file *filestruct;
|
||||
int ret;
|
||||
|
||||
/* Sanity check */
|
||||
@ -87,19 +87,20 @@ int bchdev_unregister(FAR const char *chardev)
|
||||
|
||||
/* Open the character driver associated with chardev */
|
||||
|
||||
fd = nx_open(chardev, O_RDONLY);
|
||||
if (fd < 0)
|
||||
ret = file_open(&filestruct, chardev, O_RDONLY);
|
||||
if (ret < 0)
|
||||
{
|
||||
_err("ERROR: Failed to open %s: %d\n", chardev, fd);
|
||||
return fd;
|
||||
_err("ERROR: Failed to open %s: %d\n", chardev, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Get a reference to the internal data structure. On success, we
|
||||
* will hold a reference count on the state structure.
|
||||
*/
|
||||
|
||||
ret = ioctl(fd, DIOC_GETPRIV, (unsigned long)((uintptr_t)&bch));
|
||||
(void)close(fd);
|
||||
ret = file_ioctl(&filestruct, DIOC_GETPRIV,
|
||||
(unsigned long)((uintptr_t)&bch));
|
||||
(void)file_close_detached(&filestruct);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user