• 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 OAM PCM MODULE
15  */
16 #include "non_os.h"
17 #include "log_common.h"
18 #include "log_buffer.h"
19 #include "log_oam_ota.h"
20 #ifdef SDT_LOG_BY_UART
21 #include "sdt_by_uart_external.h"
22 #endif
23 
log_oml_ota_init(void)24 void log_oml_ota_init(void)
25 {
26     /* Set initialization success flag */
27     log_oml_ota_set(OM_OTA_OPEN);
28     log_oml_ota_write_register_callback(log_oml_ota_write_deal);
29 }
30 
log_oml_ota_write_deal(uint8_t mode_id,uint16_t msg_id,uint16_t length,const uint8_t * msg_buffer)31 void log_oml_ota_write_deal(uint8_t mode_id, uint16_t msg_id, uint16_t length, const uint8_t *msg_buffer)
32 {
33 #if (USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG == NO)
34     if (log_get_local_log_level() == LOG_LEVEL_NONE) {
35         return;
36     }
37 
38     om_ota_header_t ota_header;
39     uint8_t tail = OM_FRAME_DELIMITER;
40 #ifndef SDT_LOG_BY_UART
41     uint32_t available = 0;
42 #endif
43 
44     /* Check if initialization or OTA can output */
45     if (log_oml_ota_get() == OM_OTA_CLOSED) {
46         return;
47     }
48 
49     /* Check parameter */
50     if (length > OTA_DATA_MAX_SIZE || msg_buffer == NULL) {
51         return;
52     }
53 
54     /* Fill in the structure */
55     ota_header.header.frame_start = OM_FRAME_DELIMITER;
56     ota_header.header.func_type = OM_MSG_TYPE_OTA;
57     ota_header.header.prime_id = mode_id;
58     ota_header.header.frame_len = (uint16_t)sizeof(om_ota_header_t) + length + (uint16_t)sizeof(tail);
59     ota_header.header.sn = get_log_sn_number();
60     ota_header.msg_id = msg_id;
61     ota_header.data_len = length;
62 
63     non_os_enter_critical();
64 #ifdef SDT_LOG_BY_UART
65     oml_write_uart_fifo((uint8_t*)&ota_header, sizeof(om_ota_header_t), LOGUART_BASE);
66     oml_write_uart_fifo((uint8_t*)msg_buffer, length, LOGUART_BASE);
67     oml_write_uart_fifo((uint8_t*)&tail, sizeof(tail), LOGUART_BASE);
68 #else
69     log_buffer_get_available_for_next_message(&available);
70 
71     // Log buffer available enough to store buffer and time_us
72     if (ota_header.header.frame_len - sizeof(uint32_t) < available) {
73         log_event((uint8_t *)&ota_header, sizeof(om_ota_header_t));
74         log_event(msg_buffer, length);
75         log_event(&tail, sizeof(tail));
76     }
77 #endif
78     non_os_exit_critical();
79     return;
80 #else
81     UNUSED(mode_id);
82     UNUSED(msg_id);
83     UNUSED(length);
84     UNUSED(msg_buffer);
85 #endif
86 }
87 
log_oml_ota_switch(uint8_t on)88 void log_oml_ota_switch(uint8_t on)
89 {
90     log_oml_ota_set((om_ota_config_t)on);
91 }
92 
93