main.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. *
  3. * Copyright (c) 2020 Project CHIP Authors
  4. * All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /** @file "main.cpp"
  19. *
  20. * Main application.
  21. */
  22. /*****************************************************************************
  23. * Includes Definitions
  24. *****************************************************************************/
  25. // FreeRTOS
  26. #include "FreeRTOS.h"
  27. #include "task.h"
  28. // Qorvo CHIP library
  29. #include "qvCHIP.h"
  30. // CHIP includes
  31. #include <platform/CHIPDeviceLayer.h>
  32. #include <support/CHIPMem.h>
  33. #include <support/CHIPPlatformMemory.h>
  34. #include <support/logging/CHIPLogging.h>
  35. // Application level logic
  36. #include "AppTask.h"
  37. using namespace ::chip;
  38. using namespace ::chip::Inet;
  39. using namespace ::chip::DeviceLayer;
  40. using namespace ::chip::DeviceLayer::Internal;
  41. /*****************************************************************************
  42. * Macro Definitions
  43. *****************************************************************************/
  44. /*****************************************************************************
  45. * External Function Definitions
  46. *****************************************************************************/
  47. /*****************************************************************************
  48. * Application Function Definitions
  49. *****************************************************************************/
  50. int Application_Init(void)
  51. {
  52. /* Launch application task */
  53. ChipLogProgress(NotSpecified, "============================");
  54. ChipLogProgress(NotSpecified, "Qorvo " APP_NAME " Launching");
  55. ChipLogProgress(NotSpecified, "============================");
  56. CHIP_ERROR ret = GetAppTask().StartAppTask();
  57. if (ret != CHIP_NO_ERROR)
  58. {
  59. ChipLogError(NotSpecified, "GetAppTask().Init() failed");
  60. return -1;
  61. }
  62. return 0;
  63. }
  64. int CHIP_Init(void)
  65. {
  66. CHIP_ERROR ret = chip::Platform::MemoryInit();
  67. if (ret != CHIP_NO_ERROR)
  68. {
  69. ChipLogError(NotSpecified, "Platform::MemoryInit() failed");
  70. goto exit;
  71. }
  72. ChipLogProgress(NotSpecified, "Init CHIP Stack");
  73. ret = PlatformMgr().InitChipStack();
  74. if (ret != CHIP_NO_ERROR)
  75. {
  76. ChipLogError(NotSpecified, "PlatformMgr().InitChipStack() failed");
  77. goto exit;
  78. }
  79. #if CHIP_ENABLE_OPENTHREAD
  80. ChipLogProgress(NotSpecified, "Initializing OpenThread stack");
  81. ret = ThreadStackMgr().InitThreadStack();
  82. if (ret != CHIP_NO_ERROR)
  83. {
  84. ChipLogError(NotSpecified, "ThreadStackMgr().InitThreadStack() failed");
  85. goto exit;
  86. }
  87. #if CHIP_DEVICE_CONFIG_THREAD_FTD
  88. ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
  89. #else
  90. ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
  91. #endif
  92. if (ret != CHIP_NO_ERROR)
  93. {
  94. ChipLogError(NotSpecified, "ConnectivityMgr().SetThreadDeviceType() failed");
  95. goto exit;
  96. }
  97. ChipLogProgress(NotSpecified, "Starting OpenThread task");
  98. ret = ThreadStackMgrImpl().StartThreadTask();
  99. if (ret != CHIP_NO_ERROR)
  100. {
  101. ChipLogError(NotSpecified, "ThreadStackMgr().StartThreadTask() failed");
  102. goto exit;
  103. }
  104. #endif // CHIP_ENABLE_OPENTHREAD
  105. ChipLogProgress(NotSpecified, "Starting Platform Manager Event Loop");
  106. ret = PlatformMgr().StartEventLoopTask();
  107. if (ret != CHIP_NO_ERROR)
  108. {
  109. ChipLogError(NotSpecified, "PlatformMgr().StartEventLoopTask() failed");
  110. goto exit;
  111. }
  112. exit:
  113. return ret;
  114. }
  115. /*****************************************************************************
  116. * --- Main
  117. *****************************************************************************/
  118. int main(void)
  119. {
  120. int result;
  121. /* Initialize Qorvo stack */
  122. result = qvCHIP_init();
  123. if (result < 0)
  124. {
  125. goto exit;
  126. }
  127. /* Initialize CHIP stack */
  128. result = CHIP_Init();
  129. if (result != CHIP_NO_ERROR)
  130. {
  131. goto exit;
  132. }
  133. /* Application task */
  134. result = Application_Init();
  135. if (result < 0)
  136. {
  137. goto exit;
  138. }
  139. /* Start FreeRTOS */
  140. vTaskStartScheduler();
  141. exit:
  142. return 0;
  143. }