• 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:  LOG BUFFER INTERFACE
15  * Author:
16  * Create:  2018-10-15
17  */
18 
19 #ifndef NON_OS_LOG_BUFFER_H
20 #define NON_OS_LOG_BUFFER_H
21 
22 #include <stdint.h>
23 #include "log_buffer_common.h"
24 #include "log_memory_section.h"
25 
26 /**
27  * @defgroup connectivity_drivers_non_os_log LOG
28  * @ingroup  connectivity_drivers_non_os
29  * @{
30  */
31 #define CHR_VALUE_NULL        0
32 #define CHR_VALUE_SHFIT_24BIT 24
33 #define CHR_INFO1_SHFIT_16BIT 16
34 #define CHR_INFO2_SHFIT_8BIT  8
35 #define CHR_VALUE_MASK        0xff
36 #define CHR_BUFFER_WL_RATIO   2
37 #define CHR_EXTEND_PARAM_MAX_LEN            128
38 
39 #define chr_tws_value_group(EVENT, INFO1, INFO2, INFO3) (((uint32_t)((uint32_t)(EVENT) & CHR_VALUE_MASK) << \
40                                                         CHR_VALUE_SHFIT_24BIT) | \
41                                                         ((uint32_t)((uint32_t)(INFO1) & CHR_VALUE_MASK) << \
42                                                         CHR_INFO1_SHFIT_16BIT) | \
43                                                         ((uint32_t)((uint32_t)(INFO2) & CHR_VALUE_MASK) << \
44                                                         CHR_INFO2_SHFIT_8BIT) | \
45                                                         ((INFO3) & CHR_VALUE_MASK))
46 
47 #define chr_wear_value_group(EVENT, INFO1, INFO2, INFO3) (((uint32_t)((uint32_t)(EVENT) & CHR_VALUE_MASK) << \
48                                                          CHR_VALUE_SHFIT_24BIT) | \
49                                                          ((uint32_t)((uint32_t)(INFO1) & CHR_VALUE_MASK) << \
50                                                          CHR_INFO1_SHFIT_16BIT) | \
51                                                          ((uint32_t)((uint32_t)(INFO2) & CHR_VALUE_MASK) << \
52                                                          CHR_INFO2_SHFIT_8BIT) | \
53                                                          ((INFO3) & CHR_VALUE_MASK))
54 
55 typedef enum {
56     LOG_RET_OK,
57     LOG_RET_ERROR_IN_PARAMETERS,
58     LOG_RET_ERROR_NOT_ENOUGH_SPACE,
59     LOG_RET_ERROR_CORRUPT_SHARED_MEMORY,
60     LOG_RET_ERROR_OVERFLOW
61 } log_ret_t;
62 
63 typedef enum {
64     MASS_RET_OK,
65     MASS_RET_ERROR_IN_PARAMETERS,
66     MASS_RET_ERROR_NOT_ENOUGH_SPACE,
67     MASS_RET_ERROR_CORRUPT_SHARED_MEMORY,
68     MASS_MEM_COPY_FAIL,
69     MASS_OVER_BUFFER_THD,
70 } mass_data_ret_t;
71 
72 #define EVENT_ID_BEGIN          943900000
73 #define EVENT_ID_END            943999999
74 #define get_event_id(id, info1) (EVENT_ID_BEGIN + (((id) << 8) | (info1)))
75 
76 typedef enum {
77     MASS_EVENT_POINT,
78     MASS_ERROR_POINT,
79     MASS_EVENT_POINT_EXTEND,
80     MASS_ERROR_POINT_EXTEND,
81 } mass_point_type_t;
82 
83 // upload chr type
84 typedef enum {
85     CHR_DFT = 0x0,
86     CHR_UE_INT = 0x01,
87     CHR_UE_STR = 0x02,
88     CHR_UE_JSON = 0x03,
89     CHR_UE_BETA = 0x04,
90     CHR_END,
91 } chr_type_t;
92 
93 typedef struct {
94     uint32_t time_stamp;
95     uint32_t event_id;       // diff from the 1 byte event ids, compose of EVENT_BEGIN | eventId<<8 | info1
96     uint8_t event_info;      // info2
97     uint8_t magic_number;
98     uint8_t chr_up_type;     // upload chr format type
99     uint8_t role;         // byte align
100     uint32_t sub_event_info;  // info3
101     uint32_t version;
102     uint32_t psn;
103 } system_event_s_t, system_error_s_t;
104 
105 #ifdef FEATURE_PLT_LB_CHECK
106 typedef enum {
107     LOG_BUF_RET_OK = 0,
108     LOG_BUF_RLW_MAGIC_ERROR = 1,
109     LOG_RET_RGW_TOEND_MAGIC_ERROR = 2,
110     LOG_RET_RGW_LASTONE_MAGIC_ERROR = 3,
111     LOG_RET_MEMCPY_ERROR = 4,
112 } log_buffer_check_error_t;
113 #endif
114 
115 #pragma pack(1)
116 typedef struct {
117     uint8_t type;              // 0-event, 1-error.
118     uint8_t event_id;
119     uint8_t info1;
120     uint8_t info2;
121     uint16_t info3;
122     uint8_t data_len;
123     uint8_t data[CHR_EXTEND_PARAM_MAX_LEN];
124 } chr_extend_data_t;
125 #pragma pack()
126 
127 /**
128  * @brief  Initialize the log buffer module to log in the given log memory region section.
129  * @return LOG_RET_OK or an error value
130  */
131 void log_buffer_init(log_memory_region_section_t logsec);
132 
133 #if (BTH_WITH_SMART_WEAR == YES) && defined(SUPPORT_IPC)
134 /**
135  * @brief  record the system event.
136  * @return void
137  */
138 void massdata_record_system_event(uint8_t event_id, uint8_t info1, uint8_t info2, uint8_t info3);
139 
140 /**
141  * @brief  record the system error.
142  * @return void
143  */
144 void massdata_record_system_error(uint8_t event_id, uint8_t info1, uint8_t info2, uint8_t info3);
145 
146 #else
147 #if (CORE == APPS)
148 /**
149  * @brief  record the system event
150  * @param  eid chr info1
151  * @param  sub_eid chr info2
152  * @param  code mass chr info3
153  * @param  sub_code chr info4
154  * @return void
155  */
156 void chr_record_ue(uint8_t eid, uint8_t sub_eid, uint8_t code, uint32_t sub_code);
157 
158 /**
159  * @brief  record the system event.
160  * @return void
161  */
162 void massdata_record_system_event(uint8_t event_id, uint8_t info1, uint8_t info2, uint32_t info3);
163 
164 /**
165  * @brief  record the system error.
166  * @return void
167  */
168 void massdata_record_system_error(uint8_t event_id, uint8_t info1, uint8_t info2, uint32_t info3);
169 
170 #elif (CORE == BT)
171 
172 void massdata_set_role(uint8_t role);
173 
174 /**
175  * @brief  record the system event
176  * @param  eid chr info1
177  * @param  sub_eid chr info2
178  * @param  code mass chr info3
179  * @param  sub_code chr info4
180  * @return void
181  */
182 void chr_record_ue(uint8_t eid, uint8_t sub_eid, uint8_t code, uint32_t sub_code);
183 
184 /**
185  * @brief  record the system event.
186  * @return void
187  */
188 void massdata_record_system_event(uint8_t event_id, uint8_t info1, uint8_t info2, uint32_t info3);
189 
190 /**
191  * @brief  record the system error.
192  * @return void
193  */
194 void massdata_record_system_error(uint8_t event_id, uint8_t info1, uint8_t info2, uint32_t info3);
195 #endif
196 #endif
197 
198 void log_buffer_massdata_record_system_error_wear(uint8_t event_id, uint8_t info1, uint8_t info2, uint8_t info3);
199 
200 /**
201  * @brief  init the mass share mem.
202  * @return void
203  */
204 void mass_buffer_init(mass_data_memory_region_section_t sec);
205 
206 /**
207  * @brief  write seg in the mass share mem.
208  * @return LOG_RET_OK or an error value
209  */
210 uint32_t mass_data_write_roll_buffer(const uint8_t *data, uint32_t length);
211 
212 /**
213  * @brief  triger mass data to flush.
214  * @return LOG_RET_OK or an error value
215  */
216 uint32_t massdata_triger_event(void);
217 
218 /**
219  * @brief  triger mass data to flush by queue.
220  * @param  pay_i mass data payload
221  * @param  type event or error
222  * @return LOG_RET_OK or an error value
223  */
224 uint32_t massdata_triger_queue(const uint8_t *pay_i, uint32_t type);
225 
226 /**
227  * @brief  Add data to the circular buffer with updating the write index.
228  * @param  lb_header Header of the log buffer.
229  * @param  buffer Pointer to the buffer.
230  * @param  was_empty Was empty or not.
231  */
232 void log_buffer_write(const log_buffer_header_t *lb_header, const uint8_t *buffer, bool *was_empty);
233 
234 /**
235  * @brief  Get the available space for the next message
236  * @param  av available space will be stored here
237  * @return LOG_RET_OK or an error code
238  */
239 log_ret_t log_buffer_get_available_for_next_message(uint32_t *av);
240 
241 #ifdef FEATURE_PLT_LB_CHECK
242 uint8_t log_buffer_check(void);
243 #endif
244 
245 #if (USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG == YES)
246 log_ret_t compress_log_write(const uint8_t *data, uint32_t length);
247 #endif
248 
249 /**
250  * @brief  Record chr event
251  * @param  chr_event type of chr event
252  */
253 void log_buffer_record_system_event(uint32_t chr_event);
254 
255 /**
256  * @brief  Record chr error
257  * @param  chr_error type of chr error
258  */
259 void log_buffer_record_system_error(uint32_t chr_error);
260 
261 /**
262  * @brief  Record chr info with extend parameter.
263  * @param  extend_data type of chr information
264  */
265 void massdata_record_system_info_with_extend(chr_extend_data_t *extend_data);
266 
267 /**
268  * @}
269  */
270 #endif
271