• 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: diag mem
15  * This file should be changed only infrequently and with great care.
16  */
17 
18 #include "zdiag_mem.h"
19 #include "diag_adapt_layer.h"
20 #include "diag_dfx.h"
21 #include "diag_pkt.h"
22 #include "zdiag_debug.h"
23 #include "errcode.h"
24 
diag_pkt_need_cross_task(diag_pkt_handle_t * pkt)25 errcode_t diag_pkt_need_cross_task(diag_pkt_handle_t *pkt)
26 {
27     uint8_t *buf = NULL;
28 
29     if (pkt->single_task == false) {
30         return ERRCODE_SUCC;
31     }
32 
33     uint32_t copyed_size = 0;
34     uint32_t total_size = diag_pkt_handle_get_total_size(pkt);
35     buf = dfx_malloc(0, total_size);
36     if (buf == NULL) {
37         return ERRCODE_FAIL;
38     }
39 
40     diag_dfx_alloc_pkt(0, total_size);
41 
42     for (unsigned i = 0; i < pkt->data_cnt; i++) {
43         if (memcpy_s(buf + copyed_size, total_size - copyed_size, pkt->data[i], pkt->data_len[i]) != EOK) {
44             dfx_log_debug("memcpy fail\r\n");
45         }
46         copyed_size += pkt->data_len[i];
47     }
48 
49     diag_pkt_handle_init(pkt, 1);
50     diag_pkt_handle_set_data(pkt, DIAG_PKT_DATA_ID_DATA_0, buf, (uint16_t)total_size, DIAG_PKT_DATA_DFX_MALLOC);
51     return ERRCODE_SUCC;
52 }
53 
diag_pkt_free(diag_pkt_handle_t * pkt)54 void diag_pkt_free(diag_pkt_handle_t *pkt)
55 {
56     if ((pkt->need_free) != 0) {
57         dfx_assert(pkt->data_cnt == 1);
58         dfx_free(0, pkt->data[0]);
59         diag_dfx_free_pkt(0, pkt->data_len[0]);
60         diag_pkt_handle_clean(pkt);
61         return;
62     }
63     return;
64 }
65