Ticket #1868: lm32irq.diff

File lm32irq.diff, 3.4 KB (added by Sebastien Bourdeauducq, on 08/01/11 at 09:09:09)

patch

  • cpukit/score/cpu/lm32/irq.c

    commit e0d4d55f693886b991c1b35b53091d005cea8cf5
    Author: Sebastien Bourdeauducq <sebastien@milkymist.org>
    Date:   Sat Jul 30 17:13:51 2011 +0200
    
        new LM32 interrupt handler (based on NIOS)
    
    diff --git a/cpukit/score/cpu/lm32/irq.c b/cpukit/score/cpu/lm32/irq.c
    index 0bf648d..d07d7cf 100644
    a b  
    11/*
    2  *  lm32 interrupt handler
     2 *  lm32 exception and interrupt handler
    33 *
    44 *  Derived from c4x/irq.c and nios2/irq.c
    55 *
    6  *  COPYRIGHT (c) 1989-2009.
     6 *  COPYRIGHT (c) 1989-2007.
    77 *  On-Line Applications Research Corporation (OAR).
    88 *
    99 *  The license and distribution terms for this file may be
    1010 *  found in the file LICENSE in this distribution or at
    1111 *  http://www.rtems.com/license/LICENSE.
    1212 *
    13  *  $Id: irq.c,v 1.8 2011/04/21 19:05:14 jennifer Exp $
     13 *  $Id: irq.c,v 1.9 2011/04/21 19:05:14 jennifer Exp $
    1414 */
    1515
    1616#ifdef HAVE_CONFIG_H
     
    1919
    2020#include <rtems/system.h>
    2121#include <rtems/score/cpu.h>
    22 #include <rtems/score/thread.h>
    2322#include <rtems/score/isr.h>
    24 #include <rtems/score/percpu.h>
     23#include <rtems/score/thread.h>
    2524
    2625/*
    2726 *  This routine provides the RTEMS interrupt management.
     
    2928 *  Upon entry, interrupts are disabled
    3029 */
    3130
    32 #if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
    33   unsigned long    *_old_stack_ptr;
    34 #endif
     31unsigned long    *_old_stack_ptr;
    3532
    3633void *_exception_stack_frame;
    3734
    void __ISR_Handler(uint32_t vector, CPU_Interrupt_frame *ifr) 
    4441
    4542  /* Interrupts are disabled upon entry to this Handler */
    4643
    47   _Thread_Dispatch_increment_disable_level();
    48 
    49 #if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
    5044  if ( _ISR_Nest_level == 0 ) {
    5145    /* Install irq stack */
    5246    _old_stack_ptr = stack_ptr;
    5347    stack_ptr = _CPU_Interrupt_stack_high - 4;
    5448  }
    55 #endif
    5649
    5750  _ISR_Nest_level++;
    5851
     52  _Thread_Dispatch_increment_disable_level();
     53
    5954  if ( _ISR_Vector_table[ vector] )
    6055  {
    6156    (*_ISR_Vector_table[ vector ])(vector, ifr);
    void __ISR_Handler(uint32_t vector, CPU_Interrupt_frame *ifr) 
    6459  /* Make sure that interrupts are disabled again */
    6560  _CPU_ISR_Disable( level );
    6661
     62  _Thread_Dispatch_decrement_disable_level();
     63
    6764  _ISR_Nest_level--;
    6865
    69 #if( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
    70   if( _ISR_Nest_level == 0)
     66  if( _ISR_Nest_level == 0) {
    7167    stack_ptr = _old_stack_ptr;
    72 #endif
    7368
    74   _Thread_Dispatch_decrement_disable_level();
     69    if( !_Thread_Dispatch_in_critical_section() )
     70    {
     71      if ( _Thread_Dispatch_necessary ) {
     72        _CPU_ISR_Enable( level );
     73        /* save off our stack frame so the context switcher can get to it */
     74        _exception_stack_frame = ifr;
     75        _Thread_Dispatch();
     76        /* and make sure its clear in case we didn't dispatch. if we did, its
     77         * already cleared */
     78        _exception_stack_frame = NULL;
     79        /* may have switched to another task and not return here immed. */
     80        _CPU_ISR_Disable( level ); /* Keep _pairs_ of Enable/Disable */
     81      }
     82    }
     83  }
    7584
    7685  _CPU_ISR_Enable( level );
    77 
    78   if ( _ISR_Nest_level )
    79     return;
    80 
    81   if ( _Thread_Dispatch_necessary ) {
    82 
    83     /* save off our stack frame so the context switcher can get to it */
    84     _exception_stack_frame = ifr;
    85 
    86     _Thread_Dispatch();
    87 
    88     /* and make sure its clear in case we didn't dispatch. if we did, its
    89      * already cleared */
    90     _exception_stack_frame = NULL;
    91   }
    9286}
    93