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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Source/] [portable/] [MPLAB/] [PIC32MX/] [port.c] - Blame information for rev 572

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
 * Implementation of functions defined in portable.h for the PIC32MX port.
56
  *----------------------------------------------------------*/
57
 
58
/* Scheduler include files. */
59
#include "FreeRTOS.h"
60
#include "task.h"
61
 
62
/* Hardware specifics. */
63
#define portTIMER_PRESCALE 8
64
 
65
/* Bits within various registers. */
66
#define portIE_BIT                                      ( 0x00000001 )
67
#define portEXL_BIT                                     ( 0x00000002 )
68
#define portSW0_ENABLE                          ( 0x00000100 )
69
 
70
/* The EXL bit is set to ensure interrupts do not occur while the context of
71
the first task is being restored. */
72
#define portINITIAL_SR                          ( portIE_BIT | portEXL_BIT | portSW0_ENABLE )
73
 
74
/* Records the interrupt nesting depth.  This starts at one as it will be
75
decremented to 0 when the first task starts. */
76
volatile unsigned portBASE_TYPE uxInterruptNesting = 0x01;
77
 
78
/* Stores the task stack pointer when a switch is made to use the system stack. */
79
unsigned portBASE_TYPE uxSavedTaskStackPointer = 0;
80
 
81
/* The stack used by interrupt service routines that cause a context switch. */
82
portSTACK_TYPE xISRStack[ configISR_STACK_SIZE ] = { 0 };
83
 
84
/* The top of stack value ensures there is enough space to store 6 registers on
85
the callers stack, as some functions seem to want to do this. */
86
const portBASE_TYPE * const xISRStackTop = &( xISRStack[ configISR_STACK_SIZE - 7 ] );
87
 
88
/* Place the prototype here to ensure the interrupt vector is correctly installed. */
89
extern void __attribute__( (interrupt(ipl1), vector(_TIMER_1_VECTOR))) vT1InterruptHandler( void );
90
 
91
/*
92
 * The software interrupt handler that performs the yield.
93
 */
94
void __attribute__( (interrupt(ipl1), vector(_CORE_SOFTWARE_0_VECTOR))) vPortYieldISR( void );
95
 
96
/*-----------------------------------------------------------*/
97
 
98
/*
99
 * See header file for description.
100
 */
101
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
102
{
103
        *pxTopOfStack = (portSTACK_TYPE) 0xDEADBEEF;
104
        pxTopOfStack--;
105
 
106
        *pxTopOfStack = (portSTACK_TYPE) 0x12345678;    /* Word to which the stack pointer will be left pointing after context restore. */
107
        pxTopOfStack--;
108
 
109
        *pxTopOfStack = (portSTACK_TYPE) _CP0_GET_CAUSE();
110
        pxTopOfStack--;
111
 
112
        *pxTopOfStack = (portSTACK_TYPE) portINITIAL_SR; /* CP0_STATUS */
113
        pxTopOfStack--;
114
 
115
        *pxTopOfStack = (portSTACK_TYPE) pxCode;                /* CP0_EPC */
116
        pxTopOfStack--;
117
 
118
        *pxTopOfStack = (portSTACK_TYPE) NULL;                  /* ra */
119
        pxTopOfStack -= 15;
120
 
121
        *pxTopOfStack = (portSTACK_TYPE) pvParameters; /* Parameters to pass in */
122
        pxTopOfStack -= 14;
123
 
124
        *pxTopOfStack = (portSTACK_TYPE) 0x00000000;    /* critical nesting level - no longer used. */
125
        pxTopOfStack--;
126
 
127
        return pxTopOfStack;
128
}
129
/*-----------------------------------------------------------*/
130
 
131
/*
132
 * Setup a timer for a regular tick.
133
 */
134
void prvSetupTimerInterrupt( void )
135
{
136
const unsigned long ulCompareMatch = ( (configPERIPHERAL_CLOCK_HZ / portTIMER_PRESCALE) / configTICK_RATE_HZ ) - 1;
137
 
138
        OpenTimer1( ( T1_ON | T1_PS_1_8 | T1_SOURCE_INT ), ulCompareMatch );
139
        ConfigIntTimer1( T1_INT_ON | configKERNEL_INTERRUPT_PRIORITY );
140
}
141
/*-----------------------------------------------------------*/
142
 
143
void vPortEndScheduler(void)
144
{
145
        /* It is unlikely that the scheduler for the PIC port will get stopped
146
        once running.  If required disable the tick interrupt here, then return
147
        to xPortStartScheduler(). */
148
        for( ;; );
149
}
150
/*-----------------------------------------------------------*/
151
 
152
portBASE_TYPE xPortStartScheduler( void )
153
{
154
extern void vPortStartFirstTask( void );
155
extern void *pxCurrentTCB;
156
 
157
        /* Setup the software interrupt. */
158
        mConfigIntCoreSW0( CSW_INT_ON | CSW_INT_PRIOR_1 | CSW_INT_SUB_PRIOR_0 );
159
 
160
        /* Setup the timer to generate the tick.  Interrupts will have been
161
        disabled by the time we get here. */
162
        prvSetupTimerInterrupt();
163
 
164
        /* Kick off the highest priority task that has been created so far.
165
        Its stack location is loaded into uxSavedTaskStackPointer. */
166
        uxSavedTaskStackPointer = *( unsigned portBASE_TYPE * ) pxCurrentTCB;
167
        vPortStartFirstTask();
168
 
169
        /* Should never get here as the tasks will now be executing. */
170
        return pdFALSE;
171
}
172
/*-----------------------------------------------------------*/
173
 
174
void vPortIncrementTick( void )
175
{
176
unsigned portBASE_TYPE uxSavedStatus;
177
 
178
        uxSavedStatus = uxPortSetInterruptMaskFromISR();
179
                vTaskIncrementTick();
180
        vPortClearInterruptMaskFromISR( uxSavedStatus );
181
 
182
        /* If we are using the preemptive scheduler then we might want to select
183
        a different task to execute. */
184
        #if configUSE_PREEMPTION == 1
185
                SetCoreSW0();
186
        #endif /* configUSE_PREEMPTION */
187
 
188
        /* Clear timer 0 interrupt. */
189
        mT1ClearIntFlag();
190
}
191
/*-----------------------------------------------------------*/
192
 
193
unsigned portBASE_TYPE uxPortSetInterruptMaskFromISR( void )
194
{
195
unsigned portBASE_TYPE uxSavedStatusRegister;
196
 
197
        asm volatile ( "di" );
198
        uxSavedStatusRegister = _CP0_GET_STATUS() | 0x01;
199
        _CP0_SET_STATUS( ( uxSavedStatusRegister | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) );
200
 
201
        return uxSavedStatusRegister;
202
}
203
/*-----------------------------------------------------------*/
204
 
205
void vPortClearInterruptMaskFromISR( unsigned portBASE_TYPE uxSavedStatusRegister )
206
{
207
        _CP0_SET_STATUS( uxSavedStatusRegister );
208
}
209
/*-----------------------------------------------------------*/
210
 
211
 
212
 
213
 
214
 

powered by: WebSVN 2.1.0

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