• 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 READER MODULE INTERFACE.
15  * Author:
16  * Create:  2018-10-15
17  */
18 
19 #ifndef NON_OS_LOG_BUFFER_READER_H
20 #define NON_OS_LOG_BUFFER_READER_H
21 
22 #include "log_memory_definitions.h"
23 #include "log_buffer_common.h"
24 
25 /**
26  * @addtogroup connectivity_drivers_non_os_log
27  * @{
28  */
29 typedef enum {
30     LOG_READER_RET_OK,
31     LOG_READER_RET_BUSY,
32     LOG_READER_RET_ERROR,
33     LOG_READER_RET_TIMEDOUT,
34     LOG_READER_RET_ERROR_OVERFLOW_ON_DISCARDING,
35     LOG_READER_RET_THERE_IS_NO_NEXT_MESSAGE,
36     LOG_READER_RET_ERROR_IN_PARAMS,
37     LOG_READER_RET_ERROR_TRYING_TO_DISCARD_WHEN_EMPTY,
38     LOG_READER_RET_ERROR_CORRUPT_SHARED_MEMORY,
39 } log_reader_ret_t;
40 
41 /**
42  * @brief  Initialize the log buffer reader module
43  */
44 log_reader_ret_t log_buffer_reader_init(void);
45 
46 /**
47  * @brief  Lock the next message in the log buffer and returns its parameters.
48  * @param  lmsec log memory section of the region holding the next message
49  * @param  lb_header The log_buffer_header_t for the next log will be stored here
50  * @return LOG_READER_RET_OK if the next message was locked, LOG_READER_RET_THERE_IS_NO_NEXT_MESSAGE if there is no
51  * next message to lock, an error code otherwise.
52  */
53 log_reader_ret_t log_buffer_reader_lock_next(log_memory_region_section_t *lmsec, const log_buffer_header_t *lb_header);
54 
55 /**
56  * @brief  Claim the next message in the buffer.
57  * @param  lmsec log memory section
58  * @param  r1 (return value) a pointer to the first part of the message
59  * @param  len1 (return value) length of the first part of the message
60  * @param  r2 (return value) a pointer to the first part of the message ( in case is not in a contiguous memory block)
61  * @param  len2 (return value) length of the first part of the message  ( in case is not in a contiguous memory block)
62  * @return LOG_READER_RET_OK or an error code
63  */
64 log_reader_ret_t log_buffer_reader_claim_next(log_memory_region_section_t lmsec, uint8_t **r1,
65                                               uint32_t *len1, uint8_t **r2, uint32_t *len2);
66 
67 /**
68  * @brief  Discard a previously claimed message
69  * @param  lmsec log memory section
70  * @return LOG_READER_RET_OK or an error code
71  */
72 log_reader_ret_t log_buffer_reader_discard(log_memory_region_section_t lmsec);
73 
74 /**
75  * @brief  Get the used space in a log memory section.
76  * @param  lmsec log memory section
77  * @param  used_space used space in bytes
78  * @return LOG_READER_RET_OK or an error code
79  */
80 log_reader_ret_t log_buffer_get_used_space(log_memory_region_section_t lmsec, uint32_t *used_space);
81 
82 /**
83  * @brief  Recovery error log region.
84  * @param  lmsec log memory section
85  */
86 void log_buffer_reader_error_recovery(log_memory_region_section_t lmsec);
87 
88 /**
89  * @}
90  */
91 #endif
92