1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2003. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #include <stdio.h> |
---|
13 | #include <stdlib.h> |
---|
14 | |
---|
15 | #include <bsp.h> |
---|
16 | #include <rtems/score/timespec.h> /* _Timespec_Substract */ |
---|
17 | |
---|
18 | struct timespec start; |
---|
19 | #if defined(INCLUDE_TO_ISR) |
---|
20 | struct timespec to_isr; |
---|
21 | #endif |
---|
22 | struct timespec stop_in_task; |
---|
23 | |
---|
24 | rtems_id semaphore; |
---|
25 | rtems_id task_id; |
---|
26 | |
---|
27 | void irqforce(int); |
---|
28 | |
---|
29 | void ISR( uint32_t arg ) |
---|
30 | { |
---|
31 | rtems_status_code status; |
---|
32 | #if defined(INCLUDE_TO_ISR) |
---|
33 | _TOD_Get( &to_isr ); |
---|
34 | #endif |
---|
35 | status = rtems_semaphore_release( semaphore ); |
---|
36 | } |
---|
37 | |
---|
38 | rtems_task ISR_Task( |
---|
39 | rtems_task_argument argument |
---|
40 | ) |
---|
41 | { |
---|
42 | rtems_status_code status; |
---|
43 | struct timespec diff1, diff2; |
---|
44 | |
---|
45 | #define print_timespec( _t ) \ |
---|
46 | printf ( "%ld:%ld ", (long) _t.tv_sec, (long) _t.tv_nsec ); |
---|
47 | |
---|
48 | /* |
---|
49 | * Print base overhead |
---|
50 | */ |
---|
51 | |
---|
52 | _TOD_Get( &start ); |
---|
53 | _TOD_Get( &stop_in_task ); |
---|
54 | _Timespec_Subtract( &start, &stop_in_task, &diff1 ); |
---|
55 | printf( "Timer Overhead: " ); |
---|
56 | print_timespec( start ); |
---|
57 | print_timespec( stop_in_task ); |
---|
58 | printf( "--> " ); |
---|
59 | print_timespec( diff1 ); |
---|
60 | printf( "\n" ); |
---|
61 | |
---|
62 | while (1) { |
---|
63 | status = rtems_semaphore_obtain( semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
---|
64 | _TOD_Get( &stop_in_task ); |
---|
65 | |
---|
66 | _Timespec_Subtract( &start, &stop_in_task, &diff2 ); |
---|
67 | print_timespec( start ); |
---|
68 | #if defined(INCLUDE_TO_ISR) |
---|
69 | _Timespec_Subtract( &start, &to_isr, &diff1 ); |
---|
70 | print_timespec( to_isr ); |
---|
71 | #endif |
---|
72 | print_timespec( stop_in_task ); |
---|
73 | printf( "--> " ); |
---|
74 | #if defined(INCLUDE_TO_ISR) |
---|
75 | print_timespec( diff1 ); |
---|
76 | #endif |
---|
77 | print_timespec( diff2 ); |
---|
78 | printf( "\n" ); |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | rtems_task Init( |
---|
83 | rtems_task_argument argument |
---|
84 | ) |
---|
85 | { |
---|
86 | rtems_status_code status; |
---|
87 | rtems_time_of_day time; |
---|
88 | int i; |
---|
89 | |
---|
90 | puts( "\n\n*** IRQ FORCE TEST ***" ); |
---|
91 | |
---|
92 | time.year = 2007; |
---|
93 | time.month = 10; |
---|
94 | time.day = 17; |
---|
95 | time.hour = 13; |
---|
96 | time.minute = 45; |
---|
97 | time.second = 0; |
---|
98 | time.ticks = 0; |
---|
99 | |
---|
100 | status = rtems_clock_set( &time ); |
---|
101 | |
---|
102 | /* |
---|
103 | * Create the simple semaphore used to wake us up |
---|
104 | */ |
---|
105 | |
---|
106 | status = rtems_semaphore_create( |
---|
107 | rtems_build_name( 'A', 'I', 'S', 'R' ), |
---|
108 | 0, |
---|
109 | RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_FIFO, |
---|
110 | 0, |
---|
111 | &semaphore |
---|
112 | ); |
---|
113 | |
---|
114 | status = rtems_task_create( |
---|
115 | rtems_build_name( 'A', 'I', 'S', 'R' ), |
---|
116 | 1, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, |
---|
117 | RTEMS_DEFAULT_ATTRIBUTES, &task_id |
---|
118 | ); |
---|
119 | status = rtems_task_start( task_id, ISR_Task, 1 ); |
---|
120 | |
---|
121 | |
---|
122 | /* |
---|
123 | * Now generate the interrupt and time it |
---|
124 | */ |
---|
125 | |
---|
126 | set_vector( ISR, 17, 1 ); |
---|
127 | for ( i=0 ; i<= 10 ; i++ ) { |
---|
128 | sleep(1); |
---|
129 | _TOD_Get( &start ); |
---|
130 | irqforce(1); |
---|
131 | } |
---|
132 | sleep(1); |
---|
133 | |
---|
134 | exit( 0 ); |
---|
135 | } |
---|
136 | |
---|
137 | /**************** START OF CONFIGURATION INFORMATION ****************/ |
---|
138 | |
---|
139 | #define CONFIGURE_INIT |
---|
140 | |
---|
141 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
142 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
143 | |
---|
144 | #define CONFIGURE_MAXIMUM_TASKS 4 |
---|
145 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
146 | |
---|
147 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
148 | #define CONFIGURE_INIT_TASK_PRIORITY 5 |
---|
149 | #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_PREEMPT |
---|
150 | |
---|
151 | #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) |
---|
152 | |
---|
153 | #include <rtems/confdefs.h> |
---|
154 | |
---|
155 | /**************** END OF CONFIGURATION INFORMATION ****************/ |
---|
156 | |
---|