• 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: sample data
15  * This file should be changed only infrequently and with great care.
16  */
17 #include "errcode.h"
18 #include "diag.h"
19 #include "soc_diag_cmd_id.h"
20 #include "dfx_adapt_layer.h"
21 #include "diag_adapt_layer.h"
22 #include "diag_sample_data_st.h"
23 #include "diag_bt_sample_data.h"
24 
25 typedef struct {
26     uint32_t transmit_id;
27     uint16_t offset;
28 } diag_sample_data_transmit_info_t;
29 
30 diag_sample_data_transmit_info_t g_sample_data_transmit_ctrl[DIAG_SAMPLE_DATA_TRANSMIT_ID_COUNT];
31 
sample_data_get_transmit_info(uint32_t transmit_id)32 static diag_sample_data_transmit_info_t* sample_data_get_transmit_info(uint32_t transmit_id)
33 {
34     uint32_t index;
35     for (index = 0; index < DIAG_SAMPLE_DATA_TRANSMIT_ID_COUNT; index++) {
36         if (g_sample_data_transmit_ctrl[index].transmit_id == transmit_id) {
37             return &g_sample_data_transmit_ctrl[index];
38         }
39     }
40     return NULL;
41 }
42 
sample_data_add_transmit_info(uint32_t transmit_id)43 static diag_sample_data_transmit_info_t* sample_data_add_transmit_info(uint32_t transmit_id)
44 {
45     uint32_t index;
46     for (index = 0; index < DIAG_SAMPLE_DATA_TRANSMIT_ID_COUNT; index++) {
47         if (g_sample_data_transmit_ctrl[index].transmit_id == 0) {
48             break;
49         }
50     }
51     if (index < DIAG_SAMPLE_DATA_TRANSMIT_ID_COUNT) {
52         g_sample_data_transmit_ctrl[index].transmit_id = transmit_id;
53         g_sample_data_transmit_ctrl[index].offset = 0;
54         return &g_sample_data_transmit_ctrl[index];
55     }
56     return NULL;
57 }
58 
diag_sample_data_report_start(uint32_t transmit_id)59 errcode_t diag_sample_data_report_start(uint32_t transmit_id)
60 {
61     diag_sample_data_transmit_info_t *transmit_info = sample_data_get_transmit_info(transmit_id);
62     if (transmit_info != NULL) {
63         transmit_info->offset = 0;
64         return ERRCODE_SUCC;
65     } else {
66         transmit_info = sample_data_add_transmit_info(transmit_id);
67         if (transmit_info != NULL) {
68             return ERRCODE_SUCC;
69         } else {
70             dfx_log_err("transmit_id(0x%x) start error \r\n", transmit_id);
71             return ERRCODE_FAIL;
72         }
73     }
74 }
75 
diag_sample_data_report_stop(uint32_t transmit_id)76 errcode_t diag_sample_data_report_stop(uint32_t transmit_id)
77 {
78     diag_sample_data_transmit_info_t *transmit_info = sample_data_get_transmit_info(transmit_id);
79     if (transmit_info != NULL) {
80         transmit_info->transmit_id = 0;
81         transmit_info->offset = 0;
82     }
83     return ERRCODE_SUCC;
84 }
85 
diag_sample_data_report(uint32_t transmit_id,uint8_t * buf,uint32_t size)86 errcode_t diag_sample_data_report(uint32_t transmit_id, uint8_t *buf, uint32_t size)
87 {
88     uint8_t *data[2];
89     uint16_t len[2];
90     diag_sample_data_reply_pkt_t ind;
91     diag_sample_data_transmit_info_t *transmit_info = sample_data_get_transmit_info(transmit_id);
92 
93     if (transmit_info == NULL) {
94         dfx_log_debug("sample_data_report transmit_id(0x%x) not start \r\n", transmit_id);
95         return ERRCODE_FAIL;
96     }
97 
98     data[0] = (uint8_t*)&ind;
99     len[0] = (uint16_t)sizeof(diag_sample_data_reply_pkt_t);
100     data[1] = buf;
101     len[1] = (uint16_t)size;
102 
103     ind.offset = transmit_info->offset;
104     ind.size = size;
105     ind.ret = ERRCODE_SUCC;
106     ind.transmit_id = transmit_id;
107     ind.crc = 0;
108     uapi_diag_report_packets_normal(DIAG_CMD_ID_SAMPLE_DATA, NULL, data, len, 2); /* pkt_cnt 为2 */
109     transmit_info->offset += (uint16_t)size;
110     return ERRCODE_SUCC;
111 }