check more error codes

This commit is contained in:
Kevin Hester 2021-03-09 16:45:40 +08:00
parent 5b0d8381b9
commit 772f2a15ff
5 changed files with 54 additions and 40 deletions

2
proto

@ -1 +1 @@
Subproject commit 7c025b9a4d54bb410ec17ee653122861b413f177 Subproject commit e56f2770c33216ba94f289e2fb7f0b2dfd33aca2

View File

@ -1,9 +1,9 @@
#include "RedirectablePrint.h" #include "RedirectablePrint.h"
#include "concurrency/OSThread.h"
#include "configuration.h" #include "configuration.h"
#include <assert.h> #include <assert.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include "concurrency/OSThread.h"
/** /**
* A printer that doesn't go anywhere * A printer that doesn't go anywhere
@ -55,14 +55,17 @@ size_t RedirectablePrint::vprintf(const char *format, va_list arg)
size_t RedirectablePrint::logDebug(const char *format, ...) size_t RedirectablePrint::logDebug(const char *format, ...)
{ {
size_t r = 0;
if (!inDebugPrint) {
inDebugPrint = true;
va_list arg; va_list arg;
va_start(arg, format); va_start(arg, format);
// Cope with 0 len format strings, but look for new line terminator // Cope with 0 len format strings, but look for new line terminator
bool hasNewline = *format && format[strlen(format) - 1] == '\n'; bool hasNewline = *format && format[strlen(format) - 1] == '\n';
size_t r = 0;
// If we are the first message on a report, include the header // If we are the first message on a report, include the header
if (!isContinuationMessage) { if (!isContinuationMessage) {
struct timeval tv; struct timeval tv;
@ -96,6 +99,8 @@ size_t RedirectablePrint::logDebug(const char *format, ...)
va_end(arg); va_end(arg);
isContinuationMessage = !hasNewline; isContinuationMessage = !hasNewline;
inDebugPrint = false;
}
return r; return r;
} }

View File

@ -19,6 +19,8 @@ class RedirectablePrint : public Print
/// Used to allow multiple logDebug messages to appear on a single log line /// Used to allow multiple logDebug messages to appear on a single log line
bool isContinuationMessage = false; bool isContinuationMessage = false;
volatile bool inDebugPrint = false;
public: public:
RedirectablePrint(Print *_dest) : dest(_dest) {} RedirectablePrint(Print *_dest) : dest(_dest) {}

View File

@ -1,5 +1,6 @@
#include "concurrency/BinarySemaphoreFreeRTOS.h" #include "concurrency/BinarySemaphoreFreeRTOS.h"
#include "configuration.h" #include "configuration.h"
#include <assert.h>
#ifdef HAS_FREE_RTOS #ifdef HAS_FREE_RTOS
@ -9,6 +10,7 @@ namespace concurrency
BinarySemaphoreFreeRTOS::BinarySemaphoreFreeRTOS() BinarySemaphoreFreeRTOS::BinarySemaphoreFreeRTOS()
{ {
semaphore = xSemaphoreCreateBinary(); semaphore = xSemaphoreCreateBinary();
assert(semaphore);
} }
BinarySemaphoreFreeRTOS::~BinarySemaphoreFreeRTOS() BinarySemaphoreFreeRTOS::~BinarySemaphoreFreeRTOS()

View File

@ -101,25 +101,30 @@ template <class T> class MemoryPool : public Allocator<T>
/// Return a buffer for use by others /// Return a buffer for use by others
virtual void release(T *p) virtual void release(T *p)
{ {
assert(dead.enqueue(p, 0));
assert(p >= buf && assert(p >= buf &&
(size_t)(p - buf) < (size_t)(p - buf) <
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
assert(dead.enqueue(p, 0));
} }
#ifdef HAS_FREE_RTOS #ifdef HAS_FREE_RTOS
/// Return a buffer from an ISR, if higherPriWoken is set to true you have some work to do ;-) /// Return a buffer from an ISR, if higherPriWoken is set to true you have some work to do ;-)
void releaseFromISR(T *p, BaseType_t *higherPriWoken) void releaseFromISR(T *p, BaseType_t *higherPriWoken)
{ {
assert(dead.enqueueFromISR(p, higherPriWoken));
assert(p >= buf && assert(p >= buf &&
(size_t)(p - buf) < (size_t)(p - buf) <
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
assert(dead.enqueueFromISR(p, higherPriWoken));
} }
#endif #endif
protected: protected:
/// Return a queable object which has been prefilled with zeros - allow timeout to wait for available buffers (you /// Return a queable object which has been prefilled with zeros - allow timeout to wait for available buffers (you
/// probably don't want this version). /// probably don't want this version).
virtual T *alloc(TickType_t maxWait) { return dead.dequeuePtr(maxWait); } virtual T *alloc(TickType_t maxWait)
{
T *p = dead.dequeuePtr(maxWait);
assert(p);
return p;
}
}; };