1 /** 2 **************************************************************************************** 3 * 4 * @file app_log_store.h 5 * 6 * @brief App Log Store API 7 * 8 **************************************************************************************** 9 * @attention 10 #####Copyright (c) 2019 GOODIX 11 All rights reserved. 12 13 Redistribution and use in source and binary forms, with or without 14 modification, are permitted provided that the following conditions are met: 15 * Redistributions of source code must retain the above copyright 16 notice, this list of conditions and the following disclaimer. 17 * Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in the 19 documentation and/or other materials provided with the distribution. 20 * Neither the name of GOODIX nor the names of its contributors may be used 21 to endorse or promote products derived from this software without 22 specific prior written permission. 23 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 POSSIBILITY OF SUCH DAMAGE. 35 ***************************************************************************************** 36 */ 37 38 #ifndef __APP_LOG_STORE_H__ 39 #define __APP_LOG_STORE_H__ 40 41 #include "custom_config.h" 42 #if APP_LOG_STORE_ENABLE 43 #include "gr55xx_sys.h" 44 #include "ring_buffer.h" 45 #include <string.h> 46 #include <stdarg.h> 47 #include <stdint.h> 48 #include <stdbool.h> 49 50 /** 51 * @defgroup APP_LOG_STORE_MAROC Defines 52 * @{ 53 */ 54 #define APP_LOG_STORE_RUN_ON_OS 0 /**< Is run on OS. */ 55 #define APP_LOG_STORE_LINE_SIZE 280 /**< Size for every line's log. */ 56 #define APP_LOG_STORE_CACHE_NUM 10 /**< Number of log lines cache. */ 57 /** @} */ 58 59 /** 60 * @defgroup APP_LOG_STORE_TYPEDEF Typedefs 61 * @{ 62 */ 63 /**@brief APP LOG Store flash data dump callback type. */ 64 typedef void (*app_log_store_dump_cb_t)(uint8_t *p_data, uint16_t len); 65 /** @} */ 66 67 /** 68 * @defgroup APP_LOG_STORE_STRUCT Structures 69 * @{ 70 */ 71 /**@brief The date and time structure. The packed size is 7 bytes. */ 72 typedef struct { 73 uint16_t year; /**< Year time element. */ 74 uint8_t month; /**< Month time element. */ 75 uint8_t day; /**< Day time element. */ 76 uint8_t hour; /**< Hour time element. */ 77 uint8_t min; /**< Minute time element. */ 78 uint8_t sec; /**< Second time element. */ 79 uint16_t msec; /**< Millisecond time element. */ 80 } app_log_store_time_t; 81 82 /**@brief App log store operation functions. */ 83 typedef struct { 84 bool (*flash_init)(void); /**< Flash init. */ 85 bool (*flash_erase)(const uint32_t addr, const uint32_t size); /**< Flash erase. */ 86 uint32_t (*flash_read)(const uint32_t addr, uint8_t *buf, const uint32_t size); /**< Flash read. */ 87 uint32_t (*flash_write)(const uint32_t addr, const uint8_t *buf, const uint32_t size); /**< Flash write. */ 88 void (*time_get)(app_log_store_time_t *p_time); /**< Get real time. */ 89 } app_log_store_op_t; 90 91 /**@brief App log store init stucture. */ 92 typedef struct { 93 uint16_t nv_tag; /**< NVDS Tag for app log store env. */ 94 uint32_t db_addr; /**< Start address of app log db flash. */ 95 uint32_t db_size; /**< Size of app log db flash. */ 96 uint16_t blk_size; /**< Block size in the flash for erase minimum granularity */ 97 } app_log_store_info_t; 98 /** @} */ 99 100 /** 101 * @defgroup APP_LOG_STORE_FUNCTION Functions 102 * @{ 103 */ 104 /** 105 ***************************************************************************************** 106 * @brief Initialize app log store module. 107 * 108 * @param[in] p_info: Pointer to log store information. 109 * @param[in] p_op_func: Pointer to log store opteration functions. 110 * 111 * @return Result of initialization. 112 ***************************************************************************************** 113 */ 114 uint16_t app_log_store_init(app_log_store_info_t *p_info, app_log_store_op_t *p_op_func); 115 116 /** 117 ***************************************************************************************** 118 * @brief Save app log data to flash. 119 * 120 * @param[in] p_data: Pointer to app log data. 121 * @param[in] length: Length of app log data. 122 * 123 * @return Result of save. 124 ***************************************************************************************** 125 */ 126 uint16_t app_log_store_save(const uint8_t *p_data, uint16_t length); 127 128 /** 129 ***************************************************************************************** 130 * @brief Dump app log data from flash. 131 * 132 * @param[in] dump_cb: Dump callback. 133 * 134 * @return Result of dump. 135 ***************************************************************************************** 136 */ 137 uint16_t app_log_store_dump(app_log_store_dump_cb_t dump_cb); 138 139 /** 140 ***************************************************************************************** 141 * @brief Flush app log store cache to flash. 142 ***************************************************************************************** 143 */ 144 void app_log_store_flush(void); 145 146 /** 147 ***************************************************************************************** 148 * @brief App log store clear. 149 ***************************************************************************************** 150 */ 151 void app_log_store_clear(void); 152 153 /** 154 ***************************************************************************************** 155 * @brief App log store dump is ongoing or not. 156 ***************************************************************************************** 157 */ 158 bool app_log_store_dump_ongoing(void); 159 160 /** 161 ***************************************************************************************** 162 * @brief App log store schedule for save and dump. 163 ***************************************************************************************** 164 */ 165 void app_log_store_schedule(void); 166 /** @} */ 167 #endif 168 #endif 169