1 /* 2 * Copyright (c) 2021 Bestechnic (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 #ifndef _CONSOLE_H 16 #define _CONSOLE_H 17 18 #include <stdint.h> 19 #include <stddef.h> 20 #include <string.h> 21 22 #define CONSOLE_DUMP_STACK_EN 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define CMD_CBSIZE 128 29 #define CMD_PROMPT "best_wifi> " 30 #define CMD_MAXARGS 16 31 #define CMD_LIST_COUNT 128 32 #define CONSOLE_RING_BUFFER_SIZE 512// mast be 2^n 33 //2 TODO: This value should be equal to CONSOLE cmd_list elements number!!! 34 #ifdef __WIFI_NVR_SUPPORT__ 35 #define MAX_CMD_ITEMS (10) 36 #else 37 #define MAX_CMD_ITEMS (8) 38 #endif 39 40 typedef struct cmd_tbl_s { 41 char *name; /* Command Name */ 42 int maxargs; /* maximum number of arguments */ 43 int (*cmd)(struct cmd_tbl_s *, int, char *[], void *handler); 44 char *usage; /* Usage message(short)*/ 45 } cmd_tbl_t; 46 47 extern cmd_tbl_t cmd_list[CMD_LIST_COUNT]; 48 extern unsigned int cmd_cntr; 49 50 #define console_strtoul simple_strtoul 51 #define console_cmd_usage show_cmd_usage 52 #define console_cmd_add add_cmd_to_list 53 54 extern void console_init(void); 55 extern void console_puts(const char *s); 56 extern void console_putc(char c); 57 58 extern void nts_free(void *rmem); 59 extern void *nts_malloc(size_t size); 60 extern void *nts_calloc(size_t count, size_t size); 61 62 extern void init_console_irq_buffer(void); 63 extern void uninit_console_irq_buffer(void); 64 extern int run_command (void *handler, char *cmd); 65 extern int handle_char (const char c, char *prompt); 66 extern uint32_t simple_strtoul(const char *cp,char **endp,unsigned int base); 67 extern void show_cmd_usage(const cmd_tbl_t *cmd); 68 extern int add_cmd_to_list(const cmd_tbl_t *cmd); 69 int do_help(cmd_tbl_t *cmd, int argc, char *argv[], void *handler); 70 extern int cmd_get_data_size(const char *arg, int default_size); 71 int get_at_cmd_echo(); 72 void console_task_start(void); 73 #ifdef __cplusplus 74 } 75 #endif 76 77 78 #endif 79 80