OK I am experiencing an interesting behavior
The idea is to read sensor values every X seconds i.e 3s here) on a nordic uC but I when I check the logic analyzer, it seems to be happening a lot more frequently despite the delay used in Read()
.
Another issue is with xQueueReceive
which somehow ends up in an unknown address after its execution (couldn’t debug myself; may check with the nordic team on it)
// system.cpp
SystemTask::SystemTask(Sensor& _sensor, QueueHandle_t& _q) : sensor(_sensor), q(_q) {}
void SystemTask::Start()
{
if (xTaskCreate(SystemTask::Process, "Run", 350, this, 0, &taskHandle) != pdPASS)
{
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
}
void SystemTask::Process(void* instance)
{
auto* app = static_cast<SystemTask*>(instance);
app->Run();
}
void SystemTask::Run()
{
sensor.Start();
while(true)
{
/* should be blocking the thread but for some reason ends up in an unknown state
if (xQueueReceive(mTaskQueue, &mMessage, portMAX_DELAY) == pdPASS)
{
}
*/
vTaskDelay(pdMS_TO_TICKS(10000));
}
}
// sensor.cpp
void Sensor::Start()
{
if (xTaskCreate(Sensor::Process, "Process", 100, this, 0, &mTaskHandle) != pdPASS)
{
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
}
void Sensor::Process(void* instance)
{
auto* app = static_cast<Sensor*>(instance);
app->Run();
}
void Sensor::Run()
{
ConfigI2C();
Write(buffer, 1); // write byte
// read loop every 3s
while(true)
{
Read();
vTaskDelay(pdMS_TO_TICKS(3000));
}
}
// main.cpp
int main()
{
static constexpr uint8_t queueSize = 10;
static constexpr uint8_t itemSize = 1;
QueueHandle_t q = xQueueCreate(queueSize, itemSize);
Sensor sensor;
systemTask.Start(sensor, q);
vTaskStartScheduler();
}
Here’s the visuals: Screenshot-2023-05-28-at-11-30-44-PM hosted at ImgBB — ImgBB
clearly the read calls are made a lot more frequent than 3000s so I am curious what may be going on here despite a 3s delay?
There’s nowhere else Read() is invoked