Implemented I2C scanner app (#97)

This commit is contained in:
Ken Van Hoeylandt
2024-11-28 21:42:18 +01:00
committed by GitHub
parent 6094b9c3f2
commit 3f62ec2efa
19 changed files with 451 additions and 44 deletions
+15 -14
View File
@@ -35,7 +35,7 @@ Mutex::Mutex(MutexType type) : type(type) {
tt_crash("Mutex type unknown/corrupted");
}
tt_check(semaphore != nullptr);
tt_assert(semaphore != nullptr);
}
Mutex::~Mutex() {
@@ -47,7 +47,6 @@ Mutex::~Mutex() {
TtStatus Mutex::acquire(uint32_t timeout) const {
tt_assert(!TT_IS_IRQ_MODE());
tt_assert(semaphore);
TtStatus status = TtStatusOk;
tt_mutex_info(mutex, "acquire");
@@ -55,52 +54,54 @@ TtStatus Mutex::acquire(uint32_t timeout) const {
case MutexTypeNormal:
if (xSemaphoreTake(semaphore, timeout) != pdPASS) {
if (timeout != 0U) {
status = TtStatusErrorTimeout;
return TtStatusErrorTimeout;
} else {
status = TtStatusErrorResource;
return TtStatusErrorResource;
}
} else {
return TtStatusOk;
}
break;
case MutexTypeRecursive:
if (xSemaphoreTakeRecursive(semaphore, timeout) != pdPASS) {
if (timeout != 0U) {
status = TtStatusErrorTimeout;
return TtStatusErrorTimeout;
} else {
status = TtStatusErrorResource;
return TtStatusErrorResource;
}
} else {
return TtStatusOk;
}
break;
default:
tt_crash("mutex type unknown/corrupted");
}
return status;
}
TtStatus Mutex::release() const {
assert(!TT_IS_IRQ_MODE());
tt_assert(semaphore);
TtStatus status = TtStatusOk;
tt_mutex_info(mutex, "release");
switch (type) {
case MutexTypeNormal: {
if (xSemaphoreGive(semaphore) != pdPASS) {
status = TtStatusErrorResource;
return TtStatusErrorResource;
} else {
return TtStatusOk;
}
break;
}
case MutexTypeRecursive:
if (xSemaphoreGiveRecursive(semaphore) != pdPASS) {
status = TtStatusErrorResource;
return TtStatusErrorResource;
} else {
return TtStatusOk;
}
break;
default:
tt_crash("mutex type unknown/corrupted");
}
return status;
}
ThreadId Mutex::getOwner() const {