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