Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSImplClassicIntr
0007  *
0008  * @brief This source file contains the rtems_interrupt_handler_install()
0009  *   implementation.
0010  */
0011 
0012 /*
0013  * Copyright (C) 2021 embedded brains GmbH & Co. KG
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #include <bsp/irq-generic.h>
0038 #include <rtems/malloc.h>
0039 
0040 #include <stdlib.h>
0041 
0042 static rtems_status_code bsp_interrupt_handler_do_replace(
0043   rtems_vector_number     vector,
0044   const char             *info,
0045   rtems_interrupt_handler routine,
0046   void                   *arg
0047 )
0048 {
0049   rtems_interrupt_entry  *entry;
0050   rtems_interrupt_entry **unused;
0051 
0052   entry = bsp_interrupt_entry_find( vector, routine, arg, &unused );
0053 
0054   if ( entry == NULL ) {
0055     return RTEMS_UNSATISFIED;
0056   }
0057 
0058   entry->handler = routine;
0059   entry->info = info;
0060 
0061   return RTEMS_SUCCESSFUL;
0062 }
0063 
0064 static rtems_status_code bsp_interrupt_handler_replace(
0065   rtems_vector_number     vector,
0066   const char             *info,
0067   rtems_interrupt_handler routine,
0068   void                   *arg
0069 )
0070 {
0071   rtems_status_code sc;
0072 
0073   sc = bsp_interrupt_check_and_lock( vector, routine );
0074 
0075   if ( sc != RTEMS_SUCCESSFUL ) {
0076     return sc;
0077   }
0078 
0079   sc = bsp_interrupt_handler_do_replace( vector, info, routine, arg );
0080   bsp_interrupt_unlock();
0081 
0082   return sc;
0083 }
0084 
0085 rtems_status_code rtems_interrupt_handler_install(
0086   rtems_vector_number     vector,
0087   const char             *info,
0088   rtems_option            options,
0089   rtems_interrupt_handler routine,
0090   void                   *arg
0091 )
0092 {
0093   rtems_interrupt_entry *entry;
0094   rtems_status_code      sc;
0095 
0096   if ( RTEMS_INTERRUPT_IS_REPLACE( options ) ) {
0097     return bsp_interrupt_handler_replace( vector, info, routine, arg );
0098   }
0099 
0100   entry = rtems_malloc( sizeof( *entry ) );
0101 
0102   if ( entry == NULL ) {
0103     return RTEMS_NO_MEMORY;
0104   }
0105 
0106   rtems_interrupt_entry_initialize( entry, routine, arg, info );
0107   sc = rtems_interrupt_entry_install( vector, options, entry );
0108 
0109   if ( sc != RTEMS_SUCCESSFUL ) {
0110     free( entry );
0111   }
0112 
0113   return sc;
0114 }