add isWaiting for AdaMsg

This commit is contained in:
hathach committed 2018-01-17 21:41:29 +07:00
1 parent 2d04696be1
commit a70d157656
2 files changed
+19 -1

No files matched your search

@@ -36,15 +36,21 @@
#include "AdaMsg.h"
AdaMsg::AdaMsg(void)
void AdaMsg::_init(void)
{
_dynamic = true;
_waiting = false;
_sem = NULL;
buffer = NULL;
remaining = xferlen = 0;
}
AdaMsg::AdaMsg(void)
{
_init();
}
// dynamic mean semaphore is malloced and freed only when in action
void AdaMsg::begin(bool dynamic)
{
@@ -58,6 +64,7 @@ void AdaMsg::begin(bool dynamic)
void AdaMsg::stop(void)
{
if (!_dynamic) vSemaphoreDelete(_sem);
_init();
}
void AdaMsg::prepare(void* buf, uint16_t bufsize)
@@ -82,10 +89,12 @@ int32_t AdaMsg::waitUntilComplete(uint32_t ms)
int result = -1;
_waiting = true;
if ( xSemaphoreTake(_sem, ms2tick(ms) ) )
{
result = xferlen;
}
_waiting = false;
if (_dynamic)
{
@@ -96,6 +105,11 @@ int32_t AdaMsg::waitUntilComplete(uint32_t ms)
return result;
}
bool AdaMsg::isWaiting(void)
{
return _waiting;
}
uint16_t AdaMsg::feed(void* data, uint16_t len)
{
len = min16(len, remaining);
@@ -42,8 +42,11 @@ class AdaMsg
{
private:
bool _dynamic;
volatile bool _waiting;
SemaphoreHandle_t _sem;
void _init(void);
public:
uint8_t* buffer;
uint16_t remaining;
@@ -57,6 +60,7 @@ class AdaMsg
void prepare(void* buf, uint16_t bufsize);
int32_t waitUntilComplete(uint32_t ms);
bool isWaiting(void);
uint16_t feed(void* data, uint16_t len);
void complete(void);