2 FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
54 /* Kernel includes. */
\r
55 #include "FreeRTOS.h"
\r
57 /* Machine includes */
\r
59 #include <machine/intrinsics.h>
\r
60 #include <machine/cint.h>
\r
61 /*---------------------------------------------------------------------------*/
\r
64 * This reference is required by the Save/Restore Context Macros.
\r
66 extern volatile unsigned portBASE_TYPE * pxCurrentTCB;
\r
67 /*-----------------------------------------------------------*/
\r
70 * This file contains base definitions for all of the possible traps in the system.
\r
71 * It is suggested to provide implementations for all of the traps but for
\r
72 * the time being they simply trigger a DEBUG instruction so that it is easy
\r
73 * to see what caused a particular trap.
\r
75 * Trap Class 6, the SYSCALL, is used exclusively by the operating system.
\r
78 /* The Trap Classes. */
\r
79 #define portMMU_TRAP 0
\r
80 #define portIPT_TRAP 1
\r
81 #define portIE_TRAP 2
\r
82 #define portCM_TRAP 3
\r
83 #define portSBP_TRAP 4
\r
84 #define portASSERT_TRAP 5
\r
85 #define portNMI_TRAP 7
\r
87 /* MMU Trap Identifications. */
\r
88 #define portTIN_MMU_VIRTUAL_ADDRESS_FILL 0
\r
89 #define portTIN_MMU_VIRTUAL_ADDRESS_PROTECTION 1
\r
91 /* Internal Protection Trap Identifications. */
\r
92 #define portTIN_IPT_PRIVILIGED_INSTRUCTION 1
\r
93 #define portTIN_IPT_MEMORY_PROTECTION_READ 2
\r
94 #define portTIN_IPT_MEMORY_PROTECTION_WRITE 3
\r
95 #define portTIN_IPT_MEMORY_PROTECTION_EXECUTION 4
\r
96 #define portTIN_IPT_MEMORY_PROTECTION_PERIPHERAL_ACCESS 5
\r
97 #define portTIN_IPT_MEMORY_PROTECTION_NULL_ADDRESS 6
\r
98 #define portTIN_IPT_MEMORY_PROTECTION_GLOBAL_REGISTER_WRITE_PROTECTION 7
\r
100 /* Instruction Error Trap Identifications. */
\r
101 #define portTIN_IE_ILLEGAL_OPCODE 1
\r
102 #define portTIN_IE_UNIMPLEMENTED_OPCODE 2
\r
103 #define portTIN_IE_INVALID_OPERAND 3
\r
104 #define portTIN_IE_DATA_ADDRESS_ALIGNMENT 4
\r
105 #define portTIN_IE_INVALID_LOCAL_MEMORY_ADDRESS 5
\r
107 /* Context Management Trap Identifications. */
\r
108 #define portTIN_CM_FREE_CONTEXT_LIST_DEPLETION 1
\r
109 #define portTIN_CM_CALL_DEPTH_OVERFLOW 2
\r
110 #define portTIN_CM_CALL_DEPTH_UNDEFLOW 3
\r
111 #define portTIN_CM_FREE_CONTEXT_LIST_UNDERFLOW 4
\r
112 #define portTIN_CM_CALL_STACK_UNDERFLOW 5
\r
113 #define portTIN_CM_CONTEXT_TYPE 6
\r
114 #define portTIN_CM_NESTING_ERROR 7
\r
116 /* System Bus and Peripherals Trap Identifications. */
\r
117 #define portTIN_SBP_PROGRAM_FETCH_SYNCHRONOUS_ERROR 1
\r
118 #define portTIN_SBP_DATA_ACCESS_SYNCHRONOUS_ERROR 2
\r
119 #define portTIN_SBP_DATA_ACCESS_ASYNCHRONOUS_ERROR 3
\r
120 #define portTIN_SBP_COPROCESSOR_TRAP_ASYNCHRONOUS_ERROR 4
\r
121 #define portTIN_SBP_PROGRAM_MEMORY_INTEGRITY_ERROR 5
\r
122 #define portTIN_SBP_DATA_MEMORY_INTEGRITY_ERROR 6
\r
124 /* Assertion Trap Identifications. */
\r
125 #define portTIN_ASSERT_ARITHMETIC_OVERFLOW 1
\r
126 #define portTIN_ASSERT_STICKY_ARITHMETIC_OVERFLOW 2
\r
128 /* Non-maskable Interrupt Trap Identifications. */
\r
129 #define portTIN_NMI_NON_MASKABLE_INTERRUPT 0
\r
130 /*---------------------------------------------------------------------------*/
\r
132 void vMMUTrap( int iTrapIdentification );
\r
133 void vInternalProtectionTrap( int iTrapIdentification );
\r
134 void vInstructionErrorTrap( int iTrapIdentification );
\r
135 void vContextManagementTrap( int iTrapIdentification );
\r
136 void vSystemBusAndPeripheralsTrap( int iTrapIdentification );
\r
137 void vAssertionTrap( int iTrapIdentification );
\r
138 void vNonMaskableInterruptTrap( int iTrapIdentification );
\r
139 /*---------------------------------------------------------------------------*/
\r
141 void vTrapInstallHandlers( void )
\r
143 if ( 0 == _install_trap_handler ( portMMU_TRAP, vMMUTrap ) )
\r
147 if ( 0 == _install_trap_handler ( portIPT_TRAP, vInternalProtectionTrap ) )
\r
151 if ( 0 == _install_trap_handler ( portIE_TRAP, vInstructionErrorTrap ) )
\r
155 if ( 0 == _install_trap_handler ( portCM_TRAP, vContextManagementTrap ) )
\r
159 if ( 0 == _install_trap_handler ( portSBP_TRAP, vSystemBusAndPeripheralsTrap ) )
\r
163 if ( 0 == _install_trap_handler ( portASSERT_TRAP, vAssertionTrap ) )
\r
167 /* Trap Handler 6 (Syscall) is installed in port.c as it is fundamental to
\r
168 * the OS operation. These trap handlers is are place holders.
\r
169 * if ( 0 != _install_trap_handler ( portMMU_TRAP, vMMUTrap ) )
\r
174 if ( 0 == _install_trap_handler ( portNMI_TRAP, vNonMaskableInterruptTrap ) )
\r
179 /*-----------------------------------------------------------*/
\r
181 void vMMUTrap( int iTrapIdentification )
\r
183 switch ( iTrapIdentification )
\r
185 case portTIN_MMU_VIRTUAL_ADDRESS_FILL:
\r
186 case portTIN_MMU_VIRTUAL_ADDRESS_PROTECTION:
\r
192 /*---------------------------------------------------------------------------*/
\r
194 void vInternalProtectionTrap( int iTrapIdentification )
\r
196 switch ( iTrapIdentification )
\r
198 case portTIN_IPT_PRIVILIGED_INSTRUCTION:
\r
199 /* Instruction is not allowed at current execution level, eg DISABLE at User-0. */
\r
200 case portTIN_IPT_MEMORY_PROTECTION_READ:
\r
201 /* Load word using invalid address. */
\r
202 case portTIN_IPT_MEMORY_PROTECTION_WRITE:
\r
203 /* Store Word using invalid address. */
\r
204 case portTIN_IPT_MEMORY_PROTECTION_EXECUTION:
\r
205 /* PC jumped to an address outside of the valid range. */
\r
206 case portTIN_IPT_MEMORY_PROTECTION_PERIPHERAL_ACCESS:
\r
207 /* Access to a peripheral denied at current execution level. */
\r
208 case portTIN_IPT_MEMORY_PROTECTION_NULL_ADDRESS:
\r
209 /* NULL Pointer. */
\r
210 case portTIN_IPT_MEMORY_PROTECTION_GLOBAL_REGISTER_WRITE_PROTECTION:
\r
211 /* Tried to modify a global address pointer register. */
\r
213 pxCurrentTCB[ 0 ] = _mfcr( $PCXI );
\r
218 /*---------------------------------------------------------------------------*/
\r
220 void vInstructionErrorTrap( int iTrapIdentification )
\r
222 switch ( iTrapIdentification )
\r
224 case portTIN_IE_ILLEGAL_OPCODE:
\r
225 case portTIN_IE_UNIMPLEMENTED_OPCODE:
\r
226 case portTIN_IE_INVALID_OPERAND:
\r
227 case portTIN_IE_DATA_ADDRESS_ALIGNMENT:
\r
228 case portTIN_IE_INVALID_LOCAL_MEMORY_ADDRESS:
\r
234 /*---------------------------------------------------------------------------*/
\r
236 void vContextManagementTrap( int iTrapIdentification )
\r
238 switch ( iTrapIdentification )
\r
240 case portTIN_CM_FREE_CONTEXT_LIST_DEPLETION:
\r
241 case portTIN_CM_CALL_DEPTH_OVERFLOW:
\r
242 case portTIN_CM_CALL_DEPTH_UNDEFLOW:
\r
243 case portTIN_CM_FREE_CONTEXT_LIST_UNDERFLOW:
\r
244 case portTIN_CM_CALL_STACK_UNDERFLOW:
\r
245 case portTIN_CM_CONTEXT_TYPE:
\r
246 case portTIN_CM_NESTING_ERROR:
\r
252 /*---------------------------------------------------------------------------*/
\r
254 void vSystemBusAndPeripheralsTrap( int iTrapIdentification )
\r
256 switch ( iTrapIdentification )
\r
258 case portTIN_SBP_PROGRAM_FETCH_SYNCHRONOUS_ERROR:
\r
259 case portTIN_SBP_DATA_ACCESS_SYNCHRONOUS_ERROR:
\r
260 case portTIN_SBP_DATA_ACCESS_ASYNCHRONOUS_ERROR:
\r
261 case portTIN_SBP_COPROCESSOR_TRAP_ASYNCHRONOUS_ERROR:
\r
262 case portTIN_SBP_PROGRAM_MEMORY_INTEGRITY_ERROR:
\r
263 case portTIN_SBP_DATA_MEMORY_INTEGRITY_ERROR:
\r
269 /*---------------------------------------------------------------------------*/
\r
271 void vAssertionTrap( int iTrapIdentification )
\r
273 switch ( iTrapIdentification )
\r
275 case portTIN_ASSERT_ARITHMETIC_OVERFLOW:
\r
276 case portTIN_ASSERT_STICKY_ARITHMETIC_OVERFLOW:
\r
282 /*---------------------------------------------------------------------------*/
\r
284 void vNonMaskableInterruptTrap( int iTrapIdentification )
\r
286 switch ( iTrapIdentification )
\r
288 case portTIN_NMI_NON_MASKABLE_INTERRUPT:
\r
294 /*---------------------------------------------------------------------------*/
\r