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 for the
21 * QPG6100 platform using the Qorvo QPG6100 library and the OpenThread
25 /* this file behaves like a config.h, comes first */
26 #include <platform/internal/CHIPDeviceLayerInternal.h>
28 #include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp>
29 #include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>
31 #include <platform/OpenThread/OpenThreadUtils.h>
32 #include <platform/ThreadStackManager.h>
34 #include <support/CHIPMem.h>
35 #include <support/CHIPPlatformMemory.h>
37 #include <openthread/heap.h>
38 // Qorvo OpenThread functions
40 #include "alarm_qorvo.h"
41 #include "radio_qorvo.h"
42 #include "random_qorvo.h"
46 namespace DeviceLayer {
48 using namespace ::chip::DeviceLayer::Internal;
50 ThreadStackManagerImpl ThreadStackManagerImpl::sInstance;
52 CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack(void)
54 return InitThreadStack(NULL);
57 CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance * otInst)
59 CHIP_ERROR err = CHIP_NO_ERROR;
61 // Initialize Low level QPG OpenThread glue
66 // Initialize the generic implementation base classes.
67 err = GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>::DoInit();
69 err = GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>::DoInit(otInst);
76 bool ThreadStackManagerImpl::IsInitialized()
78 return sInstance.mThreadStackLock != NULL;
81 void ThreadStackManagerImpl::_OnCHIPoBLEAdvertisingStart(void)
83 // If Thread-over-BLE is enabled, ensure that ToBLE advertising is stopped before
84 // starting CHIPoBLE advertising. This is accomplished by disabling the OpenThread
85 // IPv6 interface via a call to otIp6SetEnabled(false).
87 // On platforms where there is no native support for simultaneous BLE advertising
88 // it is necessary to coordinate between the different
89 // advertising modes a CHIP device may employ. This arises in particular when a
90 // device supports both CHIPoBLE and ToBLE, each of which requires a separate advertising
91 // regime. The OnCHIPoBLEAdvertisingStart()/OnCHIPoBLEAdvertisingStop() methods handle
92 // the switching between the two modes.
94 #if OPENTHREAD_CONFIG_ENABLE_TOBLE
96 otIp6SetEnabled(OTInstance(), false);
101 void ThreadStackManagerImpl::_OnCHIPoBLEAdvertisingStop(void)
103 // If Thread-over-BLE is enabled, and a Thread provision exists, ensure that ToBLE
104 // advertising is re-activated once CHIPoBLE advertising stops.
106 #if OPENTHREAD_CONFIG_ENABLE_TOBLE
108 if (otThreadGetDeviceRole(OTInstance()) != OT_DEVICE_ROLE_DISABLED && otDatasetIsCommissioned(OTInstance()))
110 otIp6SetEnabled(OTInstance(), true);
116 } // namespace DeviceLayer
119 using namespace ::chip::DeviceLayer;
122 * Glue function called directly by the OpenThread stack when tasklet processing work
125 extern "C" void otTaskletsSignalPending(otInstance * p_instance)
127 ThreadStackMgrImpl().SignalThreadActivityPending();
131 * Glue function called directly by the OpenThread stack when system event processing work
134 extern "C" void otSysEventSignalPending(void)
136 BaseType_t yieldRequired = ThreadStackMgrImpl().SignalThreadActivityPendingFromISR();
137 portYIELD_FROM_ISR(yieldRequired);