maxikrie commented on issue #8207:
URL: https://github.com/apache/nuttx/issues/8207#issuecomment-1399331021

   This however results in the desired behavior
   
   ```
        printf("Hello, World!!\n");
   
        uint32_t N = 1000;
        uint32_t time[N];
        useconds_t sleep_time = 100;
   
        int tmr_id = open("/dev/timer0", O_RDONLY);
        if (tmr_id < 0)
        {
                fprintf(stderr, "ERROR: Failed to open timer: %d\n", errno);
                close(tmr_id);
                return EXIT_FAILURE;
        }
   
        ioctl(tmr_id, TCIOC_SETTIMEOUT, 100);
   
        struct timer_notify_s notify;
   
        notify.pid = getpid();
        notify.periodic = true;
   
        notify.event.sigev_notify = SIGEV_SIGNAL;
        notify.event.sigev_signo = SIGUSR1;
        notify.event.sigev_value.sival_ptr = NULL;
   
        int ret = ioctl(tmr_id, TCIOC_NOTIFICATION,
                        (unsigned long) ((uintptr_t) &notify));
        if (ret < 0)
        {
                fprintf(stderr, "ERROR: Failed to set the timer handler: %d\n", 
errno);
                close(tmr_id);
                return EXIT_FAILURE;
        }
   
        ret = ioctl(tmr_id, TCIOC_START, 0);
        if (ret < 0)
        {
                fprintf(stderr, "ERROR: Failed to start the timer: %d\n", 
errno);
                close(tmr_id);
                return EXIT_FAILURE;
        }
   
        sigset_t mask;
        sigaddset(&mask, SIGUSR1);
   
        struct timespec t1;
        clock_gettime(0, &t1);
   
        struct timespec t_start;
        clock_gettime(0, &t_start);
        for (int i = 0; i < N; i++)
        {
                siginfo_t info;
                int bla = sigwaitinfo(&mask, &info);
                struct timespec t2;
                clock_gettime(0, &t2);
                struct timespec dt;
                clock_timespec_subtract(&t2, &t1, &dt);
                t1 = t2;
                time[i] = dt.tv_nsec / 1000;
        }
   
        struct timespec t_end;
        clock_gettime(0, &t_end);
   
        struct timespec dt;
        clock_timespec_subtract(&t_end, &t_start, &dt);
        printf("Average sleep time: %ld (%ld)\n", dt.tv_nsec / 1000 / N,
                        sleep_time);
   
        for (int i = 0; i < N; i++)
        {
                printf("Iteration %d: sleep time %ld (%ld)\n", i, time[i], 
sleep_time);
        }
        return 0;
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to