3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2020 Nest Labs, Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 * Provides an implementation of the ThreadStackManager object for
23 * K32W platforms using the NXP SDK and the OpenThread
28 /* this file behaves like a config.h, comes first */
29 #include <platform/internal/CHIPDeviceLayerInternal.h>
31 #include <platform/OpenThread/OpenThreadUtils.h>
32 #include <platform/ThreadStackManager.h>
34 #include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp>
35 #include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>
38 namespace DeviceLayer {
40 using namespace ::chip::DeviceLayer::Internal;
42 ThreadStackManagerImpl ThreadStackManagerImpl::sInstance;
44 CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack(void)
46 return InitThreadStack(NULL);
49 CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance * otInst)
51 CHIP_ERROR err = CHIP_NO_ERROR;
53 // Initialize the generic implementation base classes.
54 err = GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>::DoInit();
56 err = GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>::DoInit(otInst);
59 otCliUartInit(OTInstance());
65 bool ThreadStackManagerImpl::IsInitialized()
67 return sInstance.mThreadStackLock != NULL;
70 } // namespace DeviceLayer
73 using namespace ::chip::DeviceLayer;
76 * Glue function called directly by the OpenThread stack when tasklet processing work
79 extern "C" void otTaskletsSignalPending(otInstance * p_instance)
81 ThreadStackMgrImpl().SignalThreadActivityPending();
85 * Glue function called directly by the OpenThread stack when system event processing work
88 extern "C" void otSysEventSignalPending(void)
90 BaseType_t yieldRequired = ThreadStackMgrImpl().SignalThreadActivityPendingFromISR();
91 portYIELD_FROM_ISR(yieldRequired);
94 extern "C" void * pvPortCallocRtos(size_t num, size_t size)
96 size_t totalAllocSize = (size_t)(num * size);
98 if (size && totalAllocSize / size != num)
101 void * p = pvPortMalloc(totalAllocSize);
105 memset(p, 0, totalAllocSize);
111 extern "C" void * otPlatCAlloc(size_t aNum, size_t aSize)
113 return pvPortCallocRtos(aNum, aSize);
116 extern "C" void otPlatFree(void * aPtr)
118 return vPortFree(aPtr);