3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2019 Nest Labs, Inc.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * Provides an implementation of the ThreadStackManager object
22 * for EFR32 platforms using the Silicon Labs SDK and the OpenThread
28 #include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h>
29 #include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h>
31 #include <openthread/tasklet.h>
32 #include <openthread/thread.h>
34 extern "C" void otSysEventSignalPending(void);
37 namespace DeviceLayer {
39 class ThreadStackManager;
40 class ThreadStackManagerImpl;
42 extern int GetEntropy_EFR32(uint8_t * buf, size_t bufSize);
46 * Concrete implementation of the ThreadStackManager singleton object for EFR32 platforms
47 * using the Silicon Labs SDK and the OpenThread stack.
49 class ThreadStackManagerImpl final : public ThreadStackManager,
50 public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>,
51 public Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>
53 // Allow the ThreadStackManager interface class to delegate method calls to
54 // the implementation methods provided by this class.
55 friend class ThreadStackManager;
57 // Allow the generic implementation base classes to call helper methods on
59 #ifndef DOXYGEN_SHOULD_SKIP_THIS
60 friend Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
61 friend Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>;
62 friend Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>;
65 // Allow glue functions called by OpenThread to call helper methods on this
67 friend void ::otTaskletsSignalPending(otInstance * otInst);
68 friend void ::otSysEventSignalPending(void);
71 // ===== Platform-specific members that may be accessed directly by the application.
73 using ThreadStackManager::InitThreadStack;
74 CHIP_ERROR InitThreadStack(otInstance * otInst);
75 void _OnCHIPoBLEAdvertisingStart(void);
76 void _OnCHIPoBLEAdvertisingStop(void);
79 // ===== Methods that implement the ThreadStackManager abstract interface.
81 CHIP_ERROR _InitThreadStack(void);
83 // ===== Members for internal use by the following friends.
85 friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void);
86 friend ThreadStackManagerImpl & ::chip::DeviceLayer::ThreadStackMgrImpl(void);
87 friend int Internal::GetEntropy_EFR32(uint8_t * buf, size_t bufSize);
89 static ThreadStackManagerImpl sInstance;
91 static bool IsInitialized();
93 // ===== Private members for use by this class only.
95 ThreadStackManagerImpl() = default;
99 * Returns the public interface of the ThreadStackManager singleton object.
101 * Chip applications should use this to access features of the ThreadStackManager object
102 * that are common to all platforms.
104 inline ThreadStackManager & ThreadStackMgr(void)
106 return ThreadStackManagerImpl::sInstance;
110 * Returns the platform-specific implementation of the ThreadStackManager singleton object.
112 * Chip applications can use this to gain access to features of the ThreadStackManager
113 * that are specific to EFR32 platforms.
115 inline ThreadStackManagerImpl & ThreadStackMgrImpl(void)
117 return ThreadStackManagerImpl::sInstance;
120 } // namespace DeviceLayer