OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Source/] [portable/] [GCC/] [STR75x/] [portISR.c] - Blame information for rev 665

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 572 jeremybenn
/*
2
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
3
 
4
    ***************************************************************************
5
    *                                                                         *
6
    * If you are:                                                             *
7
    *                                                                         *
8
    *    + New to FreeRTOS,                                                   *
9
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
10
    *    + Looking for basic training,                                        *
11
    *    + Wanting to improve your FreeRTOS skills and productivity           *
12
    *                                                                         *
13
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
14
    *                                                                         *
15
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
16
    *                  http://www.FreeRTOS.org/Documentation                  *
17
    *                                                                         *
18
    * A pdf reference manual is also available.  Both are usually delivered   *
19
    * to your inbox within 20 minutes to two hours when purchased between 8am *
20
    * and 8pm GMT (although please allow up to 24 hours in case of            *
21
    * exceptional circumstances).  Thank you for your support!                *
22
    *                                                                         *
23
    ***************************************************************************
24
 
25
    This file is part of the FreeRTOS distribution.
26
 
27
    FreeRTOS is free software; you can redistribute it and/or modify it under
28
    the terms of the GNU General Public License (version 2) as published by the
29
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30
    ***NOTE*** The exception to the GPL is included to allow you to distribute
31
    a combined work that includes FreeRTOS without being obliged to provide the
32
    source code for proprietary components outside of the FreeRTOS kernel.
33
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36
    more details. You should have received a copy of the GNU General Public
37
    License and the FreeRTOS license exception along with FreeRTOS; if not it
38
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
39
    by writing to Richard Barry, contact details for whom are available on the
40
    FreeRTOS WEB site.
41
 
42
    1 tab == 4 spaces!
43
 
44
    http://www.FreeRTOS.org - Documentation, latest information, license and
45
    contact details.
46
 
47
    http://www.SafeRTOS.com - A version that is certified for use in safety
48
    critical systems.
49
 
50
    http://www.OpenRTOS.com - Commercial support, development, porting,
51
    licensing and training services.
52
*/
53
 
54
 
55
/*-----------------------------------------------------------
56
 * Components that can be compiled to either ARM or THUMB mode are
57
 * contained in port.c  The ISR routines, which can only be compiled
58
 * to ARM mode, are contained in this file.
59
 *----------------------------------------------------------*/
60
 
61
/*
62
*/
63
 
64
/* Scheduler includes. */
65
#include "FreeRTOS.h"
66
#include "task.h"
67
 
68
/* Constants required to handle critical sections. */
69
#define portNO_CRITICAL_NESTING         ( ( unsigned long ) 0 )
70
 
71
volatile unsigned long ulCriticalNesting = 9999UL;
72
 
73
/*-----------------------------------------------------------*/
74
 
75
/*
76
 * The scheduler can only be started from ARM mode, hence the inclusion of this
77
 * function here.
78
 */
79
void vPortISRStartFirstTask( void );
80
/*-----------------------------------------------------------*/
81
 
82
void vPortISRStartFirstTask( void )
83
{
84
        /* Simply start the scheduler.  This is included here as it can only be
85
        called from ARM mode. */
86
        asm volatile (                                                                                                          \
87
        "LDR            R0, =pxCurrentTCB                                                               \n\t"   \
88
        "LDR            R0, [R0]                                                                                \n\t"   \
89
        "LDR            LR, [R0]                                                                                \n\t"   \
90
                                                                                                                                                \
91
        /* The critical nesting depth is the first item on the stack. */        \
92
        /* Load it into the ulCriticalNesting variable. */                                      \
93
        "LDR            R0, =ulCriticalNesting                                                  \n\t"   \
94
        "LDMFD  LR!, {R1}                                                                                       \n\t"   \
95
        "STR            R1, [R0]                                                                                \n\t"   \
96
                                                                                                                                                \
97
        /* Get the SPSR from the stack. */                                                                      \
98
        "LDMFD  LR!, {R0}                                                                                       \n\t"   \
99
        "MSR            SPSR, R0                                                                                \n\t"   \
100
                                                                                                                                                \
101
        /* Restore all system mode registers for the task. */                           \
102
        "LDMFD  LR, {R0-R14}^                                                                           \n\t"   \
103
        "NOP                                                                                                            \n\t"   \
104
                                                                                                                                                \
105
        /* Restore the return address. */                                                                       \
106
        "LDR            LR, [LR, #+60]                                                                  \n\t"   \
107
                                                                                                                                                \
108
        /* And return - correcting the offset in the LR to obtain the */        \
109
        /* correct address. */                                                                                          \
110
        "SUBS PC, LR, #4                                                                                        \n\t"   \
111
        );
112
}
113
/*-----------------------------------------------------------*/
114
 
