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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Source/] [portable/] [GCC/] [ARM7_AT91SAM7S/] [port.c] - Blame information for rev 581

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
 * Implementation of functions defined in portable.h for the ARM7 port.
57
 *
58
 * Components that can be compiled to either ARM or THUMB mode are
59
 * contained in this file.  The ISR routines, which can only be compiled
60
 * to ARM mode are contained in portISR.c.
61
 *----------------------------------------------------------*/
62
 
63
/*
64
        Changes from V2.5.2
65
 
66
        + ulCriticalNesting is now saved as part of the task context, as is
67
          therefore added to the initial task stack during pxPortInitialiseStack.
68
*/
69
 
70
 
71
/* Standard includes. */
72
#include <stdlib.h>
73
 
74
/* Scheduler includes. */
75
#include "FreeRTOS.h"
76
#include "task.h"
77
 
78
/* Processor constants. */
79
#include "AT91SAM7X256.h"
80
 
81
/* Constants required to setup the task context. */
82
#define portINITIAL_SPSR                                ( ( portSTACK_TYPE ) 0x1f ) /* System mode, ARM mode, interrupts enabled. */
83
#define portTHUMB_MODE_BIT                              ( ( portSTACK_TYPE ) 0x20 )
84
#define portINSTRUCTION_SIZE                    ( ( portSTACK_TYPE ) 4 )
85
#define portNO_CRITICAL_SECTION_NESTING ( ( portSTACK_TYPE ) 0 )
86
 
87
/* Constants required to setup the tick ISR. */
88
#define portENABLE_TIMER                        ( ( unsigned char ) 0x01 )
89
#define portPRESCALE_VALUE                      0x00
90
#define portINTERRUPT_ON_MATCH          ( ( unsigned long ) 0x01 )
91
#define portRESET_COUNT_ON_MATCH        ( ( unsigned long ) 0x02 )
92
 
93
/* Constants required to setup the PIT. */
94
#define portPIT_CLOCK_DIVISOR                   ( ( unsigned long ) 16 )
95
#define portPIT_COUNTER_VALUE                   ( ( ( configCPU_CLOCK_HZ / portPIT_CLOCK_DIVISOR ) / 1000UL ) * portTICK_RATE_MS )
96
 
97
#define portINT_LEVEL_SENSITIVE  0
98
#define portPIT_ENABLE          ( ( unsigned short ) 0x1 << 24 )
99
#define portPIT_INT_ENABLE      ( ( unsigned short ) 0x1 << 25 )
100
/*-----------------------------------------------------------*/
101
 
102
/* Setup the timer to generate the tick interrupts. */
103
static void prvSetupTimerInterrupt( void );
104
 
105
/*
106
 * The scheduler can only be started from ARM mode, so
107
 * vPortISRStartFirstSTask() is defined in portISR.c.
108
 */
109
extern void vPortISRStartFirstTask( void );
110
 
111
/*-----------------------------------------------------------*/
112
 
113
/*
114
 * Initialise the stack of a task to look exactly as if a call to
115
 * portSAVE_CONTEXT had been called.
116
 *
117
 * See header file for description.
118
 */
