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: software at by zdiag
15 */
16
17 #ifdef CONFIG_AT_SUPPORT_ZDIAG
18
19 #include "nv.h"
20 #include "uapi_crc.h"
21 #include "soc_diag_cmd_id.h"
22 #include "dfx_adapt_layer.h"
23 #include "at_product.h"
24 #include "debug_print.h"
25 #include "at_zdiag.h"
26
27 #define KVALUE_MAX_LENGTH 4060
28
29 typedef struct {
30 uint32_t data_size;
31 uint8_t data[0];
32 } zdiag_at_input_t;
33
34 typedef struct {
35 uint8_t data[0];
36 } zdiag_at_output_t;
37
at_zdiag_write_func(const char * data)38 static void at_zdiag_write_func(const char *data)
39 {
40 int data_size = strlen(data);
41 if (data == NULL) {
42 return;
43 }
44 zdiag_at_output_t *at_output = (zdiag_at_output_t *)dfx_malloc(0, data_size);
45 if (at_output == NULL) {
46 return;
47 }
48 memcpy_s(at_output->data, data_size, data, data_size);
49 uapi_diag_report_packet(DIAG_CMD_SIMULATE_AT_IND, NULL, (uint8_t *)at_output, data_size, true);
50 dfx_free(0, at_output);
51 }
52
zdiag_at_init(void)53 void zdiag_at_init(void)
54 {
55 uapi_at_channel_write_register(AT_ZDIAG_PORT, at_zdiag_write_func);
56 }
57
zdiag_at_proc(uint16_t cmd_id,void * cmd_param,uint16_t cmd_param_size,diag_option_t * option)58 errcode_t zdiag_at_proc(uint16_t cmd_id, void *cmd_param, uint16_t cmd_param_size, diag_option_t *option)
59 {
60 unused(cmd_param_size);
61 unused(cmd_id);
62 unused(option);
63 static uint8_t g_at_pre_char = 0;
64 errcode_t ret;
65 zdiag_at_input_t *at_input = (zdiag_at_input_t *)cmd_param;
66
67 print_str("xxx zdiag_at_proc at_input.str: '%s', size = %u\r\n", at_input->data, at_input->data_size);
68 ret = uapi_at_channel_data_recv(AT_ZDIAG_PORT, (uint8_t *)at_input->data, (uint32_t)at_input->data_size);
69 if (ret != ERRCODE_SUCC) {
70 /* 前一个字符为'\r'时单独一个'\n'导致的CHANNEL_BUSY不打印 */
71 if (g_at_pre_char != '\r' || at_input->data_size != 1 || at_input->data[0] != '\n' ||\
72 ret != ERRCODE_AT_CHANNEL_BUSY) {
73 print_str("\r\nat_uart_rx_callback fail:0x%x\r\n", ret);
74 return ret;
75 }
76 }
77 g_at_pre_char = at_input->data[at_input->data_size - 1];
78 return ERRCODE_SUCC;
79 }
80
81 #endif