1 // Copyright 2015-2016 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 #pragma once
16 
17 #include <stdint.h>
18 #include <stdbool.h>
19 #include "esp_err.h"
20 #include "sdkconfig.h"
21 
22 #if CONFIG_SPI_FLASH_ENABLE_COUNTERS
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /**
29  * Structure holding statistics for one type of operation
30  */
31 typedef struct {
32     uint32_t count;     // number of times operation was executed
33     uint32_t time;      // total time taken, in microseconds
34     uint32_t bytes;     // total number of bytes
35 } spi_flash_counter_t;
36 
37 typedef struct {
38     spi_flash_counter_t read;
39     spi_flash_counter_t write;
40     spi_flash_counter_t erase;
41 } spi_flash_counters_t;
42 
43 /**
44  * @brief  Reset SPI flash operation counters
45  */
46 void spi_flash_reset_counters(void);
47 
48 /**
49  * @brief  Print SPI flash operation counters
50  */
51 void spi_flash_dump_counters(void);
52 
53 /**
54  * @brief  Return current SPI flash operation counters
55  *
56  * @return  pointer to the spi_flash_counters_t structure holding values
57  *          of the operation counters
58  */
59 const spi_flash_counters_t* spi_flash_get_counters(void);
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif //CONFIG_SPI_FLASH_ENABLE_COUNTERS
66