1 /*
2 * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3 */
4
5 #include <string.h>
6 #include <stdint.h>
7 #include "aos/kernel.h"
8 #include "aos/cli.h"
9 #include "cli_adapt.h"
10 #include "cli_console.h"
11 #if CLI_UAGENT_ENABLE
12 #include "cli_uagent.h"
13 #endif
14
15 static aos_task_t cli_task;
16
cli_task_create(const char * name,void (* fn)(void *),void * arg,uint32_t stack,uint32_t priority)17 int32_t cli_task_create(const char *name, void (*fn)(void *), void *arg,
18 uint32_t stack, uint32_t priority)
19 {
20 return aos_task_new_ext(&cli_task, name, fn, arg, stack, priority);
21 }
22
cli_task_exit(void)23 void cli_task_exit(void)
24 {
25 aos_task_exit(0);
26 }
27
cli_getchar(char * inbuf)28 int32_t cli_getchar(char *inbuf)
29 {
30 return cli_console_read(get_clitask_console(), inbuf, 1);
31 }
32
cli_putchar(char ch)33 int32_t cli_putchar(char ch)
34 {
35 return cli_console_write(get_clitask_console(), &ch, 1);
36 }
37
cli_putstr(char * msg)38 int32_t cli_putstr(char *msg)
39 {
40 #if CLI_UAGENT_ENABLE
41 if (g_cmd_from_cloud) {
42 return uagent_send(UAGENT_MOD_CLI, CLI_RESPONE, strlen(msg), msg, send_policy_delay);
43 }
44 #endif
45 return cli_console_write(get_clitask_console(), (void *)msg, strlen(msg));
46 }
47
cli_malloc(uint32_t size)48 void *cli_malloc(uint32_t size)
49 {
50 return aos_malloc(size);
51 }
52
cli_free(void * ptr)53 void cli_free(void *ptr)
54 {
55 aos_free(ptr);
56 }
57
aos_cli_suspend(void)58 int aos_cli_suspend(void)
59 {
60 return (int)aos_task_suspend(&cli_task);
61 }
62
aos_cli_resume(void)63 int aos_cli_resume(void)
64 {
65 return (int)aos_task_resume(&cli_task);
66 }
67