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
|
/*
* COPYRIGHT (c) 1989-2009.
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tmacros.h>
#include <intrcritical.h>
static uint32_t Maximum;
static uint32_t Maximum_current;
static rtems_id Timer;
static rtems_timer_service_routine (*TSR)( rtems_id, void * );
static uint32_t interrupt_critical_remaining_units_of_tick( void )
{
uint32_t units = 0;
rtems_interval initial = rtems_clock_get_ticks_since_boot();
while ( initial == rtems_clock_get_ticks_since_boot() ) {
++units;
}
return units;
}
static bool interrupt_critical_busy_wait( void )
{
uint32_t max = Maximum_current;
uint32_t unit = 0;
rtems_interval initial = rtems_clock_get_ticks_since_boot();
while ( unit < max && initial == rtems_clock_get_ticks_since_boot() ) {
++unit;
}
if ( max > 0 ) {
Maximum_current = max - 1;
return false;
} else {
Maximum_current = Maximum;
return true;
}
}
void interrupt_critical_section_test_support_initialize(
rtems_timer_service_routine (*tsr)( rtems_id, void * )
)
{
Timer = 0;
TSR = tsr;
if ( tsr ) {
rtems_status_code rc;
puts( "Support - rtems_timer_create - creating timer 1" );
rc = rtems_timer_create( rtems_build_name( 'T', 'M', '1', ' ' ), &Timer );
directive_failed( rc, "rtems_timer_create" );
}
/* Wait for tick change */
interrupt_critical_remaining_units_of_tick();
/* Get units for a hole tick */
Maximum = interrupt_critical_remaining_units_of_tick();
Maximum_current = Maximum;
#if 0
printf( "%d 0x%08x units\n", Maximum, Maximum );
#endif
}
bool interrupt_critical_section_test_support_delay(void)
{
if (TSR) {
rtems_status_code rc;
rc = rtems_timer_fire_after( Timer, 1, TSR, NULL );
directive_failed( rc, "timer_fire_after failed" );
}
return interrupt_critical_busy_wait();
}
|