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

Subversion Repositories openrisc

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

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
/* GCC/HCS12 port by Jefferson L Smith, 2005 */
55
 
56
/* Scheduler includes. */
57
#include "FreeRTOS.h"
58
#include "task.h"
59
 
60
/* Port includes */
61
#include <sys/ports_def.h>
62
 
63
/*-----------------------------------------------------------
64
 * Implementation of functions defined in portable.h for the HCS12 port.
65
 *----------------------------------------------------------*/
66
 
67
 
68
/*
69
 * Configure a timer to generate the RTOS tick at the frequency specified
70
 * within FreeRTOSConfig.h.
71
 */
72
static void prvSetupTimerInterrupt( void );
73
 
74
/* NOTE: Interrupt service routines must be in non-banked memory - as does the
75
scheduler startup function. */
76
#define ATTR_NEAR       __attribute__((near))
77
 
78
/* Manual context switch function.  This is the SWI ISR. */
79
// __attribute__((interrupt))
80
void ATTR_NEAR vPortYield( void );
81
 
82
/* Tick context switch function.  This is the timer ISR. */
83
// __attribute__((interrupt))
84
void ATTR_NEAR vPortTickInterrupt( void );
85
 
86
/* Function in non-banked memory which actually switches to first task. */
87
portBASE_TYPE ATTR_NEAR xStartSchedulerNear( void );
88
 
89
/* Calls to portENTER_CRITICAL() can be nested.  When they are nested the
90
critical section should not be left (i.e. interrupts should not be re-enabled)
91
until the nesting depth reaches 0.  This variable simply tracks the nesting
92
depth.  Each task maintains it's own critical nesting depth variable so
93
uxCriticalNesting is saved and restored from the task stack during a context
94
switch. */
95
volatile unsigned portBASE_TYPE uxCriticalNesting = 0x80;  // un-initialized
96
 
97
/*-----------------------------------------------------------*/
98
 
99
/*
100
 * See header file for description.
101
 */
102
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
103
{
104
 
105
 
106
        /* Setup the initial stack of the task.  The stack is set exactly as
107
        expected by the portRESTORE_CONTEXT() macro.  In this case the stack as
108
        expected by the HCS12 RTI instruction. */
109
 
110
 
111
        /* The address of the task function is placed in the stack byte at a time. */
112
        *pxTopOfStack   = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 1 );
113
        *--pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 0 );
114
 
115
        /* Next are all the registers that form part of the task context. */
116
 
117
        /* Y register */
118
        *--pxTopOfStack = ( portSTACK_TYPE ) 0xff;
119
        *--pxTopOfStack = ( portSTACK_TYPE ) 0xee;
120
 
121
        /* X register */
122
        *--pxTopOfStack = ( portSTACK_TYPE ) 0xdd;
123
        *--pxTopOfStack = ( portSTACK_TYPE ) 0xcc;
124
 
125
        /* A register contains parameter high byte. */
126
        *--pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 0 );
127
 
128
        /* B register contains parameter low byte. */
129
        *--pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 1 );
130
 
131
        /* CCR: Note that when the task starts interrupts will be enabled since
132
        "I" bit of CCR is cleared */
133
        *--pxTopOfStack = ( portSTACK_TYPE ) 0x80;              // keeps Stop disabled (MCU default)
134
 
135
        /* tmp softregs used by GCC. Values right now don't     matter. */
136
        __asm("\n\
137
                movw _.frame, 2,-%0                                                     \n\
138
                movw _.tmp, 2,-%0                                                       \n\
139
                movw _.z, 2,-%0                                                         \n\
140
                movw _.xy, 2,-%0                                                        \n\
141
                ;movw _.d2, 2,-%0                                                       \n\
142
                ;movw _.d1, 2,-%0                                                       \n\
143
        ": "=A"(pxTopOfStack) : "0"(pxTopOfStack) );
144
 
145
        #ifdef BANKED_MODEL
146
                /* The page of the task. */
147
                *--pxTopOfStack = 0x30;      // can only directly start in PPAGE 0x30
148
        #endif
149
 
150
        /* The critical nesting depth is initialised with 0 (meaning not in
151
        a critical section). */
152
        *--pxTopOfStack = ( portSTACK_TYPE ) 0x00;
153
 
154
 
155
        return pxTopOfStack;
156
}
157
/*-----------------------------------------------------------*/
158
 
