OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [psxtests/] [psx11/] [task.c] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*  Task_1
2
 *
3
 *  This routine serves as a test task.  It verifies the basic task
4
 *  switching capabilities of the executive.
5
 *
6
 *  Input parameters:
7
 *    argument - task argument
8
 *
9
 *  Output parameters:  NONE
10
 *
11
 *  COPYRIGHT (c) 1989-1999.
12
 *  On-Line Applications Research Corporation (OAR).
13
 *
14
 *  The license and distribution terms for this file may be
15
 *  found in the file LICENSE in this distribution or at
16
 *  http://www.OARcorp.com/rtems/license.html.
17
 *
18
 *  task.c,v 1.5 1999/11/17 17:51:31 joel Exp
19
 */
20
 
21
#include "system.h"
22
#include <time.h>
23
#include <sched.h>
24
 
25
void diff_timespec(
26
  struct timespec *start,
27
  struct timespec *stop,
28
  struct timespec *result
29
)
30
{
31
   int nsecs_per_sec = 1000000000;
32
 
33
   result->tv_sec = stop->tv_sec - start->tv_sec;
34
   if ( stop->tv_nsec < start->tv_nsec ) {
35
      result->tv_nsec = nsecs_per_sec - start->tv_nsec + stop->tv_nsec;
36
      result->tv_sec--;
37
   } else
38
      result->tv_nsec = stop->tv_nsec - start->tv_nsec;
39
 
40
}
41
 
42
void *Task_1(
43
  void *argument
44
)
45
{
46
  int status;
47
  struct timespec start;
48
  struct timespec current;
49
  struct timespec difference;
50
  struct timespec delay;
51
 
52
  status = clock_gettime( CLOCK_REALTIME, &start );
53
  assert( !status );
54
 
55
  status = sched_rr_get_interval( getpid(), &delay );
56
  assert( !status );
57
 
58
  /* double the rr interval for confidence */
59
 
60
  delay.tv_sec *= 2;
61
  delay.tv_nsec *= 2;
62
  if ( delay.tv_nsec >= 1000000000 ) {   /* handle overflow/carry */
63
    delay.tv_nsec -= 1000000000;
64
    delay.tv_sec++;
65
  }
66
 
67
 
68
  puts( "Task_1: killing time" );
69
  for ( ; ; ) {
70
 
71
    status = clock_gettime( CLOCK_REALTIME, &current );
72
    assert( !status );
73
 
74
    diff_timespec( &start, &current, &difference );
75
 
76
    if ( difference.tv_sec < delay.tv_sec )
77
      continue;
78
 
79
    if ( difference.tv_sec > delay.tv_sec )
80
      break;
81
 
82
    if ( difference.tv_nsec > delay.tv_nsec )
83
      break;
84
 
85
  }
86
 
87
  puts( "Task_1: exitting" );
88
  pthread_exit( NULL );
89
 
90
  return NULL; /* just so the compiler thinks we returned something */
91
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.