source: rtems/c/src/lib/libcpu/sh/sh7032/score/cpu_asm.c @ 49cdf40

4.115
Last change on this file since 49cdf40 was 49cdf40, checked in by Sebastian Huber <sebastian.huber@…>, on 06/12/13 at 07:25:39

score: Add and use _Thread_Dispatch_is_enabled()

Delete _Thread_Dispatch_in_critical_section() and
_Thread_Is_dispatching_enabled().

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 *  This file contains the basic algorithms for all assembly code used
3 *  in an specific CPU port of RTEMS.  These algorithms must be implemented
4 *  in assembly language
5 *
6 *  NOTE:  This port uses a C file with inline assembler instructions
7 *
8 *  Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
9 *           Bernd Becker (becker@faw.uni-ulm.de)
10 *
11 *  COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
12 *
13 *  This program is distributed in the hope that it will be useful,
14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 *
18 *  COPYRIGHT (c) 1998.
19 *  On-Line Applications Research Corporation (OAR).
20 *
21 *  The license and distribution terms for this file may be
22 *  found in the file LICENSE in this distribution or at
23 *  http://www.rtems.com/license/LICENSE.
24 *
25 */
26
27/*
28 *  This is supposed to be an assembly file.  This means that system.h
29 *  and cpu.h should not be included in a "real" cpu_asm file.  An
30 *  implementation in assembly should include "cpu_asm.h"
31 */
32
33#include <rtems/system.h>
34#include <rtems/score/cpu.h>
35#include <rtems/score/isr.h>
36#include <rtems/score/thread.h>
37#include <rtems/score/sh.h>
38
39#include <rtems/score/ispsh7032.h>
40#include <rtems/score/iosh7032.h>
41#include <rtems/score/sh_io.h>
42
43/* from cpu_isps.c */
44extern proc_ptr         _Hardware_isr_Table[];
45
46#if (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
47  unsigned long    *_old_stack_ptr;
48#endif
49
50register unsigned long  *stack_ptr __asm__ ("r15");
51
52/*
53 * sh_set_irq_priority
54 *
55 * this function sets the interrupt level of the specified interrupt
56 *
57 * parameters:
58 *             - irq : interrupt number
59 *             - prio: priority to set for this interrupt number
60 *
61 * returns:    0 if ok
62 *             -1 on error
63 */
64
65unsigned int sh_set_irq_priority(
66  unsigned int irq,
67  unsigned int prio )
68{
69  uint32_t         shiftcount;
70  uint32_t         prioreg;
71  uint16_t         temp16;
72  ISR_Level        level;
73
74  /*
75   * first check for valid interrupt
76   */
77  if (( irq > 113) || (_Hardware_isr_Table[irq] == _dummy_isp))
78    return -1;
79  /*
80   * check for valid irq priority
81   */
82  if ( prio > 15 )
83    return -1;
84
85  /*
86   * look up appropriate interrupt priority register
87   */
88  if ( irq > 71)
89    {
90      irq = irq - 72;
91      shiftcount = 12 - ((irq & ~0x03) % 16);
92
93      switch( irq / 16)
94        {
95        case 0: { prioreg = INTC_IPRC; break;}
96        case 1: { prioreg = INTC_IPRD; break;}
97        case 2: { prioreg = INTC_IPRE; break;}
98        default: return -1;
99        }
100    }
101  else
102    {
103      shiftcount = 12 - 4 * ( irq % 4);
104      if ( irq > 67)
105        prioreg = INTC_IPRB;
106      else
107        prioreg = INTC_IPRA;
108    }
109
110  /*
111   * Set the interrupt priority register
112   */
113  _ISR_Disable( level );
114
115    temp16 = read16( prioreg);
116    temp16 &= ~( 15 << shiftcount);
117    temp16 |= prio << shiftcount;
118    write16( temp16, prioreg);
119
120  _ISR_Enable( level );
121
122  return 0;
123}
124
125/*
126 *  This routine provides the RTEMS interrupt management.
127 */
128
129void __ISR_Handler( uint32_t   vector)
130{
131  ISR_Level level;
132
133  _ISR_Disable( level );
134
135  _Thread_Dispatch_increment_disable_level();
136
137#if (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
138  if ( _ISR_Nest_level == 0 )
139    {
140      /* Install irq stack */
141      _old_stack_ptr = stack_ptr;
142      stack_ptr = _CPU_Interrupt_stack_high;
143    }
144
145#endif
146
147  _ISR_Nest_level++;
148
149  _ISR_Enable( level );
150
151  /* call isp */
152  if ( _ISR_Vector_table[ vector])
153    (*_ISR_Vector_table[ vector ])( vector );
154
155  _ISR_Disable( level );
156
157  _Thread_Dispatch_decrement_disable_level();
158
159  _ISR_Nest_level--;
160
161#if(CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
162
163  if ( _ISR_Nest_level == 0 )
164    /* restore old stack pointer */
165    stack_ptr = _old_stack_ptr;
166#endif
167
168  _ISR_Enable( level );
169
170  if ( _ISR_Nest_level )
171    return;
172
173  if ( !_Thread_Dispatch_is_enabled() ) {
174    return;
175  }
176
177  if ( _Thread_Dispatch_necessary ) {
178    _Thread_Dispatch();
179  }
180}
Note: See TracBrowser for help on using the repository browser.