| 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 |
|
|
#ifndef PORTMACRO_H
|
| 54 |
|
|
#define PORTMACRO_H
|
| 55 |
|
|
|
| 56 |
|
|
#ifdef __cplusplus
|
| 57 |
|
|
extern "C" {
|
| 58 |
|
|
#endif
|
| 59 |
|
|
|
| 60 |
|
|
//-----------------------------------------------------------
|
| 61 |
|
|
// Port specific definitions
|
| 62 |
|
|
//-----------------------------------------------------------
|
| 63 |
|
|
// Type definitions.
|
| 64 |
|
|
#define portCHAR char
|
| 65 |
|
|
#define portFLOAT float
|
| 66 |
|
|
#define portDOUBLE double
|
| 67 |
|
|
#define portLONG long
|
| 68 |
|
|
#define portSHORT short
|
| 69 |
|
|
#define portSTACK_TYPE unsigned portLONG
|
| 70 |
|
|
#define portBASE_TYPE long
|
| 71 |
|
|
#define portTickType unsigned portLONG
|
| 72 |
|
|
#define portMAX_DELAY (portTickType)0xffffffff
|
| 73 |
|
|
|
| 74 |
|
|
#if( configUSE_16_BIT_TICKS == 1 )
|
| 75 |
|
|
#effor "configUSE_16_BIT_TICKS must be 0"
|
| 76 |
|
|
#endif
|
| 77 |
|
|
|
| 78 |
|
|
/*-----------------------------------------------------------*/
|
| 79 |
|
|
#define portSTACK_GROWTH -1
|
| 80 |
|
|
#define portTICK_RATE_MS ( (portTickType) 1000 / configTICK_RATE_HZ )
|
| 81 |
|
|
#define portBYTE_ALIGNMENT 4
|
| 82 |
|
|
#define portCRITICAL_NESTING_IN_TCB 1
|
| 83 |
|
|
#define portINSTRUCTION_SIZE ( ( portSTACK_TYPE ) 4 )
|
| 84 |
|
|
#define portNO_CRITICAL_SECTION_NESTING ( ( portSTACK_TYPE ) 0 )
|
| 85 |
|
|
|
| 86 |
|
|
#define portYIELD_FROM_ISR() vTaskSwitchContext()
|
| 87 |
|
|
#define portYIELD() { \
|
| 88 |
621 |
filepang |
__asm__ __volatile__ ( "l.sw -4(r1), r11" ); \
|
| 89 |
572 |
jeremybenn |
__asm__ __volatile__ ( "l.addi r11, r0, 0x0FCC" ); \
|
| 90 |
|
|
__asm__ __volatile__ ( "l.sys 0x0FCC" ); \
|
| 91 |
|
|
__asm__ __volatile__ ( "l.nop " ); \
|
| 92 |
|
|
}
|
| 93 |
|
|
#define portNOP() __asm__ __volatile__ ( "l.nop" )
|
| 94 |
|
|
|
| 95 |
|
|
|
| 96 |
|
|
/*
|
| 97 |
|
|
* naked attribute is ignored or32-elf-gcc 4.5.1-or32-1.0rc1
|
| 98 |
|
|
* use assemble routines in portasm.S
|
| 99 |
|
|
*/
|
| 100 |
|
|
#if 0
|
| 101 |
|
|
extern void vPortDisableInterrupts( void ) __attribute__ ((__naked__));
|
| 102 |
|
|
extern void vPortEnableInterrupts( void ) __attribute__ ((__naked__));
|
| 103 |
|
|
#else
|
| 104 |
|
|
void vPortDisableInterrupts( void );
|
| 105 |
|
|
void vPortEnableInterrupts( void );
|
| 106 |
|
|
#endif
|
| 107 |
|
|
|
| 108 |
|
|
#define portDISABLE_INTERRUPTS() vPortDisableInterrupts()
|
| 109 |
|
|
#define portENABLE_INTERRUPTS() vPortEnableInterrupts()
|
| 110 |
|
|
|
| 111 |
|
|
/*-----------------------------------------------------------*/
|
| 112 |
|
|
|
| 113 |
|
|
|
| 114 |
|
|
// Critical section handling.
|
| 115 |
|
|
// switch supervisormode, disable tick interrupt and all external interrupt, switch back usermode
|
| 116 |
|
|
#define portENTER_CRITICAL() { \
|
| 117 |
621 |
filepang |
__asm__ __volatile__ ( "l.sw -4(r1), r11" ); \
|
| 118 |
572 |
jeremybenn |
__asm__ __volatile__ ( "l.addi r11, r0, 0x0FCE" ); \
|
| 119 |
|
|
__asm__ __volatile__ ( "l.sys 0x0FCE" ); \
|
| 120 |
|
|
__asm__ __volatile__ ( "l.nop " ); \
|
| 121 |
|
|
}
|
| 122 |
|
|
|
| 123 |
|
|
// switch supervisormode, enable tick interrupt and all external interrupt, switch back usermode
|
| 124 |
|
|
#define portEXIT_CRITICAL() { \
|
| 125 |
621 |
filepang |
__asm__ __volatile__ ( "l.sw -4(r1), r11" ); \
|
| 126 |
572 |
jeremybenn |
__asm__ __volatile__ ( "l.addi r11, r0, 0x0FCF" ); \
|
| 127 |
|
|
__asm__ __volatile__ ( "l.sys 0x0FCF" ); \
|
| 128 |
|
|
__asm__ __volatile__ ( "l.nop " ); \
|
| 129 |
|
|
}
|
| 130 |
|
|
|
| 131 |
|
|
/* Task function macros as described on the FreeRTOS.org WEB site. */
|
| 132 |
|
|
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
|
| 133 |
|
|
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
|
| 134 |
|
|
|
| 135 |
|
|
#ifdef __cplusplus
|
| 136 |
|
|
}
|
| 137 |
|
|
#endif
|
| 138 |
|
|
|
| 139 |
|
|
// Macro to save all registers, stack pointer into the TCB.
|
| 140 |
|
|
#define portSAVE_CONTEXT() \
|
| 141 |
|
|
asm volatile ( \
|
| 142 |
|
|
" .global pxCurrentTCB \n\t" \
|
| 143 |
|
|
" # make rooms in stack \n\t" \
|
| 144 |
621 |
filepang |
" l.addi r1, r1, -128 \n\t" \
|
| 145 |
572 |
jeremybenn |
" # early save r3-r5, these are clobber register\n\t" \
|
| 146 |
|
|
" l.sw 0x08(r1), r3 \n\t" \
|
| 147 |
|
|
" l.sw 0x0C(r1), r4 \n\t" \
|
| 148 |
|
|
" l.sw 0x10(r1), r5 \n\t" \
|
| 149 |
|
|
" # save SPR_ESR_BASE(0), SPR_EPCR_BASE(0)\n\t" \
|
| 150 |
|
|
" l.mfspr r3, r0, (0<<11) + 64 \n\t" \
|
| 151 |
|
|
" l.mfspr r4, r0, (0<<11) + 32 \n\t" \
|
| 152 |
|
|
" l.sw 0x78(r1), r3 \n\t" \
|
| 153 |
|
|
" l.sw 0x7C(r1), r4 \n\t" \
|
| 154 |
|
|
" l.sw 0x00(r1), r9 \n\t" \
|
| 155 |
|
|
" # disable interrupts \n\t" \
|
| 156 |
|
|
" l.jal vPortDisableInterrupts \n\t" \
|
| 157 |
|
|
" # Save Context \n\t" \
|
| 158 |
|
|
" l.sw 0x04(r1), r2 \n\t" \
|
| 159 |
|
|
" l.sw 0x14(r1), r6 \n\t" \
|
| 160 |
|
|
" l.sw 0x18(r1), r7 \n\t" \
|
| 161 |
|
|
" l.sw 0x1C(r1), r8 \n\t" \
|
| 162 |
|
|
" l.sw 0x20(r1), r10 \n\t" \
|
| 163 |
|
|
" l.sw 0x24(r1), r11 \n\t" \
|
| 164 |
|
|
" l.sw 0x28(r1), r12 \n\t" \
|
| 165 |
|
|
" l.sw 0x2C(r1), r13 \n\t" \
|
| 166 |
|
|
" l.sw 0x30(r1), r14 \n\t" \
|
| 167 |
|
|
" l.sw 0x34(r1), r15 \n\t" \
|
| 168 |
|
|
" l.sw 0x38(r1), r16 \n\t" \
|
| 169 |
|
|
" l.sw 0x3C(r1), r17 \n\t" \
|
| 170 |
|
|
" l.sw 0x40(r1), r18 \n\t" \
|
| 171 |
|
|
" l.sw 0x44(r1), r19 \n\t" \
|
| 172 |
|
|
" l.sw 0x48(r1), r20 \n\t" \
|
| 173 |
|
|
" l.sw 0x4C(r1), r21 \n\t" \
|
| 174 |
|
|
" l.sw 0x50(r1), r22 \n\t" \
|
| 175 |
|
|
" l.sw 0x54(r1), r23 \n\t" \
|
| 176 |
|
|
" l.sw 0x58(r1), r24 \n\t" \
|
| 177 |
|
|
" l.sw 0x5C(r1), r25 \n\t" \
|
| 178 |
|
|
" l.sw 0x60(r1), r26 \n\t" \
|
| 179 |
|
|
" l.sw 0x64(r1), r27 \n\t" \
|
| 180 |
|
|
" l.sw 0x68(r1), r28 \n\t" \
|
| 181 |
|
|
" l.sw 0x6C(r1), r29 \n\t" \
|
| 182 |
|
|
" l.sw 0x70(r1), r30 \n\t" \
|
| 183 |
|
|
" l.sw 0x74(r1), r31 \n\t" \
|
| 184 |
|
|
" # Save the top of stack in TCB \n\t" \
|
| 185 |
|
|
" l.movhi r3, hi(pxCurrentTCB) \n\t" \
|
| 186 |
|
|
" l.ori r3, r3, lo(pxCurrentTCB)\n\t" \
|
| 187 |
|
|
" l.lwz r3, 0x0(r3) \n\t" \
|
| 188 |
|
|
" l.sw 0x0(r3), r1 \n\t" \
|
| 189 |
|
|
" # restore clobber register \n\t" \
|
| 190 |
|
|
" l.lwz r3, 0x08(r1) \n\t" \
|
| 191 |
|
|
" l.lwz r4, 0x0C(r1) \n\t" \
|
| 192 |
|
|
" l.lwz r5, 0x10(r1) \n\t" \
|
| 193 |
|
|
);
|
| 194 |
|
|
|
| 195 |
|
|
#define portRESTORE_CONTEXT() \
|
| 196 |
|
|
asm volatile ( \
|
| 197 |
|
|
" .global pxCurrentTCB \n\t" \
|
| 198 |
|
|
" # restore stack pointer \n\t" \
|
| 199 |
|
|
" l.movhi r3, hi(pxCurrentTCB) \n\t" \
|
| 200 |
|
|
" l.ori r3, r3, lo(pxCurrentTCB)\n\t" \
|
| 201 |
|
|
" l.lwz r3, 0x0(r3) \n\t" \
|
| 202 |
|
|
" l.lwz r1, 0x0(r3) \n\t" \
|
| 203 |
|
|
" # restore context \n\t" \
|
| 204 |
|
|
" l.lwz r9, 0x00(r1) \n\t" \
|
| 205 |
|
|
" l.lwz r2, 0x04(r1) \n\t" \
|
| 206 |
|
|
" l.lwz r6, 0x14(r1) \n\t" \
|
| 207 |
|
|
" l.lwz r7, 0x18(r1) \n\t" \
|
| 208 |
|
|
" l.lwz r8, 0x1C(r1) \n\t" \
|
| 209 |
|
|
" l.lwz r10, 0x20(r1) \n\t" \
|
| 210 |
|
|
" l.lwz r11, 0x24(r1) \n\t" \
|
| 211 |
|
|
" l.lwz r12, 0x28(r1) \n\t" \
|
| 212 |
|
|
" l.lwz r13, 0x2C(r1) \n\t" \
|
| 213 |
|
|
" l.lwz r14, 0x30(r1) \n\t" \
|
| 214 |
|
|
" l.lwz r15, 0x34(r1) \n\t" \
|
| 215 |
|
|
" l.lwz r16, 0x38(r1) \n\t" \
|
| 216 |
|
|
" l.lwz r17, 0x3C(r1) \n\t" \
|
| 217 |
|
|
" l.lwz r18, 0x40(r1) \n\t" \
|
| 218 |
|
|
" l.lwz r19, 0x44(r1) \n\t" \
|
| 219 |
|
|
" l.lwz r20, 0x48(r1) \n\t" \
|
| 220 |
|
|
" l.lwz r21, 0x4C(r1) \n\t" \
|
| 221 |
|
|
" l.lwz r22, 0x50(r1) \n\t" \
|
| 222 |
|
|
" l.lwz r23, 0x54(r1) \n\t" \
|
| 223 |
|
|
" l.lwz r24, 0x58(r1) \n\t" \
|
| 224 |
|
|
" l.lwz r25, 0x5C(r1) \n\t" \
|
| 225 |
|
|
" l.lwz r26, 0x60(r1) \n\t" \
|
| 226 |
|
|
" l.lwz r27, 0x64(r1) \n\t" \
|
| 227 |
|
|
" l.lwz r28, 0x68(r1) \n\t" \
|
| 228 |
|
|
" l.lwz r29, 0x6C(r1) \n\t" \
|
| 229 |
|
|
" l.lwz r30, 0x70(r1) \n\t" \
|
| 230 |
|
|
" l.lwz r31, 0x74(r1) \n\t" \
|
| 231 |
|
|
" # restore SPR_ESR_BASE(0), SPR_EPCR_BASE(0)\n\t" \
|
| 232 |
|
|
" l.lwz r3, 0x78(r1) \n\t" \
|
| 233 |
|
|
" l.lwz r4, 0x7C(r1) \n\t" \
|
| 234 |
|
|
" l.mtspr r0, r3, (0<<11) + 64 \n\t" \
|
| 235 |
|
|
" l.mtspr r0, r4, (0<<11) + 32 \n\t" \
|
| 236 |
|
|
" # restore clobber register \n\t" \
|
| 237 |
|
|
" l.lwz r3, 0x08(r1) \n\t" \
|
| 238 |
|
|
" l.lwz r4, 0x0C(r1) \n\t" \
|
| 239 |
|
|
" l.lwz r5, 0x10(r1) \n\t" \
|
| 240 |
621 |
filepang |
" l.addi r1, r1, 128 \n\t" \
|
| 241 |
572 |
jeremybenn |
" l.rfe \n\t" \
|
| 242 |
|
|
" l.nop \n\t" \
|
| 243 |
|
|
);
|
| 244 |
|
|
|
| 245 |
|
|
#endif /* PORTMACRO_H */
|