• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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  * Description: offline log file saved to the storage
15  */
16 
17 #ifndef LOG_FILE_H
18 #define LOG_FILE_H
19 
20 #include <stdint.h>
21 #include "errcode.h"
22 #include "dfx_feature_config.h"
23 
24 /*
25  * 文件类型名
26  */
27 #if defined(CONFIG_DFX_STORE_DIAG_ONLY) && (CONFIG_DFX_STORE_DIAG_ONLY == DFX_YES)
28 typedef enum {
29     STORE_DIAG,
30     STORE_MAX
31 } store_service_t;
32 #else
33 typedef enum {
34     STORE_DIAG,
35     STORE_DUMP,
36     STORE_DOTTING,
37     STORE_MAX
38 } store_service_t;
39 #endif
40 
41 /*
42  * 文件头存储信息
43  */
44 typedef struct {
45     uint32_t start_flag;        /* 固定为0xaabbccdd */
46     uint32_t version;           /* 版本号 */
47     uint32_t update_time;       /* 多文件存储时进行判别文件顺序,可以是时间戳等  */
48     uint32_t cur_pos;           /* 将要写入的文件位置  */
49     uint32_t file_size;         /* service设置的文件最大字节数 */
50     uint32_t first_record_pos;  /* 本文件第一个有效的record */
51     uint32_t records;           /* 当前文件的记录条数 */
52     uint8_t service_type;       /* 业务类型, 对应store_service  */
53     uint8_t offset;             /* head size; 即文件中记录区的起始位置 */
54     uint16_t crc;               /* 文件头的CRC校验 */
55 } store_file_head_t;
56 
57 /*
58  * 日志存储格式信息
59  */
60 typedef struct {
61     const char *name;           /* 文件名字,多文件存储时,会在name后面增加后缀_0 、_1 ... */
62     const char *path;           /* 文件所在目录,以‘/’结尾 */
63     uint32_t file_size;         /* 每个文件的最大容量 unit:字节 */
64     uint16_t cache_size;        /* 初始创建文件时申请缓存大小; 关闭、删除文件时释放 */
65     uint8_t enable_cache;       /* 是否支持缓存 */
66     uint8_t mult_files;         /* 支持的存储文件个数, 为1时表示单文件存储 */
67 } store_file_cfg_t;
68 
69 /*
70  * 离线存储功能初始化
71  */
72 errcode_t uapi_logfile_init(void);
73 
74 /*
75  * 打开日志存放的文件
76  * service_type 文件类型
77  * cfg 存储格式信息
78  */
79 errcode_t uapi_logfile_open(store_service_t service_type, const store_file_cfg_t *cfg);
80 
81 /*
82  * 写日志到已打开的文件中
83  * service_type 文件类型
84  * sub_type 存储硬件类型
85  * data 日志数据的指针
86  * data_len 日志数据的长度
87  */
88 errcode_t uapi_logfile_write(store_service_t service_type, uint8_t sub_type, uint8_t *data, uint32_t data_len);
89 
90 /*
91  * 关闭日志存放的文件,并摧毁线程,关闭定时器,释放使用者分配的缓存
92  * service_type 文件类型
93  */
94 errcode_t uapi_logfile_close(store_service_t service_type);
95 
96 /*
97  * 同步离线日志文件数据
98  */
99 errcode_t uapi_logfile_fsync(store_service_t service_type);
100 
101 /*
102  * 暂时停止日志文件的写入(资源不释放,暂时不再接受日志的写入,和对flash的操作)
103  * service_type 文件类型
104  */
105 errcode_t uapi_logfile_suspend(store_service_t service_type);
106 
107 /*
108  * 恢复日志文件的写入
109  * service_type 文件类型
110  */
111 errcode_t uapi_logfile_resume(store_service_t service_type);
112 
113 /*
114  * 日志文件重置(删除或擦除日志文件)
115  * service_type 文件类型
116  * cfg 存储格式信息
117  */
118 errcode_t uapi_logfile_reset(store_service_t service_type, store_file_cfg_t *cfg);
119 
120 #endif /* LOG_FILE_H */
121