115
void vPortTickISR( void )
116
{
117
        /* Increment the RTOS tick count, then look for the highest priority
118
        task that is ready to run. */
119
        vTaskIncrementTick();
120
 
121
        #if configUSE_PREEMPTION == 1
122
                vTaskSwitchContext();
123
        #endif
124
 
125
        /* Ready for the next interrupt. */
126
        TB_ClearITPendingBit( TB_IT_Update );
127
}
128
 
129
/*-----------------------------------------------------------*/
130
 
131
/*
132
 * The interrupt management utilities can only be called from ARM mode.  When
133
 * THUMB_INTERWORK is defined the utilities are defined as functions here to
134
 * ensure a switch to ARM mode.  When THUMB_INTERWORK is not defined then
135
 * the utilities are defined as macros in portmacro.h - as per other ports.
136
 */
137
#ifdef THUMB_INTERWORK
138
 
139
        void vPortDisableInterruptsFromThumb( void ) __attribute__ ((naked));
140
        void vPortEnableInterruptsFromThumb( void ) __attribute__ ((naked));
141
 
142
        void vPortDisableInterruptsFromThumb( void )
143
        {
144
                asm volatile (
145
                        "STMDB  SP!, {R0}               \n\t"   /* Push R0.                                                                     */
146
                        "MRS    R0, CPSR                \n\t"   /* Get CPSR.                                                            */
147
                        "ORR    R0, R0, #0xC0   \n\t"   /* Disable IRQ, FIQ.                                            */
148
                        "MSR    CPSR, R0                \n\t"   /* Write back modified value.                           */
149
                        "LDMIA  SP!, {R0}               \n\t"   /* Pop R0.                                                                      */
150
                        "BX             R14" );                                 /* Return back to thumb.                                        */
151
        }
152
 
153
        void vPortEnableInterruptsFromThumb( void )
154
        {
155
                asm volatile (
156
                        "STMDB  SP!, {R0}               \n\t"   /* Push R0.                                                                     */
157
                        "MRS    R0, CPSR                \n\t"   /* Get CPSR.                                                            */
158
                        "BIC    R0, R0, #0xC0   \n\t"   /* Enable IRQ, FIQ.                                                     */
159
                        "MSR    CPSR, R0                \n\t"   /* Write back modified value.                           */
160
                        "LDMIA  SP!, {R0}               \n\t"   /* Pop R0.                                                                      */
161
                        "BX             R14" );                                 /* Return back to thumb.                                        */
162
        }
163
 
164
#endif /* THUMB_INTERWORK */
165
/*-----------------------------------------------------------*/
166
 
167
void vPortEnterCritical( void )
168
{
169
        /* Disable interrupts as per portDISABLE_INTERRUPTS();                                                  */
170
        asm volatile (
171
                "STMDB  SP!, {R0}                       \n\t"   /* Push R0.                                                             */
172
                "MRS    R0, CPSR                        \n\t"   /* Get CPSR.                                                    */
173
                "ORR    R0, R0, #0xC0           \n\t"   /* Disable IRQ, FIQ.                                    */
174
                "MSR    CPSR, R0                        \n\t"   /* Write back modified value.                   */
175
                "LDMIA  SP!, {R0}" );                           /* Pop R0.                                                              */
176
 
177
        /* Now interrupts are disabled ulCriticalNesting can be accessed
178
        directly.  Increment ulCriticalNesting to keep a count of how many times
179
        portENTER_CRITICAL() has been called. */
180
        ulCriticalNesting++;
181
}
182
/*-----------------------------------------------------------*/
183
 
184
void vPortExitCritical( void )
185
{
186
        if( ulCriticalNesting > portNO_CRITICAL_NESTING )
187
        {
188
                /* Decrement the nesting count as we are leaving a critical section. */
189
                ulCriticalNesting--;
190
 
191
                /* If the nesting level has reached zero then interrupts should be
192
                re-enabled. */
193
                if( ulCriticalNesting == portNO_CRITICAL_NESTING )
194
                {
195
                        /* Enable interrupts as per portEXIT_CRITICAL().                                        */
196
                        asm volatile (
197
                                "STMDB  SP!, {R0}               \n\t"   /* Push R0.                                             */
198
                                "MRS    R0, CPSR                \n\t"   /* Get CPSR.                                    */
199
                                "BIC    R0, R0, #0xC0   \n\t"   /* Enable IRQ, FIQ.                             */
200
                                "MSR    CPSR, R0                \n\t"   /* Write back modified value.   */
201
                                "LDMIA  SP!, {R0}" );                   /* Pop R0.                                              */
202
                }
203
        }
204
}
205
 
206
 
207
 
208
 
209
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.