bc14524d30ec0363602883081d202b231e95b1de
[platform/upstream/connectedhomeip.git] / examples / shell / qpg6100 / main.cpp
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *
5  *    Licensed under the Apache License, Version 2.0 (the "License");
6  *    you may not use this file except in compliance with the License.
7  *    You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *    Unless required by applicable law or agreed to in writing, software
12  *    distributed under the License is distributed on an "AS IS" BASIS,
13  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *    See the License for the specific language governing permissions and
15  *    limitations under the License.
16  */
17
18 #include "FreeRTOS.h"
19 #include "task.h"
20
21 #include <lib/shell/shell.h>
22
23 #include <lib/core/CHIPCore.h>
24 #include <lib/support/Base64.h>
25 #include <lib/support/CHIPArgParser.hpp>
26 #include <lib/support/CodeUtils.h>
27 #include <lib/support/RandUtils.h>
28 #include <support/logging/CHIPLogging.h>
29
30 #include <ChipShellCollection.h>
31
32 #include "qvCHIP.h"
33
34 #if CHIP_ENABLE_OPENTHREAD
35 extern "C" {
36 #include <openthread/platform/platform-softdevice.h>
37 }
38 #endif // CHIP_ENABLE_OPENTHREAD
39
40 using namespace chip;
41 using namespace chip::Shell;
42
43 namespace {
44
45 const size_t kShellTaskStackSize = 2048;
46 const int kShellTaskPriority     = 1;
47 TaskHandle_t sShellTaskHandle;
48
49 void ShellCLIMain(void * pvParameter)
50 {
51     // Initialize the default streamer that was linked.
52     const int rc = streamer_init(streamer_get());
53
54     if (rc != 0)
55     {
56         ChipLogError(Shell, "Streamer initialization failed: %d", rc);
57         return;
58     }
59
60     ChipLogDetail(Shell, "Initializing CHIP shell commands: %d", rc);
61
62     cmd_device_init();
63     cmd_base64_init();
64     cmd_misc_init();
65     cmd_btp_init();
66     cmd_otcli_init();
67
68     ChipLogDetail(Shell, "Run CHIP shell Task: %d", rc);
69
70     shell_task(nullptr);
71 }
72
73 } // namespace
74
75 int StartShellTask(void)
76 {
77     int ret = 0;
78
79     // Start Shell task.
80     if (xTaskCreate(ShellCLIMain, "SHELL", kShellTaskStackSize / sizeof(StackType_t), NULL, kShellTaskPriority,
81                     &sShellTaskHandle) != pdPASS)
82     {
83         ret = -1;
84     }
85
86     return ret;
87 }
88
89 int main(void)
90 {
91     /* Initialize platform */
92     qvCHIP_init();
93
94     /* Launch shell task */
95     StartShellTask();
96
97     /* Start FreeRTOS */
98     vTaskStartScheduler();
99     return 0;
100 }