1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 #ifndef __LOG_SECTION_H__
5 #define __LOG_SECTION_H__
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 #include <string.h>
11 
12 #if 0
13 void init_dump_log(void);
14 void dump_whole_logs(void);
15 //void log_update_time_stamp(void);
16 //void set_dump_log_flush(bool isEnable);
17 //bool is_dump_log_flush_pending(void);
18 //void flush_dump_log_handler(void);
19 void clear_dump_log(void);
20 uint32_t test_dump_log_from_flash(uint32_t addr,uint32_t size);
21 #else
22 
23 #define LOG_DUMP_SECTOR_SIZE             0x1000
24 #define LOG_DUMP_SECTOR_BUFFER_COUNT     4
25 #define LOG_DUMP_BUFFER_LEN              (LOG_DUMP_SECTOR_SIZE*LOG_DUMP_SECTOR_BUFFER_COUNT)
26 #define LOG_DUMP_NORFALSH_BUFFER_LEN     (LOG_DUMP_BUFFER_LEN*2)
27 
28 #define DATA_BUFFER_STATE_FREE           0
29 #define DATA_BUFFER_STATE_WRITTING       0x1
30 #define DATA_BUFFER_STATE_WRITTEN        0x2
31 
32 #define DUMP_LOG_MAGIC                   0xd5151001
33 #define DUMP_LOG_VERSION                 0x00010001
34 // #define DUMP_LOG_NEWLINE  '\n'
35 
36 enum LOG_DUMP_FLUSH_STATE
37 {
38     LOG_DUMP_FLASH_STATE_IDLE,
39     LOG_DUMP_FLASH_STATE_ERASED,
40     LOG_DUMP_FLASH_STATE_WRITTING,
41     LOG_DUMP_FLASH_STATE_WRITTEN,
42 };
43 
44 typedef struct
45 {
46     uint32_t magic;
47     uint32_t version;
48     uint32_t seqnum;
49     uint8_t is_bootup;
50     uint8_t reseved[3];
51 }LOG_DUMP_HEADER;
52 
53 
54 typedef struct{
55     uint32_t state;
56     uint32_t offset;
57     uint8_t buffer[LOG_DUMP_BUFFER_LEN];
58 }DATA_BUFFER;
59 
60 void log_dump_init(void);
61 int log_dump_flush(void);
62 void log_dump_notify_handler(enum HAL_TRACE_STATE_T state);
63 void log_dump_output_handler(const unsigned char *buf, unsigned int buf_len);
64 void log_dump_callback(void* param);
65 void log_dump_clear(void);
66 
67 //uint32_t test_log_dump_from_flash(uint32_t addr,uint32_t size);
68 #endif
69 #ifdef __cplusplus
70 }
71 #endif
72 #endif
73 
74 
75