blob: be9d29619aae4fdecd7d27588285901e3ecc5f47 [file] [log] [blame]
/*
* Copyright (c) 2022 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>
#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>
#include <openthread/platform/entropy.h>
#include <lib/support/CHIPPlatformMemory.h>
#include <mbedtls/platform.h>
#include <openthread_port.h>
#include <utils_list.h>
namespace chip {
namespace DeviceLayer {
using namespace ::chip::DeviceLayer::Internal;
ThreadStackManagerImpl ThreadStackManagerImpl::sInstance;
CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack(void)
{
return InitThreadStack(NULL);
}
CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance * otInst)
{
CHIP_ERROR err = CHIP_NO_ERROR;
ot_alarmInit();
ot_radioInit();
// Initialize the generic implementation base classes.
err = GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>::DoInit();
SuccessOrExit(err);
err = GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>::DoInit(otInst);
SuccessOrExit(err);
mbedtls_platform_set_calloc_free(pvPortCalloc, vPortFree);
exit:
return err;
}
bool ThreadStackManagerImpl::IsInitialized()
{
return sInstance.mThreadStackLock != NULL;
}
} // namespace DeviceLayer
} // namespace chip
using namespace ::chip::DeviceLayer;
ot_system_event_t ot_system_event_var;
void otSysProcessDrivers(otInstance * aInstance)
{
ot_system_event_t sevent = OT_SYSTEM_EVENT_NONE;
OT_GET_NOTIFY(sevent);
ot_alarmTask(sevent);
// ot_uartTask(sevent);
ot_radioTask(sevent);
}
extern "C" void otTaskletsSignalPending(otInstance * p_instance)
{
otSysEventSignalPending();
}
extern "C" void otSysEventSignalPending(void)
{
if (xPortIsInsideInterrupt())
{
BaseType_t yieldRequired = ThreadStackMgrImpl().SignalThreadActivityPendingFromISR();
portYIELD_FROM_ISR(yieldRequired);
}
else
{
ThreadStackMgrImpl().SignalThreadActivityPending();
}
}
extern "C" otInstance * otrGetInstance()
{
return ThreadStackMgrImpl().OTInstance();
}
extern "C" void * otPlatCAlloc(size_t aNum, size_t aSize)
{
return calloc(aNum, aSize);
}
extern "C" void otPlatFree(void * aPtr)
{
free(aPtr);
}