ea78c9518be6d91f527777a1aa3dedd1b00717f9
[platform/upstream/connectedhomeip.git] / examples / lock-app / qpg6100 / src / main.cpp
1 /*\r
2  *\r
3  *    Copyright (c) 2020 Project CHIP Authors\r
4  *    All rights reserved.\r
5  *\r
6  *    Licensed under the Apache License, Version 2.0 (the "License");\r
7  *    you may not use this file except in compliance with the License.\r
8  *    You may obtain a copy of the License at\r
9  *\r
10  *        http://www.apache.org/licenses/LICENSE-2.0\r
11  *\r
12  *    Unless required by applicable law or agreed to in writing, software\r
13  *    distributed under the License is distributed on an "AS IS" BASIS,\r
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
15  *    See the License for the specific language governing permissions and\r
16  *    limitations under the License.\r
17  */\r
18 /*\r
19  * Copyright (c) 2020, Qorvo Inc\r
20  *\r
21  *\r
22  *\r
23  * This software is owned by Qorvo Inc\r
24  * and protected under applicable copyright laws.\r
25  * It is delivered under the terms of the license\r
26  * and is intended and supplied for use solely and\r
27  * exclusively with products manufactured by\r
28  * Qorvo Inc.\r
29  *\r
30  *\r
31  * THIS SOFTWARE IS PROVIDED IN AN "AS IS"\r
32  * CONDITION. NO WARRANTIES, WHETHER EXPRESS,\r
33  * IMPLIED OR STATUTORY, INCLUDING, BUT NOT\r
34  * LIMITED TO, IMPLIED WARRANTIES OF\r
35  * MERCHANTABILITY AND FITNESS FOR A\r
36  * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
37  * QORVO INC. SHALL NOT, IN ANY\r
38  * CIRCUMSTANCES, BE LIABLE FOR SPECIAL,\r
39  * INCIDENTAL OR CONSEQUENTIAL DAMAGES,\r
40  * FOR ANY REASON WHATSOEVER.\r
41  *\r
42  * $Change: 154416 $\r
43  * $DateTime: 2020/08/21 09:47:42 $\r
44  *\r
45  */\r
46 \r
47 /** @file "main.cpp"\r
48  *\r
49  * Main application.\r
50  */\r
51 \r
52 /*****************************************************************************\r
53  *                    Includes Definitions\r
54  *****************************************************************************/\r
55 \r
56 // FreeRTOS\r
57 #include "FreeRTOS.h"\r
58 #include "task.h"\r
59 \r
60 // Qorvo CHIP library\r
61 #include "qvCHIP.h"\r
62 \r
63 // CHIP includes\r
64 #include <platform/CHIPDeviceLayer.h>\r
65 #include <support/logging/CHIPLogging.h>\r
66 \r
67 // Application level logic\r
68 #include "AppTask.h"\r
69 \r
70 using namespace ::chip;\r
71 using namespace ::chip::Inet;\r
72 using namespace ::chip::DeviceLayer;\r
73 using namespace ::chip::DeviceLayer::Internal;\r
74 \r
75 /*****************************************************************************\r
76  *                    Macro Definitions\r
77  *****************************************************************************/\r
78 \r
79 #define APP_NAME "Lock-app"\r
80 \r
81 /*****************************************************************************\r
82  *                    External Function Definitions\r
83  *****************************************************************************/\r
84 \r
85 /*****************************************************************************\r
86  *                    Application Function Definitions\r
87  *****************************************************************************/\r
88 \r
89 int Application_Init(void)\r
90 {\r
91     int ret = CHIP_ERROR_MAX;\r
92 \r
93     /* Launch application task */\r
94     ChipLogProgress(NotSpecified, "============================");\r
95     ChipLogProgress(NotSpecified, "Qorvo " APP_NAME " Launching");\r
96     ChipLogProgress(NotSpecified, "============================");\r
97 \r
98     ret = GetAppTask().StartAppTask();\r
99     if (ret != CHIP_NO_ERROR)\r
100     {\r
101         ChipLogError(NotSpecified, "GetAppTask().Init() failed");\r
102         return -1;\r
103     }\r
104 \r
105     return 0;\r
106 }\r
107 \r
108 int CHIP_Init(void)\r
109 {\r
110     int ret = CHIP_ERROR_MAX;\r
111 \r
112     ChipLogProgress(NotSpecified, "Init CHIP Stack");\r
113     ret = PlatformMgr().InitChipStack();\r
114     if (ret != CHIP_NO_ERROR)\r
115     {\r
116         ChipLogError(NotSpecified, "PlatformMgr().InitChipStack() failed");\r
117         goto exit;\r
118     }\r
119 \r
120     ChipLogProgress(NotSpecified, "Starting Platform Manager Event Loop");\r
121     ret = PlatformMgr().StartEventLoopTask();\r
122     if (ret != CHIP_NO_ERROR)\r
123     {\r
124         ChipLogError(NotSpecified, "PlatformMgr().StartEventLoopTask() failed");\r
125         goto exit;\r
126     }\r
127 \r
128 exit:\r
129     return ret;\r
130 }\r
131 \r
132 /*****************************************************************************\r
133  * --- Main\r
134  *****************************************************************************/\r
135 \r
136 int main(void)\r
137 {\r
138     int result;\r
139 \r
140     /* Initialize Qorvo stack */\r
141     result = qvCHIP_init();\r
142     if (result < 0)\r
143     {\r
144         goto exit;\r
145     }\r
146 \r
147     /* Initialize CHIP stack */\r
148     result = CHIP_Init();\r
149     if (result != CHIP_NO_ERROR)\r
150     {\r
151         goto exit;\r
152     }\r
153 \r
154     /* Application task */\r
155     result = Application_Init();\r
156     if (result < 0)\r
157     {\r
158         goto exit;\r
159     }\r
160 \r
161     /* Start FreeRTOS */\r
162     vTaskStartScheduler();\r
163 \r
164 exit:\r
165     return 0;\r
166 }\r