• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
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  */
15 
16 /**
17  ****************************************************************************************
18  *
19  * @file lega_at_api.h
20  *
21  * @brief AT API.
22  *
23  ****************************************************************************************
24  */
25 #ifndef _LEGA_AT_API_H_
26 #define _LEGA_AT_API_H_
27 #ifdef CFG_PLF_DUET
28 #include "duet_uart.h"
29 #else
30 #include "lega_uart.h"
31 #endif
32 
33 #include <stdio.h>
34 #ifndef LWIP_IGNORE
35 #include "lwip/ip_addr.h"
36 #endif
37 #include "target_config.h"
38 #if (LOSCFG_KERNEL_PRINTF != 0)
39 #define TASKLIST_SUPPORT
40 #define HEAPSHOW_SUPPORT
41 // LOS_TaskInfoMonitor
42 #endif
43 
44 #define LEGA_AT_VERSION        "AT-V2.1.3"
45 
46 #define     AT_TASK_NAME                "AT_task"
47 #define     AT_TASK_PRIORITY            (20)
48 #define     AT_TASK_STACK_SIZE          2048
49 
50 typedef struct _cmd_entry {
51     char *name;
52     int (*function)(int, char **);
53     char *help;
54 } cmd_entry;
55 
56 #define AT_MAX_COMMANDS           90
57 struct cli_cmd_t {
58     int cmds_num;
59     cmd_entry *cmds[AT_MAX_COMMANDS];
60 };
61 
62 typedef struct {
63     uint8_t   uart_echo;       /* echo uart input info log */
64     uint8_t   max_txpwr;       /* max tx power for both sta and softap */
65     uint8_t   flag_sap;        /* flag of user set softap ip config */
66     uint8_t   flag_sta;        /* flag of user set sta ip config */
67     uint8_t   dis_dhcp;        /* disable dhcp func, use static ip */
68     uint8_t   at_scan;         /* scan flag which indicate call by at task */
69     uint8_t   sta_connected;   /* indicate status of station is connected */
70     uint8_t   sap_opend;       /* indicate status of softap is open done */
71 #ifndef LWIP_IGNORE
72     ip_addr_t at_ping;         /* save ping ip addr for at cmd */
73 #endif
74     char      staip[16];       /* Local IP address on the target wlan interface for station mode, ASCII */
75     char      stagw[16];       /* Router IP address on the target wlan interface for station mode, ASCII */
76     char      stamask[16];     /* Netmask on the target wlan interface for station mode, ASCII */
77     char      sapip[16];       /* Local IP address on the target wlan interface for softap mode, ASCII */
78     char      sapgw[16];       /* Router IP address on the target wlan interface for softap mode, ASCII */
79     char      sapmask[16];     /* Netmask on the target wlan interface for softap mode, ASCII */
80     char      start_ip[16];    /* start ip addr of dhcp pool in softap mode */
81     char      end_ip[16];      /* end ip addr of dhcp pool in softap mode */
82 } _at_user_info;
83 
84 typedef enum {
85     CONFIG_OK,          /* indicate at cmd set success and response OK */
86     PARAM_RANGE,        /* indicate some at cmd param is out of range */
87     PARAM_MISS,         /* indicate at cmd param is less than needed count */
88     CONFIG_FAIL,        /* indicate at cmd set failed, or execute fail */
89     CONN_TIMEOUT,       /* indicate connect timeout in station mode */
90     CONN_EAPOL_FAIL,    /* indicate 4-way handshake failed in station mode */
91     CONN_DHCP_FAIL,     /* indicate got ip by dhcp failed in station mode */
92     WAIT_PEER_RSP,
93     RSP_NULL = 0xFF
94 } lega_at_rsp_status_t;
95 
96 typedef struct {
97     char *command;  /* at cmd string */
98     int (*function)(int argc, char **argv); /* at cmd proccess function */
99 } lega_at_cmd_entry;
100 
101 #ifdef CFG_SDIO_SUPPORT
102 typedef void (*lega_at_sdio_host_tx_hdlr)(uint8_t *data, uint32_t data_len);
103 typedef struct {
104     uint32_t sdio_data_len;
105     uint32_t p_sdio_at_cmd;
106 } at_msg_t;
107 #endif
108 
109 /** @brief  register user at cmd.
110  *
111  * @param cmd_entry    : user at cmd array pointer
112  * @param cmd_num      : user at cmd number
113  */
114 void lega_at_cmd_register(cmd_entry *cmd);
115 
116 /** @brief  at init functin, user should call it before use at cmd
117  *  @return    0       : on success.
118  *  @return    other   : error occurred
119  */
120 int lega_at_init(const char *task_name, uint8_t task_pri, uint32_t task_stack_size);
121 
122 /** @brief  at deinit functin, user should call it when donot use at any more, to free resources
123  *  @return    0       : on success.
124  *  @return    other   : error occurred
125  */
126 int lega_at_deinit(void);
127 
128 /** @brief  at command callback function, used to register to uart.
129  */
130 void at_handle_uartirq(char ch);
131 
132 /** @brief  uart handle for receiving at command.
133  */
134 
135 #ifdef CFG_PLF_DUET
136 extern duet_uart_dev_t lega_at_uart;
137 #else
138 extern lega_uart_dev_t lega_at_uart;
139 #endif
140 
141 /** @brief  at register init functin, register all support cmd and user register cmd
142  */
143 void lega_at_cmd_register_all(void);
144 
145 /** @brief  register user cmd
146  */
147 void lega_at_user_cmd_register(void);
148 
149 /** @brief  at response, OK indicate success, others indicate failed.
150  */
151 void lega_at_response(lega_at_rsp_status_t status);
152 
153 extern char at_dbgflg;
154 
155 #ifdef PRINTF2_SUPPORT
156 extern int printf2(const char *format, ...);
157 #else
158 #define printf2 printf
159 #endif
160 
161 #define dbg_at(Fmt, ...)         do {if (at_dbgflg) printf2(Fmt "\r\n", ## __VA_ARGS__);} while (0)
162 #define dbg_atnn(Fmt, ...)       do {if (at_dbgflg) printf2(Fmt, ## __VA_ARGS__);} while (0)
163 #define at_rspdata(Fmt, ...)     printf2("+" Fmt "\r\n", ## __VA_ARGS__)
164 #define at_rspdatann(Fmt, ...)   printf2("+" Fmt, ## __VA_ARGS__)
165 #define at_rspinfor(Fmt, ...)    printf2(Fmt "\r\n", ## __VA_ARGS__)
166 #define at_rspinfornn(Fmt, ...)  printf2(Fmt, ## __VA_ARGS__)
167 
168 #endif  // _LEGA_AT_API_H_
169 
170