Commit 223af9c2 authored by Miguel Jimenez Lopez's avatar Miguel Jimenez Lopez

sw: Improve user exit mechanism for irq-demo

parent 6ba4b281
......@@ -35,6 +35,7 @@ static void destroy_user_arguments(user_args args);
static void show_help(void);
static unsigned int check_user_stop(void);
static void set_stdin_as_nonblocking(void);
#endif
......@@ -70,6 +70,8 @@ int main(int argc, char *argv[])
enable_fmc_dio_device_irq(dev, TEST_FMC_DIO_CH);
setup_fmc_dio_device_irq(dev, user_arguments->irq_period, TEST_FMC_DIO_COUNT);
set_stdin_as_nonblocking();
while(!user_stop) {
demo_irq_process_loop(dev, sengine);
user_stop = check_user_stop();
......@@ -148,22 +150,14 @@ static void show_help(void)
static unsigned int check_user_stop(void)
{
int ret = 0;
char c;
fd_set fds;
struct timeval tv;
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds);
c = getchar();
tv.tv_sec = 0;
tv.tv_usec = 1;
if(select(STDIN_FILENO+1, &fds, NULL, NULL, &tv) == 1) {
c = getchar();
if(c == 'q')
ret = 1;
}
return (c == 'q');
}
return ret;
static void set_stdin_as_nonblocking(void)
{
fcntl (STDIN_FILENO, F_SETFL, O_NONBLOCK);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment