Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:52

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  Init
0004  *
0005  *  This routine is the initialization task for this test program.
0006  *  It is called from init_exec and has the responsibility for creating
0007  *  and starting the tasks that make up the test.  If the time of day
0008  *  clock is required for the test, it should also be set to a known
0009  *  value by this function.
0010  *
0011  *  Input parameters:  NONE
0012  *
0013  *  Output parameters:  NONE
0014  *
0015  *  COPYRIGHT (c) 1989-1999.
0016  *  On-Line Applications Research Corporation (OAR).
0017  *
0018  * Redistribution and use in source and binary forms, with or without
0019  * modification, are permitted provided that the following conditions
0020  * are met:
0021  * 1. Redistributions of source code must retain the above copyright
0022  *    notice, this list of conditions and the following disclaimer.
0023  * 2. Redistributions in binary form must reproduce the above copyright
0024  *    notice, this list of conditions and the following disclaimer in the
0025  *    documentation and/or other materials provided with the distribution.
0026  *
0027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0037  * POSSIBILITY OF SUCH DAMAGE.
0038  *
0039  *  OAR init.c Template modified by T. Straumann who provided
0040  *  the implementation of this application.
0041  */
0042 
0043 #define CONFIGURE_INIT
0044 
0045 #include <rtems.h>
0046 
0047 /* functions */
0048 rtems_task Init(
0049   rtems_task_argument argument
0050 );
0051                                                                                                                                                             
0052 /* configuration information */
0053 #include <bsp.h> /* for device driver prototypes */
0054 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
0055 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0056 #define CONFIGURE_MAXIMUM_TASKS            1
0057 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0058 #include <confdefs.h>
0059 
0060 #include <stdio.h>
0061 #include <stdlib.h>
0062 
0063 #include <bsp/irq.h>
0064 #include <rtems/bspIo.h>
0065 
0066 
0067 void noop(){}
0068 int  connected() {return 1;}
0069 
0070 rtems_irq_connect_data blah = { 0, 0, noop, noop, connected };
0071 extern void discovery_pic_set_debug_irq();
0072 
0073 #define WIRE_IRQ (BSP_IRQ_GPP_0 + 6)
0074 #define ABRT_IRQ (BSP_IRQ_GPP_0 + 2)
0075 
0076 static volatile int testno=0;
0077 static volatile int wloops =0;
0078 static volatile int aloops =0;
0079 
0080 void wire_hdl()
0081 {
0082     if ( 1 == testno ) {
0083         BSP_disable_irq_at_pic(WIRE_IRQ);
0084     }
0085 
0086     if ( 2 == testno || 3 == testno ) {
0087         discovery_pic_set_debug_irq(0);
0088         printk("WIRE -- this message should be printed %s\n", 3==testno ? "FIRST":"SECOND");
0089     } else {
0090     }
0091 
0092     /* assume the driver checks for less than 1000 loops */
0093     if ( ++wloops > 1000) {
0094         printk("wire IRQ. FAILURE -- driver couldn't catch runaway ISR. Disabling IRQ source.\n");
0095         discovery_pic_set_debug_irq(0);
0096         BSP_disable_irq_at_pic(WIRE_IRQ);
0097     }
0098     /*
0099     */
0100 }
0101 
0102 void abrt_hdl()
0103 {
0104     aloops++;
0105     if ( 2 == testno || 3 == testno ) {
0106         discovery_pic_set_debug_irq(1);
0107         printk("ABRT -- this message should be printed %s\n", 2==testno ? "FIRST":"SECOND");
0108     } else 
0109         printk("ABRT IRQ\n");
0110 
0111     if ( 1== testno ) {
0112         BSP_enable_irq_at_pic(WIRE_IRQ);
0113     }
0114     BSP_disable_irq_at_pic(ABRT_IRQ);
0115 }
0116 
0117 
0118 rtems_task Init(
0119   rtems_task_argument ignored
0120 )
0121 {
0122   blah.name = WIRE_IRQ;
0123   blah.hdl  = wire_hdl;
0124   if (!BSP_install_rtems_irq_handler(&blah)) {
0125     fprintf(stderr,"installing handler 1 failed\n");
0126   }
0127   blah.name = ABRT_IRQ;
0128   blah.hdl  = abrt_hdl;
0129   if (!BSP_install_rtems_irq_handler(&blah)) {
0130     fprintf(stderr,"installing handler 2 failed\n");
0131   }
0132   printf("Hello, testing the ISR dispatcher...\n");
0133   printf(" 1. Trying to catch runaway interrupt\n");
0134   printf("    If the system freezes, the test failed!\n");
0135   fflush(stdout); sleep(1);
0136   aloops = wloops = 0;
0137   discovery_pic_set_debug_irq(1);
0138   printf("    >>> %s\n", wloops<1000 ? "SUCCESS" : "FAILED");
0139   discovery_pic_set_debug_irq(0);
0140 
0141   testno++;
0142   printf(" 2. Testing enabling / disabling interrupt from ISR\n");
0143   printf("    Hit the ABORT key for this test\n");
0144   fflush(stdout); sleep(1);
0145   aloops = wloops = 0;
0146   BSP_disable_irq_at_pic(WIRE_IRQ);
0147   BSP_irq_set_priority(ABRT_IRQ,1);
0148   BSP_enable_irq_at_pic(ABRT_IRQ);
0149   discovery_pic_set_debug_irq(1);
0150   while (!aloops)
0151     ;
0152   discovery_pic_set_debug_irq(0);
0153   sleep(2);
0154   printf("    >>> disabling ABRT IRQ from isr %s\n", 1==aloops ? "SUCCESS":"FAILURE");
0155   printf("        flashing  WIRE IRQ from isr %s\n", 1==wloops ? "SUCCESS":"FAILURE");
0156 
0157   
0158   testno++;
0159   printf(" 3. Testing interrupt priorities\n");
0160   BSP_irq_set_priority(ABRT_IRQ,2);
0161   BSP_irq_set_priority(WIRE_IRQ,2);
0162   BSP_enable_irq_at_pic(ABRT_IRQ);
0163   BSP_enable_irq_at_pic(WIRE_IRQ);
0164   printf("    Hit the ABORT key for this test\n");
0165   fflush(stdout); sleep(1);
0166   aloops = wloops = 0;
0167   while (!aloops)
0168     ;
0169   sleep(2);
0170   testno++;
0171   printf("    Now we are raising the priority of the wire interrupt\n");
0172   BSP_irq_set_priority(WIRE_IRQ,3);
0173   BSP_enable_irq_at_pic(ABRT_IRQ);
0174   printf("    Hit the ABORT key for this test\n");
0175   fflush(stdout); sleep(1);
0176   aloops = wloops = 0;
0177   while (!aloops)
0178     ;
0179 
0180   sleep(2);
0181   printf( "That's it; we're done...\n" );
0182   exit( 0 );
0183 }