Fixes and improvements (#185)

- unPhone improvements related to power and boot (add boot count logging)
- Cleanup of Mutex acquire/release
- Removed `tt_assert()` in favour of `assert()`
- Fix sim build (likely failed due to migration of GitHub Actions to Ubuntu 24.04)
This commit is contained in:
Ken Van Hoeylandt 2025-01-24 22:49:29 +01:00 committed by GitHub
parent 3be251d8fb
commit d86dc40472
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
47 changed files with 223 additions and 177 deletions

View File

@ -1,5 +1,8 @@
name: Build Firmware
on: [push]
on:
push:
pull_request:
types: [opened, synchronize, reopened]
permissions: read-all

View File

@ -1,5 +1,8 @@
name: Build SDK
on: [push]
on:
push:
pull_request:
types: [opened, synchronize, reopened]
permissions: read-all

View File

@ -1,9 +1,12 @@
# Disabled because of issue: https://github.com/libsdl-org/setup-sdl/issues/23
name: Build Simulator
on: [push]
on:
push:
pull_request:
types: [opened, synchronize, reopened]
jobs:
Build-Simulator-Linux:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: "Build"

View File

@ -1,5 +1,8 @@
name: Tests
on: [push]
on:
push:
pull_request:
types: [opened, synchronize, reopened]
jobs:
Run:
runs-on: ubuntu-latest

View File

@ -140,7 +140,7 @@ bool YellowDisplay::start() {
}
bool YellowDisplay::stop() {
tt_assert(displayHandle != nullptr);
assert(displayHandle != nullptr);
lvgl_port_remove_disp(displayHandle);

View File

@ -159,7 +159,7 @@ bool TdeckDisplay::start() {
}
bool TdeckDisplay::stop() {
tt_assert(displayHandle != nullptr);
assert(displayHandle != nullptr);
lvgl_port_remove_disp(displayHandle);

View File

@ -102,7 +102,7 @@ bool Core2Display::start() {
}
bool Core2Display::stop() {
tt_assert(displayHandle != nullptr);
assert(displayHandle != nullptr);
lvgl_port_remove_disp(displayHandle);

View File

@ -119,7 +119,7 @@ bool CoreS3Display::start() {
}
bool CoreS3Display::stop() {
tt_assert(displayHandle != nullptr);
assert(displayHandle != nullptr);
lvgl_port_remove_disp(displayHandle);

View File

@ -69,7 +69,7 @@ void lvgl_task_start() {
nullptr
);
tt_assert(task_result == pdTRUE);
assert(task_result == pdTRUE);
}
lv_disp_t* displayHandle = nullptr;

View File

@ -33,7 +33,7 @@ void freertosMain() {
nullptr
);
tt_assert(task_result == pdTRUE);
assert(task_result == pdTRUE);
// Blocks forever
vTaskStartScheduler();

View File

@ -1,3 +1,4 @@
#include "Preferences.h"
#include "TactilityCore.h"
#include "UnPhoneFeatures.h"
#include <esp_sleep.h>
@ -8,6 +9,55 @@ extern UnPhoneFeatures unPhoneFeatures;
static std::unique_ptr<tt::Thread> powerThread;
static const char* bootCountKey = "boot_count";
static const char* powerOffCountKey = "power_off_count";
static const char* powerSleepKey = "power_sleep_key";
class DeviceStats {
private:
tt::Preferences preferences = tt::Preferences("unphone");
int32_t getValue(const char* key) {
int32_t value = 0;
preferences.optInt32(key, value);
return value;
}
void setValue(const char* key, int32_t value) {
preferences.putInt32(key, value);
}
void increaseValue(const char* key) {
int32_t new_value = getValue(key) + 1;
setValue(key, new_value);
}
public:
void notifyBootStart() {
increaseValue(bootCountKey);
}
void notifyPowerOff() {
increaseValue(powerOffCountKey);
}
void notifyPowerSleep() {
increaseValue(powerSleepKey);
}
void printInfo() {
TT_LOG_I("TAG", "Device stats:");
TT_LOG_I("TAG", " boot: %ld", getValue(bootCountKey));
TT_LOG_I("TAG", " power off: %ld", getValue(powerOffCountKey));
TT_LOG_I("TAG", " power sleep: %ld", getValue(powerSleepKey));
}
};
DeviceStats bootStats;
enum class PowerState {
Initial,
On,
@ -16,6 +66,7 @@ enum class PowerState {
#define DEBUG_POWER_STATES false
#if DEBUG_POWER_STATES
/** Helper method to use the buzzer to signal the different power stages */
static void powerInfoBuzz(uint8_t count) {
if (DEBUG_POWER_STATES) {
@ -33,6 +84,7 @@ static void powerInfoBuzz(uint8_t count) {
}
}
}
#endif
static void updatePowerSwitch() {
static PowerState last_state = PowerState::Initial;
@ -46,19 +98,28 @@ static void updatePowerSwitch() {
if (!unPhoneFeatures.isUsbPowerConnected()) { // and usb unplugged we go into shipping mode
TT_LOG_W(TAG, "Shipping mode until USB connects");
#if DEBUG_POWER_STATES
unPhoneFeatures.setExpanderPower(true);
powerInfoBuzz(3);
unPhoneFeatures.setExpanderPower(false);
#endif
unPhoneFeatures.turnPeripheralsOff();
bootStats.notifyPowerOff();
unPhoneFeatures.setShipping(true); // tell BM to stop supplying power until USB connects
} else { // When power switch is off, but USB is plugged in, we wait (deep sleep) until USB is unplugged.
TT_LOG_W(TAG, "Waiting for USB disconnect to power off");
#if DEBUG_POWER_STATES
powerInfoBuzz(2);
#endif
unPhoneFeatures.turnPeripheralsOff();
bootStats.notifyPowerSleep();
// Deep sleep for 1 minute, then awaken to check power state again
// GPIO trigger from power switch also awakens the device
unPhoneFeatures.wakeOnPowerSwitch();
@ -70,9 +131,9 @@ static void updatePowerSwitch() {
last_state = PowerState::On;
TT_LOG_W(TAG, "Power on");
unPhoneFeatures.setShipping(false);
unPhoneFeatures.setExpanderPower(true);
#if DEBUG_POWER_STATES
powerInfoBuzz(1);
#endif
}
}
}
@ -95,6 +156,11 @@ static void startPowerSwitchThread() {
}
static bool unPhonePowerOn() {
// Print early, in case of early crash (info will be from previous boot)
bootStats.printInfo();
bootStats.notifyBootStart();
if (!unPhoneFeatures.init()) {
TT_LOG_E(TAG, "UnPhoneFeatures init failed");
return false;

View File

@ -283,13 +283,11 @@ bool UnPhoneFeatures::setShipping(bool on) const {
if (on) {
TT_LOG_W(TAG, "setShipping: on");
batteryManagement.setWatchDogTimer(Bq24295::WatchDogTimer::Disabled);
// Set bit 5 to disable
batteryManagement.setOperationControlBitOn(1 << 5);
batteryManagement.setBatFetOn(false);
} else {
TT_LOG_W(TAG, "setShipping: off");
batteryManagement.setWatchDogTimer(Bq24295::WatchDogTimer::Enabled40s);
// Clear bit 5 to enable
batteryManagement.setOperationControlBitOff(1 << 5);
batteryManagement.setBatFetOn(true);
}
return true;
}

View File

@ -60,18 +60,16 @@ bool Bq24295::setWatchDogTimer(WatchDogTimer in) const {
// endregoin
// region Operation Control
// region Operation Control (REG07)
bool Bq24295::getOperationControl(uint8_t value) const {
return readRegister8(registers::OPERATION_CONTROL, value);
}
bool Bq24295::setOperationControlBitOn(uint8_t mask) const {
return bitOn(registers::OPERATION_CONTROL, mask);
}
bool Bq24295::setOperationControlBitOff(uint8_t mask) const {
return bitOff(registers::OPERATION_CONTROL, mask);
bool Bq24295::setBatFetOn(bool on) const {
if (on) {
// bit 5 low means bat fet is on
return bitOff(registers::OPERATION_CONTROL, BIT(5));
} else {
// bit 5 high means bat fet is off
return bitOn(registers::OPERATION_CONTROL, BIT(5));
}
}
// endregion

View File

@ -26,9 +26,7 @@ public:
bool isUsbPowerConnected() const;
bool getOperationControl(uint8_t value) const;
bool setOperationControlBitOn(uint8_t mask) const;
bool setOperationControlBitOff(uint8_t mask) const;
bool setBatFetOn(bool on) const;
bool getStatus(uint8_t& value) const;
bool getVersion(uint8_t& value) const;

View File

@ -56,7 +56,7 @@ bool UnPhoneDisplay::start() {
}
bool UnPhoneDisplay::stop() {
tt_assert(displayHandle != nullptr);
assert(displayHandle != nullptr);
lv_display_delete(displayHandle);
displayHandle = nullptr;

View File

@ -51,7 +51,7 @@ void getLimit() {
Preprocessor functions are written in snake-case and prefixed with `tt_`, for example:
```c++
#define tt_assert(x) __tt_assert_internal(x)
#define tt_check(x) if (!(x)) { /* .. */ }
```
### Type names

View File

@ -14,6 +14,7 @@
- M5Stack Core only shows 4MB of SPIRAM in use
# TODOs
- Extend unPhone power driver: add charging status, usb connection status, etc.
- Expose app::Paths to TactilityC
- Refactor ServiceManifest into C++ class-based design like the App class
- Experiment with what happens when using C++ code in an external app (without using standard library!)

View File

@ -41,7 +41,7 @@ private:
const std::shared_ptr<app::AppManifest>& manifest
) {
if (manifest->location.isInternal()) {
tt_assert(manifest->createApp != nullptr);
assert(manifest->createApp != nullptr);
return manifest->createApp();
} else if (manifest->location.isExternal()) {
if (manifest->createApp != nullptr) {

View File

@ -135,7 +135,7 @@ static void register_and_start_user_services(const std::vector<const service::Se
void run(const Configuration& config) {
TT_LOG_D(TAG, "run");
tt_assert(config.hardware);
assert(config.hardware);
const hal::Configuration& hardware = *config.hardware;
// Assign early so starting services can use it

View File

@ -25,7 +25,7 @@ State AppInstance::getState() const {
* Consider not exposing bundle, but expose `app_get_bundle_int(key)` methods with locking in it.
*/
const AppManifest& AppInstance::getManifest() const {
tt_assert(manifest != nullptr);
assert(manifest != nullptr);
return *manifest;
}
@ -50,7 +50,7 @@ std::shared_ptr<const Bundle> AppInstance::getParameters() const {
}
std::unique_ptr<Paths> AppInstance::getPaths() const {
tt_assert(manifest != nullptr);
assert(manifest != nullptr);
return std::make_unique<AppInstancePaths>(*manifest);
}

View File

@ -188,8 +188,8 @@ bool registerElfApp(const std::string& filePath) {
std::shared_ptr<App> createElfApp(const std::shared_ptr<AppManifest>& manifest) {
TT_LOG_I(TAG, "createElfApp");
tt_assert(manifest != nullptr);
tt_assert(manifest->location.isExternal());
assert(manifest != nullptr);
assert(manifest->location.isExternal());
return std::make_shared<ElfApp>(manifest->location.getPath());
}

View File

@ -50,7 +50,7 @@ private:
static void onButtonClickedCallback(lv_event_t* e) {
auto appContext = service::loader::getCurrentAppContext();
tt_assert(appContext != nullptr);
assert(appContext != nullptr);
auto app = std::static_pointer_cast<AlertDialogApp>(appContext->getApp());
app->onButtonClicked(e);
}

View File

@ -36,9 +36,9 @@ private:
kernel::systemEventPublish(kernel::SystemEvent::BootSplash);
auto* lvgl_display = lv_display_get_default();
tt_assert(lvgl_display != nullptr);
assert(lvgl_display != nullptr);
auto* hal_display = (hal::Display*)lv_display_get_user_data(lvgl_display);
tt_assert(hal_display != nullptr);
assert(hal_display != nullptr);
if (hal_display->supportsBacklightDuty()) {
int32_t backlight_duty = app::display::getBacklightDuty();
hal_display->setBacklightDuty(backlight_duty);

View File

@ -24,9 +24,9 @@ static uint8_t gamma = 255;
static void onBacklightSliderEvent(lv_event_t* event) {
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
auto* lvgl_display = lv_display_get_default();
tt_assert(lvgl_display != nullptr);
assert(lvgl_display != nullptr);
auto* hal_display = (tt::hal::Display*)lv_display_get_user_data(lvgl_display);
tt_assert(hal_display != nullptr);
assert(hal_display != nullptr);
if (hal_display->supportsBacklightDuty()) {
int32_t slider_value = lv_slider_get_value(slider);
@ -41,9 +41,9 @@ static void onBacklightSliderEvent(lv_event_t* event) {
static void onGammaSliderEvent(lv_event_t* event) {
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
auto* lvgl_display = lv_display_get_default();
tt_assert(lvgl_display != nullptr);
assert(lvgl_display != nullptr);
auto* hal_display = (tt::hal::Display*)lv_display_get_user_data(lvgl_display);
tt_assert(hal_display != nullptr);
assert(hal_display != nullptr);
if (hal_display->getGammaCurveCount() > 0) {
int32_t slider_value = lv_slider_get_value(slider);
@ -57,9 +57,9 @@ static void onGammaSliderEvent(lv_event_t* event) {
static tt::hal::Display* getHalDisplay(lv_obj_t* widget) {
auto* lvgl_display = lv_obj_get_display(widget);
tt_assert(lvgl_display != nullptr);
assert(lvgl_display != nullptr);
auto* hal_display = (tt::hal::Display*)lv_display_get_user_data(lvgl_display);
tt_assert(hal_display != nullptr);
assert(hal_display != nullptr);
return hal_display;
}
@ -135,7 +135,7 @@ class DisplayApp : public App {
lv_obj_add_event_cb(gamma_slider, onGammaSliderEvent, LV_EVENT_VALUE_CHANGED, nullptr);
auto* hal_display = getHalDisplay(parent);
tt_assert(hal_display != nullptr);
assert(hal_display != nullptr);
if (!hal_display->supportsBacklightDuty()) {
lv_slider_set_value(brightness_slider, 255, LV_ANIM_OFF);

View File

@ -101,7 +101,7 @@ void GpioApp::onTimer(TT_UNUSED std::shared_ptr<void> context) {
void GpioApp::startTask() {
lock();
tt_assert(timer == nullptr);
assert(timer == nullptr);
timer = std::make_unique<Timer>(
Timer::Type::Periodic,
&onTimer
@ -111,7 +111,7 @@ void GpioApp::startTask() {
}
void GpioApp::stopTask() {
tt_assert(timer);
assert(timer);
timer->stop();
timer = nullptr;

View File

@ -160,7 +160,7 @@ void I2cScannerApp::onScanTimerCallback(TT_UNUSED std::shared_ptr<void> context)
bool I2cScannerApp::getPort(i2c_port_t* outPort) {
if (mutex.acquire(100 / portTICK_PERIOD_MS) == TtStatusOk) {
*outPort = this->port;
tt_assert(mutex.release() == TtStatusOk);
assert(mutex.release() == TtStatusOk);
return true;
} else {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "getPort");
@ -171,7 +171,7 @@ bool I2cScannerApp::getPort(i2c_port_t* outPort) {
bool I2cScannerApp::addAddressToList(uint8_t address) {
if (mutex.acquire(100 / portTICK_PERIOD_MS) == TtStatusOk) {
scannedAddresses.push_back(address);
tt_assert(mutex.release() == TtStatusOk);
assert(mutex.release() == TtStatusOk);
return true;
} else {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "addAddressToList");
@ -257,7 +257,7 @@ void I2cScannerApp::startScanning() {
}
void I2cScannerApp::stopScanning() {
if (mutex.acquire(250 / portTICK_PERIOD_MS) == TtStatusOk) {
tt_assert(scanTimer != nullptr);
assert(scanTimer != nullptr);
scanState = ScanStateStopped;
tt_check(mutex.release() == TtStatusOk);
} else {

View File

@ -57,7 +57,7 @@ private:
static void onButtonClickedCallback(lv_event_t* e) {
auto appContext = service::loader::getCurrentAppContext();
tt_assert(appContext != nullptr);
assert(appContext != nullptr);
auto app = std::static_pointer_cast<InputDialogApp>(appContext->getApp());
app->onButtonClicked(e);
}

View File

@ -47,7 +47,7 @@ private:
static void onListItemSelectedCallback(lv_event_t* e) {
auto appContext = service::loader::getCurrentAppContext();
tt_assert(appContext != nullptr);
assert(appContext != nullptr);
auto app = std::static_pointer_cast<SelectionDialogApp>(appContext->getApp());
app->onListItemSelected(e);
}

View File

@ -21,7 +21,7 @@ bool initDisplay(const hal::Configuration& config) {
}
lv_display_t* lvgl_display = display->getLvglDisplay();
tt_assert(lvgl_display);
assert(lvgl_display);
if (display->supportsBacklightDuty()) {
display->setBacklightDuty(0);
@ -30,7 +30,7 @@ bool initDisplay(const hal::Configuration& config) {
void* existing_display_user_data = lv_display_get_user_data(lvgl_display);
// esp_lvgl_port users user_data by default, so we have to modify the source
// this is a check for when we upgrade esp_lvgl_port and forget to modify it again
tt_assert(existing_display_user_data == nullptr);
assert(existing_display_user_data == nullptr);
lv_display_set_user_data(lvgl_display, display);
lv_display_rotation_t rotation = app::display::getRotation();
@ -43,8 +43,8 @@ bool initDisplay(const hal::Configuration& config) {
bool initTouch(hal::Display* display, hal::Touch* touch) {
TT_LOG_I(TAG, "Touch init");
tt_assert(display);
tt_assert(touch);
assert(display);
assert(touch);
if (touch->start(display->getLvglDisplay())) {
return true;
} else {
@ -55,8 +55,8 @@ bool initTouch(hal::Display* display, hal::Touch* touch) {
bool initKeyboard(hal::Display* display, hal::Keyboard* keyboard) {
TT_LOG_I(TAG, "Keyboard init");
tt_assert(display);
tt_assert(keyboard);
assert(display);
assert(keyboard);
if (keyboard->isAttached()) {
if (keyboard->start(display->getLvglDisplay())) {
lv_indev_t* keyboard_indev = keyboard->getLvglIndev();

View File

@ -5,9 +5,9 @@ namespace tt::lvgl {
hal::Display* getDisplay() {
auto* lvgl_display = lv_display_get_default();
tt_assert(lvgl_display != nullptr);
assert(lvgl_display != nullptr);
auto* hal_display = (tt::hal::Display*)lv_display_get_user_data(lvgl_display);
tt_assert(hal_display != nullptr);
assert(hal_display != nullptr);
return hal_display;
}

View File

@ -66,7 +66,7 @@ Gui* gui_alloc() {
}
void gui_free(Gui* instance) {
tt_assert(instance != nullptr);
assert(instance != nullptr);
delete instance->thread;
lv_group_delete(instance->keyboardGroup);
@ -78,17 +78,17 @@ void gui_free(Gui* instance) {
}
void lock() {
tt_assert(gui);
tt_check(gui->mutex.acquire(configTICK_RATE_HZ) == TtStatusOk);
assert(gui);
tt_check(gui->mutex.lock(configTICK_RATE_HZ));
}
void unlock() {
tt_assert(gui);
tt_check(gui->mutex.release() == TtStatusOk);
assert(gui);
tt_check(gui->mutex.unlock());
}
void requestDraw() {
tt_assert(gui);
assert(gui);
ThreadId thread_id = gui->thread->getId();
thread_flags_set(thread_id, GUI_THREAD_FLAG_DRAW);
}
@ -147,7 +147,7 @@ class GuiService : public Service {
public:
void onStart(TT_UNUSED ServiceContext& service) override {
tt_assert(gui == nullptr);
assert(gui == nullptr);
gui = gui_alloc();
gui->thread->setPriority(THREAD_PRIORITY_SERVICE);
@ -155,7 +155,7 @@ public:
}
void onStop(TT_UNUSED ServiceContext& service) override {
tt_assert(gui != nullptr);
assert(gui != nullptr);
lock();
ThreadId thread_id = gui->thread->getId();

View File

@ -27,7 +27,7 @@ static lv_obj_t* createAppViews(Gui* gui, lv_obj_t* parent) {
}
void redraw(Gui* gui) {
tt_assert(gui);
assert(gui);
// Lock GUI and LVGL
lock();

View File

@ -44,14 +44,14 @@ static Loader* loader_alloc() {
}
static void loader_free() {
tt_assert(loader_singleton != nullptr);
assert(loader_singleton != nullptr);
delete loader_singleton;
loader_singleton = nullptr;
}
void startApp(const std::string& id, std::shared_ptr<const Bundle> parameters) {
TT_LOG_I(TAG, "Start app %s", id.c_str());
tt_assert(loader_singleton);
assert(loader_singleton);
auto message = std::make_shared<LoaderMessageAppStart>(id, std::move(parameters));
loader_singleton->dispatcherThread->dispatch(onStartAppMessage, message);
}
@ -63,7 +63,7 @@ void stopApp() {
}
std::shared_ptr<app::AppContext> _Nullable getCurrentAppContext() {
tt_assert(loader_singleton);
assert(loader_singleton);
if (loader_singleton->mutex.lock(10 / portTICK_PERIOD_MS)) {
auto app = loader_singleton->appStack.top();
loader_singleton->mutex.unlock();
@ -79,7 +79,7 @@ std::shared_ptr<app::App> _Nullable getCurrentApp() {
}
std::shared_ptr<PubSub> getPubsub() {
tt_assert(loader_singleton);
assert(loader_singleton);
// it's safe to return pubsub without locking
// because it's never freed and loader is never exited
// also the loader instance cannot be obtained until the pubsub is created
@ -256,7 +256,7 @@ static void stopAppInternal() {
// If there's a previous app, resume it
if (!loader_singleton->appStack.empty()) {
instance_to_resume = loader_singleton->appStack.top();
tt_assert(instance_to_resume);
assert(instance_to_resume);
transitionAppToState(instance_to_resume, app::StateShowing);
}

View File

@ -12,7 +12,7 @@ void tt_app_register(
const ExternalAppManifest* manifest
) {
#ifdef ESP_PLATFORM
tt_assert((manifest->createData == nullptr) == (manifest->destroyData == nullptr));
assert((manifest->createData == nullptr) == (manifest->destroyData == nullptr));
tt::app::setElfAppManifest(
manifest->name,
manifest->icon,

View File

@ -1,7 +1,7 @@
/**
* @file check.h
*
* Tactility crash and assert functions.
* Tactility crash and check functions.
*
* The main problem with crashing is that you can't do anything without disturbing registers,
* and if you disturb registers, you won't be able to see the correct register values in the debugger.
@ -65,30 +65,3 @@ namespace tt {
*/
#define tt_check(x, ...) if (!(x)) { TT_LOG_E("check", "Failed: %s", #x); tt::_crash(); }
/** Only in debug build: Assert condition and crash if assert failed */
#ifdef TT_DEBUG
#define tt_assert_internal(__e, __m) \
do { \
if (!(__e)) { \
TT_LOG_E("assert", "%s", #__e); \
if (__m) { \
__tt_crash(#__m); \
} else { \
__tt_crash(""); \
} \
} \
} while (0)
#else
#define __tt_assert(__e, __m) \
do { \
((void)(__e)); \
((void)(__m)); \
} while (0)
#endif
/** Assert condition and crash if failed
* @warning only will do check if firmware compiled in debug mode
* @param[in] condition to check
*/
#define tt_assert(expression) assert(expression)

View File

@ -9,19 +9,19 @@
namespace tt {
EventFlag::EventFlag() {
tt_assert(!TT_IS_IRQ_MODE());
assert(!TT_IS_IRQ_MODE());
handle = xEventGroupCreate();
tt_check(handle);
}
EventFlag::~EventFlag() {
tt_assert(!TT_IS_IRQ_MODE());
assert(!TT_IS_IRQ_MODE());
vEventGroupDelete(handle);
}
uint32_t EventFlag::set(uint32_t flags) const {
tt_assert(handle);
tt_assert((flags & TT_EVENT_FLAG_INVALID_BITS) == 0U);
assert(handle);
assert((flags & TT_EVENT_FLAG_INVALID_BITS) == 0U);
uint32_t rflags;
BaseType_t yield;
@ -43,7 +43,7 @@ uint32_t EventFlag::set(uint32_t flags) const {
}
uint32_t EventFlag::clear(uint32_t flags) const {
tt_assert((flags & TT_EVENT_FLAG_INVALID_BITS) == 0U);
assert((flags & TT_EVENT_FLAG_INVALID_BITS) == 0U);
uint32_t rflags;
@ -84,8 +84,8 @@ uint32_t EventFlag::wait(
uint32_t options,
uint32_t timeout
) const {
tt_assert(!TT_IS_IRQ_MODE());
tt_assert((flags & TT_EVENT_FLAG_INVALID_BITS) == 0U);
assert(!TT_IS_IRQ_MODE());
assert((flags & TT_EVENT_FLAG_INVALID_BITS) == 0U);
BaseType_t wait_all;
BaseType_t exit_clear;

View File

@ -5,13 +5,13 @@
namespace tt {
MessageQueue::MessageQueue(uint32_t capacity, uint32_t msg_size) {
tt_assert(!TT_IS_ISR() && (capacity > 0U) && (msg_size > 0U));
assert(!TT_IS_ISR() && (capacity > 0U) && (msg_size > 0U));
queue_handle = xQueueCreate(capacity, msg_size);
tt_check(queue_handle);
}
MessageQueue::~MessageQueue() {
tt_assert(!TT_IS_ISR());
assert(!TT_IS_ISR());
vQueueDelete(queue_handle);
}

View File

@ -35,18 +35,18 @@ Mutex::Mutex(Type type) : type(type) {
tt_crash("Mutex type unknown/corrupted");
}
tt_assert(semaphore != nullptr);
assert(semaphore != nullptr);
}
Mutex::~Mutex() {
tt_assert(!TT_IS_IRQ_MODE());
assert(!TT_IS_IRQ_MODE());
vSemaphoreDelete(semaphore);
semaphore = nullptr; // If the mutex is used after release, this might help debugging
}
TtStatus Mutex::acquire(TickType_t timeout) const {
tt_assert(!TT_IS_IRQ_MODE());
tt_assert(semaphore != nullptr);
assert(!TT_IS_IRQ_MODE());
assert(semaphore != nullptr);
tt_mutex_info(mutex, "acquire");
@ -78,7 +78,7 @@ TtStatus Mutex::acquire(TickType_t timeout) const {
TtStatus Mutex::release() const {
assert(!TT_IS_IRQ_MODE());
tt_assert(semaphore);
assert(semaphore);
tt_mutex_info(mutex, "release");
switch (type) {
@ -101,8 +101,8 @@ TtStatus Mutex::release() const {
}
ThreadId Mutex::getOwner() const {
tt_assert(!TT_IS_IRQ_MODE());
tt_assert(semaphore);
assert(!TT_IS_IRQ_MODE());
assert(semaphore);
return (ThreadId)xSemaphoreGetMutexHolder(semaphore);
}

View File

@ -20,8 +20,8 @@ PubSubSubscription* tt_pubsub_subscribe(std::shared_ptr<PubSub> pubsub, PubSubCa
}
void tt_pubsub_unsubscribe(std::shared_ptr<PubSub> pubsub, PubSubSubscription* pubsub_subscription) {
tt_assert(pubsub);
tt_assert(pubsub_subscription);
assert(pubsub);
assert(pubsub_subscription);
tt_check(pubsub->mutex.acquire(TtWaitForever) == TtStatusOk);
bool result = false;

View File

@ -5,8 +5,8 @@
namespace tt {
Semaphore::Semaphore(uint32_t maxCount, uint32_t initialCount) {
tt_assert(!TT_IS_IRQ_MODE());
tt_assert((maxCount > 0U) && (initialCount <= maxCount));
assert(!TT_IS_IRQ_MODE());
assert((maxCount > 0U) && (initialCount <= maxCount));
if (maxCount == 1U) {
handle = xSemaphoreCreateBinary();
@ -24,7 +24,7 @@ Semaphore::Semaphore(uint32_t maxCount, uint32_t initialCount) {
}
Semaphore::~Semaphore() {
tt_assert(!TT_IS_IRQ_MODE());
assert(!TT_IS_IRQ_MODE());
vSemaphoreDelete(handle);
}

View File

@ -7,7 +7,7 @@
namespace tt {
StreamBuffer::StreamBuffer(size_t size, size_t triggerLevel) {
tt_assert(size != 0);
assert(size != 0);
handle = xStreamBufferCreate(size, triggerLevel);
tt_check(handle);
};

View File

@ -42,17 +42,17 @@ __attribute__((__noreturn__)) void thread_catch() { //-V1082
static void thread_body(void* context) {
tt_assert(context);
assert(context);
auto* data = static_cast<Thread::Data*>(context);
// Store thread data instance to thread local storage
tt_assert(pvTaskGetThreadLocalStoragePointer(nullptr, 0) == nullptr);
assert(pvTaskGetThreadLocalStoragePointer(nullptr, 0) == nullptr);
vTaskSetThreadLocalStoragePointer(nullptr, 0, data->thread);
tt_assert(data->state == Thread::State::Starting);
assert(data->state == Thread::State::Starting);
setState(data, Thread::State::Running);
data->callbackResult = data->callback(data->callbackContext);
tt_assert(data->state == Thread::State::Running);
assert(data->state == Thread::State::Running);
setState(data, Thread::State::Stopped);
@ -102,36 +102,36 @@ Thread::Thread(
Thread::~Thread() {
// Ensure that use join before free
tt_assert(data.state == State::Stopped);
tt_assert(data.taskHandle == nullptr);
assert(data.state == State::Stopped);
assert(data.taskHandle == nullptr);
}
void Thread::setName(const std::string& newName) {
tt_assert(data.state == State::Stopped);
assert(data.state == State::Stopped);
data.name = newName;
}
void Thread::setStackSize(size_t stackSize) {
tt_assert(data.state == State::Stopped);
tt_assert(stackSize % 4 == 0);
assert(data.state == State::Stopped);
assert(stackSize % 4 == 0);
data.stackSize = stackSize;
}
void Thread::setCallback(Callback callback, _Nullable void* callbackContext) {
tt_assert(data.state == State::Stopped);
assert(data.state == State::Stopped);
data.callback = callback;
data.callbackContext = callbackContext;
}
void Thread::setPriority(Priority priority) {
tt_assert(data.state == State::Stopped);
assert(data.state == State::Stopped);
data.priority = priority;
}
void Thread::setStateCallback(StateCallback callback, _Nullable void* callbackContext) {
tt_assert(data.state == State::Stopped);
assert(data.state == State::Stopped);
data.stateCallback = callback;
data.stateCallbackContext = callbackContext;
}
@ -141,9 +141,9 @@ Thread::State Thread::getState() const {
}
void Thread::start() {
tt_assert(data.callback);
tt_assert(data.state == State::Stopped);
tt_assert(data.stackSize > 0U && data.stackSize < (UINT16_MAX * sizeof(StackType_t)));
assert(data.callback);
assert(data.state == State::Stopped);
assert(data.stackSize > 0U && data.stackSize < (UINT16_MAX * sizeof(StackType_t)));
setState(&data, State::Starting);
@ -210,7 +210,7 @@ ThreadId Thread::getId() const {
}
int32_t Thread::getReturnCode() const {
tt_assert(data.state == State::Stopped);
assert(data.state == State::Stopped);
return data.callbackResult;
}
@ -232,7 +232,7 @@ Thread::Priority thread_get_current_priority() {
}
void thread_yield() {
tt_assert(!TT_IS_IRQ_MODE());
assert(!TT_IS_IRQ_MODE());
taskYIELD();
}

View File

@ -15,7 +15,7 @@ static void timer_callback(TimerHandle_t hTimer) {
}
Timer::Timer(Type type, Callback callback, std::shared_ptr<void> callbackContext) {
tt_assert((!TT_IS_ISR()) && (callback != nullptr));
assert((!TT_IS_ISR()) && (callback != nullptr));
this->callback = callback;
this->callbackContext = std::move(callbackContext);
@ -28,39 +28,39 @@ Timer::Timer(Type type, Callback callback, std::shared_ptr<void> callbackContext
}
this->timerHandle = xTimerCreate(nullptr, portMAX_DELAY, (BaseType_t)reload, this, timer_callback);
tt_assert(this->timerHandle);
assert(this->timerHandle);
}
Timer::~Timer() {
tt_assert(!TT_IS_ISR());
assert(!TT_IS_ISR());
tt_check(xTimerDelete(timerHandle, portMAX_DELAY) == pdPASS);
}
bool Timer::start(TickType_t interval) {
tt_assert(!TT_IS_ISR());
tt_assert(interval < portMAX_DELAY);
assert(!TT_IS_ISR());
assert(interval < portMAX_DELAY);
return xTimerChangePeriod(timerHandle, interval, portMAX_DELAY) == pdPASS;
}
bool Timer::restart(TickType_t interval) {
tt_assert(!TT_IS_ISR());
tt_assert(interval < portMAX_DELAY);
assert(!TT_IS_ISR());
assert(interval < portMAX_DELAY);
return xTimerChangePeriod(timerHandle, interval, portMAX_DELAY) == pdPASS &&
xTimerReset(timerHandle, portMAX_DELAY) == pdPASS;
}
bool Timer::stop() {
tt_assert(!TT_IS_ISR());
assert(!TT_IS_ISR());
return xTimerStop(timerHandle, portMAX_DELAY) == pdPASS;
}
bool Timer::isRunning() {
tt_assert(!TT_IS_ISR());
assert(!TT_IS_ISR());
return xTimerIsTimerActive(timerHandle) == pdTRUE;
}
TickType_t Timer::getExpireTime() {
tt_assert(!TT_IS_ISR());
assert(!TT_IS_ISR());
return xTimerGetExpiryTime(timerHandle);
}
@ -74,10 +74,10 @@ bool Timer::setPendingCallback(PendingCallback callback, void* callbackContext,
}
void Timer::setThreadPriority(Thread::Priority priority) {
tt_assert(!TT_IS_ISR());
assert(!TT_IS_ISR());
TaskHandle_t task_handle = xTimerGetTimerDaemonTaskHandle();
tt_assert(task_handle); // Don't call this method before timer task start
assert(task_handle); // Don't call this method before timer task start
vTaskPrioritySet(task_handle, static_cast<UBaseType_t>(priority));
}

View File

@ -17,7 +17,7 @@ bool isRunning() {
}
int32_t lock() {
tt_assert(!TT_IS_ISR());
assert(!TT_IS_ISR());
int32_t lock;
@ -42,7 +42,7 @@ int32_t lock() {
}
int32_t unlock() {
tt_assert(!TT_IS_ISR());
assert(!TT_IS_ISR());
int32_t lock;
@ -72,7 +72,7 @@ int32_t unlock() {
}
int32_t restoreLock(int32_t lock) {
tt_assert(!TT_IS_ISR());
assert(!TT_IS_ISR());
switch (xTaskGetSchedulerState()) {
case taskSCHEDULER_SUSPENDED:
@ -108,7 +108,7 @@ uint32_t getTickFrequency() {
}
void delayTicks(TickType_t ticks) {
tt_assert(!TT_IS_ISR());
assert(!TT_IS_ISR());
if (ticks == 0U) {
taskYIELD();
} else {
@ -117,7 +117,7 @@ void delayTicks(TickType_t ticks) {
}
TtStatus delayUntilTick(TickType_t tick) {
tt_assert(!TT_IS_ISR());
assert(!TT_IS_ISR());
TickType_t tcnt, delay;
TtStatus stat;

View File

@ -29,7 +29,7 @@ private:
void update() {
auto sdcard = tt::hal::getConfiguration()->sdcard;
tt_assert(sdcard);
assert(sdcard);
if (lock(50)) {
auto new_state = sdcard->getState();

View File

@ -312,7 +312,7 @@ bool isConnectionSecure() {
}
int getRssi() {
tt_assert(wifi_singleton);
assert(wifi_singleton);
static int rssi = 0;
if (esp_wifi_sta_get_rssi(&rssi) == ESP_OK) {
return rssi;
@ -326,7 +326,7 @@ int getRssi() {
static void scan_list_alloc(std::shared_ptr<Wifi> wifi) {
auto lockable = wifi->dataMutex.scoped();
if (lockable->lock(TtWaitForever)) {
tt_assert(wifi->scan_list == nullptr);
assert(wifi->scan_list == nullptr);
wifi->scan_list = static_cast<wifi_ap_record_t*>(malloc(sizeof(wifi_ap_record_t) * wifi->scan_list_limit));
wifi->scan_list_count = 0;
}
@ -344,7 +344,7 @@ static void scan_list_alloc_safely(std::shared_ptr<Wifi> wifi) {
static void scan_list_free(std::shared_ptr<Wifi> wifi) {
auto lockable = wifi->dataMutex.scoped();
if (lockable->lock(TtWaitForever)) {
tt_assert(wifi->scan_list != nullptr);
assert(wifi->scan_list != nullptr);
free(wifi->scan_list);
wifi->scan_list = nullptr;
wifi->scan_list_count = 0;
@ -643,7 +643,7 @@ static void dispatchDisable(std::shared_ptr<void> context) {
TT_LOG_E(TAG, "Failed to deinit");
}
tt_assert(wifi->netif != nullptr);
assert(wifi->netif != nullptr);
esp_netif_destroy(wifi->netif);
wifi->netif = nullptr;
wifi->setScanActive(false);
@ -941,7 +941,7 @@ class WifiService final : public Service {
public:
void onStart(ServiceContext& service) override {
tt_assert(wifi_singleton == nullptr);
assert(wifi_singleton == nullptr);
wifi_singleton = std::make_shared<Wifi>();
wifi_singleton->autoConnectTimer = std::make_unique<Timer>(Timer::Type::Periodic, onAutoConnectTimer, wifi_singleton);
@ -956,7 +956,7 @@ public:
void onStop(ServiceContext& service) override {
auto wifi = wifi_singleton;
tt_assert(wifi != nullptr);
assert(wifi != nullptr);
RadioState state = wifi->getRadioState();
if (state != RadioState::Off) {

View File

@ -44,7 +44,7 @@ static void publish_event_simple(Wifi* wifi, EventType type) {
// region Public functions
std::shared_ptr<PubSub> getPubsub() {
tt_assert(wifi);
assert(wifi);
return wifi->pubsub;
}
@ -57,26 +57,26 @@ std::string getConnectionTarget() {
}
void scan() {
tt_assert(wifi);
assert(wifi);
wifi->scan_active = false; // TODO: enable and then later disable automatically
}
bool isScanning() {
tt_assert(wifi);
assert(wifi);
return wifi->scan_active;
}
void connect(const settings::WifiApSettings* ap, bool remember) {
tt_assert(wifi);
assert(wifi);
// TODO: implement
}
void disconnect() {
tt_assert(wifi);
assert(wifi);
}
void setScanRecords(uint16_t records) {
tt_assert(wifi);
assert(wifi);
// TODO: implement
}
@ -114,7 +114,7 @@ std::vector<ApRecord> getScanResults() {
}
void setEnabled(bool enabled) {
tt_assert(wifi != nullptr);
assert(wifi != nullptr);
if (enabled) {
wifi->radio_state = RadioState::On;
wifi->secure_connection = true;