Skip to content

Commit

Permalink
feat: adding suspend, resume, delay & fixing 'create_static'
Browse files Browse the repository at this point in the history
#68

Test needs a little more work, and haven't run it on device yet
  • Loading branch information
malachib committed Dec 9, 2024
1 parent c33b1fd commit 77d8f55
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
31 changes: 26 additions & 5 deletions src/estd/port/freertos/wrapper/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ class task
return pcTaskGetName(t);
}

void delay(const TickType_t xTicksToDelay) const
{
vTaskDelay(xTicksToDelay);
}

void resume() const
{
vTaskResume(t);
}

void suspend() const
{
vTaskSuspend(t);
}

#if configUSE_APPLICATION_TASK_TAG
TaskHookFunction_t tag() const
{
Expand Down Expand Up @@ -120,15 +135,21 @@ class task
#endif

#if configSUPPORT_STATIC_ALLOCATION
BaseType_t create_static(TaskFunction_t pvTaskCode,
const char * const pcName,
using static_type = StaticTask_t;

static task create_static(TaskFunction_t pvTaskCode,
const char* const pcName,
const configSTACK_DEPTH_TYPE uxStackDepth,
void *pvParameters,
void* pvParameters,
UBaseType_t uxPriority,
StackType_t* const puxStackBuffer,
StaticTask_t* const pxTaskBuffer)
static_type* const pxTaskBuffer)
{
return xTaskCreate(pvTaskCode, pcName, uxStackDepth, pvParameters, uxPriority, &t);
return task(xTaskCreateStatic(pvTaskCode,
pcName, uxStackDepth,
pvParameters, uxPriority,
puxStackBuffer,
pxTaskBuffer));
}
#endif

Expand Down
22 changes: 21 additions & 1 deletion test/unity/freertos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,30 @@

#include <estd/port/freertos/wrapper/task.h>

using namespace estd::freertos::wrapper;

static void test_task1(void* p)
{

}

static void test_static_task_wrapper()
{
// DEBT: Do a malloc for these in SPIRAM for ESP32
static task::static_type storage;
static unsigned char stack[2048];

task t = task::create_static(test_task1, "unity:freertos1",
sizeof stack / 4, nullptr, 3, stack, &storage);

t.suspend();
t.resume();
}

#ifdef ESP_IDF_TESTING
TEST_CASE("freertos tests", "[freertos]")
{

RUN_TEST(test_static_task_wrapper);
}
#endif

Expand Down
1 change: 1 addition & 0 deletions test/unity/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ static void test_event_groups()

}

// DEBT: Move some of this out to 'freertos.cpp' test area
static void test_freertos()
{
freertos::sync_sem.create_binary();
Expand Down

0 comments on commit 77d8f55

Please sign in to comment.