2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
96 /* Kernel includes. */
\r
97 #include "FreeRTOS.h"
\r
99 /* Machine includes */
\r
100 #include <tc1782.h>
\r
101 #include <machine/intrinsics.h>
\r
102 #include <machine/cint.h>
\r
103 /*---------------------------------------------------------------------------*/
\r
106 * This reference is required by the Save/Restore Context Macros.
\r
108 extern volatile uint32_t *pxCurrentTCB;
\r
109 /*-----------------------------------------------------------*/
\r
112 * This file contains base definitions for all of the possible traps in the system.
\r
113 * It is suggested to provide implementations for all of the traps but for
\r
114 * the time being they simply trigger a DEBUG instruction so that it is easy
\r
115 * to see what caused a particular trap.
\r
117 * Trap Class 6, the SYSCALL, is used exclusively by the operating system.
\r
120 /* The Trap Classes. */
\r
121 #define portMMU_TRAP 0
\r
122 #define portIPT_TRAP 1
\r
123 #define portIE_TRAP 2
\r
124 #define portCM_TRAP 3
\r
125 #define portSBP_TRAP 4
\r
126 #define portASSERT_TRAP 5
\r
127 #define portNMI_TRAP 7
\r
129 /* MMU Trap Identifications. */
\r
130 #define portTIN_MMU_VIRTUAL_ADDRESS_FILL 0
\r
131 #define portTIN_MMU_VIRTUAL_ADDRESS_PROTECTION 1
\r
133 /* Internal Protection Trap Identifications. */
\r
134 #define portTIN_IPT_PRIVILIGED_INSTRUCTION 1
\r
135 #define portTIN_IPT_MEMORY_PROTECTION_READ 2
\r
136 #define portTIN_IPT_MEMORY_PROTECTION_WRITE 3
\r
137 #define portTIN_IPT_MEMORY_PROTECTION_EXECUTION 4
\r
138 #define portTIN_IPT_MEMORY_PROTECTION_PERIPHERAL_ACCESS 5
\r
139 #define portTIN_IPT_MEMORY_PROTECTION_NULL_ADDRESS 6
\r
140 #define portTIN_IPT_MEMORY_PROTECTION_GLOBAL_REGISTER_WRITE_PROTECTION 7
\r
142 /* Instruction Error Trap Identifications. */
\r
143 #define portTIN_IE_ILLEGAL_OPCODE 1
\r
144 #define portTIN_IE_UNIMPLEMENTED_OPCODE 2
\r
145 #define portTIN_IE_INVALID_OPERAND 3
\r
146 #define portTIN_IE_DATA_ADDRESS_ALIGNMENT 4
\r
147 #define portTIN_IE_INVALID_LOCAL_MEMORY_ADDRESS 5
\r
149 /* Context Management Trap Identifications. */
\r
150 #define portTIN_CM_FREE_CONTEXT_LIST_DEPLETION 1
\r
151 #define portTIN_CM_CALL_DEPTH_OVERFLOW 2
\r
152 #define portTIN_CM_CALL_DEPTH_UNDEFLOW 3
\r
153 #define portTIN_CM_FREE_CONTEXT_LIST_UNDERFLOW 4
\r
154 #define portTIN_CM_CALL_STACK_UNDERFLOW 5
\r
155 #define portTIN_CM_CONTEXT_TYPE 6
\r
156 #define portTIN_CM_NESTING_ERROR 7
\r
158 /* System Bus and Peripherals Trap Identifications. */
\r
159 #define portTIN_SBP_PROGRAM_FETCH_SYNCHRONOUS_ERROR 1
\r
160 #define portTIN_SBP_DATA_ACCESS_SYNCHRONOUS_ERROR 2
\r
161 #define portTIN_SBP_DATA_ACCESS_ASYNCHRONOUS_ERROR 3
\r
162 #define portTIN_SBP_COPROCESSOR_TRAP_ASYNCHRONOUS_ERROR 4
\r
163 #define portTIN_SBP_PROGRAM_MEMORY_INTEGRITY_ERROR 5
\r
164 #define portTIN_SBP_DATA_MEMORY_INTEGRITY_ERROR 6
\r
166 /* Assertion Trap Identifications. */
\r
167 #define portTIN_ASSERT_ARITHMETIC_OVERFLOW 1
\r
168 #define portTIN_ASSERT_STICKY_ARITHMETIC_OVERFLOW 2
\r
170 /* Non-maskable Interrupt Trap Identifications. */
\r
171 #define portTIN_NMI_NON_MASKABLE_INTERRUPT 0
\r
172 /*---------------------------------------------------------------------------*/
\r
174 void vMMUTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
175 void vInternalProtectionTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
176 void vInstructionErrorTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
177 void vContextManagementTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
178 void vSystemBusAndPeripheralsTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
179 void vAssertionTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
180 void vNonMaskableInterruptTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
181 /*---------------------------------------------------------------------------*/
\r
183 void vTrapInstallHandlers( void )
\r
185 if( 0 == _install_trap_handler ( portMMU_TRAP, vMMUTrap ) )
\r
190 if( 0 == _install_trap_handler ( portIPT_TRAP, vInternalProtectionTrap ) )
\r
195 if( 0 == _install_trap_handler ( portIE_TRAP, vInstructionErrorTrap ) )
\r
200 if( 0 == _install_trap_handler ( portCM_TRAP, vContextManagementTrap ) )
\r
205 if( 0 == _install_trap_handler ( portSBP_TRAP, vSystemBusAndPeripheralsTrap ) )
\r
210 if( 0 == _install_trap_handler ( portASSERT_TRAP, vAssertionTrap ) )
\r
215 if( 0 == _install_trap_handler ( portNMI_TRAP, vNonMaskableInterruptTrap ) )
\r
220 /*-----------------------------------------------------------*/
\r
222 void vMMUTrap( int iTrapIdentification )
\r
224 switch( iTrapIdentification )
\r
226 case portTIN_MMU_VIRTUAL_ADDRESS_FILL:
\r
227 case portTIN_MMU_VIRTUAL_ADDRESS_PROTECTION:
\r
233 /*---------------------------------------------------------------------------*/
\r
235 void vInternalProtectionTrap( int iTrapIdentification )
\r
237 /* Deliberate fall through to default. */
\r
238 switch( iTrapIdentification )
\r
240 case portTIN_IPT_PRIVILIGED_INSTRUCTION:
\r
241 /* Instruction is not allowed at current execution level, eg DISABLE at User-0. */
\r
243 case portTIN_IPT_MEMORY_PROTECTION_READ:
\r
244 /* Load word using invalid address. */
\r
246 case portTIN_IPT_MEMORY_PROTECTION_WRITE:
\r
247 /* Store Word using invalid address. */
\r
249 case portTIN_IPT_MEMORY_PROTECTION_EXECUTION:
\r
250 /* PC jumped to an address outside of the valid range. */
\r
252 case portTIN_IPT_MEMORY_PROTECTION_PERIPHERAL_ACCESS:
\r
253 /* Access to a peripheral denied at current execution level. */
\r
255 case portTIN_IPT_MEMORY_PROTECTION_NULL_ADDRESS:
\r
256 /* NULL Pointer. */
\r
258 case portTIN_IPT_MEMORY_PROTECTION_GLOBAL_REGISTER_WRITE_PROTECTION:
\r
259 /* Tried to modify a global address pointer register. */
\r
263 pxCurrentTCB[ 0 ] = _mfcr( $PCXI );
\r
268 /*---------------------------------------------------------------------------*/
\r
270 void vInstructionErrorTrap( int iTrapIdentification )
\r
272 /* Deliberate fall through to default. */
\r
273 switch( iTrapIdentification )
\r
275 case portTIN_IE_ILLEGAL_OPCODE:
\r
276 case portTIN_IE_UNIMPLEMENTED_OPCODE:
\r
277 case portTIN_IE_INVALID_OPERAND:
\r
278 case portTIN_IE_DATA_ADDRESS_ALIGNMENT:
\r
279 case portTIN_IE_INVALID_LOCAL_MEMORY_ADDRESS:
\r
285 /*---------------------------------------------------------------------------*/
\r
287 void vContextManagementTrap( int iTrapIdentification )
\r
289 /* Deliberate fall through to default. */
\r
290 switch( iTrapIdentification )
\r
292 case portTIN_CM_FREE_CONTEXT_LIST_DEPLETION:
\r
293 case portTIN_CM_CALL_DEPTH_OVERFLOW:
\r
294 case portTIN_CM_CALL_DEPTH_UNDEFLOW:
\r
295 case portTIN_CM_FREE_CONTEXT_LIST_UNDERFLOW:
\r
296 case portTIN_CM_CALL_STACK_UNDERFLOW:
\r
297 case portTIN_CM_CONTEXT_TYPE:
\r
298 case portTIN_CM_NESTING_ERROR:
\r
304 /*---------------------------------------------------------------------------*/
\r
306 void vSystemBusAndPeripheralsTrap( int iTrapIdentification )
\r
308 /* Deliberate fall through to default. */
\r
309 switch( iTrapIdentification )
\r
311 case portTIN_SBP_PROGRAM_FETCH_SYNCHRONOUS_ERROR:
\r
312 case portTIN_SBP_DATA_ACCESS_SYNCHRONOUS_ERROR:
\r
313 case portTIN_SBP_DATA_ACCESS_ASYNCHRONOUS_ERROR:
\r
314 case portTIN_SBP_COPROCESSOR_TRAP_ASYNCHRONOUS_ERROR:
\r
315 case portTIN_SBP_PROGRAM_MEMORY_INTEGRITY_ERROR:
\r
316 case portTIN_SBP_DATA_MEMORY_INTEGRITY_ERROR:
\r
322 /*---------------------------------------------------------------------------*/
\r
324 void vAssertionTrap( int iTrapIdentification )
\r
326 /* Deliberate fall through to default. */
\r
327 switch( iTrapIdentification )
\r
329 case portTIN_ASSERT_ARITHMETIC_OVERFLOW:
\r
330 case portTIN_ASSERT_STICKY_ARITHMETIC_OVERFLOW:
\r
336 /*---------------------------------------------------------------------------*/
\r
338 void vNonMaskableInterruptTrap( int iTrapIdentification )
\r
340 /* Deliberate fall through to default. */
\r
341 switch( iTrapIdentification )
\r
343 case portTIN_NMI_NON_MASKABLE_INTERRUPT:
\r
349 /*---------------------------------------------------------------------------*/
\r