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
47 changed files with 223 additions and 177 deletions
+1 -28
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)
+7 -7
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;
+2 -2
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);
}
+7 -7
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);
}
+2 -2
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;
+3 -3
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);
}
+1 -1
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);
};
+17 -17
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();
}
+12 -12
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));
}
+5 -5
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;