Initialize SystemTask, DisplayApp and HeartRateTask as global static variable instead of variables on the heap. We don't need them on the heap as we know their size at build time, it'll reduce memory fragmentation and it'll make memory analysis easier.

This commit is contained in:
Jean-François Milants
2021-06-06 15:56:03 +02:00
parent 79f0fcb07a
commit 7f9cc51b05
28 changed files with 223 additions and 170 deletions

View File

@@ -159,7 +159,7 @@ void AlertNotificationClient::OnNotification(ble_gap_event* event) {
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
notificationManager.Push(std::move(notif));
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification);
systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
}
}

View File

@@ -79,7 +79,7 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
break;
}
auto event = Pinetime::System::SystemTask::Messages::OnNewNotification;
auto event = Pinetime::System::Messages::OnNewNotification;
notificationManager.Push(std::move(notif));
systemTask.PushMessage(event);
}

View File

@@ -205,7 +205,7 @@ int DfuService::ControlPointHandler(uint16_t connectionHandle, os_mbuf* om) {
bleController.State(Pinetime::Controllers::Ble::FirmwareUpdateStates::Running);
bleController.FirmwareUpdateTotalBytes(0xffffffffu);
bleController.FirmwareUpdateCurrentBytes(0);
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleFirmwareUpdateStarted);
systemTask.PushMessage(Pinetime::System::Messages::BleFirmwareUpdateStarted);
return 0;
} else {
NRF_LOG_INFO("[DFU] -> Start DFU, mode %d not supported!", imageType);
@@ -279,7 +279,7 @@ int DfuService::ControlPointHandler(uint16_t connectionHandle, os_mbuf* om) {
}
NRF_LOG_INFO("[DFU] -> Activate image and reset!");
bleController.StopFirmwareUpdate();
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleFirmwareUpdateFinished);
systemTask.PushMessage(Pinetime::System::Messages::BleFirmwareUpdateFinished);
Reset();
bleController.State(Pinetime::Controllers::Ble::FirmwareUpdateStates::Validated);
return 0;
@@ -304,7 +304,7 @@ void DfuService::Reset() {
notificationManager.Reset();
bleController.State(Pinetime::Controllers::Ble::FirmwareUpdateStates::Error);
bleController.StopFirmwareUpdate();
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleFirmwareUpdateFinished);
systemTask.PushMessage(Pinetime::System::Messages::BleFirmwareUpdateFinished);
}
DfuService::NotificationManager::NotificationManager() {

View File

@@ -67,7 +67,7 @@ int ImmediateAlertService::OnAlertLevelChanged(uint16_t connectionHandle, uint16
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
notificationManager.Push(std::move(notif));
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification);
systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
}
}

View File

@@ -149,7 +149,7 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
bleController.Disconnect();
} else {
bleController.Connect();
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleConnected);
systemTask.PushMessage(Pinetime::System::Messages::BleConnected);
connectionHandle = event->connect.conn_handle;
// Service discovery is deffered via systemtask
}

View File

