forked from u-blox/XPLR-IOT-1-software
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx_shell_conf.c
110 lines (77 loc) · 2.96 KB
/
x_shell_conf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright 2022 u-blox Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @file
* @brief This file contains the implementation of the API to handle
* shell initialization/deintialization functions used in Sensor
* Aggregation Use Case for XPLR-IOT-1
*/
#include "x_shell_conf.h"
#include <zephyr.h>
#include <shell/shell.h>
#include <device.h>
#include <devicetree.h>
#include <shell/shell_uart.h> //shell_backend_uart_get_ptr
/* ----------------------------------------------------------------
* STATIC FUNCTION DECLARATION
* -------------------------------------------------------------- */
//** Initializes shell. Must be called from a workqueue context */
static void shellInitFromWork(struct k_work *work);
/** Callback to be triggered when the shell is unitialized*/
void shellDeinitCb(const struct shell *shell, int res);
/* ----------------------------------------------------------------
* GLOBALS
* -------------------------------------------------------------- */
/** Flag to signal if the shellDeinitCb has been triggered */
static bool gShellDeinitCbAsserted = false;
/* ----------------------------------------------------------------
* STATIC FUNCTION IMEPLEMENTATION
* -------------------------------------------------------------- */
void shellDeinitCb(const struct shell *shell, int res)
{
gShellDeinitCbAsserted = true;
}
static void shellInitFromWork(struct k_work *work)
{
const struct device *dev =
device_get_binding(CONFIG_UART_SHELL_ON_DEV_NAME);
bool log_backend = CONFIG_SHELL_BACKEND_SERIAL_LOG_LEVEL > 0;
// uint32_t level =
// (CONFIG_SHELL_BACKEND_SERIAL_LOG_LEVEL > LOG_LEVEL_DBG) ?
// CONFIG_LOG_MAX_LEVEL : CONFIG_SHELL_BACKEND_SERIAL_LOG_LEVEL;
//shell_init(shell_backend_uart_get_ptr(), dev, true, log_backend, level);
shell_init(shell_backend_uart_get_ptr(), dev, true, log_backend, 0);
}
/* ----------------------------------------------------------------
* PUBLIC FUNCTION IMEPLEMENTATION
* -------------------------------------------------------------- */
void xShellReinitTrigger(void)
{
static struct k_work shell_init_work;
gShellDeinitCbAsserted = false;
k_work_init(&shell_init_work, shellInitFromWork);
int err = k_work_submit(&shell_init_work);
(void)err;
__ASSERT_NO_MSG(err >= 0);
}
void xShellDeinit(void)
{
const struct shell *shell = shell_backend_uart_get_ptr();
shell_uninit(shell, shellDeinitCb);
return;
}
bool xShellDeinitIsComplete(void){
return gShellDeinitCbAsserted;
}