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

4.104.114.95
Last change on this file since 94e1931c was 94e1931c, checked in by Till Straumann <strauman@…>, on 12/08/07 at 23:43:24

2007-12-08 Till Straumann <strauman@…>

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