Exemplo n.º 1
0
static void timer_task_proc(void *arg)
{
	struct rt_tmbench_context *ctx = arg;
	int count;

	/* first event: one millisecond from now. */
	ctx->date = rtdm_clock_read_monotonic() + 1000000;

	while (1) {
		int err;

		for (count = 0; count < ctx->samples_per_sec; count++) {
			RTDM_EXECUTE_ATOMICALLY(
				ctx->start_time = rtdm_clock_read_monotonic();
				err =
				    rtdm_task_sleep_abs(ctx->date,
							RTDM_TIMERMODE_ABSOLUTE);
			);

			if (err)
				return;

			eval_inner_loop(ctx,
					(long)(rtdm_clock_read_monotonic() -
					       ctx->date));
		}
		eval_outer_loop(ctx);
	}
Exemplo n.º 2
0
void 
pwm_up(rtdm_timer_t *timer)
{
  int retval;
  size_t channel = 0;

  for(; channel < RC_NUM; ++channel)
    {
      // set pwm to high
      gpio_set_value(channels[channel].pwm, 1);

      // ideal time to put signal down
      down_time[channel] = rtdm_clock_read_monotonic() + up_interval[channel];
      if(reconfigured[channel])
	{
	  reconfigured[channel] = 0;
	  rtdm_timer_stop(&down_timer[channel]);
	  // request timer to fire DELTA ns earlier then needed
	  retval = rtdm_timer_start(&down_timer[channel], 
				    up_interval[channel] - DELTA,
				    PERIOD,
				    RTDM_TIMERMODE_RELATIVE);
	  if(retval)
	    rtdm_printk("TB6612FNG: error reconfiguring down-timer #%i: %i\n", 
			channel, retval);
	}
    }
}
Exemplo n.º 3
0
void 
pwm_down(rtdm_timer_t *timer)
{
  size_t channel = 0;

  // Search for our timer to determine the channel
  for(; channel < sizeof(down_timer) / sizeof(down_timer[0]); ++channel)
    {
      if(timer == &down_timer[channel])
	break;
    }

  // spin until the ideal time to put signal down
  while(down_time[channel] > rtdm_clock_read_monotonic());

  // set pwm to low
  gpio_set_value(channels[channel].pwm, 0);
}
Exemplo n.º 4
0
int setup_timer_handler(void)
{
  int ret = 0;

  priv = netdev_priv(get_vlc_dev());

  //Get the first packets in the packet ring
  rx_packet = get_rx_packet();
  tx_packet = get_tx_packet();

  //Init semas
  rtdm_sem_init(&tx_sem, 1);
  rtdm_sem_init(&rx_sem, 1);

  //Store the current time
  rx_sleep_slot = rtdm_clock_read_monotonic();
  tx_sleep_slot = rx_sleep_slot + sleep_increment / 2;

  early_late_slot = do_div(sleep_increment, 5);

  //Return an error if either is NULL
  if(!rx_packet || !tx_packet) goto error;

  //Start the rx and tx handler tasks
  rtdm_task_init(&rx_handler_task, "VLC rx handler", rx_handler, 
                 NULL, RTDM_TASK_HIGHEST_PRIORITY, 0);
  if(ret) goto error;

  rtdm_task_init(&tx_handler_task, "VLC tx handler", tx_handler, 
                 NULL, RTDM_TASK_HIGHEST_PRIORITY, 0);
  if(ret) goto error;

  return 0;

 error:
  rtdm_task_destroy(&rx_handler_task);
  rtdm_task_destroy(&tx_handler_task);
  return -1;
}