Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:45

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  Classic API Signal to Task from ISR
0005  *
0006  *  COPYRIGHT (c) 1989-2009.
0007  *  On-Line Applications Research Corporation (OAR).
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions
0011  * are met:
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions and the following disclaimer.
0014  * 2. Redistributions in binary form must reproduce the above copyright
0015  *    notice, this list of conditions and the following disclaimer in the
0016  *    documentation and/or other materials provided with the distribution.
0017  *
0018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0028  * POSSIBILITY OF SUCH DAMAGE.
0029  */
0030 
0031 #ifdef HAVE_CONFIG_H
0032 #include "config.h"
0033 #endif
0034 
0035 #define CONFIGURE_INIT
0036 #include "system.h"
0037 
0038 const char rtems_test_name[] = "SP 38";
0039 
0040 volatile bool signal_sent;
0041 volatile bool signal_processed;
0042 
0043 rtems_id main_task;
0044 void signal_handler(rtems_signal_set signals);
0045 rtems_timer_service_routine test_signal_from_isr(
0046   rtems_id  timer,
0047   void     *arg
0048 );
0049 
0050 void signal_handler(
0051   rtems_signal_set signals
0052 )
0053 {
0054   signal_processed = TRUE;
0055 }
0056 
0057 rtems_timer_service_routine test_signal_from_isr(
0058   rtems_id  timer,
0059   void     *arg
0060 )
0061 {
0062   rtems_status_code     status;
0063 
0064   status = rtems_signal_send( main_task, 0x0a0b0c0d );
0065   directive_failed_with_level( status, "rtems_signal_send", 1 );
0066 
0067   signal_sent = TRUE;
0068 }
0069 
0070 rtems_task Init(
0071   rtems_task_argument argument
0072 )
0073 {
0074   rtems_status_code     status;
0075   rtems_id              timer;
0076   rtems_interval        start;
0077   rtems_interval        now;
0078 
0079   TEST_BEGIN();
0080 
0081   main_task = rtems_task_self();
0082 
0083   /*
0084    *  Timer used in multiple ways
0085    */
0086   status = rtems_timer_create( 1, &timer );
0087   directive_failed( status, "rtems_timer_create" );
0088 
0089   /*
0090    *  Get starting time
0091    */
0092   start = rtems_clock_get_ticks_since_boot();
0093 
0094   status = rtems_signal_catch( signal_handler, RTEMS_DEFAULT_MODES );
0095   directive_failed( status, "rtems_signal_catch" );
0096   puts( "rtems_signal_catch - handler installed" );
0097 
0098   /*
0099    * Test Signal from ISR
0100    */
0101   signal_sent = FALSE;
0102 
0103   status = rtems_timer_fire_after( timer, 10, test_signal_from_isr, NULL );
0104   directive_failed( status, "timer_fire_after failed" );
0105 
0106   while (1) {
0107     now = rtems_clock_get_ticks_since_boot();
0108     if ( (now-start) > 100 ) {
0109       puts( "Signal from ISR did not get processed\n" );
0110       rtems_test_exit( 0 );
0111     }
0112     if ( signal_processed )
0113       break;
0114   }
0115 
0116   puts( "Signal sent from ISR has been processed" );
0117   TEST_END();
0118   rtems_test_exit( 0 );
0119 }