119
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
120
{
121
portSTACK_TYPE *pxOriginalTOS;
122
 
123
        pxOriginalTOS = pxTopOfStack;
124
 
125
        /* Setup the initial stack of the task.  The stack is set exactly as
126
        expected by the portRESTORE_CONTEXT() macro. */
127
 
128
        /* First on the stack is the return address - which in this case is the
129
        start of the task.  The offset is added to make the return address appear
130
        as it would within an IRQ ISR. */
131
        *pxTopOfStack = ( portSTACK_TYPE ) pxCode + portINSTRUCTION_SIZE;
132
        pxTopOfStack--;
133
 
134
        *pxTopOfStack = ( portSTACK_TYPE ) 0x00000000;  /* R14 */
135
        pxTopOfStack--;
136
        *pxTopOfStack = ( portSTACK_TYPE ) pxOriginalTOS; /* Stack used when task starts goes in R13. */
137
        pxTopOfStack--;
138
        *pxTopOfStack = ( portSTACK_TYPE ) 0x12121212;  /* R12 */
139
        pxTopOfStack--;
140
        *pxTopOfStack = ( portSTACK_TYPE ) 0x11111111;  /* R11 */
141
        pxTopOfStack--;
142
        *pxTopOfStack = ( portSTACK_TYPE ) 0x10101010;  /* R10 */
143
        pxTopOfStack--;
144
        *pxTopOfStack = ( portSTACK_TYPE ) 0x09090909;  /* R9 */
145
        pxTopOfStack--;
146
        *pxTopOfStack = ( portSTACK_TYPE ) 0x08080808;  /* R8 */
147
        pxTopOfStack--;
148
        *pxTopOfStack = ( portSTACK_TYPE ) 0x07070707;  /* R7 */
149
        pxTopOfStack--;
150
        *pxTopOfStack = ( portSTACK_TYPE ) 0x06060606;  /* R6 */
151
        pxTopOfStack--;
152
        *pxTopOfStack = ( portSTACK_TYPE ) 0x05050505;  /* R5 */
153
        pxTopOfStack--;
154
        *pxTopOfStack = ( portSTACK_TYPE ) 0x04040404;  /* R4 */
155
        pxTopOfStack--;
156
        *pxTopOfStack = ( portSTACK_TYPE ) 0x03030303;  /* R3 */
157
        pxTopOfStack--;
158
        *pxTopOfStack = ( portSTACK_TYPE ) 0x02020202;  /* R2 */
159
        pxTopOfStack--;
160
        *pxTopOfStack = ( portSTACK_TYPE ) 0x01010101;  /* R1 */
161
        pxTopOfStack--;
162
 
163
        /* When the task starts is will expect to find the function parameter in
164
        R0. */
165
        *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R0 */
166
        pxTopOfStack--;
167
 
168
        /* The last thing onto the stack is the status register, which is set for
169
        system mode, with interrupts enabled. */
170
        *pxTopOfStack = ( portSTACK_TYPE ) portINITIAL_SPSR;
171
 
172
        #ifdef THUMB_INTERWORK
173
        {
174
                /* We want the task to start in thumb mode. */
175
                *pxTopOfStack |= portTHUMB_MODE_BIT;
176
        }
177
        #endif
178
 
179
        pxTopOfStack--;
180
 
181
        /* Some optimisation levels use the stack differently to others.  This
182
        means the interrupt flags cannot always be stored on the stack and will
183
        instead be stored in a variable, which is then saved as part of the
184
        tasks context. */
185
        *pxTopOfStack = portNO_CRITICAL_SECTION_NESTING;
186
 
187
        return pxTopOfStack;
188
}
189
/*-----------------------------------------------------------*/
190
 
191
portBASE_TYPE xPortStartScheduler( void )
192
{
193
        /* Start the timer that generates the tick ISR.  Interrupts are disabled
194
        here already. */
195
        prvSetupTimerInterrupt();
196
 
197
        /* Start the first task. */
198
        vPortISRStartFirstTask();
199
 
200
        /* Should not get here! */
201
        return 0;
202
}
203
/*-----------------------------------------------------------*/
204
 
205
void vPortEndScheduler( void )
206
{
207
        /* It is unlikely that the ARM port will require this function as there
208
        is nothing to return to.  */
209
}
210
/*-----------------------------------------------------------*/
211
 
212
/*
213
 * Setup the timer 0 to generate the tick interrupts at the required frequency.
214
 */
215
static void prvSetupTimerInterrupt( void )
216
{
217
AT91PS_PITC pxPIT = AT91C_BASE_PITC;
218
 
219
        /* Setup the AIC for PIT interrupts.  The interrupt routine chosen depends
220
        on whether the preemptive or cooperative scheduler is being used. */
221
        #if configUSE_PREEMPTION == 0
222
 
223
                extern void ( vNonPreemptiveTick ) ( void );
224
                AT91F_AIC_ConfigureIt( AT91C_ID_SYS, AT91C_AIC_PRIOR_HIGHEST, portINT_LEVEL_SENSITIVE, ( void (*)(void) ) vNonPreemptiveTick );
225
 
226
        #else
227
 
228
                extern void ( vPreemptiveTick )( void );
229
                AT91F_AIC_ConfigureIt( AT91C_ID_SYS, AT91C_AIC_PRIOR_HIGHEST, portINT_LEVEL_SENSITIVE, ( void (*)(void) ) vPreemptiveTick );
230
 
231
        #endif
232
 
233
        /* Configure the PIT period. */
234
        pxPIT->PITC_PIMR = portPIT_ENABLE | portPIT_INT_ENABLE | portPIT_COUNTER_VALUE;
235
 
236
        /* Enable the interrupt.  Global interrupts are disables at this point so
237
        this is safe. */
238
    AT91C_BASE_AIC->AIC_IECR = 0x1 << AT91C_ID_SYS;
239
}
240
/*-----------------------------------------------------------*/
241
 
242
 
243
 

powered by: WebSVN 2.1.0

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