Exemplo n.º 1
0
/* reads for a message from the device */
int uid_read_message( struct MW_UID_MESSAGE *m, unsigned long timeout )
{
  rtems_status_code status;
  size_t            size = 0;
  unsigned long micro_secs = timeout*1000;
  int wait = ( timeout != 0 );

  status = rtems_message_queue_receive( queue_id,
                                       (void*)m,
                                       &size,
                                       wait ? RTEMS_WAIT : RTEMS_NO_WAIT,
                                       RTEMS_MICROSECONDS_TO_TICKS(micro_secs));

  if( status == RTEMS_SUCCESSFUL )
  {
     return size;
  }
  else if( ( status == RTEMS_UNSATISFIED ) || ( status == RTEMS_TIMEOUT ) )
  {
     /* this macro returns -1 */
     rtems_set_errno_and_return_minus_one( ETIMEDOUT );
  }
  /* Here we have one error condition */
#ifdef MW_DEBUG_ON
  printk( "UID_Queue: error reading queue: %d\n", status );
#endif
  return -1;
}
Exemplo n.º 2
0
/**
 * BDBUF Sleep.
 */
static bool
bdbuf_sleep (unsigned long msecs)
{
  rtems_status_code sc;
  sc = rtems_task_wake_after (RTEMS_MICROSECONDS_TO_TICKS (msecs * 1000));
  if (sc != RTEMS_SUCCESSFUL)
  {
    bdbuf_test_printf ("sleep wake after failed: ");
    bdbuf_test_print_sc (sc, true);
    return false;
  }
  return true;
}
Exemplo n.º 3
0
/**
 * BDBUf wait for the wait event.
 */
static rtems_status_code
bdbuf_watch (unsigned long timeout)
{
  rtems_status_code sc;
  rtems_event_set   out;
  sc = rtems_event_receive (RTEMS_EVENT_1,
                            RTEMS_WAIT | RTEMS_EVENT_ANY,
                            RTEMS_MICROSECONDS_TO_TICKS (timeout * 1000),
                            &out);
  if (sc != RTEMS_SUCCESSFUL)
  {
    bdbuf_test_printf ("watch: receive failed: ");
    bdbuf_test_print_sc (sc, true);
  }
  else if ((out & RTEMS_EVENT_1) == 0)
  {
    bdbuf_test_printf ("watch: received wrong event: %08x", out);
  }
  return sc;
}
Exemplo n.º 4
0
void
osip_usleep (int useconds)
{
#if defined(__PALMOS__) && (__PALMOS__ >= 0x06000000)
  /* This bit will work for the Protein API, but not the Palm 68K API */
  nsecs_t nanoseconds = useconds * 1000;

  SysThreadDelay (nanoseconds, P_ABSOLUTE_TIMEOUT);
#elif defined(__PALMOS__) && (__PALMOS__ < 0x06000000)
  UInt32 stoptime = TimGetTicks () + (useconds / 1000000) * SysTicksPerSecond ();

  while (stoptime > TimGetTicks ())
    /* I wish there was some type of yield function here */
    ;
#elif defined(WIN32)
  Sleep (useconds / 1000);
#elif defined(__rtems__)
    rtems_task_wake_after( RTEMS_MICROSECONDS_TO_TICKS(useconds) );
#elif defined(__arc__)
  struct timespec req;
  struct timespec rem;
  req.tv_sec = (int) useconds / 1000000;
  req.tv_nsec = (int) (useconds % 1000000)*1000;
  nanosleep (&req, &rem);
#else
  struct timeval delay;
  int sec;

  sec = (int) useconds / 1000000;
  if (sec > 0)
    {
      delay.tv_sec = sec;
      delay.tv_usec = 0;
  } else
    {
      delay.tv_sec = 0;
      delay.tv_usec = useconds;
    }
  select (0, 0, 0, 0, &delay);
#endif
}
Exemplo n.º 5
0
Arquivo: ide.c Projeto: atixing/rtems
/*
 * Once tasking has started we use a task sleep.
 */
