TactilityKernel improvements and more (#459)
This commit is contained in:
committed by
GitHub
parent
96eccbdc8d
commit
dfe2c865d1
@@ -67,6 +67,7 @@ public:
|
||||
}
|
||||
|
||||
if (shutdown) {
|
||||
mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -86,14 +87,14 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume 1 or more dispatched function (if any) until the queue is empty.
|
||||
* Consume 1 or more dispatched functions (if any) until the queue is empty.
|
||||
* @warning The timeout is only the wait time before consuming the message! It is not a limit to the total execution time when calling this method.
|
||||
* @param[in] timeout the ticks to wait for a message
|
||||
* @return the amount of messages that were consumed
|
||||
*/
|
||||
uint32_t consume(TickType_t timeout = kernel::MAX_TICKS) {
|
||||
// Wait for signal
|
||||
if (!eventFlag.wait(WAIT_FLAG, false, true, timeout)) {
|
||||
if (!eventFlag.wait(WAIT_FLAG, false, true, nullptr, timeout)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,42 +33,27 @@ public:
|
||||
}
|
||||
|
||||
enum class Error {
|
||||
Unknown,
|
||||
Timeout,
|
||||
Resource,
|
||||
Parameter,
|
||||
IsrStatus
|
||||
Resource
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the flags.
|
||||
* @param[in] flags the flags to set
|
||||
* @param[out] outFlags optional resulting flags: this is set when the return value is true
|
||||
* @param[out] outError optional error output: this is set when the return value is false
|
||||
* @return true on success
|
||||
*/
|
||||
bool set(uint32_t flags, uint32_t* outFlags = nullptr, Error* outError = nullptr) const {
|
||||
bool set(uint32_t flags) const {
|
||||
assert(handle);
|
||||
if (xPortInIsrContext() == pdTRUE) {
|
||||
uint32_t result;
|
||||
BaseType_t yield = pdFALSE;
|
||||
if (xEventGroupSetBitsFromISR(handle.get(), flags, &yield) == pdFAIL) {
|
||||
if (outError != nullptr) {
|
||||
*outError = Error::Resource;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
if (outFlags != nullptr) {
|
||||
*outFlags = flags;
|
||||
}
|
||||
portYIELD_FROM_ISR(yield);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
auto result = xEventGroupSetBits(handle.get(), flags);
|
||||
if (outFlags != nullptr) {
|
||||
*outFlags = result;
|
||||
}
|
||||
xEventGroupSetBits(handle.get(), flags);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -76,31 +61,19 @@ public:
|
||||
/**
|
||||
* Clear flags
|
||||
* @param[in] flags the flags to clear
|
||||
* @param[out] outFlags optional resulting flags: this is set when the return value is true
|
||||
* @param[out] outError optional error output: this is set when the return value is false
|
||||
* @return true on success
|
||||
*/
|
||||
bool clear(uint32_t flags, uint32_t* outFlags = nullptr, Error* outError = nullptr) const {
|
||||
bool clear(uint32_t flags) const {
|
||||
if (xPortInIsrContext() == pdTRUE) {
|
||||
uint32_t result = xEventGroupGetBitsFromISR(handle.get());
|
||||
if (xEventGroupClearBitsFromISR(handle.get(), flags) == pdFAIL) {
|
||||
if (outError != nullptr) {
|
||||
*outError = Error::Resource;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (outFlags != nullptr) {
|
||||
*outFlags = result;
|
||||
}
|
||||
portYIELD_FROM_ISR(pdTRUE);
|
||||
return true;
|
||||
} else {
|
||||
auto result = xEventGroupClearBits(handle.get(), flags);
|
||||
if (outFlags != nullptr) {
|
||||
*outFlags = result;
|
||||
}
|
||||
return true;
|
||||
xEventGroupClearBits(handle.get(), flags);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,16 +93,14 @@ public:
|
||||
* @param[in] awaitAll If true, await for all bits to be set. Otherwise, await for any.
|
||||
* @param[in] clearOnExit If true, clears all the bits on exit, otherwise don't clear.
|
||||
* @param[in] timeout the maximum amount of ticks to wait for flags to be set
|
||||
* @param[out] outFlags optional resulting flags: this is set when the return value is true
|
||||
* @param[out] outError optional error output: this is set when the return value is false
|
||||
* @param[out] outFlags optional resulting flags: this is set when the return value is true. Only set when return value is true.
|
||||
*/
|
||||
bool wait(
|
||||
uint32_t flags,
|
||||
bool awaitAll = false,
|
||||
bool clearOnExit = true,
|
||||
TickType_t timeout = kernel::MAX_TICKS,
|
||||
uint32_t* outFlags = nullptr,
|
||||
Error* outError = nullptr
|
||||
TickType_t timeout = kernel::MAX_TICKS
|
||||
) const {
|
||||
assert(xPortInIsrContext() == pdFALSE);
|
||||
|
||||
@@ -144,14 +115,8 @@ public:
|
||||
auto invalid_flags = awaitAll
|
||||
? ((flags & result_flags) != flags) // await all
|
||||
: ((flags & result_flags) == 0U); // await any
|
||||
|
||||
if (invalid_flags) {
|
||||
if (outError != nullptr) {
|
||||
if (timeout > 0U) { // assume time-out
|
||||
*outError = Error::Timeout;
|
||||
} else {
|
||||
*outError = Error::Resource;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user