-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmain.cpp
More file actions
239 lines (202 loc) · 6.45 KB
/
Copy pathmain.cpp
File metadata and controls
239 lines (202 loc) · 6.45 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
*
* Copyright (c) 2020 Project CHIP Authors
* All rights reserved.
*
* 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 "main.cpp"
*
* Main application.
*/
/*****************************************************************************
* Includes Definitions
*****************************************************************************/
// FreeRTOS
#include "FreeRTOS.h"
#include "task.h"
#if defined(GP_APP_DIVERSITY_POWERCYCLECOUNTING)
#include "powercycle_counting.h"
#endif
// Qorvo CHIP library
#include "qvCHIP.h"
#include "qvIO.h"
// CHIP includes
#include <lib/support/CHIPMem.h>
#include <lib/support/CHIPPlatformMemory.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/CHIPDeviceLayer.h>
#if PW_RPC_ENABLED
#include "Rpc.h"
#endif // PW_RPC_ENABLED
#if ENABLE_CHIP_SHELL
#include "shell_common/shell.h"
#endif // ENABLE_CHIP_SHELL
// Application level logic
#include "AppTask.h"
#include "ota.h"
using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::DeviceLayer;
using namespace ::chip::DeviceLayer::Internal;
namespace {
constexpr uint32_t kInitOTARequestorDelaySec = 3;
constexpr int extDiscTimeoutSecs = 20;
} // namespace
/*****************************************************************************
* Macro Definitions
*****************************************************************************/
/*****************************************************************************
* External Function Definitions
*****************************************************************************/
/*****************************************************************************
* Application Function Definitions
*****************************************************************************/
CHIP_ERROR CHIP_Init(void);
void Application_Init(void)
{
CHIP_ERROR error;
#if defined(GP_APP_DIVERSITY_POWERCYCLECOUNTING)
gpAppFramework_Reset_Init();
#endif
/* Initialize IO */
qvIO_Init();
/* Initialize CHIP stack */
error = CHIP_Init();
if (error != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "CHIP_Init failed");
return;
}
/* Launch application task */
ChipLogProgress(NotSpecified, "============================");
ChipLogProgress(NotSpecified, "Qorvo " APP_NAME " Launching");
ChipLogProgress(NotSpecified, "============================");
error = GetAppTask().Init();
if (error != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "GetAppTask().Init() failed");
return;
}
error = GetAppTask().StartAppTask();
if (error != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "GetAppTask().StartAppTask() failed");
return;
}
}
void ChipEventHandler(const ChipDeviceEvent * aEvent, intptr_t /* arg */)
{
switch (aEvent->Type)
{
case DeviceEventType::kDnssdInitialized:
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
InitializeOTARequestor();
#endif
break;
default:
break;
}
}
CHIP_ERROR CHIP_Init(void)
{
CHIP_ERROR ret = CHIP_NO_ERROR;
#if PW_RPC_ENABLED
ret = (CHIP_ERROR) chip::rpc::Init();
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "rpc::Init() failed");
goto exit;
}
#endif
ret = chip::Platform::MemoryInit();
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Platform::MemoryInit() failed");
goto exit;
}
#if ENABLE_CHIP_SHELL
ret = (CHIP_ERROR) ShellTask::Start();
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "ShellTask::Start() failed");
goto exit;
}
#endif // ENABLE_CHIP_SHELL
ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "PlatformMgr().InitChipStack() failed");
goto exit;
}
#if CHIP_ENABLE_OPENTHREAD
ChipLogProgress(NotSpecified, "Initializing OpenThread stack");
ret = ThreadStackMgr().InitThreadStack();
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "ThreadStackMgr().InitThreadStack() failed");
goto exit;
}
#if CONFIG_CHIP_THREAD_SSED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SynchronizedSleepyEndDevice);
qvIO_EnableSleep(true);
#elif CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
qvIO_EnableSleep(true);
#elif CHIP_DEVICE_CONFIG_THREAD_FTD
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
qvIO_EnableSleep(false);
#else
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
qvIO_EnableSleep(false);
#endif
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "ConnectivityMgr().SetThreadDeviceType() failed");
goto exit;
}
ChipLogProgress(NotSpecified, "Starting OpenThread task");
ret = ThreadStackMgrImpl().StartThreadTask();
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "ThreadStackMgr().StartThreadTask() failed");
goto exit;
}
#endif // CHIP_ENABLE_OPENTHREAD
ChipLogProgress(NotSpecified, "Starting Platform Manager Event Loop");
PlatformMgr().AddEventHandler(ChipEventHandler, 0);
ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "PlatformMgr().StartEventLoopTask() failed");
goto exit;
}
exit:
return ret;
}
/*****************************************************************************
* --- Main
*****************************************************************************/
int main(void)
{
int result;
/* Initialize Qorvo stack */
result = qvCHIP_init(Application_Init);
if (result < 0)
{
return 0;
}
/* Start FreeRTOS */
vTaskStartScheduler();
return 0;
}