static void pc386_ide_tasking_sleep (void)
{
  rtems_task_wake_after (RTEMS_MICROSECONDS_TO_TICKS (10000) ?
                         RTEMS_MICROSECONDS_TO_TICKS (10000) : 1);
}
Exemplo n.º 6
0
static void
capture_wait (uint32_t period)
{
  rtems_task_wake_after (RTEMS_MICROSECONDS_TO_TICKS (period * 1000));
}
Exemplo n.º 7
0
int
rtems_bsd_run_rc_conf_script(const char* name,
                             const char* text,
                             int         timeout,
                             bool        verbose)
{
  rtems_bsd_rc_conf   rc_conf;
  rtems_task_priority priority;
  rtems_id            worker;
  rtems_status_code   sc;
  int                 r = 0;

  if (verbose)
    printf("rc.conf: start: %s size:%lu, timeout: %i\n",
           name, strlen(text), timeout);

  r = rc_conf_create(&rc_conf, name, text, timeout, verbose);
  if (r < 0) {
    fprintf(stderr, "error: %s: parse error: %s\n",
            name, strerror(errno));
    return -1;
  }

  sc = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
  if (sc != RTEMS_SUCCESSFUL) {
    fprintf(stderr, "error: %s: get priority: %s\n",
            name, rtems_status_text(sc));
    errno = EIO;
    return -1;
  }

  sc = rtems_task_create(rtems_build_name('B', 'S', 'D', 'r' ),
                         priority,
                         32 * 1024,
                         RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
                         RTEMS_LOCAL | RTEMS_FLOATING_POINT,
                         &worker);
  if (sc != RTEMS_SUCCESSFUL) {
    fprintf (stderr, "error: worker create: %s", rtems_status_text(sc));
    errno = EIO;
    return -1;
  }

  sc = rtems_task_start(worker,
                        rc_conf_worker,
                        (rtems_task_argument) &rc_conf);
  if (sc != RTEMS_SUCCESSFUL) {
    fprintf (stderr, "error: worker start: %s", rtems_status_text(sc));
    errno = EIO;
    return - 1;
  }

  if (timeout >= 0) {
    rtems_event_set out = 0;
    rtems_interval  ticks;

    if (timeout == 0)
      ticks = RTEMS_NO_TIMEOUT;
    else
      ticks = RTEMS_MICROSECONDS_TO_TICKS(timeout * 1000000UL);

    sc = rtems_event_receive(RTEMS_EVENT_1,
                             RTEMS_WAIT | RTEMS_EVENT_ANY,
                             ticks,
                             &out);
    if (sc != RTEMS_SUCCESSFUL) {
      if (sc != RTEMS_TIMEOUT) {
        fprintf (stderr, "error: worker event in: %s", rtems_status_text(sc));
        errno = EIO;
      }
      else {
        lock(&rc_conf);
        rc_conf.waiter = 0;
        unlock(&rc_conf);
        errno = ETIMEDOUT;
      }
      r = -1;
    }
    else {
      lock(&rc_conf);
      errno = rc_conf.error_code;
      if (errno != 0)
        r = -1;
      unlock(&rc_conf);
      rc_conf_destroy(&rc_conf);
    }
  }

  return r;
}
Exemplo n.º 8
0
void rtems_cpu_usage_top_with_plugin(
  const rtems_printer *printer
)
{
  rtems_status_code      sc;
  rtems_task_priority    priority;
  rtems_name             name;
  rtems_id               id;
  rtems_cpu_usage_data   data;
  int                    show_lines = 25;

  memset(&data, 0, sizeof(data));

  data.thread_run = true;
  data.single_page = true;
  data.sort_order = RTEMS_TOP_SORT_CURRENT;
  data.poll_rate_usecs = 3000;
  data.show = show_lines;
  data.printer = printer;

  sc = rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);

  if (sc != RTEMS_SUCCESSFUL)
  {
    rtems_printf (printer,
                  "error: cannot obtain the current priority: %s\n", rtems_status_text (sc));
    return;
  }

  name = rtems_build_name('C', 'P', 'l', 't');

  sc = rtems_task_create (name, priority, 4 * 1024,
                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
                          &id);

  if (sc != RTEMS_SUCCESSFUL)
  {
    rtems_printf (printer,
                  "error: cannot create helper thread: %s\n", rtems_status_text (sc));
    return;
  }

  sc = rtems_task_start (id, rtems_cpuusage_top_thread, (rtems_task_argument) &data);
  if (sc != RTEMS_SUCCESSFUL)
  {
    rtems_printf (printer,
                  "error: cannot start helper thread: %s\n", rtems_status_text (sc));
    rtems_task_delete (id);
    return;
  }

  while (true)
  {
    int c = getchar ();

    if ((c == '\r') || (c == '\n') || (c == 'q') || (c == 'Q'))
    {
      int loops = 50;

      data.thread_run = false;

      rtems_event_send(id, RTEMS_EVENT_1);

      while (loops && data.thread_active)
        rtems_task_wake_after (RTEMS_MICROSECONDS_TO_TICKS (100000));

      rtems_printf (printer, "load monitoring stopped.\n");
      return;
    }
    else if (c == '<')
    {
      if (data.sort_order == 0)
        data.sort_order = RTEMS_TOP_SORT_MAX;
      else
        --data.sort_order;
      rtems_event_send(id, RTEMS_EVENT_1);
    }
    else if (c == '>')
    {
      if (data.sort_order >= RTEMS_TOP_SORT_MAX)
        data.sort_order = 0;
      else
        ++data.sort_order;
      rtems_event_send(id, RTEMS_EVENT_1);
    }
    else if ((c == 's') || (c == 'S'))
    {
      data.single_page = !data.single_page;
      rtems_event_send(id, RTEMS_EVENT_1);
    }
    else if ((c == 'a') || (c == 'A'))
    {
      if (data.show == 0)
        data.show = show_lines;
      else
        data.show = 0;
      rtems_event_send(id, RTEMS_EVENT_1);
    }
    else if (c == '+')
    {
      ++show_lines;
      if (data.show != 0)
        data.show = show_lines;
    }
    else if (c == '-')
    {
      if (show_lines > 5)
        --show_lines;
      if (data.show != 0)
        data.show = show_lines;
    }
    else if (c == ' ')
    {
      rtems_event_send(id, RTEMS_EVENT_1);
    }
  }
}