This commit is contained in:
Ken Van Hoeylandt 2026-01-02 20:35:38 +01:00
parent 10cc269d9d
commit 94d9c1d611
10 changed files with 32 additions and 11 deletions

View File

@ -1,6 +1,8 @@
#include "Bq25896.h" #include "Bq25896.h"
#define TAG "BQ27220" #include <Tactility/Log.h>
constexpr auto* TAG = "BQ27220";
void Bq25896::powerOff() { void Bq25896::powerOff() {
TT_LOG_I(TAG, "Power off"); TT_LOG_I(TAG, "Power off");

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <Tactility/hal/i2c/I2cDevice.h> #include <Tactility/hal/i2c/I2cDevice.h>
#include <Tactility/Log.h>
class Drv2605 : public tt::hal::i2c::I2cDevice { class Drv2605 : public tt::hal::i2c::I2cDevice {

View File

@ -33,7 +33,7 @@ bool tt_lock_acquire(LockHandle handle, TickType timeout) {
} }
void tt_lock_release(LockHandle handle) { void tt_lock_release(LockHandle handle) {
return HANDLE_AS_LOCK(handle)->unlock(); HANDLE_AS_LOCK(handle)->unlock();
} }
void tt_lock_free(LockHandle handle) { void tt_lock_free(LockHandle handle) {

View File

@ -6,8 +6,10 @@
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
static portMUX_TYPE critical_mutex; static portMUX_TYPE critical_mutex;
#define TT_ENTER_CRITICAL() taskENTER_CRITICAL(&critical_mutex) #define TT_ENTER_CRITICAL() taskENTER_CRITICAL(&critical_mutex)
#define TT_EXIT_CRITICAL() taskEXIT_CRITICAL(&critical_mutex)
#else #else
#define TT_ENTER_CRITICAL() taskENTER_CRITICAL() #define TT_ENTER_CRITICAL() taskENTER_CRITICAL()
#define TT_EXIT_CRITICAL() taskEXIT_CRITICAL()
#endif #endif
namespace tt::kernel::critical { namespace tt::kernel::critical {
@ -34,7 +36,7 @@ void exit(CriticalInfo info) {
if (info.fromIsr) { if (info.fromIsr) {
taskEXIT_CRITICAL_FROM_ISR(info.isrm); taskEXIT_CRITICAL_FROM_ISR(info.isrm);
} else if (info.kernelRunning) { } else if (info.kernelRunning) {
TT_ENTER_CRITICAL(); TT_EXIT_CRITICAL();
} else { } else {
portENABLE_INTERRUPTS(); portENABLE_INTERRUPTS();
} }

View File

@ -37,14 +37,17 @@ private:
Mutex mutex; Mutex mutex;
std::queue<Function> queue = {}; std::queue<Function> queue = {};
EventGroup eventFlag; EventGroup eventFlag;
bool shutdown = false;
public: public:
explicit Dispatcher() = default; explicit Dispatcher() = default;
~Dispatcher() { ~Dispatcher() {
mutex.lock(); shutdown = true;
mutex.unlock(); if (mutex.lock()) {
mutex.unlock();
}
} }
/** /**
@ -62,6 +65,10 @@ public:
return false; return false;
} }
if (shutdown) {
return false;
}
queue.push(std::move(function)); queue.push(std::move(function));
if (queue.size() == BACKPRESSURE_WARNING_COUNT) { if (queue.size() == BACKPRESSURE_WARNING_COUNT) {
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
@ -89,6 +96,10 @@ public:
return 0; return 0;
} }
if (shutdown) {
return 0;
}
// Mutate // Mutate
bool processing = true; bool processing = true;
uint32_t consumed = 0; uint32_t consumed = 0;
@ -112,7 +123,7 @@ public:
#endif #endif
} }
} while (processing); } while (processing && !shutdown);
return consumed; return consumed;
} }

View File

@ -79,7 +79,7 @@ public:
* @param[out] outError optional error output: this is set when the return value is false * @param[out] outError optional error output: this is set when the return value is false
* @return true on success * @return true on success
*/ */
uint32_t clear(uint32_t flags, uint32_t* outFlags = nullptr, Error* outError = nullptr) const { bool clear(uint32_t flags, uint32_t* outFlags = nullptr, Error* outError = nullptr) const {
if (xPortInIsrContext() == pdTRUE) { if (xPortInIsrContext() == pdTRUE) {
uint32_t result = xEventGroupGetBitsFromISR(handle.get()); uint32_t result = xEventGroupGetBitsFromISR(handle.get());
if (xEventGroupClearBitsFromISR(handle.get(), flags) == pdFAIL) { if (xEventGroupClearBitsFromISR(handle.get(), flags) == pdFAIL) {

View File

@ -88,11 +88,12 @@ private:
portBASE_TYPE affinity = -1; portBASE_TYPE affinity = -1;
void setState(State newState) { void setState(State newState) {
// mutex.lock(); mutex.lock();
state = newState; state = newState;
if (stateCallback) { if (stateCallback) {
stateCallback(state, stateCallbackContext); stateCallback(state, stateCallbackContext);
} }
mutex.unlock();
} }
public: public:
@ -127,7 +128,7 @@ public:
void setStackSize(size_t newStackSize) { void setStackSize(size_t newStackSize) {
mutex.lock(); mutex.lock();
assert(state == State::Stopped); assert(state == State::Stopped);
assert(stackSize % 4 == 0); assert(newStackSize % 4 == 0);
stackSize = newStackSize; stackSize = newStackSize;
mutex.unlock(); mutex.unlock();
} }

View File

@ -35,13 +35,13 @@ constexpr TickType_t getTicks() {
/** @return the amount of milliseconds that has passed in the main kernel tasks */ /** @return the amount of milliseconds that has passed in the main kernel tasks */
constexpr size_t getMillis() { constexpr size_t getMillis() {
return getTicks() / portTICK_PERIOD_MS; return getTicks() * portTICK_PERIOD_MS;
} }
/** @return the microseconds that have passed since boot */ /** @return the microseconds that have passed since boot */
constexpr int64_t getMicrosSinceBoot() { constexpr int64_t getMicrosSinceBoot() {
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
return static_cast<unsigned long>(esp_timer_get_time()); return esp_timer_get_time();
#else #else
timeval tv; timeval tv;
gettimeofday(&tv, nullptr); gettimeofday(&tv, nullptr);

View File

@ -48,6 +48,8 @@ int main(int argc, char** argv) {
assert(task_result == pdPASS); assert(task_result == pdPASS);
vTaskStartScheduler(); vTaskStartScheduler();
return data.result;
} }
extern "C" { extern "C" {

View File

@ -48,6 +48,8 @@ int main(int argc, char** argv) {
assert(task_result == pdPASS); assert(task_result == pdPASS);
vTaskStartScheduler(); vTaskStartScheduler();
return data.result;
} }
extern "C" { extern "C" {