• 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: dfx channel
15  * This file should be changed only infrequently and with great care.
16  */
17 
18 #include "dfx_adapt_layer.h"
19 #include "diag.h"
20 #include "diag_ind_src.h"
21 #include "diag_channel.h"
22 #include "diag_adapt_layer.h"
23 #include "log_uart.h"
24 #include "dfx_channel.h"
25 
26 diag_channel_id_t g_diag_channel_id = DIAG_CHANNEL_ID_INVALID;
27 
diag_uart_rx_proc(uint8_t * buffer,uint16_t length)28 void diag_uart_rx_proc(uint8_t *buffer, uint16_t length)
29 {
30 #ifndef SUPPORT_DIAG_V2_PROTOCOL
31     soc_diag_channel_rx_mux_char_data(g_diag_channel_id, buffer, length);
32 #else
33     uapi_diag_channel_rx_mux_char_data(DIAG_CHANNEL_ID_0, buffer, length);
34 #endif
35 }
36 
diag_channel_uart_output(void * fd,dfx_data_type_t data_type,uint8_t * data[],uint16_t len[],uint8_t cnt)37 static int32_t diag_channel_uart_output(void *fd, dfx_data_type_t data_type, uint8_t *data[],
38     uint16_t len[], uint8_t cnt)
39 {
40     unused(fd);
41     unused(data_type);
42     for (uint8_t i = 0; i < cnt; i++) {
43         log_uart_send_buffer(data[i], len[i]);
44     }
45     return ERRCODE_SUCC;
46 }
47 
diag_register_channel(void)48 errcode_t diag_register_channel(void)
49 {
50     g_diag_channel_id = DIAG_CHANNEL_ID_0;
51 #ifndef SUPPORT_DIAG_V2_PROTOCOL
52     if (soc_diag_channel_init(g_diag_channel_id, SOC_DIAG_CHANNEL_ATTR_NEED_RX_BUF) != ERRCODE_SUCC) {
53         return ERRCODE_FAIL;
54     }
55     if (soc_diag_channel_set_connect_hso_addr(g_diag_channel_id, diag_adapt_get_default_dst()) != ERRCODE_SUCC) {
56         return ERRCODE_FAIL;
57     }
58     if (soc_diag_channel_set_tx_hook(g_diag_channel_id, diag_channel_uart_output) != ERRCODE_SUCC) {
59         return ERRCODE_FAIL;
60     }
61 #else /* SUPPORT_DIAG_V2_PROTOCOL */
62 
63     if (uapi_diag_channel_init(g_diag_channel_id, DIAG_CHANNEL_ATTR_NEED_RX_BUF) != ERRCODE_SUCC) {
64         return ERRCODE_FAIL;
65     }
66     if (uapi_diag_channel_set_connect_hso_addr(g_diag_channel_id, (uint8_t)diag_adapt_get_default_dst()) !=
67         ERRCODE_SUCC) {
68         return ERRCODE_FAIL;
69     }
70     if (uapi_diag_channel_set_tx_hook(g_diag_channel_id, diag_channel_uart_output) != ERRCODE_SUCC) {
71         return ERRCODE_FAIL;
72     }
73 
74 #endif /* SUPPORT_DIAG_V2_PROTOCOL */
75     return ERRCODE_SUCC;
76 }