• 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: zdiag pkt
15  * This file should be changed only infrequently and with great care.
16  */
17 #ifndef __ZDIAG_PKT_H__
18 #define __ZDIAG_PKT_H__
19 #include "diag_common.h"
20 #include "diag.h"
21 
22 
23 typedef enum {
24     DIAG_PKT_MEM_TYPE_HEAD_STACK_DATA_STACK,
25     DIAG_PKT_MEM_TYPE_HEAD_DATA_DFX_MALLOC,
26 } diag_pkt_mem_type_t;
27 
28 typedef enum {
29     DIAG_PKT_DATA_ID_DATA_0,
30     DIAG_PKT_DATA_ID_DATA_1,
31     DIAG_PKT_DATA_ID_DATA_2,
32     DIAG_PKT_DATA_ID_USR_MAX,
33 } diag_pkt_data_id_t;
34 
35 #define DIAG_PKT_DATA_ATTRIBUTE_SINGLE_TASK 0x1
36 #define DIAG_PKT_DATA_ATTRIBUTE_DYN_MEM 0x2
37 
38 typedef enum {
39     DIAG_PKT_DATA_STACK = DIAG_PKT_DATA_ATTRIBUTE_SINGLE_TASK,
40     DIAG_PKT_DATA_DFX_MALLOC = DIAG_PKT_DATA_ATTRIBUTE_DYN_MEM,
41 } diag_pkt_data_type_t;
42 
43 typedef struct {
44     uint8_t *data[DIAG_PKT_DATA_ID_USR_MAX];
45     uint16_t data_len[DIAG_PKT_DATA_ID_USR_MAX];
46     uint8_t data_cnt : 2;
47     uint8_t need_free : 1;      /* true:pkt有数据需要释放 false:pkt无数据需要释放 */
48     uint8_t single_task : 1;    /* true:pkt有数据无法跨任务传递 false:pkt无数据无法跨任务传递 */
49     uint8_t critical : 1;       /* 非调度报文,如:死机 */
50 } diag_pkt_handle_t;
51 
52 /**
53  * @if Eng
54  * @brief  Structure for diag ack.
55  * @else
56  * @brief  diag应答结构体
57  * @endif
58  */
59 typedef struct {
60     uint16_t sn;               /*!< @if Eng cmd sn.
61                                     @else   命令sn @endif */
62     uint8_t ctrl;              /*!< @if Eng ack mode.
63                                     @else   应答模式 @endif */
64     uint8_t pad;
65     uint16_t cmd_id;           /*!< @if Eng cmd id.
66                                     @else   应答id @endif */
67     uint16_t param_size;       /*!< @if Eng param size.
68                                     @else   应答内容大小 @endif */
69     uint8_t *param;            /*!< @if Eng data.
70                                     @else   应答内容 @endif */
71 } msp_diag_ack_param_t;
72 
73 errcode_t zdiag_check_mux_pkt(msp_mux_packet_head_stru_t *mux, uint16_t size);
74 errcode_t zdiag_check_hcc_pkt(const uint8_t *data, uint16_t size);
75 void diag_pkt_handle_init(diag_pkt_handle_t *pkt, uint8_t data_cnt);
76 void diag_pkt_set_critical(diag_pkt_handle_t *pkt);
77 void diag_pkt_handle_set_data(diag_pkt_handle_t *pkt, uint8_t idx, uint8_t *data,
78                               uint16_t data_len, diag_pkt_data_type_t attribute);
79 
80 void zdiag_mk_log_pkt(diag_cmd_log_layer_ind_stru_t *log_pkt, uint32_t module_id, uint32_t msg_id);
81 void zdiag_mk_log_pkt_sn(diag_cmd_log_layer_ind_stru_t *log_pkt, uint32_t module_id, uint32_t msg_id, uint32_t sn);
82 void diag_mk_ind_header(msp_diag_head_ind_stru_t *ind, uint16_t cmd_id, uint16_t packet_size);
83 void diag_mk_req_header(msp_diag_head_req_stru_t *req, uint16_t cmd_id, uint16_t packet_size);
84 void diag_mk_cnf_header(msp_diag_head_cnf_stru_t *cnf, msp_diag_ack_param_t *ack);
85 void diag_mk_mux_header_1(msp_mux_packet_head_stru_t *mux, uint8_t type, uint16_t cmd_id, uint16_t pkt_size);
86 void diag_mk_mux_header_2(msp_mux_packet_head_stru_t *mux, diag_addr dst, uint16_t crc16);
87 
diag_pkt_handle_get_mux(const diag_pkt_handle_t * pkt)88 static inline msp_mux_packet_head_stru_t *diag_pkt_handle_get_mux(const diag_pkt_handle_t *pkt)
89 {
90     return (msp_mux_packet_head_stru_t *)pkt->data[0];
91 }
92 
diag_receive_pkt_handle_get_ind(const diag_pkt_handle_t * pkt)93 static inline msp_diag_head_ind_stru_t *diag_receive_pkt_handle_get_ind(const diag_pkt_handle_t *pkt)
94 {
95     return (msp_diag_head_ind_stru_t *)(pkt->data[0] + DIAG_MUX_HEADER_SIZE);
96 }
97 
diag_receive_pkt_handle_get_ind_data(const diag_pkt_handle_t * pkt)98 static inline uint8_t *diag_receive_pkt_handle_get_ind_data(const diag_pkt_handle_t *pkt)
99 {
100     return pkt->data[0] + DIAG_MUX_HEADER_SIZE + DIAG_IND_HEADER_SIZE;
101 }
102 
diag_receive_pkt_handle_get_req(const diag_pkt_handle_t * pkt)103 static inline msp_diag_head_req_stru_t *diag_receive_pkt_handle_get_req(const diag_pkt_handle_t *pkt)
104 {
105     return (msp_diag_head_req_stru_t *)(pkt->data[0] + DIAG_MUX_HEADER_SIZE);
106 }
107 
diag_receive_pkt_handle_get_req_data(const diag_pkt_handle_t * pkt)108 static inline uint8_t *diag_receive_pkt_handle_get_req_data(const diag_pkt_handle_t *pkt)
109 {
110     return pkt->data[0] + DIAG_MUX_HEADER_SIZE + DIAG_REQ_HEADER_SIZE;
111 }
112 
diag_pkt_handle_get_total_size(const diag_pkt_handle_t * pkt)113 static inline uint32_t diag_pkt_handle_get_total_size(const diag_pkt_handle_t *pkt)
114 {
115     uint32_t total_size = 0;
116     for (int i = 0; i < pkt->data_cnt; i++) {
117         total_size += (uint32_t)pkt->data_len[i];
118     }
119     return total_size;
120 }
121 
diag_pkt_handle_clean(diag_pkt_handle_t * pkt)122 static inline void diag_pkt_handle_clean(diag_pkt_handle_t *pkt)
123 {
124     pkt->need_free = false;
125     for (int i = 0; i < pkt->data_cnt; i++) {
126         pkt->data[i] = NULL;
127         pkt->data_len[i] = 0;
128     }
129     pkt->data_cnt = 0;
130 }
131 
diag_pkt_cnt_increase(diag_pkt_handle_t * pkt,uint8_t cnt)132 static inline void diag_pkt_cnt_increase(diag_pkt_handle_t *pkt, uint8_t cnt)
133 {
134     pkt->data_cnt += cnt;
135 }
136 
137 #endif
138