timer_gpout example: use /dev/gpioN instead of /dev/gpoutN

This commit is contained in:
Jari van Ewijk 2021-12-09 14:44:28 +01:00 committed by Xiang Xiao
parent 71f5af47e4
commit 128996fb5f
3 changed files with 19 additions and 19 deletions

View File

@ -1740,8 +1740,8 @@ Example configuration:
- `EXAMPLES_TIMER_GPOUT_TIM_DEVNAME` This is the name of the timer device that will be used. - `EXAMPLES_TIMER_GPOUT_TIM_DEVNAME` This is the name of the timer device that will be used.
Default: `/dev/timer0`. Default: `/dev/timer0`.
- `EXAMPLES_TIMER_GPOUT_GPOUT_DEVNAME` This is the name of the gpout device that will be used. - `EXAMPLES_TIMER_GPOUT_GPIO_DEVNAME` This is the name of the gpout device that will be used.
Default: `/dev/gpout0`. Default: `/dev/gpio0`.
- `EXAMPLES_TIMER_GPOUT_INTERVAL` This is the timer interval in microseconds. - `EXAMPLES_TIMER_GPOUT_INTERVAL` This is the timer interval in microseconds.
Default: `1000000`. Default: `1000000`.
- `EXAMPLES_TIMER_GPOUT_SIGNO` This is the signal number that is used to notify that a timer - `EXAMPLES_TIMER_GPOUT_SIGNO` This is the signal number that is used to notify that a timer

View File

@ -27,11 +27,11 @@ config EXAMPLES_TIMER_GPOUT_TIM_DEVNAME
---help--- ---help---
This is the name of the timer device that will be used. This is the name of the timer device that will be used.
config EXAMPLES_TIMER_GPOUT_GPOUT_DEVNAME config EXAMPLES_TIMER_GPOUT_GPIO_DEVNAME
string "GPOUT device name" string "GPOUT device name"
default "/dev/gpout0" default "/dev/gpio0"
---help--- ---help---
This is the name of the gpout device that will be used. This is the name of the gpio device that will be used.
config EXAMPLES_TIMER_GPOUT_INTERVAL config EXAMPLES_TIMER_GPOUT_INTERVAL
int "Timer interval (microseconds)" int "Timer interval (microseconds)"

View File

@ -38,7 +38,7 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define DEVNAME_SIZE 16 #define DEVNAME_SIZE 32
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
@ -49,7 +49,7 @@
****************************************************************************/ ****************************************************************************/
static char g_devtim[DEVNAME_SIZE]; static char g_devtim[DEVNAME_SIZE];
static char g_devgpout[DEVNAME_SIZE]; static char g_devgpio[DEVNAME_SIZE];
static bool g_timer_gpout_daemon_started = false; static bool g_timer_gpout_daemon_started = false;
/**************************************************************************** /****************************************************************************
@ -104,7 +104,7 @@ static int timer_gpout_daemon(int argc, char *argv[])
sigset_t set; sigset_t set;
struct siginfo value; struct siginfo value;
int fd_timer; int fd_timer;
int fd_gpout; int fd_gpio;
int ret; int ret;
bool state = false; bool state = false;
@ -128,14 +128,14 @@ static int timer_gpout_daemon(int argc, char *argv[])
/* Open the GPIO driver */ /* Open the GPIO driver */
printf("Open %s\n", g_devgpout); printf("Open %s\n", g_devgpio);
fd_gpout = open(g_devgpout, O_RDWR); fd_gpio = open(g_devgpio, O_RDWR);
if (fd_gpout < 0) if (fd_gpio < 0)
{ {
int errcode = errno; int errcode = errno;
printf("timer_gpout_daemon: Failed to open %s: %d\n", printf("timer_gpout_daemon: Failed to open %s: %d\n",
g_devgpout, errcode); g_devgpio, errcode);
close(fd_timer); close(fd_timer);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -214,26 +214,26 @@ static int timer_gpout_daemon(int argc, char *argv[])
goto errout; goto errout;
} }
/* Change the gpout state */ /* Change the gpio state */
state = !state; state = !state;
/* Write the pin value */ /* Write the pin value */
ret = ioctl(fd_gpout, GPIOC_WRITE, (unsigned long)state); ret = ioctl(fd_gpio, GPIOC_WRITE, (unsigned long)state);
if (ret < 0) if (ret < 0)
{ {
int errcode = errno; int errcode = errno;
printf("timer_gpout_daemon: Failed to write value" printf("timer_gpout_daemon: Failed to write value"
" %u from %s: %d\n", " %u from %s: %d\n",
(unsigned int)state, g_devgpout, errcode); (unsigned int)state, g_devgpio, errcode);
goto errout; goto errout;
} }
} }
errout: errout:
close(fd_timer); close(fd_timer);
close(fd_gpout); close(fd_gpio);
g_timer_gpout_daemon_started = false; g_timer_gpout_daemon_started = false;
printf("timer_gpout_daemon: Terminating!\n"); printf("timer_gpout_daemon: Terminating!\n");
@ -264,7 +264,7 @@ int main(int argc, FAR char *argv[])
/* Use the ones configured on menuconfig */ /* Use the ones configured on menuconfig */
strcpy(g_devtim, CONFIG_EXAMPLES_TIMER_GPOUT_TIM_DEVNAME); strcpy(g_devtim, CONFIG_EXAMPLES_TIMER_GPOUT_TIM_DEVNAME);
strcpy(g_devgpout, CONFIG_EXAMPLES_TIMER_GPOUT_GPOUT_DEVNAME); strcpy(g_devgpio, CONFIG_EXAMPLES_TIMER_GPOUT_GPIO_DEVNAME);
/* Or the ones passed as arguments */ /* Or the ones passed as arguments */
@ -276,13 +276,13 @@ int main(int argc, FAR char *argv[])
strcpy(g_devtim, optarg); strcpy(g_devtim, optarg);
break; break;
case 'g': case 'g':
strcpy(g_devgpout, optarg); strcpy(g_devgpio, optarg);
break; break;
case ':': case ':':
fprintf(stderr, "ERROR: Option needs a value\n"); fprintf(stderr, "ERROR: Option needs a value\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
default: /* '?' */ default: /* '?' */
fprintf(stderr, "Usage: %s [-d /dev/timerx] [-d /dev/gpoutx]\n", fprintf(stderr, "Usage: %s [-d /dev/timerx] [-d /dev/gpiox]\n",
argv[0]); argv[0]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }