Minor improvements: use std::make_unique when creating unique_ptr, check the code is running from an IRQ before calling xQueueSendFromISR or xQueueSend)
This commit is contained in:
parent
caca6a5cff
commit
b1925ff286
6 changed files with 44 additions and 24 deletions
|
@ -45,6 +45,12 @@
|
||||||
using namespace Pinetime::Applications;
|
using namespace Pinetime::Applications;
|
||||||
using namespace Pinetime::Applications::Display;
|
using namespace Pinetime::Applications::Display;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
static inline bool in_isr(void) {
|
||||||
|
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
||||||
Components::LittleVgl& lvgl,
|
Components::LittleVgl& lvgl,
|
||||||
Drivers::Cst816S& touchPanel,
|
Drivers::Cst816S& touchPanel,
|
||||||
|
@ -364,12 +370,15 @@ void DisplayApp::IdleState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayApp::PushMessage(Messages msg) {
|
void DisplayApp::PushMessage(Messages msg) {
|
||||||
BaseType_t xHigherPriorityTaskWoken;
|
if(in_isr()) {
|
||||||
xHigherPriorityTaskWoken = pdFALSE;
|
BaseType_t xHigherPriorityTaskWoken;
|
||||||
xQueueSendFromISR(msgQueue, &msg, &xHigherPriorityTaskWoken);
|
xHigherPriorityTaskWoken = pdFALSE;
|
||||||
if (xHigherPriorityTaskWoken) {
|
xQueueSendFromISR(msgQueue, &msg, &xHigherPriorityTaskWoken);
|
||||||
/* Actual macro used here is port specific. */
|
if (xHigherPriorityTaskWoken) {
|
||||||
// TODO : should I do something here?
|
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
xQueueSend(msgQueue, &msg, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen1() {
|
||||||
__TIME__);
|
__TIME__);
|
||||||
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
|
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
|
||||||
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
||||||
return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label));
|
return std::make_unique<Screens::Label>(0, 5, app, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
|
std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
|
||||||
|
@ -161,7 +161,7 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
|
||||||
brightnessController.ToString(),
|
brightnessController.ToString(),
|
||||||
resetReason);
|
resetReason);
|
||||||
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
||||||
return std::unique_ptr<Screen>(new Screens::Label(1, 4, app, label));
|
return std::make_unique<Screens::Label>(1, 4, app, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Screen> SystemInfo::CreateScreen3() {
|
std::unique_ptr<Screen> SystemInfo::CreateScreen3() {
|
||||||
|
@ -195,7 +195,7 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen3() {
|
||||||
(int) mon.free_biggest_size,
|
(int) mon.free_biggest_size,
|
||||||
0);
|
0);
|
||||||
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
||||||
return std::unique_ptr<Screen>(new Screens::Label(2, 5, app, label));
|
return std::make_unique<Screens::Label>(2, 5, app, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sortById(const TaskStatus_t& lhs, const TaskStatus_t& rhs) {
|
bool sortById(const TaskStatus_t& lhs, const TaskStatus_t& rhs) {
|
||||||
|
@ -229,7 +229,7 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
|
||||||
lv_table_set_cell_value(infoTask, i + 1, 2, std::to_string(tasksStatus[i].usStackHighWaterMark).c_str());
|
lv_table_set_cell_value(infoTask, i + 1, 2, std::to_string(tasksStatus[i].usStackHighWaterMark).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::unique_ptr<Screen>(new Screens::Label(3, 5, app, infoTask));
|
return std::make_unique<Screens::Label>(3, 5, app, infoTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Screen> SystemInfo::CreateScreen5() {
|
std::unique_ptr<Screen> SystemInfo::CreateScreen5() {
|
||||||
|
@ -245,5 +245,5 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen5() {
|
||||||
"#FFFF00 JF002/InfiniTime#");
|
"#FFFF00 JF002/InfiniTime#");
|
||||||
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
|
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
|
||||||
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
||||||
return std::unique_ptr<Screen>(new Screens::Label(4, 5, app, label));
|
return std::make_unique<Screens::Label>(4, 5, app, label);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ std::unique_ptr<Screen> Settings::CreateScreen1() {
|
||||||
{Symbols::clock, "Watch face", Apps::SettingWatchFace},
|
{Symbols::clock, "Watch face", Apps::SettingWatchFace},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
return std::unique_ptr<Screen>(new Screens::List(0, 2, app, settingsController, applications));
|
return std::make_unique<Screens::List>(0, 2, app, settingsController, applications);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Screen> Settings::CreateScreen2() {
|
std::unique_ptr<Screen> Settings::CreateScreen2() {
|
||||||
|
@ -58,5 +58,5 @@ std::unique_ptr<Screen> Settings::CreateScreen2() {
|
||||||
{Symbols::list, "About", Apps::SysInfo},
|
{Symbols::list, "About", Apps::SysInfo},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
return std::unique_ptr<Screen>(new Screens::List(1, 2, app, settingsController, applications));
|
return std::make_unique<Screens::List>(1, 2, app, settingsController, applications);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ namespace Pinetime {
|
||||||
|
|
||||||
bool Refresh() override;
|
bool Refresh() override;
|
||||||
|
|
||||||
void OnButtonEvent(lv_obj_t* object, lv_event_t event);
|
|
||||||
bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override;
|
bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -132,17 +132,17 @@ void SpiMaster::OnEndEvent() {
|
||||||
|
|
||||||
spiBaseAddress->TASKS_START = 1;
|
spiBaseAddress->TASKS_START = 1;
|
||||||
} else {
|
} else {
|
||||||
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||||
if (taskToNotify != nullptr) {
|
if (taskToNotify != nullptr) {
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
|
||||||
vTaskNotifyGiveFromISR(taskToNotify, &xHigherPriorityTaskWoken);
|
vTaskNotifyGiveFromISR(taskToNotify, &xHigherPriorityTaskWoken);
|
||||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||||
}
|
}
|
||||||
|
|
||||||
nrf_gpio_pin_set(this->pinCsn);
|
nrf_gpio_pin_set(this->pinCsn);
|
||||||
currentBufferAddr = 0;
|
currentBufferAddr = 0;
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
BaseType_t xHigherPriorityTaskWoken2 = pdFALSE;
|
||||||
xSemaphoreGiveFromISR(mutex, &xHigherPriorityTaskWoken);
|
xSemaphoreGiveFromISR(mutex, &xHigherPriorityTaskWoken2);
|
||||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
portYIELD_FROM_ISR(xHigherPriorityTaskWoken | xHigherPriorityTaskWoken2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,12 @@
|
||||||
|
|
||||||
using namespace Pinetime::System;
|
using namespace Pinetime::System;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
static inline bool in_isr(void) {
|
||||||
|
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void IdleTimerCallback(TimerHandle_t xTimer) {
|
void IdleTimerCallback(TimerHandle_t xTimer) {
|
||||||
|
|
||||||
NRF_LOG_INFO("IdleTimerCallback");
|
NRF_LOG_INFO("IdleTimerCallback");
|
||||||
|
@ -392,12 +398,18 @@ void SystemTask::PushMessage(System::Messages msg) {
|
||||||
if (msg == Messages::GoToSleep) {
|
if (msg == Messages::GoToSleep) {
|
||||||
isGoingToSleep = true;
|
isGoingToSleep = true;
|
||||||
}
|
}
|
||||||
BaseType_t xHigherPriorityTaskWoken;
|
|
||||||
xHigherPriorityTaskWoken = pdFALSE;
|
if(in_isr()) {
|
||||||
xQueueSendFromISR(systemTasksMsgQueue, &msg, &xHigherPriorityTaskWoken);
|
BaseType_t xHigherPriorityTaskWoken;
|
||||||
if (xHigherPriorityTaskWoken) {
|
xHigherPriorityTaskWoken = pdFALSE;
|
||||||
/* Actual macro used here is port specific. */
|
xQueueSendFromISR(systemTasksMsgQueue, &msg, &xHigherPriorityTaskWoken);
|
||||||
// TODO: should I do something here?
|
if (xHigherPriorityTaskWoken) {
|
||||||
|
/* Actual macro used here is port specific. */
|
||||||
|
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
xQueueSend(systemTasksMsgQueue, &msg, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue