Beispiel #1
0
/** Przetwarza po kolei wszystkie timery.
*/
void timers_process(void) {
	uint8_t t;
	for (t=0;t<TIMERS_NUM;t++) {
		if (timer_status(t) == TIM_STATUS_ACTIVE) {
			timer_switch_out(t,ON);
		} else if (timer_status(t) == TIM_STATUS_NOTACTIVE || timer_status(t) == TIM_STATUS_NOT_WDAY || timer_status(t) == TIM_STATUS_BLOCKED) {
			timer_switch_out(t,OFF);
		}
	}
}
Beispiel #2
0
int timer_main(int argc, char *argv[])
#endif
{
  struct timer_sethandler_s handler;
  int ret;
  int fd;
  int i;

  /* Open the timer device */

  printf("Open %s\n", CONFIG_EXAMPLE_TIMER_DEVNAME);

  fd = open(CONFIG_EXAMPLE_TIMER_DEVNAME, O_RDONLY);
  if (fd < 0)
    {
      fprintf(stderr, "ERROR: Failed to open %s: %d\n",
              CONFIG_EXAMPLE_TIMER_DEVNAME, errno);
      return EXIT_FAILURE;
    }

  /* Show the timer status before setting the timer interval */

  timer_status(fd);

  /* Set the timer interval */

  printf("Set timer interval to %lu\n",
         (unsigned long)CONFIG_EXAMPLE_TIMER_INTERVAL);

  ret = ioctl(fd, TCIOC_SETTIMEOUT, CONFIG_EXAMPLE_TIMER_INTERVAL);
  if (ret < 0)
    {
      fprintf(stderr, "ERROR: Failed to set the timer interval: %d\n", errno);
      close(fd);
      return EXIT_FAILURE;
    }

  /* Show the timer status before attaching the timer handler */

  timer_status(fd);

  /* Attach the timer handler
   *
   * NOTE: If no handler is attached, the timer stop at the first interrupt.
   */

  printf("Attach timer handler\n");

  handler.newhandler = timer_handler;
  handler.oldhandler = NULL;

  ret = ioctl(fd, TCIOC_SETHANDLER, (unsigned long)((uintptr_t)&handler));
  if (ret < 0)
    {
      fprintf(stderr, "ERROR: Failed to set the timer handler: %d\n", errno);
      close(fd);
      return EXIT_FAILURE;
    }

  /* Show the timer status before starting */

  timer_status(fd);

  /* Start the timer */

  printf("Start the timer\n");

  ret = ioctl(fd, TCIOC_START, 0);
  if (ret < 0)
    {
      fprintf(stderr, "ERROR: Failed to start the timer: %d\n", errno);
      close(fd);
      return EXIT_FAILURE;
    }

  /* Wait a bit showing timer status */

  for (i = 0; i < CONFIG_EXAMPLE_TIMER_NSAMPLES; i++)
    {
      usleep(CONFIG_EXAMPLE_TIMER_DELAY);
      timer_status(fd);
    }

  /* Stop the timer */

  printf("Stop the timer\n");

  ret = ioctl(fd, TCIOC_STOP, 0);
  if (ret < 0)
    {
      fprintf(stderr, "ERROR: Failed to stop the timer: %d\n", errno);
      close(fd);
      return EXIT_FAILURE;
    }

  /* Show the timer status before starting */

  timer_status(fd);

  /* Close the timer driver */

  printf("Finished\n");
  close(fd);
  return EXIT_SUCCESS;
}