1 | /* |
---|
2 | * Classic API Signal to Task from ISR |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2009. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.org/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #define CONFIGURE_INIT |
---|
17 | #include "system.h" |
---|
18 | |
---|
19 | const char rtems_test_name[] = "SP 38"; |
---|
20 | |
---|
21 | volatile bool signal_sent; |
---|
22 | volatile bool signal_processed; |
---|
23 | |
---|
24 | rtems_id main_task; |
---|
25 | void signal_handler(rtems_signal_set signals); |
---|
26 | rtems_timer_service_routine test_signal_from_isr( |
---|
27 | rtems_id timer, |
---|
28 | void *arg |
---|
29 | ); |
---|
30 | |
---|
31 | void signal_handler( |
---|
32 | rtems_signal_set signals |
---|
33 | ) |
---|
34 | { |
---|
35 | signal_processed = TRUE; |
---|
36 | } |
---|
37 | |
---|
38 | rtems_timer_service_routine test_signal_from_isr( |
---|
39 | rtems_id timer, |
---|
40 | void *arg |
---|
41 | ) |
---|
42 | { |
---|
43 | rtems_status_code status; |
---|
44 | |
---|
45 | status = rtems_signal_send( main_task, 0x0a0b0c0d ); |
---|
46 | directive_failed_with_level( status, "rtems_signal_send", 1 ); |
---|
47 | |
---|
48 | signal_sent = TRUE; |
---|
49 | } |
---|
50 | |
---|
51 | rtems_task Init( |
---|
52 | rtems_task_argument argument |
---|
53 | ) |
---|
54 | { |
---|
55 | rtems_status_code status; |
---|
56 | rtems_id timer; |
---|
57 | rtems_interval start; |
---|
58 | rtems_interval now; |
---|
59 | |
---|
60 | TEST_BEGIN(); |
---|
61 | |
---|
62 | main_task = rtems_task_self(); |
---|
63 | |
---|
64 | /* |
---|
65 | * Timer used in multiple ways |
---|
66 | */ |
---|
67 | status = rtems_timer_create( 1, &timer ); |
---|
68 | directive_failed( status, "rtems_timer_create" ); |
---|
69 | |
---|
70 | /* |
---|
71 | * Get starting time |
---|
72 | */ |
---|
73 | start = rtems_clock_get_ticks_since_boot(); |
---|
74 | |
---|
75 | status = rtems_signal_catch( signal_handler, RTEMS_DEFAULT_MODES ); |
---|
76 | directive_failed( status, "rtems_signal_catch" ); |
---|
77 | puts( "rtems_signal_catch - handler installed" ); |
---|
78 | |
---|
79 | /* |
---|
80 | * Test Signal from ISR |
---|
81 | */ |
---|
82 | signal_sent = FALSE; |
---|
83 | |
---|
84 | status = rtems_timer_fire_after( timer, 10, test_signal_from_isr, NULL ); |
---|
85 | directive_failed( status, "timer_fire_after failed" ); |
---|
86 | |
---|
87 | while (1) { |
---|
88 | now = rtems_clock_get_ticks_since_boot(); |
---|
89 | if ( (now-start) > 100 ) { |
---|
90 | puts( "Signal from ISR did not get processed\n" ); |
---|
91 | rtems_test_exit( 0 ); |
---|
92 | } |
---|
93 | if ( signal_processed ) |
---|
94 | break; |
---|
95 | } |
---|
96 | |
---|
97 | puts( "Signal sent from ISR has been processed" ); |
---|
98 | TEST_END(); |
---|
99 | rtems_test_exit( 0 ); |
---|
100 | } |
---|