@@ -5,9 +5,6 @@
using namespace Pinetime::Controllers;
DateTime::DateTime(System::SystemTask& systemTask) : systemTask {systemTask} {
}
void DateTime::SetTime(
uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter) {
std::tm tm = {
@@ -70,7 +67,8 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
// Notify new day to SystemTask
if (hour == 0 and not isMidnightAlreadyNotified) {
isMidnightAlreadyNotified = true;
systemTask.PushMessage(System::SystemTask::Messages::OnNewDay);
if(systemTask != nullptr)
systemTask->PushMessage(System::Messages::OnNewDay);
} else if (hour != 0) {
isMidnightAlreadyNotified = false;
}
@@ -104,6 +102,10 @@ const char* DateTime::DayOfWeekShortToStringLow() {
return DateTime::DaysStringShortLow[(uint8_t) dayOfWeek];
}
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
this->systemTask = systemTask;
}
char const* DateTime::DaysStringLow[] = {"--", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
char const* DateTime::DaysStringShortLow[] = {"--", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

View File

@@ -27,8 +27,6 @@ namespace Pinetime {
December
};
DateTime(System::SystemTask& systemTask);
void SetTime(uint16_t year,
uint8_t month,
uint8_t day,
@@ -75,8 +73,9 @@ namespace Pinetime {
return uptime;
}
void Register(System::SystemTask* systemTask);
private:
System::SystemTask& systemTask;
uint16_t year = 0;
Months month = Months::Unknown;
uint8_t day = 0;
@@ -90,6 +89,7 @@ namespace Pinetime {
std::chrono::seconds uptime {0};
bool isMidnightAlreadyNotified = false;
System::SystemTask* systemTask = nullptr;
static char const* DaysString[];
static char const* DaysStringShort[];

View File

@@ -4,9 +4,6 @@
using namespace Pinetime::Controllers;
HeartRateController::HeartRateController(Pinetime::System::SystemTask& systemTask) : systemTask {systemTask} {
}
void HeartRateController::Update(HeartRateController::States newState, uint8_t heartRate) {
this->state = newState;
if (this->heartRate != heartRate) {

View File

@@ -15,8 +15,7 @@ namespace Pinetime {
public:
enum class States { Stopped, NotEnoughData, NoTouch, Running };
explicit HeartRateController(System::SystemTask& systemTask);
HeartRateController() = default;
void Start();
void Stop();
void Update(States newState, uint8_t heartRate);
@@ -32,7 +31,6 @@ namespace Pinetime {
void SetService(Pinetime::Controllers::HeartRateService* service);
private:
System::SystemTask& systemTask;
Applications::HeartRateTask* task = nullptr;
States state = States::Stopped;
uint8_t heartRate = 0;

View File

@@ -38,9 +38,8 @@ namespace {
}
}
Ppg::Ppg(float spl)
: offset {spl},
hpf {0.87033078, -1.74066156, 0.87033078, -1.72377617, 0.75754694},
Ppg::Ppg()
: hpf {0.87033078, -1.74066156, 0.87033078, -1.72377617, 0.75754694},
agc {20, 0.971, 2},
lpf {0.11595249, 0.23190498, 0.11595249, -0.72168143, 0.18549138} {
}
@@ -67,13 +66,7 @@ float Ppg::HeartRate() {
dataIndex = 0;
return hr;
}
int cccount = 0;
float Ppg::ProcessHeartRate() {
if (cccount > 2)
asm("nop");
cccount++;
auto t0 = Trough(data.data(), dataIndex, 7, 48);
if (t0 < 0)
return 0;

View File

@@ -8,8 +8,7 @@ namespace Pinetime {
namespace Controllers {
class Ppg {
public:
explicit Ppg(float spl);
Ppg();
int8_t Preprocess(float spl);
float HeartRate();

View File

@@ -12,14 +12,17 @@ using namespace Pinetime::Controllers;
APP_TIMER_DEF(timerAppTimer);
TimerController::TimerController(System::SystemTask& systemTask) : systemTask{systemTask} {
namespace {
void TimerEnd(void* p_context) {
auto* controller = static_cast<Pinetime::Controllers::TimerController*> (p_context);
if(controller != nullptr)
controller->OnTimerEnd();
}
}
void TimerController::Init() {
app_timer_create(&timerAppTimer, APP_TIMER_MODE_SINGLE_SHOT, timerEnd);
app_timer_create(&timerAppTimer, APP_TIMER_MODE_SINGLE_SHOT, TimerEnd);
}
void TimerController::StartTimer(uint32_t duration) {
@@ -47,13 +50,6 @@ uint32_t TimerController::GetTimeRemaining() {
return (static_cast<TickType_t>(deltaTicks) / static_cast<TickType_t>(configTICK_RATE_HZ)) * 1000;
}
void TimerController::timerEnd(void* p_context) {
auto* controller = static_cast<Controllers::TimerController*> (p_context);
controller->timerRunning = false;
controller->systemTask.PushMessage(System::SystemTask::Messages::OnTimerDone);
}
void TimerController::StopTimer() {
app_timer_stop(timerAppTimer);
timerRunning = false;
@@ -61,4 +57,13 @@ void TimerController::StopTimer() {
bool TimerController::IsRunning() {
return timerRunning;
}
}
void TimerController::OnTimerEnd() {
timerRunning = false;
if(systemTask != nullptr)
systemTask->PushMessage(System::Messages::OnTimerDone);
}
void TimerController::Register(Pinetime::System::SystemTask* systemTask) {
this->systemTask = systemTask;
}

View File

@@ -12,7 +12,7 @@ namespace Pinetime {
class TimerController {
public:
TimerController(Pinetime::System::SystemTask& systemTask);
TimerController() = default;
void Init();
@@ -23,12 +23,13 @@ namespace Pinetime {
uint32_t GetTimeRemaining();
bool IsRunning();
void OnTimerEnd();
void Register(System::SystemTask* systemTask);
private:
System::SystemTask& systemTask;
static void timerEnd(void* p_context);
System::SystemTask* systemTask = nullptr;
TickType_t endTicks;
bool timerRunning = false;
};