1 // Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef _xtensa_perfmon_apis_H_
16 #define _xtensa_perfmon_apis_H_
17 #include "xtensa_perfmon_access.h"
18 #include "xtensa_perfmon_masks.h"
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 
26 /**
27  * @brief Performance monitor configuration structure
28  *
29  * Structure to configure performance counter to measure dedicated function
30  */
31 typedef struct xtensa_perfmon_config {
32     int repeat_count;       /*!< how much times function will be called before the calback will be repeated */
33     float max_deviation;    /*!<  Difference between min and max counter number 0..1, 0 - no difference, 1 - not used */
34     void *call_params;      /*!<  This pointer will be passed to the call_function as a parameter */
35     void (*call_function)(void *params); /*!< pointer to the function that have to be called */
36     void (*callback)(void *params, uint32_t select, uint32_t mask, uint32_t value); /*!< pointer to the function that will be called with result parameters */
37     void *callback_params;  /*!<  parameter that will be passed to the callback */
38     int tracelevel;         /*!<  trace level for all counters.
39                                   In case of negative value, the filter will be ignored.
40                                   If it's >=0, then the perfmon will count only when interrupt level > tracelevel. It's useful to monitor interrupts. */
41     uint32_t  counters_size;/*!<  amount of counter in the list */
42     const uint32_t *select_mask;  /*!<  list of the select/mask parameters */
43 } xtensa_perfmon_config_t;
44 
45 
46 /**
47  * @brief      Execute PM
48  *
49  * Execute performance counter for dedicated function with defined parameters
50  *
51  * @param[in] config: pointer to the configuration structure
52  *
53  * @return
54  *      - ESP_OK if no errors
55  *      - ESP_ERR_INVALID_ARG if one of the required parameters not defined
56  *      - ESP_FAIL - counter overflow
57  */
58 esp_err_t xtensa_perfmon_exec(const xtensa_perfmon_config_t *config);
59 
60 /**
61  * @brief      Dump PM results
62  *
63  * Callback to dump perfmon result to a FILE* stream specified in
64  * perfmon_config_t::callback_params. If callback_params is set to NULL, will print to stdout
65  *
66  * @param[in] params:   used parameters passed from configuration (callback_params).
67  *                      This parameter expected as FILE* hanle, where data will be stored.
68  *                      If this parameter NULL, then data will be stored to the stdout.
69  * @param[in] select:   select value for current counter
70  * @param[in] mask:     mask value for current counter
71  * @param[in] value:    counter value for current counter
72  *
73  */
74 void xtensa_perfmon_view_cb(void *params, uint32_t select, uint32_t mask, uint32_t value);
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif // _xtensa_perfmon_apis_H_
81