3 * Copyright (c) 2020 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * Provides an implementation of the ThreadStackManager object
21 * for Qorvo platforms and the OpenThread
27 #include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h>
28 #include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h>
30 #include <openthread/tasklet.h>
31 #include <openthread/thread.h>
33 extern "C" void otSysEventSignalPending(void);
36 namespace DeviceLayer {
38 class ThreadStackManager;
39 class ThreadStackManagerImpl;
41 extern int GetEntropy(uint8_t * buf, size_t bufSize);
45 * Concrete implementation of the ThreadStackManager singleton object for Qorvo platforms
46 * using the OpenThread stack.
48 class ThreadStackManagerImpl final : public ThreadStackManager,
49 public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>,
50 public Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>
52 // Allow the ThreadStackManager interface class to delegate method calls to
53 // the implementation methods provided by this class.
54 friend class ThreadStackManager;
56 // Allow the generic implementation base classes to call helper methods on
58 #ifndef DOXYGEN_SHOULD_SKIP_THIS
59 friend Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
60 friend Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>;
61 friend Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>;
64 // Allow glue functions called by OpenThread to call helper methods on this
66 friend void ::otTaskletsSignalPending(otInstance * otInst);
67 friend void ::otSysEventSignalPending(void);
70 // ===== Platform-specific members that may be accessed directly by the application.
72 using ThreadStackManager::InitThreadStack;
73 CHIP_ERROR InitThreadStack(otInstance * otInst);
74 void _OnCHIPoBLEAdvertisingStart(void);
75 void _OnCHIPoBLEAdvertisingStop(void);
78 // ===== Methods that implement the ThreadStackManager abstract interface.
80 CHIP_ERROR _InitThreadStack(void);
82 // ===== Members for internal use by the following friends.
84 friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void);
85 friend ThreadStackManagerImpl & ::chip::DeviceLayer::ThreadStackMgrImpl(void);
86 friend int Internal::GetEntropy(uint8_t * buf, size_t bufSize);
88 static ThreadStackManagerImpl sInstance;
90 static bool IsInitialized();
92 // ===== Private members for use by this class only.
94 ThreadStackManagerImpl() = default;
98 * Returns the public interface of the ThreadStackManager singleton object.
100 * chip applications should use this to access features of the ThreadStackManager object
101 * that are common to all platforms.
103 inline ThreadStackManager & ThreadStackMgr(void)
105 return ThreadStackManagerImpl::sInstance;
109 * Returns the platform-specific implementation of the ThreadStackManager singleton object.
111 * chip applications can use this to gain access to features of the ThreadStackManager
112 * that are specific to the platform.
114 inline ThreadStackManagerImpl & ThreadStackMgrImpl(void)
116 return ThreadStackManagerImpl::sInstance;
119 } // namespace DeviceLayer