1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** ThreadX Component                                                     */
17 /**                                                                       */
18 /**   Execution Profile Kit                                               */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 #ifndef TX_EXECUTION_PROFILE_H
25 #define TX_EXECUTION_PROFILE_H
26 
27 
28 /*  The thread execution profile kit is designed to track thread execution time
29     based on the hardware timer defined by TX_EXECUTION_TIME_SOURCE and
30     TX_EXECUTION_MAX_TIME_SOURCE below. When the thread's total time reaches
31     the maximum value, it remains there until the time is reset to 0 via a call
32     to tx_thread_execution_time_reset. There are several assumptions to the
33     operation of this kit, as follows:
34 
35     1.  The TX_EXECUTION_TIME_SOURCE and TX_EXECUTION_MAX_TIME_SOURCE macros are
36         defined to utilize a local hardware time source.
37 
38     2.  The following routines are called from assembly code:
39             VOID  _tx_execution_thread_enter(void);
40             VOID  _tx_execution_thread_exit(void);
41             VOID  _tx_execution_isr_enter(void);
42             VOID  _tx_execution_isr_exit(void);
43 
44     3.  The ThreadX library must be rebuilt with TX_EXECUTION_PROFILE_ENABLE so
45         the assembly code macros are enabled to call the execution profile routines.
46 
47     4.  Add tx_execution_profile.c to the application build.  */
48 
49 /* Define the basic time typedefs for 64-bit accumulation and a 32-bit timer source, which is the
50    most common configuration.  */
51 
52 typedef unsigned long long              EXECUTION_TIME;
53 typedef unsigned long                   EXECUTION_TIME_SOURCE_TYPE;
54 /* For 64-bit time source, the typedef would be:  */
55 /* typedef unsigned long long              EXECUTION_TIME_SOURCE_TYPE;  */
56 
57 /* Define basic constants for the execution profile kit.  */
58 
59 /*  Example for Cortex-M targets:  */
60 #ifndef TX_EXECUTION_TIME_SOURCE
61 #define TX_EXECUTION_TIME_SOURCE         (EXECUTION_TIME_SOURCE_TYPE) *((volatile ULONG *) 0xE0001004)
62 #endif
63 #ifndef TX_EXECUTION_MAX_TIME_SOURCE
64 #define TX_EXECUTION_MAX_TIME_SOURCE     0xFFFFFFFF
65 #endif
66 
67 /* For 64-bit time source, the constant would be:  */
68 /*#define TX_EXECUTION_TIME_SOURCE         (EXECUTION_TIME_SOURCE_TYPE) *((volatile unsigned long long *) 0xE0001004)  */
69 /*#define TX_EXECUTION_MAX_TIME_SOURCE     0xFFFFFFFFFFFFFFFF  */
70 
71 
72 /* Define APIs of the execution profile kit.  */
73 
74 struct TX_THREAD_STRUCT;
75 VOID  _tx_execution_initialize(void);
76 VOID  _tx_execution_thread_enter(void);
77 VOID  _tx_execution_thread_exit(void);
78 VOID  _tx_execution_isr_enter(void);
79 VOID  _tx_execution_isr_exit(void);
80 UINT  _tx_execution_thread_time_reset(struct TX_THREAD_STRUCT *thread_ptr);
81 UINT  _tx_execution_thread_total_time_reset(void);
82 UINT  _tx_execution_isr_time_reset(void);
83 UINT  _tx_execution_idle_time_reset(void);
84 UINT  _tx_execution_thread_time_get(struct TX_THREAD_STRUCT *thread_ptr, EXECUTION_TIME *total_time);
85 UINT  _tx_execution_thread_total_time_get(EXECUTION_TIME *total_time);
86 UINT  _tx_execution_isr_time_get(EXECUTION_TIME *total_time);
87 UINT  _tx_execution_idle_time_get(EXECUTION_TIME *total_time);
88 
89 #endif
90