Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Thread] move off joiner start from timer task #2199

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class GenericThreadStackManagerImpl_FreeRTOS
static void OnJoinerTimer(TimerHandle_t xTimer);

portTickType mJoinerExpire;
bool mJoinerStartPending = false;
};

// Instruct the compiler to instantiate the template only when explicitly told to do so.
Expand Down
22 changes: 12 additions & 10 deletions src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,20 @@ void GenericThreadStackManagerImpl_FreeRTOS<ImplClass>::OnJoinerTimer(TimerHandl
GenericThreadStackManagerImpl_FreeRTOS<ImplClass> * self =
static_cast<GenericThreadStackManagerImpl_FreeRTOS<ImplClass> *>(pvTimerGetTimerID(xTimer));

ChipLogDetail(DeviceLayer, "Thread joiner timer running");

if (xTaskGetTickCount() > self->mJoinerExpire || self->Impl()->IsThreadProvisioned())
{
ChipLogDetail(DeviceLayer, "Thread joiner timer stopped");

VerifyOrDie(pdPASS == xTimerStop(xTimer, portMAX_DELAY) && pdPASS == xTimerDelete(xTimer, portMAX_DELAY));
}
else
else if (!self->mJoinerStartPending)
{
CHIP_ERROR error = self->Impl()->JoinerStart();
ChipLogDetail(DeviceLayer, "Request Thread joiner start");

ChipLogDetail(DeviceLayer, "Thread joiner timer triggered: %s", chip::ErrorStr(error));
self->mJoinerStartPending = true;
self->Impl()->SignalThreadActivityPending();
}
}

Expand All @@ -145,7 +148,6 @@ void GenericThreadStackManagerImpl_FreeRTOS<ImplClass>::ThreadTaskMain(void * ar

ChipLogDetail(DeviceLayer, "Thread task running");

// Capture the Thread task handle.
self->mThreadTask = xTaskGetCurrentTaskHandle();

// Try starting joiner within 15m.
Expand All @@ -157,17 +159,17 @@ void GenericThreadStackManagerImpl_FreeRTOS<ImplClass>::ThreadTaskMain(void * ar

while (true)
{
// Lock the Thread stack.
self->Impl()->LockThreadStack();

// Process any pending Thread activity.
self->Impl()->ProcessThreadActivity();

// Unlock the Thread stack.
self->Impl()->UnlockThreadStack();

// Wait for a signal that more activity is pending.
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);

if (self->mJoinerStartPending)
{
self->mJoinerStartPending = false;
self->Impl()->JoinerStart();
}
}
}

Expand Down