source: rtems/c/src/lib/libcpu/powerpc/new-exceptions/bspsupport/nested_irq_test.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Test nested interrupts.
3 *
4 * Author: Till Straumann <strauman@slac.stanford.edu>, 2007
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *  http://www.rtems.org/license/LICENSE.
9 */
10
11
12/*
13 * Needs board with 2 available openpic timers
14 *
15 * 'timer_instdis(timer, install, period)'
16 *
17 * installs 'timer_isr' to openpic timer # 'timer'.
18 * The interrupt priority is set to 8 + timer#
19 *
20 * The timer_isr prints a message then polls
21 * the variable 'timer_poll' while it has the value
22 * of the timer # then sets it to -1 and prints
23 * the 'leave' message.
24 *
25 * To test nested interrupts:
26 *
27 *  timer_instdis(0, 1, period)
28 *  wait_a_bit()
29 *  timer_instdis(1, 1, period)
30 *  timer_poll = 0;
31 *
32 *  As soon as timer 0's IRQ fires the
33 *  isr prints
34 *     TIMER ISR (0) ...
35 *  then starts polling (since timer_poll == 0 )
36 *  eventually, timer 1 goes off, interrupts (because
37 *  it's priority is 9 (i.e., higher than timer 0's priority)
38 *  and prints
39 *     TIMER ISR (1)
40 *  it skips polling since timer_poll is 0, not 1 but
41 *  resets timer_poll -1 and prints
42 *     Leaving ISR (1)
43 *  timer 0 isr resumes polling and finds timer_poll == -1
44 *  so it also writes -1 to timer_poll and exits, printing
45 *     Leaving ISR (0)
46 *
47 *  The timer IRQs can be unhooked with
48 *     timer_instdis( 0, 0, period );
49 *     timer_instdis( 1, 0, period );
50 */
51#include <rtems.h>
52#include <rtems/bspIo.h>
53#include <bsp/openpic.h>
54#include <bsp/irq.h>
55#include <inttypes.h>
56#include <stdio.h>
57
58volatile int timer_poll=-1;
59
60static void timer_isr(rtems_irq_hdl_param p)
61{
62uint32_t top;
63uint32_t r1;
64uint32_t lat = (OpenPIC->Global.Timer[(int)p].Current_Count & 0x7fffffff);
65
66        lat = OpenPIC->Global.Timer[(int)p].Base_Count - lat;
67
68        asm volatile("mfspr %0, %2; mr %1, 1":"=r"(top),"=r"(r1):"i"(SPRG1));
69        printk("Timer ISR (%i): LAT: 0x%08x, TOP 0x%08x, BOT 0x%08x, SP 0x%08x\n",
70                (int)p, lat, top, top-rtems_configuration_get_interrupt_stack_size(), r1);
71        printk("_ISR_Nest_level %i\n", _ISR_Nest_level);
72        while ( timer_poll == (int)p )
73                ;
74        timer_poll = -1;
75
76        printk("Leaving ISR (%i)\n",(int)p);
77}
78
79int timer_instdis(int t, int inst, unsigned period)
80{
81rtems_irq_connect_data xx;
82        xx.name   = BSP_MISC_IRQ_LOWEST_OFFSET + t;
83        xx.hdl    = timer_isr;
84        xx.handle = (rtems_irq_hdl_param)t;
85        xx.on     = 0;
86        xx.off    = 0;
87        xx.isOn   = 0;
88        if ( !inst ) {
89                openpic_maptimer(t, 0);
90                openpic_inittimer(t, 0, 0);
91        }
92        if ( ! ( inst ? BSP_install_rtems_irq_handler(&xx) : BSP_remove_rtems_irq_handler(&xx) ) ) {
93                openpic_maptimer(t, 0);
94                openpic_inittimer(t, 0, 0);
95                fprintf(stderr,"unable to %s timer ISR #%i\n", inst ? "install" : "remove", t);
96                return -1;
97        }
98        if ( inst ) {
99                openpic_maptimer( t, 1 );
100                openpic_inittimer( t, 8 + t, OPENPIC_VEC_SOURCE - BSP_PCI_IRQ_LOWEST_OFFSET + xx.name );
101                openpic_settimer( t, period, 1 );
102        }
103        return 0;
104}
105
Note: See TracBrowser for help on using the repository browser.