1/**
2* @file hi_at.h
3* Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8*     http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17/** @defgroup iot_at  AT Command
18 *  @ingroup dfx
19 */
20#ifndef __HI_AT_H__
21#define __HI_AT_H__
22#include <hi_types.h>
23
24typedef hi_u32 (*at_call_back_func)(hi_s32 argc, const hi_char **argv);
25
26typedef struct {
27    hi_char *at_cmd_name;
28    hi_s8   at_cmd_len;
29    at_call_back_func at_test_cmd;
30    at_call_back_func at_query_cmd;
31    at_call_back_func at_setup_cmd;
32    at_call_back_func at_exe_cmd;
33} at_cmd_func;
34
35typedef enum {
36    AT_IDLE,
37    AT_CMD_PROCESS,
38    AT_DATA_RECVING,
39    AT_DATA_SENDING,
40    AT_TRANSPARENT,
41} at_state_machine;
42
43typedef struct {
44    at_state_machine at_state;
45    hi_u16 send_len;
46    hi_u16 trans_len;
47    hi_bool is_first_recv_data;
48    hi_bool is_first_over_data;
49    hi_u16 is_recv_end_char_flag;
50} at_cmd_ctrl;
51
52typedef  hi_s32 (*hi_at_input_func)(hi_u8 *data, hi_u32 data_len);
53typedef  hi_s32 (*hi_at_output_func)(const hi_u8 *data, hi_u32 data_len);
54
55/**
56* @ingroup  iot_at
57* @brief  Get at registered output function.
58CNcomment:获取AT注册的输出函数。CNend
59*
60* @par 描述:
61*      Get at registered output function.
62CNcomment:获取AT注册的输出函数。CNend
63*
64* @attention None.
65* @param  None.
66*
67* @retval #g_at_output_func   At output function.
68* @par 依赖:
69*           @li hi_at.h:Describes at command APIs. CNcomment:文件用于描述at指令相关接口。CNend
70* @see  None
71*/
72hi_at_output_func hi_at_get_register_output_func(hi_void);
73
74/**
75* @ingroup  iot_at
76* @brief  Registration command processing function.CNcomment:注册命令处理函数。CNend
77*
78* @par 描述:
79*           @li This command is invoked during initialization and cannot be invoked by multiple tasks.
80CNcomment:在初始化阶段调用, 不支持多任务调用。CNend
81*           @li A maximum of 20 different command tables can be registered.
82CNcomment:最多能注册20个不同的命令表。CNend
83*
84* @attention None
85* @param  cmd_tbl    [IN] type #at_cmd_func*,Command table, which must be declared as a constant array and
86*                    transferred to this parameter.CNcomment:命令表,
87必须申明为常量数组传给该参数。CNend
88* @param  cmd_num    [IN] type #hi_u16,The number of commands. The value must be equal to the actual number of
89*                    commands in the command table. If it is less than the actual command number, only the number of
90*                    commands equal to this value is registered. If it is greater than the actual command number,
91*                    the command table will be accessed out of bounds.
92CNcomment:命令表中命令的个数,该值必须等于命令表中实际的命令个数,如果小于实际命令数,则只注册等于该值的命令个数,
93          大于实际命令个数将会导致越界访问命令表。CNend
94*
95* @retval #HI_ERR_SUCCESS         Success.
96* @retval #Other     Failure. For details, see hi_errno.h.
97* @par 依赖:
98*           @li hi_at.h:Describes at command APIs. CNcomment:文件用于描述at指令相关接口。CNend
99* @see  None
100*/
101hi_u32 hi_at_register_cmd(HI_CONST at_cmd_func *cmd_tbl, hi_u16 cmd_num);
102
103/**
104* @ingroup  iot_at
105* @brief  Register system AT command. CNcomment:注册系统AT命令。CNend
106*
107* @par 描述:
108*           Register system AT command. CNcomment:该函数用于注册系统AT命令。CNend
109* @param None
110* @retval None
111*
112* @par 依赖:
113*           @li hi_at.h:Describes at command APIs. CNcomment:文件用于描述at指令相关接口。CNend
114* @see  None
115*/
116hi_void hi_at_sys_cmd_register(hi_void);
117
118/**
119* @ingroup  iot_at
120* @brief  Formats the data and outputs it to AT command terminal.
121CNcomment:将数据格式化输出到AT命令终端。CNend
122*
123* @par 描述: Formats the data and outputs it to AT command terminal.
124CNcomment:将数据格式化输出到AT命令终端。CNend
125* @attention None
126*
127* @param fmt      [IN]  type #const hi_char *。 Formatting control string.CNcomment:格式化控制字符串。CNend
128* @param ...      [IN]  Optional parameter CNcomment:可选参数。CNend
129*
130* @retval #>=0 Return the number of bytes stored in terminal, not counting the terminating null character.
131CNcomment:返回输出到终端的字节数,不包括结束符CNend
132* @retval #-1 Failure
133*
134* @par 依赖:
135*           @li hi_at.h:Describes at command APIs. CNcomment:文件用于描述at指令相关接口。CNend
136* @see None
137*/
138hi_s32 hi_at_printf(const hi_char *fmt, ...);
139
140/**
141* @ingroup  iot_at
142* @brief  Initializes the AT task. CNcomment:AT命令任务初始化。CNend
143*
144* @par 描述:
145*           Initializes the AT task. CNcomment:该函数用于初始化AT命令任务。CNend
146* @param None
147* @retval #HI_ERR_SUCCESS         Success.
148* @retval #Other     Failure. For details, see hi_errno.h.
149*
150* @par 依赖:
151*           @li hi_at.h:Describes at command APIs. CNcomment:文件用于描述at指令相关接口。CNend
152* @see  None
153*/
154hi_u32 hi_at_init(hi_void);
155
156/**
157* @ingroup  iot_at
158* @brief  Set taks size of AT. CNcomment:设置AT相关任务栈大小。CNend
159*
160* @par 描述:
161*         Set taks size of AT. CNcomment:设置AT相关任务栈大小。CNend
162*
163* @attention AT task stack size needs to be set before AT initialization.
164CNcomment:AT任务栈大小需要在AT初始化之前设置。CNend
165* @param  channel_task_size      [IN] type #hi_u16 channel task size, task size should not smaller than 0x600.
166CNcomment:通道任务栈大小, 任务栈大小不低于0x600。Nend
167* @param  process_task_size      [IN] type #hi_u16 process task size, task size should not smaller than 0xc00.
168CNcomment:处理任务栈大小, 任务栈大小不低于0xc00。CNend
169*
170* @retval None
171* @par 依赖:
172*           @li hi_at.h:Describes at command APIs. CNcomment:文件用于描述at指令相关接口。CNend
173* @see  None
174*/
175hi_void hi_at_set_task_size(hi_u16 channel_task_size, hi_u16 process_task_size);
176
177/**
178* @ingroup  iot_at
179* @brief  Set whether to check the UART busy status when low power vote.
180CNcomment:设置低功耗投票时是否检查UART busy状态。CNend
181*
182* @par 描述:
183*      Set whether to check the UART busy status when low power vote.
184CNcomment:设置低功耗投票时是否检查UART busy状态。CNend
185*
186* @attention UART busy status is checked by default.
187CNcomment:默认低功耗睡眠投票时检查UART busy状态。CNend
188* @param  enable         [IN] type #hi_bool,enable status. CNcomment:设置是否检查UART busy状态。CNend
189*
190* @retval None
191* @par 依赖:
192*           @li hi_at.h:Describes at command APIs. CNcomment:文件用于描述at指令相关接口。CNend
193* @see  None
194*/
195hi_void hi_at_set_check_uart_busy(hi_bool enable);
196
197/**
198* @ingroup  iot_at
199* @brief  Register at input function to replace uart input.
200CNcomment:注册AT输入函数,代替默认从UART读取AT输入数据。CNend
201*
202* @par 描述:
203*      Register at input function to replace uart input.
204CNcomment:注册AT输入函数,代替默认从UART读取AT输入数据。CNend
205*
206* @attention Should set suitable task size; input func should not continuous read data without break. otherwise,
207a watchdog may happen.not support register HI_NULL when at channel is already uart.
208CNcomment:根据输入函数实现,设置合适的栈大小;输入函数不能持续
209返回有效数据避免触发看门狗。当AT通道已经是UART时,不支持注
210册AT 输入函数为HI_NULL。CNend
211* @param  at_input_func      [IN] type #hi_at_input_func,at input funciton.
212CNcomment:AT输入函数。CNend
213* @retval #0                 Success.
214* @retval #Other             Failure. For details, see hi_errno.h.
215* @par 依赖:
216*           @li hi_at.h:Describes at command APIs. CNcomment:文件用于描述at指令相关接口。CNend
217* @see  None
218*/
219hi_u32 hi_at_register_input_func(hi_at_input_func at_input_func);
220
221/**
222* @ingroup  iot_at
223* @brief  Register at output function to replace uart output.
224CNcomment:注册AT命令输出函数,代替默认从UART输出AT相关数据。CNend
225*
226* @par 描述:
227*      Register at output function to replace uart output.
228CNcomment:注册AT命令输出函数,代替默认从UART输出AT相关数据。CNend
229*
230* @attention Should set suitable task size according to implementation of output func.
231CNcomment:根据输出函数实现,设置合适的栈大小。CNend
232* @param  at_output_func      [IN] type #hi_at_output_func,at output function.
233CNcomment:AT输出函数。CNend
234* @retval None
235* @par 依赖:
236*           @li hi_at.h:Describes at command APIs. CNcomment:文件用于描述at指令相关接口。CNend
237* @see  None
238*/
239hi_void hi_at_register_output_func(hi_at_output_func at_output_func);
240
241#endif
242