159
void vPortEndScheduler( void )
160
{
161
        /* It is unlikely that the HCS12 port will get stopped. */
162
}
163
/*-----------------------------------------------------------*/
164
 
165
static void prvSetupTimerInterrupt( void )
166
{
167
        /* Enable hardware RTI timer */
168
        /* Ignores configTICK_RATE_HZ */
169
        RTICTL = 0x50;                  // 16 MHz xtal: 976.56 Hz, 1024mS 
170
        CRGINT |= 0x80;                 // RTIE
171
}
172
/*-----------------------------------------------------------*/
173
 
174
portBASE_TYPE xPortStartScheduler( void )
175
{
176
        /* xPortStartScheduler() does not start the scheduler directly because
177
        the header file containing the xPortStartScheduler() prototype is part
178
        of the common kernel code, and therefore cannot use the CODE_SEG pragma.
179
        Instead it simply calls the locally defined xNearStartScheduler() -
180
        which does use the CODE_SEG pragma. */
181
 
182
        short register d;
183
        __asm ("jmp  xStartSchedulerNear                ; will never return": "=d"(d));
184
        return d;
185
}
186
/*-----------------------------------------------------------*/
187
 
188
portBASE_TYPE xStartSchedulerNear( void )
189
{
190
        /* Configure the timer that will generate the RTOS tick.  Interrupts are
191
        disabled when this function is called. */
192
        prvSetupTimerInterrupt();
193
 
194
        /* Restore the context of the first task. */
195
        portRESTORE_CONTEXT();
196
 
197
        portISR_TAIL();
198
 
199
        /* Should not get here! */
200
        return pdFALSE;
201
}
202
/*-----------------------------------------------------------*/
203
 
204
/*
205
 * Context switch functions.  These are interrupt service routines.
206
 */
207
 
208
/*
209
 * Manual context switch forced by calling portYIELD().  This is the SWI
210
 * handler.
211
 */
212
void vPortYield( void )
213
{
214
        portISR_HEAD();
215
        /* NOTE: This is the trap routine (swi) although not defined as a trap.
216
           It will fill the stack the same way as an ISR in order to mix preemtion
217
           and cooperative yield. */
218
 
219
        portSAVE_CONTEXT();
220
        vTaskSwitchContext();
221
        portRESTORE_CONTEXT();
222
 
223
        portISR_TAIL();
224
}
225
/*-----------------------------------------------------------*/
226
 
227
/*
228
 * RTOS tick interrupt service routine.  If the cooperative scheduler is
229
 * being used then this simply increments the tick count.  If the
230
 * preemptive scheduler is being used a context switch can occur.
231
 */
232
void vPortTickInterrupt( void )
233
{
234
        portISR_HEAD();
235
 
236
        /* Clear tick timer flag */
237
        CRGFLG = 0x80;
238
 
239
        #if configUSE_PREEMPTION == 1
240
        {
241
                /* A context switch might happen so save the context. */
242
                portSAVE_CONTEXT();
243
 
244
                /* Increment the tick ... */
245
                vTaskIncrementTick();
246
 
247
                /* ... then see if the new tick value has necessitated a
248
                context switch. */
249
                vTaskSwitchContext();
250
 
251
                /* Restore the context of a task - which may be a different task
252
                to that interrupted. */
253
                portRESTORE_CONTEXT();
254
        }
255
        #else
256
        {
257
                vTaskIncrementTick();
258
        }
259
        #endif
260
 
261
        portISR_TAIL();
262
}
263
 

powered by: WebSVN 2.1.0

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