1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2009. |
---|
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.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <tmacros.h> |
---|
15 | #include <intrcritical.h> |
---|
16 | |
---|
17 | static uint32_t Maximum; |
---|
18 | static uint32_t Maximum_current; |
---|
19 | static rtems_id Timer; |
---|
20 | static rtems_timer_service_routine (*TSR)( rtems_id, void * ); |
---|
21 | |
---|
22 | static uint32_t interrupt_critical_remaining_units_of_tick( void ) |
---|
23 | { |
---|
24 | uint32_t units = 0; |
---|
25 | rtems_interval initial = rtems_clock_get_ticks_since_boot(); |
---|
26 | |
---|
27 | while ( initial == rtems_clock_get_ticks_since_boot() ) { |
---|
28 | ++units; |
---|
29 | } |
---|
30 | |
---|
31 | return units; |
---|
32 | } |
---|
33 | |
---|
34 | static bool interrupt_critical_busy_wait( void ) |
---|
35 | { |
---|
36 | uint32_t max = Maximum_current; |
---|
37 | uint32_t unit = 0; |
---|
38 | rtems_interval initial = rtems_clock_get_ticks_since_boot(); |
---|
39 | |
---|
40 | while ( unit < max && initial == rtems_clock_get_ticks_since_boot() ) { |
---|
41 | ++unit; |
---|
42 | } |
---|
43 | |
---|
44 | if ( max > 0 ) { |
---|
45 | Maximum_current = max - 1; |
---|
46 | |
---|
47 | return false; |
---|
48 | } else { |
---|
49 | Maximum_current = Maximum; |
---|
50 | |
---|
51 | return true; |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | void interrupt_critical_section_test_support_initialize( |
---|
56 | rtems_timer_service_routine (*tsr)( rtems_id, void * ) |
---|
57 | ) |
---|
58 | { |
---|
59 | Timer = 0; |
---|
60 | TSR = tsr; |
---|
61 | if ( tsr ) { |
---|
62 | rtems_status_code rc; |
---|
63 | |
---|
64 | puts( "Support - rtems_timer_create - creating timer 1" ); |
---|
65 | rc = rtems_timer_create( rtems_build_name( 'T', 'M', '1', ' ' ), &Timer ); |
---|
66 | directive_failed( rc, "rtems_timer_create" ); |
---|
67 | } |
---|
68 | |
---|
69 | /* Wait for tick change */ |
---|
70 | interrupt_critical_remaining_units_of_tick(); |
---|
71 | |
---|
72 | /* Get units for a hole tick */ |
---|
73 | Maximum = interrupt_critical_remaining_units_of_tick(); |
---|
74 | Maximum_current = Maximum; |
---|
75 | |
---|
76 | #if 0 |
---|
77 | printf( "%d 0x%08x units\n", Maximum, Maximum ); |
---|
78 | #endif |
---|
79 | } |
---|
80 | |
---|
81 | bool interrupt_critical_section_test_support_delay(void) |
---|
82 | { |
---|
83 | if (TSR) { |
---|
84 | rtems_status_code rc; |
---|
85 | |
---|
86 | rc = rtems_timer_fire_after( Timer, 1, TSR, NULL ); |
---|
87 | directive_failed( rc, "timer_fire_after failed" ); |
---|
88 | } |
---|
89 | |
---|
90 | return interrupt_critical_busy_wait(); |
---|
91 | } |
---|