summaryrefslogtreecommitdiff
path: root/irq_test_c/init.c
blob: a67235e0f038ac677d5777e3af0c81dd20031395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 *  COPYRIGHT (c) 1989-2003.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 *
 *  $Id$
 */

#include <stdio.h>
#include <stdlib.h>

#include <bsp.h>
#include <rtems/score/timespec.h> /* _Timespec_Substract */

struct timespec start;
#if defined(INCLUDE_TO_ISR)
  struct timespec to_isr;
#endif
struct timespec stop_in_task;

rtems_id semaphore;
rtems_id task_id;

void irqforce(int);

void ISR( uint32_t arg )
{
  rtems_status_code status;
  #if defined(INCLUDE_TO_ISR)
    _TOD_Get( &to_isr );
  #endif
  status = rtems_semaphore_release( semaphore );
}

rtems_task ISR_Task(
  rtems_task_argument argument
)
{
  rtems_status_code status;
  struct timespec diff1, diff2;

  #define print_timespec( _t ) \
    printf ( "%ld:%ld ", (long) _t.tv_sec, (long) _t.tv_nsec );

  /*
   * Print base overhead
   */

  _TOD_Get( &start );
  _TOD_Get( &stop_in_task );
  _Timespec_Subtract( &start, &stop_in_task, &diff1 );
  printf( "Timer Overhead: " );
  print_timespec( start );
  print_timespec( stop_in_task );
  printf( "--> " );
  print_timespec( diff1 );
  printf( "\n" );

  while (1) {
    status = rtems_semaphore_obtain( semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
    _TOD_Get( &stop_in_task );
    
    _Timespec_Subtract( &start, &stop_in_task, &diff2 );
    print_timespec( start );
    #if defined(INCLUDE_TO_ISR)
      _Timespec_Subtract( &start, &to_isr, &diff1 );
      print_timespec( to_isr );
    #endif
    print_timespec( stop_in_task );
    printf( "--> " );
    #if defined(INCLUDE_TO_ISR)
      print_timespec( diff1 );
    #endif
    print_timespec( diff2 );
    printf( "\n" );
  }
}

rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code status;
  rtems_time_of_day time;
  int i;

  puts( "\n\n*** IRQ FORCE TEST ***" );

  time.year   = 2007;
  time.month  = 10;
  time.day    = 17;
  time.hour   = 13;
  time.minute = 45;
  time.second = 0;
  time.ticks  = 0;

  status = rtems_clock_set( &time );

  /*
   * Create the simple semaphore used to wake us up
   */

  status = rtems_semaphore_create(
    rtems_build_name( 'A', 'I', 'S', 'R' ),
    0,
    RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_FIFO,
    0,
    &semaphore
  );

  status = rtems_task_create(
    rtems_build_name( 'A', 'I', 'S', 'R' ),
    1, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES, &task_id
  );
  status = rtems_task_start( task_id, ISR_Task, 1 );


  /*
   *  Now generate the interrupt and time it
   */

  set_vector( ISR, 17, 1 );
  for ( i=0 ; i<= 10 ; i++ ) {
    sleep(1);
    _TOD_Get( &start );
    irqforce(1);
  }
  sleep(1);

  exit( 0 );
}

/**************** START OF CONFIGURATION INFORMATION ****************/

#define CONFIGURE_INIT

#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

#define CONFIGURE_MAXIMUM_TASKS             4
#define CONFIGURE_MAXIMUM_SEMAPHORES        1

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT_TASK_PRIORITY        5
#define CONFIGURE_INIT_TASK_INITIAL_MODES   RTEMS_PREEMPT

#define CONFIGURE_EXTRA_TASK_STACKS         (3 * RTEMS_MINIMUM_STACK_SIZE)

#include <rtems/confdefs.h>

/****************  END OF CONFIGURATION INFORMATION  ****************/