iLLD_TC23x  1.0
IfxCpu_Trap.h
Go to the documentation of this file.
1 /**
2  * \file IfxCpu_Trap.c
3  * \brief This file contains the APIs for Trap related functions.
4  *
5  * \version iLLD_1_0_0_11_0
6  * \copyright Copyright (c) 2012 Infineon Technologies AG. All rights reserved.
7  *
8  *
9  * IMPORTANT NOTICE
10  *
11  *
12  * Infineon Technologies AG (Infineon) is supplying this file for use
13  * exclusively with Infineon's microcontroller products. This file can be freely
14  * distributed within development tools that are supporting such microcontroller
15  * products.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
18  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
20  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
21  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
22  *
23  *
24  * \defgroup IfxLld_Cpu_Trap Trap Functions
25  * \ingroup IfxLld_Cpu
26  *
27  * \defgroup IfxLld_Cpu_Trap_Hooks Trap Function Hooks
28  * \ingroup IfxLld_Cpu_Trap
29  *
30  * \defgroup IfxLld_Cpu_Trap_Usage How to use the Trap Function Hooks?
31  * \ingroup IfxLld_Cpu_Trap
32  *
33  */
34 
35 #ifndef IFXCPU_TRAPS_H_
36 #define IFXCPU_TRAPS_H_
37 
38 /*******************************************************************************
39 ** Includes **
40 *******************************************************************************/
41 #include "Cpu/Std/Ifx_Types.h"
43 #include "Ifx_Cfg.h"
44 
45 /*******************************************************************************
46 ** Type definitions **
47 *******************************************************************************/
48 /** \addtogroup IfxLld_Cpu_Trap_Hooks
49  * \{ */
50 
51 /** \brief Enum for available Trap classes.
52  *
53  */
54 typedef enum
55 {
65 
66 /** \brief Enum for available Identification numbers under Memory Management Trap.
67  *
68  */
69 typedef enum
70 {
74 
75 /** \brief Enum for available Identification numbers under Internal Protection Trap.
76  *
77  */
78 typedef enum
79 {
88 
89 /** \brief Enum for available Identification numbers under Instruction Errors Trap.
90  *
91  */
92 typedef enum
93 {
100 
101 /** \brief Enum for available Identification numbers under Context Management Trap.
102  *
103  */
104 typedef enum
105 {
114 
115 /** \brief Enum for available Identification numbers under Bus Trap.
116  *
117  */
118 typedef enum
119 {
128 
129 /** \brief Enum for available Identification numbers under Assertion Trap.
130  *
131  */
132 typedef enum
133 {
137 
138 /** \brief Type for Identification numbers under SystemCall Trap.
139  *
140  */
142 
143 /** \brief Type for Identification number for Non Maskable Interrupt Trap.
144  *
145  */
147 
148 /** \brief Union to abstract Identification numbers under Traps.
149  *
150  */
151 typedef union
152 {
162 
163 /** \brief Structure to contain the trap information.
164  *
165  */
166 typedef struct
167 {
168  unsigned int tAddr;
169  unsigned int tId : 8;
170  unsigned int tClass : 8;
171  unsigned int tCpu : 3;
172 } IfxCpu_Trap;
173 
174 /*******************************************************************************
175 ** Global Exported variables/constants **
176 *******************************************************************************/
177 
178 /*******************************************************************************
179 ** Global Exported macros/inlines/function ptototypes **
180 *******************************************************************************/
181 /** \brief Macro to define the trap vector table.
182  * This macro is provided to define the trap vector table in the frameowrk. User shall not use
183  * this macro.
184  * Refer to the documentation to extend the trap with hook functions. \ref IfxLld_Cpu_Trap_Usage
185  */
186 #if defined(__GNUC__)
187 #define __ALIGN_TRAP_TAB__ __asm(" .align 5");
188 #define IfxCpu_Tsr_CallTSR(serviceRoutine) \
189  { \
190  __ALIGN_TRAP_TAB__; \
191  __asm("mov\t %d4, %d15"); \
192  __asm("ji\t %0" : : "a" (serviceRoutine)); \
193  __asm("rfe"); \
194  }
195 #elif defined(__DCC__)
196 #define IfxCpu_Tsr_CallTSR(serviceRoutine) \
197  { \
198  __ALIGN_TRAP_TAB__; \
199  __asm("\n#$$bp\n"); \
200  __asm(" movh.a\t %a15,"#serviceRoutine "@ha\n"); \
201  __asm(" lea\t %a15,[%a15]"#serviceRoutine "@l\n"); \
202  __asm(" mov\t %d4,%d15\n"); \
203  __asm(" ji\t %a15\n"); \
204  __asm(" rfe"); \
205  __asm("#$$ep"); \
206  }
207 #define __ALIGN_TRAP_TAB__ __asm(" .align 5");
208 #elif defined(__TASKING__)
209 #define IfxCpu_Tsr_CallTSR(serviceRoutine) \
210  { \
211  __ALIGN_TRAP_TAB__; \
212  __asm("mov\td4,d15\n\tji\t%0\n\trfe\n" : : "a" (serviceRoutine) : "d4", "d15"); \
213  }
214 #define __ALIGN_TRAP_TAB__ __asm(" .align 32");
215 #endif
216 
217 /** \} */
218 
219 /*Documentation */
220 /** \addtogroup IfxLld_Cpu_Trap_Usage
221  * \{
222  *
223  * This page describes how to use the trap function hooks with application framework.\n
224  * Framework has built in Trap Service Routines, which has minimal set of debug information.
225  * The execution of trap service is as below,\n
226  * 1) When a trap occurs, a global structure variable "trapWatch" is updated with the information:\n
227  * __a. Which CPU caused this trap,\n
228  * __b. What is the trap class and\n
229  * __c. What is the trap identification number\n
230  * 2) Call to a configurable hook function, passing structure trapWatch as parameter.\n
231  * 3) Then debug instruction executed.\n
232  * 4) Returning from the trap. (This instruction is not reached if debugger is connected because of
233  * "debug" instruction before)\n
234  * For normal cases during development, where user works with debugger, user can watch the structure variable
235  * "trapWatch" in the debugger.
236  *
237  * In case, user wants to make use of the information of trap for further processing,\n
238  * extend the traps, using the hook functions provided.
239  *
240  * \section IfxLld_Cpu_Trap_Hooks Extending the traps with hook functions.
241  *
242  * If the trap extensions are to be extended, it is very important to enable this feature. By default this
243  * feature is disabled.
244  *
245  * \subsection IfxLld_Cpu_Trap_Hooks_EnableExtn How to enable the trap extension feature?
246  * To extend the trap hook functions user must enable this feature by defining the macro
247  * "IFX_CFG_EXTEND_TRAP_HOOKS" in Ifx_Cfg.h, at path: 0_Src/0_AppSw/Config/Common/, as shown below.
248  * \code
249  * //file: Ifx_Cfg.h
250  *
251  * #define IFX_CFG_EXTEND_TRAP_HOOKS
252  *
253  * \endcode
254  * Now the compiler will accept the further configurations to extend the hooks.\n
255  * IfxCpu_Traps_Cfg.h file shall be used to extend the traps. This provide two kind of hook functions.
256  * ie. Hook for error traps and hooks (per CPU available) for system calls.
257  *
258  * \subsection IfxLld_Cpu_Trap_ErrorHooks Extending the "Error traps" with hook function.
259  * Error trap occurs as a result of an error event such as an instruction error, memory-management error
260  * or an illegal access.\n
261  * To extend the error traps, following steps are to be followed:\n
262  * \subsubsection IfxLld_Cpu_Trap_ErrorHooksStep1 Step1: Define a routine to substitute the hook for error traps.
263  * This definition shall be as user defined code (Generally in DemoApps folder).\n
264  * Considerations:\n
265  * 1. Format: IFX_INLINE void <trap extension name>(IfxCpu_Trap trapInfo)
266  * \note Define such a routine with the consideration that the trap extension hook is not a function. In case
267  * of context management error, this extension itself will not call any other function.
268  *
269  * 2. Use the information trapInfo, which is available as parameter passed to this hook and process further.
270  * Example code in a user defined file eg. Ifx_TrapExtension.h, placed under folder/subfolder: 0_AppSw/Tricore/DemoApp:
271  * \code
272  * //Example "inlined" function for trap Extension Hook.
273  * IFX_INLINE myTrapExtensionHook(IfxCpu_Trap trapInfo)
274  * {
275  * switch (trapInfo.tClass)
276  * {
277  * case IfxCpu_Trap_Class_memoryManagement:
278  * {
279  * //user code: Function calls allowed.
280  * break;
281  * }
282  * case IfxCpu_Trap_Class_internalProtection:
283  * {
284  * //user code: Function calls allowed.
285  * break;
286  * }
287  * case IfxCpu_Trap_Class_instructionErrors:
288  * {
289  * //user code: Function calls allowed.
290  * break;
291  * }
292  * case IfxCpu_Trap_Class_contextManagement:
293  * {
294  * //user code: Function calls NOT allowed.
295  * break;
296  * }
297  * case IfxCpu_Trap_Class_bus:
298  * {
299  * //user code: Function calls allowed.
300  * break;
301  * }
302  * case IfxCpu_Trap_Class_assertion:
303  * {
304  * //user code: Function calls allowed.
305  * break;
306  * }
307  * case IfxCpu_Trap_Class_nonMaskableInterrupt:
308  * {
309  * //user code: Function calls allowed.
310  * break;
311  * }
312  * case default:
313  * {
314  * break;
315  * }
316  * }
317  * }
318  * \endcode
319  * \note The error trap functions execute the debug instruction immediately after returning from extension hooks.
320  *
321  * \subsubsection IfxLld_Cpu_Trap_ErrorHooksStep2 Step2: Configure error trap hook extension function.
322  * Configure error trap hook extension function as defined above to the macro as below:
323  * \note Configuration of hook extension is available in IfxCpu_Trap_Cfg at path ../0_Src/0_AppSw/Tricore/McHalCfg/
324  *
325  * \code
326  * //file: IfxCpu_Trap_Cfg.h
327  *
328  * #include "Ifx_TrapExtension.h" //Assuming this is the file name as in above example
329  *
330  * #define IFXCPU_TRAP_CFG_TSR_HOOK(trapInfo) myTrapExtensionHook(trapInfo) //This is INLINE function.
331  *
332  * \endcode
333  * \note The exten hooks are effective only if this feature is enabled as explained in \ref Ifx_Trap_Hooks_EnableExtn
334  *
335  * \subsection IfxLld_Cpu_Trap_SysCallHooks Extending the cpu specific "system call" hook functions.
336  * Tricore architecture provides the system call trap which is executed by software trigger. The instruction "syscall"
337  * triggers this trap. Please refer Tricore architecture manual for more details.\n
338  * IfxCpu_trap driver provide hook function for each CPU separately. To extend System Call trap following steps
339  * are to be followed:\n
340  * \subsubsection IfxLld_Cpu_Trap_SysCallHooksStep1 Step1: Define routine/s to substitute the hook/s for System Call trap.
341  * This definition shall be as user defined code (Generally in DemoApps folder).\n
342  * Considerations:\n
343  * 1. Format: void <syscall function name>(IfxCpu_Trap trapInfo)
344  * It is allowed to define this trap extension as function definition, because this trap is not triggered due to any error.
345  * Depending on the application requirement, define single or per CPU instance of the extension.
346  *
347  * 2. Use the information trapInfo which is available as parameter passed to this hook and process further. The parameter
348  * passed, with syscall instruction, will be trap identification number (refer to Tricore architecture manual for more details).
349  * \note To hook extension, information about trap identification number is available through parameter "trapInfo".
350  *
351  * Example code in a user defined file eg. Ifx_TrapExtension.h, placed under folder/subfolder: 0_AppSw/Tricore/DemoApp:
352  * \code
353  * //Example function for System Call Extension Hook.
354  * IFX_INLINE mySysCallExtensionHook(IfxCpu_Trap trapInfo)
355  * {
356  * switch (trapInfo.tId)
357  * {
358  * case 0:
359  * {
360  * //user code: Function calls allowed.
361  * break;
362  * }
363  * case 1:
364  * {
365  * //user code: Function calls allowed.
366  * break;
367  * }
368  * // and so on..
369  * case default:
370  * {
371  * break;
372  * }
373  * }
374  * }
375  * \endcode
376  *
377  * \subsubsection IfxLld_Cpu_Trap_SysCallHooksStep2 Step2: Configure the extension function.\n
378  * Configure the hook extension function defined above, to the macro as below:
379  * \note Configuration of hook extension is available in IfxCpu_Trap_Cfg file at path ../0_Src/0_AppSw/Tricore/McHalCfg/
380  * \code
381  * //file: IfxCpu_Trap_Cfg.h
382  *
383  * #include "Ifx_TrapExtension.h" //Assuming this is the file name as in above example
384  *
385  * #define IFXCPU_TRAP_CFG_SYSCALL_CPU0_HOOK(trapInfo) mySysCallExtensionHook(trapInfo)
386  *
387  * #define IFXCPU_TRAP_CFG_SYSCALL_CPU1_HOOK(trapInfo) // Not used in this example
388  *
389  * #define IFXCPU_TRAP_CFG_SYSCALL_CPU2_HOOK(trapInfo) // Not used in this example
390  *
391  * #define IFXCPU_TRAP_CFG_SYSCALL_CPU3_HOOK(trapInfo) // Not used in this example
392  *
393  * #define IFXCPU_TRAP_CFG_SYSCALL_CPU4_HOOK(trapInfo) // Not used in this example
394  *
395  * #define IFXCPU_TRAP_CFG_SYSCALL_CPU5_HOOK(trapInfo) // Not used in this example
396  *
397  * \endcode
398  *
399  * \note The exten hooks are effective only if this feature is enabled as explained in \ref Ifx_Trap_Hooks_EnableExtn
400  *
401  */
402 /** \} */
403 
404 #endif /* IFXCPU_TRAPS_H_ */