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 OAM PCM MODULE
15 */
16 #include "non_os.h"
17 #include "log_common.h"
18 #include "log_buffer.h"
19 #include "log_oam_pcm.h"
20
21 static uint16_t g_log_bt_sampledata_sn_number = 0;
22 static uint8_t g_bt_sample_datastart = OM_BT_SAMPLE_DATA_OPEN;
23
log_oml_bt_sample_data_init(void)24 void log_oml_bt_sample_data_init(void)
25 {
26 /* Set initialization success flag */
27 g_bt_sample_datastart = OM_BT_SAMPLE_DATA_OPEN;
28 }
29
30 #if (USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG == NO)
log_oml_bt_sample_data_write_deal(uint8_t mode_id,uint16_t msg_id,uint16_t length,const uint8_t * msg_buffer)31 void log_oml_bt_sample_data_write_deal(uint8_t mode_id, uint16_t msg_id, uint16_t length, const uint8_t *msg_buffer)
32 {
33 om_pcm_header_t pcm_header;
34 uint8_t tail = OM_FRAME_DELIMITER;
35 uint32_t lb_available;
36
37 /* Check if initialization or OTA can output */
38 if ((g_bt_sample_datastart == OM_BT_SAMPLE_DATA_CLOSED) || (log_get_local_log_level() == LOG_LEVEL_NONE)) {
39 return;
40 }
41
42 /* Check parameter */
43 if ((length > BT_SAMPLE_DATA_MAX_SIZE) || (msg_buffer == NULL)) {
44 return;
45 }
46
47 /* Fill in the structure */
48 pcm_header.header.frame_start = OM_FRAME_DELIMITER;
49 pcm_header.header.func_type = OM_BT_SAMPLE_DATA;
50 pcm_header.header.prime_id = mode_id;
51 pcm_header.header.frame_len = (uint16_t)sizeof(om_pcm_header_t) + length + (uint16_t)sizeof(tail);
52 pcm_header.header.sn = g_log_bt_sampledata_sn_number++;
53 pcm_header.msg_id = msg_id;
54 pcm_header.data_len = length;
55
56 lb_available = 0;
57 non_os_enter_critical();
58 log_buffer_get_available_for_next_message(&lb_available);
59
60 // Log buffer available enough to store buffer and time_us
61 if (pcm_header.header.frame_len - sizeof(uint32_t) >= lb_available) {
62 non_os_exit_critical();
63 return;
64 } else {
65 log_event((uint8_t *)&pcm_header, sizeof(om_pcm_header_t));
66 log_event(msg_buffer, length);
67 log_event(&tail, sizeof(tail));
68 non_os_exit_critical();
69 }
70 }
71 #else
log_oml_bt_sample_data_write_deal(uint8_t mode_id,uint16_t msg_id,uint16_t length,const uint8_t * buffer)72 void log_oml_bt_sample_data_write_deal(uint8_t mode_id, uint16_t msg_id, uint16_t length, const uint8_t *buffer)
73 {
74 om_pcm_header_t pcm_header;
75
76 /* Check if initialization or OTA can output */
77 if ((g_bt_sample_datastart == OM_BT_SAMPLE_DATA_CLOSED) || (log_get_local_log_level() == LOG_LEVEL_NONE)) {
78 return;
79 }
80
81 /* Check parameter */
82 if ((length > BT_SAMPLE_DATA_MAX_SIZE) || (buffer == NULL)) {
83 return;
84 }
85
86 pcm_header.magic = OM_SNOOP_MAGIC_NUM;
87 pcm_header.primeid = mode_id;
88 pcm_header.sn = g_log_bt_sampledata_sn_number++;
89 pcm_header.msgid = msg_id;
90 pcm_header.datalen = length;
91
92 compress_log_write((const uint8_t *)&pcm_header, sizeof(om_pcm_header_t));
93 compress_log_write((const uint8_t *)buffer, length);
94 }
95 #endif
96
log_oml_bt_sample_data_switch(uint8_t on)97 void log_oml_bt_sample_data_switch(uint8_t on)
98 {
99 g_bt_sample_datastart = on;
100 }
101