renormalized files
This commit is contained in:
parent
42bfedd36c
commit
386f347574
File diff suppressed because it is too large
Load Diff
@ -1,117 +1,117 @@
|
||||
#ifndef _sgp4unit_
|
||||
#define _sgp4unit_
|
||||
/* ----------------------------------------------------------------
|
||||
*
|
||||
* sgp4unit.h
|
||||
*
|
||||
* this file contains the sgp4 procedures for analytical propagation
|
||||
* of a satellite. the code was originally released in the 1980 and 1986
|
||||
* spacetrack papers. a detailed discussion of the theory and history
|
||||
* may be found in the 2006 aiaa paper by vallado, crawford, hujsak,
|
||||
* and kelso.
|
||||
*
|
||||
* companion code for
|
||||
* fundamentals of astrodynamics and applications
|
||||
* 2007
|
||||
* by david vallado
|
||||
*
|
||||
* (w) 719-573-2600, email dvallado@agi.com
|
||||
*
|
||||
* current :
|
||||
* 20 apr 07 david vallado
|
||||
* misc fixes for constants
|
||||
* changes :
|
||||
* 11 aug 06 david vallado
|
||||
* chg lyddane choice back to strn3, constants, misc doc
|
||||
* 15 dec 05 david vallado
|
||||
* misc fixes
|
||||
* 26 jul 05 david vallado
|
||||
* fixes for paper
|
||||
* note that each fix is preceded by a
|
||||
* comment with "sgp4fix" and an explanation of
|
||||
* what was changed
|
||||
* 10 aug 04 david vallado
|
||||
* 2nd printing baseline working
|
||||
* 14 may 01 david vallado
|
||||
* 2nd edition baseline
|
||||
* 80 norad
|
||||
* original baseline
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// -------------------------- structure declarations ----------------------------
|
||||
typedef enum
|
||||
{
|
||||
wgs72old,
|
||||
wgs72,
|
||||
wgs84
|
||||
} gravconsttype;
|
||||
|
||||
typedef struct elsetrec
|
||||
{
|
||||
long int satnum;
|
||||
int epochyr, epochtynumrev;
|
||||
int error;
|
||||
char init, method;
|
||||
|
||||
/* Near Earth */
|
||||
int isimp;
|
||||
double aycof , con41 , cc1 , cc4 , cc5 , d2 , d3 , d4 ,
|
||||
delmo , eta , argpdot, omgcof , sinmao , t , t2cof, t3cof ,
|
||||
t4cof , t5cof , x1mth2 , x7thm1 , mdot , nodedot, xlcof , xmcof ,
|
||||
nodecf;
|
||||
|
||||
/* Deep Space */
|
||||
int irez;
|
||||
double d2201 , d2211 , d3210 , d3222 , d4410 , d4422 , d5220 , d5232 ,
|
||||
d5421 , d5433 , dedt , del1 , del2 , del3 , didt , dmdt ,
|
||||
dnodt , domdt , e3 , ee2 , peo , pgho , pho , pinco ,
|
||||
plo , se2 , se3 , sgh2 , sgh3 , sgh4 , sh2 , sh3 ,
|
||||
si2 , si3 , sl2 , sl3 , sl4 , gsto , xfact , xgh2 ,
|
||||
xgh3 , xgh4 , xh2 , xh3 , xi2 , xi3 , xl2 , xl3 ,
|
||||
xl4 , xlamo , zmol , zmos , atime , xli , xni;
|
||||
|
||||
double a , altp , alta , epochdays, jdsatepoch , nddot , ndot ,
|
||||
bstar , rcse , inclo , nodeo , ecco , argpo , mo ,
|
||||
no;
|
||||
} elsetrec;
|
||||
|
||||
// --------------------------- function declarations ----------------------------
|
||||
int sgp4init
|
||||
(
|
||||
gravconsttype whichconst, const int satn, const double epoch,
|
||||
const double xbstar, const double xecco, const double xargpo,
|
||||
const double xinclo, const double xmo, const double xno,
|
||||
const double xnodeo,
|
||||
elsetrec& satrec
|
||||
);
|
||||
|
||||
int sgp4
|
||||
(
|
||||
gravconsttype whichconst,
|
||||
elsetrec& satrec, double tsince,
|
||||
double r[], double v[]
|
||||
);
|
||||
|
||||
double gstime
|
||||
(
|
||||
double
|
||||
);
|
||||
|
||||
void getgravconst
|
||||
(
|
||||
gravconsttype,
|
||||
double&,
|
||||
double&,
|
||||
double&,
|
||||
double&,
|
||||
double&,
|
||||
double&,
|
||||
double&,
|
||||
double&
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _sgp4unit_
|
||||
#define _sgp4unit_
|
||||
/* ----------------------------------------------------------------
|
||||
*
|
||||
* sgp4unit.h
|
||||
*
|
||||
* this file contains the sgp4 procedures for analytical propagation
|
||||
* of a satellite. the code was originally released in the 1980 and 1986
|
||||
* spacetrack papers. a detailed discussion of the theory and history
|
||||
* may be found in the 2006 aiaa paper by vallado, crawford, hujsak,
|
||||
* and kelso.
|
||||
*
|
||||
* companion code for
|
||||
* fundamentals of astrodynamics and applications
|
||||
* 2007
|
||||
* by david vallado
|
||||
*
|
||||
* (w) 719-573-2600, email dvallado@agi.com
|
||||
*
|
||||
* current :
|
||||
* 20 apr 07 david vallado
|
||||
* misc fixes for constants
|
||||
* changes :
|
||||
* 11 aug 06 david vallado
|
||||
* chg lyddane choice back to strn3, constants, misc doc
|
||||
* 15 dec 05 david vallado
|
||||
* misc fixes
|
||||
* 26 jul 05 david vallado
|
||||
* fixes for paper
|
||||
* note that each fix is preceded by a
|
||||
* comment with "sgp4fix" and an explanation of
|
||||
* what was changed
|
||||
* 10 aug 04 david vallado
|
||||
* 2nd printing baseline working
|
||||
* 14 may 01 david vallado
|
||||
* 2nd edition baseline
|
||||
* 80 norad
|
||||
* original baseline
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// -------------------------- structure declarations ----------------------------
|
||||
typedef enum
|
||||
{
|
||||
wgs72old,
|
||||
wgs72,
|
||||
wgs84
|
||||
} gravconsttype;
|
||||
|
||||
typedef struct elsetrec
|
||||
{
|
||||
long int satnum;
|
||||
int epochyr, epochtynumrev;
|
||||
int error;
|
||||
char init, method;
|
||||
|
||||
/* Near Earth */
|
||||
int isimp;
|
||||
double aycof , con41 , cc1 , cc4 , cc5 , d2 , d3 , d4 ,
|
||||
delmo , eta , argpdot, omgcof , sinmao , t , t2cof, t3cof ,
|
||||
t4cof , t5cof , x1mth2 , x7thm1 , mdot , nodedot, xlcof , xmcof ,
|
||||
nodecf;
|
||||
|
||||
/* Deep Space */
|
||||
int irez;
|
||||
double d2201 , d2211 , d3210 , d3222 , d4410 , d4422 , d5220 , d5232 ,
|
||||
d5421 , d5433 , dedt , del1 , del2 , del3 , didt , dmdt ,
|
||||
dnodt , domdt , e3 , ee2 , peo , pgho , pho , pinco ,
|
||||
plo , se2 , se3 , sgh2 , sgh3 , sgh4 , sh2 , sh3 ,
|
||||
si2 , si3 , sl2 , sl3 , sl4 , gsto , xfact , xgh2 ,
|
||||
xgh3 , xgh4 , xh2 , xh3 , xi2 , xi3 , xl2 , xl3 ,
|
||||
xl4 , xlamo , zmol , zmos , atime , xli , xni;
|
||||
|
||||
double a , altp , alta , epochdays, jdsatepoch , nddot , ndot ,
|
||||
bstar , rcse , inclo , nodeo , ecco , argpo , mo ,
|
||||
no;
|
||||
} elsetrec;
|
||||
|
||||
// --------------------------- function declarations ----------------------------
|
||||
int sgp4init
|
||||
(
|
||||
gravconsttype whichconst, const int satn, const double epoch,
|
||||
const double xbstar, const double xecco, const double xargpo,
|
||||
const double xinclo, const double xmo, const double xno,
|
||||
const double xnodeo,
|
||||
elsetrec& satrec
|
||||
);
|
||||
|
||||
int sgp4
|
||||
(
|
||||
gravconsttype whichconst,
|
||||
elsetrec& satrec, double tsince,
|
||||
double r[], double v[]
|
||||
);
|
||||
|
||||
double gstime
|
||||
(
|
||||
double
|
||||
);
|
||||
|
||||
void getgravconst
|
||||
(
|
||||
gravconsttype,
|
||||
double&,
|
||||
double&,
|
||||
double&,
|
||||
double&,
|
||||
double&,
|
||||
double&,
|
||||
double&,
|
||||
double&
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,99 +1,99 @@
|
||||
#include "timevalOperations.h"
|
||||
|
||||
timeval& operator+=(timeval& lhs, const timeval& rhs) {
|
||||
int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
sum += rhs.tv_sec * 1000000. + rhs.tv_usec;
|
||||
lhs.tv_sec = sum / 1000000;
|
||||
lhs.tv_usec = sum - lhs.tv_sec * 1000000;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval operator+(timeval lhs, const timeval& rhs) {
|
||||
lhs += rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval& operator-=(timeval& lhs, const timeval& rhs) {
|
||||
int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
sum -= rhs.tv_sec * 1000000. + rhs.tv_usec;
|
||||
lhs.tv_sec = sum / 1000000;
|
||||
lhs.tv_usec = sum - lhs.tv_sec * 1000000;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval operator-(timeval lhs, const timeval& rhs) {
|
||||
lhs -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
double operator/(const timeval& lhs, const timeval& rhs) {
|
||||
double lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
double rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
|
||||
return lhs64 / rhs64;
|
||||
}
|
||||
|
||||
timeval& operator/=(timeval& lhs, double scalar) {
|
||||
int64_t product = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
product /= scalar;
|
||||
lhs.tv_sec = product / 1000000;
|
||||
lhs.tv_usec = product - lhs.tv_sec * 1000000;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval operator/(timeval lhs, double scalar) {
|
||||
lhs /= scalar;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval& operator*=(timeval& lhs, double scalar) {
|
||||
int64_t product = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
product *= scalar;
|
||||
lhs.tv_sec = product / 1000000;
|
||||
lhs.tv_usec = product - lhs.tv_sec * 1000000;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval operator*(timeval lhs, double scalar) {
|
||||
lhs *= scalar;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval operator*(double scalar, timeval rhs) {
|
||||
rhs *= scalar;
|
||||
return rhs;
|
||||
}
|
||||
|
||||
bool operator==(const timeval& lhs, const timeval& rhs) {
|
||||
int64_t lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
int64_t rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
|
||||
return lhs64 == rhs64;
|
||||
}
|
||||
bool operator!=(const timeval& lhs, const timeval& rhs) {
|
||||
return !operator==(lhs, rhs);
|
||||
}
|
||||
bool operator<(const timeval& lhs, const timeval& rhs) {
|
||||
int64_t lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
int64_t rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
|
||||
return lhs64 < rhs64;
|
||||
}
|
||||
bool operator>(const timeval& lhs, const timeval& rhs) {
|
||||
return operator<(rhs, lhs);
|
||||
}
|
||||
bool operator<=(const timeval& lhs, const timeval& rhs) {
|
||||
return !operator>(lhs, rhs);
|
||||
}
|
||||
bool operator>=(const timeval& lhs, const timeval& rhs) {
|
||||
return !operator<(lhs, rhs);
|
||||
}
|
||||
|
||||
double timevalOperations::toDouble(const timeval timeval) {
|
||||
double result = timeval.tv_sec * 1000000. + timeval.tv_usec;
|
||||
return result / 1000000.;
|
||||
}
|
||||
|
||||
timeval timevalOperations::toTimeval(const double seconds) {
|
||||
timeval tval;
|
||||
tval.tv_sec = seconds;
|
||||
tval.tv_usec = seconds *(double) 1e6 - (tval.tv_sec *1e6);
|
||||
return tval;
|
||||
}
|
||||
#include "timevalOperations.h"
|
||||
|
||||
timeval& operator+=(timeval& lhs, const timeval& rhs) {
|
||||
int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
sum += rhs.tv_sec * 1000000. + rhs.tv_usec;
|
||||
lhs.tv_sec = sum / 1000000;
|
||||
lhs.tv_usec = sum - lhs.tv_sec * 1000000;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval operator+(timeval lhs, const timeval& rhs) {
|
||||
lhs += rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval& operator-=(timeval& lhs, const timeval& rhs) {
|
||||
int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
sum -= rhs.tv_sec * 1000000. + rhs.tv_usec;
|
||||
lhs.tv_sec = sum / 1000000;
|
||||
lhs.tv_usec = sum - lhs.tv_sec * 1000000;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval operator-(timeval lhs, const timeval& rhs) {
|
||||
lhs -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
double operator/(const timeval& lhs, const timeval& rhs) {
|
||||
double lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
double rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
|
||||
return lhs64 / rhs64;
|
||||
}
|
||||
|
||||
timeval& operator/=(timeval& lhs, double scalar) {
|
||||
int64_t product = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
product /= scalar;
|
||||
lhs.tv_sec = product / 1000000;
|
||||
lhs.tv_usec = product - lhs.tv_sec * 1000000;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval operator/(timeval lhs, double scalar) {
|
||||
lhs /= scalar;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval& operator*=(timeval& lhs, double scalar) {
|
||||
int64_t product = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
product *= scalar;
|
||||
lhs.tv_sec = product / 1000000;
|
||||
lhs.tv_usec = product - lhs.tv_sec * 1000000;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval operator*(timeval lhs, double scalar) {
|
||||
lhs *= scalar;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
timeval operator*(double scalar, timeval rhs) {
|
||||
rhs *= scalar;
|
||||
return rhs;
|
||||
}
|
||||
|
||||
bool operator==(const timeval& lhs, const timeval& rhs) {
|
||||
int64_t lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
int64_t rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
|
||||
return lhs64 == rhs64;
|
||||
}
|
||||
bool operator!=(const timeval& lhs, const timeval& rhs) {
|
||||
return !operator==(lhs, rhs);
|
||||
}
|
||||
bool operator<(const timeval& lhs, const timeval& rhs) {
|
||||
int64_t lhs64 = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
int64_t rhs64 = rhs.tv_sec * 1000000. + rhs.tv_usec;
|
||||
return lhs64 < rhs64;
|
||||
}
|
||||
bool operator>(const timeval& lhs, const timeval& rhs) {
|
||||
return operator<(rhs, lhs);
|
||||
}
|
||||
bool operator<=(const timeval& lhs, const timeval& rhs) {
|
||||
return !operator>(lhs, rhs);
|
||||
}
|
||||
bool operator>=(const timeval& lhs, const timeval& rhs) {
|
||||
return !operator<(lhs, rhs);
|
||||
}
|
||||
|
||||
double timevalOperations::toDouble(const timeval timeval) {
|
||||
double result = timeval.tv_sec * 1000000. + timeval.tv_usec;
|
||||
return result / 1000000.;
|
||||
}
|
||||
|
||||
timeval timevalOperations::toTimeval(const double seconds) {
|
||||
timeval tval;
|
||||
tval.tv_sec = seconds;
|
||||
tval.tv_usec = seconds *(double) 1e6 - (tval.tv_sec *1e6);
|
||||
return tval;
|
||||
}
|
||||
|
@ -1,95 +1,95 @@
|
||||
#include "../../osal/FreeRTOS/BinSemaphUsingTask.h"
|
||||
#include "../../osal/FreeRTOS/TaskManagement.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
BinarySemaphoreUsingTask::BinarySemaphoreUsingTask() {
|
||||
handle = TaskManagement::getCurrentTaskHandle();
|
||||
if(handle == nullptr) {
|
||||
sif::error << "Could not retrieve task handle. Please ensure the"
|
||||
"constructor was called inside a task." << std::endl;
|
||||
}
|
||||
xTaskNotifyGive(handle);
|
||||
}
|
||||
|
||||
BinarySemaphoreUsingTask::~BinarySemaphoreUsingTask() {
|
||||
// Clear notification value on destruction.
|
||||
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite, nullptr);
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphoreUsingTask::acquire(TimeoutType timeoutType,
|
||||
uint32_t timeoutMs) {
|
||||
TickType_t timeout = 0;
|
||||
if(timeoutType == TimeoutType::POLLING) {
|
||||
timeout = 0;
|
||||
}
|
||||
else if(timeoutType == TimeoutType::WAITING){
|
||||
timeout = pdMS_TO_TICKS(timeoutMs);
|
||||
}
|
||||
else {
|
||||
timeout = portMAX_DELAY;
|
||||
}
|
||||
return acquireWithTickTimeout(timeoutType, timeout);
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphoreUsingTask::acquireWithTickTimeout(
|
||||
TimeoutType timeoutType, TickType_t timeoutTicks) {
|
||||
BaseType_t returncode = ulTaskNotifyTake(pdTRUE, timeoutTicks);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphoreUsingTask::release() {
|
||||
return release(this->handle);
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphoreUsingTask::release(
|
||||
TaskHandle_t taskHandle) {
|
||||
if(getSemaphoreCounter(taskHandle) == 1) {
|
||||
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||
}
|
||||
BaseType_t returncode = xTaskNotifyGive(taskHandle);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
// This should never happen.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
TaskHandle_t BinarySemaphoreUsingTask::getTaskHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounter() const {
|
||||
return getSemaphoreCounter(this->handle);
|
||||
}
|
||||
|
||||
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounter(
|
||||
TaskHandle_t taskHandle) {
|
||||
uint32_t notificationValue;
|
||||
xTaskNotifyAndQuery(taskHandle, 0, eNoAction, ¬ificationValue);
|
||||
return notificationValue;
|
||||
}
|
||||
|
||||
// Be careful with the stack size here. This is called from an ISR!
|
||||
ReturnValue_t BinarySemaphoreUsingTask::releaseFromISR(
|
||||
TaskHandle_t taskHandle, BaseType_t * higherPriorityTaskWoken) {
|
||||
if(getSemaphoreCounterFromISR(taskHandle, higherPriorityTaskWoken) == 1) {
|
||||
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||
}
|
||||
vTaskNotifyGiveFromISR(taskHandle, higherPriorityTaskWoken);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounterFromISR(
|
||||
TaskHandle_t taskHandle, BaseType_t* higherPriorityTaskWoken) {
|
||||
uint32_t notificationValue = 0;
|
||||
xTaskNotifyAndQueryFromISR(taskHandle, 0, eNoAction, ¬ificationValue,
|
||||
higherPriorityTaskWoken);
|
||||
return notificationValue;
|
||||
}
|
||||
#include "../../osal/FreeRTOS/BinSemaphUsingTask.h"
|
||||
#include "../../osal/FreeRTOS/TaskManagement.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
BinarySemaphoreUsingTask::BinarySemaphoreUsingTask() {
|
||||
handle = TaskManagement::getCurrentTaskHandle();
|
||||
if(handle == nullptr) {
|
||||
sif::error << "Could not retrieve task handle. Please ensure the"
|
||||
"constructor was called inside a task." << std::endl;
|
||||
}
|
||||
xTaskNotifyGive(handle);
|
||||
}
|
||||
|
||||
BinarySemaphoreUsingTask::~BinarySemaphoreUsingTask() {
|
||||
// Clear notification value on destruction.
|
||||
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite, nullptr);
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphoreUsingTask::acquire(TimeoutType timeoutType,
|
||||
uint32_t timeoutMs) {
|
||||
TickType_t timeout = 0;
|
||||
if(timeoutType == TimeoutType::POLLING) {
|
||||
timeout = 0;
|
||||
}
|
||||
else if(timeoutType == TimeoutType::WAITING){
|
||||
timeout = pdMS_TO_TICKS(timeoutMs);
|
||||
}
|
||||
else {
|
||||
timeout = portMAX_DELAY;
|
||||
}
|
||||
return acquireWithTickTimeout(timeoutType, timeout);
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphoreUsingTask::acquireWithTickTimeout(
|
||||
TimeoutType timeoutType, TickType_t timeoutTicks) {
|
||||
BaseType_t returncode = ulTaskNotifyTake(pdTRUE, timeoutTicks);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphoreUsingTask::release() {
|
||||
return release(this->handle);
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphoreUsingTask::release(
|
||||
TaskHandle_t taskHandle) {
|
||||
if(getSemaphoreCounter(taskHandle) == 1) {
|
||||
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||
}
|
||||
BaseType_t returncode = xTaskNotifyGive(taskHandle);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
// This should never happen.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
TaskHandle_t BinarySemaphoreUsingTask::getTaskHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounter() const {
|
||||
return getSemaphoreCounter(this->handle);
|
||||
}
|
||||
|
||||
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounter(
|
||||
TaskHandle_t taskHandle) {
|
||||
uint32_t notificationValue;
|
||||
xTaskNotifyAndQuery(taskHandle, 0, eNoAction, ¬ificationValue);
|
||||
return notificationValue;
|
||||
}
|
||||
|
||||
// Be careful with the stack size here. This is called from an ISR!
|
||||
ReturnValue_t BinarySemaphoreUsingTask::releaseFromISR(
|
||||
TaskHandle_t taskHandle, BaseType_t * higherPriorityTaskWoken) {
|
||||
if(getSemaphoreCounterFromISR(taskHandle, higherPriorityTaskWoken) == 1) {
|
||||
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||
}
|
||||
vTaskNotifyGiveFromISR(taskHandle, higherPriorityTaskWoken);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounterFromISR(
|
||||
TaskHandle_t taskHandle, BaseType_t* higherPriorityTaskWoken) {
|
||||
uint32_t notificationValue = 0;
|
||||
xTaskNotifyAndQueryFromISR(taskHandle, 0, eNoAction, ¬ificationValue,
|
||||
higherPriorityTaskWoken);
|
||||
return notificationValue;
|
||||
}
|
||||
|
@ -1,76 +1,76 @@
|
||||
#ifndef FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_
|
||||
#define FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_
|
||||
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../../tasks/SemaphoreIF.h"
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
/**
|
||||
* @brief Binary Semaphore implementation using the task notification value.
|
||||
* The notification value should therefore not be used
|
||||
* for other purposes.
|
||||
* @details
|
||||
* Additional information: https://www.freertos.org/RTOS-task-notifications.html
|
||||
* and general semaphore documentation.
|
||||
*/
|
||||
class BinarySemaphoreUsingTask: public SemaphoreIF,
|
||||
public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||
|
||||
//! @brief Default ctor
|
||||
BinarySemaphoreUsingTask();
|
||||
//! @brief Default dtor
|
||||
virtual~ BinarySemaphoreUsingTask();
|
||||
|
||||
ReturnValue_t acquire(TimeoutType timeoutType = TimeoutType::BLOCKING,
|
||||
uint32_t timeoutMs = portMAX_DELAY) override;
|
||||
ReturnValue_t release() override;
|
||||
uint8_t getSemaphoreCounter() const override;
|
||||
static uint8_t getSemaphoreCounter(TaskHandle_t taskHandle);
|
||||
static uint8_t getSemaphoreCounterFromISR(TaskHandle_t taskHandle,
|
||||
BaseType_t* higherPriorityTaskWoken);
|
||||
|
||||
/**
|
||||
* Same as acquire() with timeout in FreeRTOS ticks.
|
||||
* @param timeoutTicks
|
||||
* @return - @c RETURN_OK on success
|
||||
* - @c RETURN_FAILED on failure
|
||||
*/
|
||||
ReturnValue_t acquireWithTickTimeout(
|
||||
TimeoutType timeoutType = TimeoutType::BLOCKING,
|
||||
TickType_t timeoutTicks = portMAX_DELAY);
|
||||
|
||||
/**
|
||||
* Get handle to the task related to the semaphore.
|
||||
* @return
|
||||
*/
|
||||
TaskHandle_t getTaskHandle();
|
||||
|
||||
/**
|
||||
* Wrapper function to give back semaphore from handle
|
||||
* @param semaphore
|
||||
* @return - @c RETURN_OK on success
|
||||
* - @c RETURN_FAILED on failure
|
||||
*/
|
||||
static ReturnValue_t release(TaskHandle_t taskToNotify);
|
||||
|
||||
/**
|
||||
* Wrapper function to give back semaphore from handle when called from an ISR
|
||||
* @param semaphore
|
||||
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with
|
||||
* a higher priority was unblocked. A context switch should be requested
|
||||
* from an ISR if this is the case (see TaskManagement functions)
|
||||
* @return - @c RETURN_OK on success
|
||||
* - @c RETURN_FAILED on failure
|
||||
*/
|
||||
static ReturnValue_t releaseFromISR(TaskHandle_t taskToNotify,
|
||||
BaseType_t * higherPriorityTaskWoken);
|
||||
|
||||
protected:
|
||||
TaskHandle_t handle;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_ */
|
||||
#ifndef FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_
|
||||
#define FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_
|
||||
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../../tasks/SemaphoreIF.h"
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
/**
|
||||
* @brief Binary Semaphore implementation using the task notification value.
|
||||
* The notification value should therefore not be used
|
||||
* for other purposes.
|
||||
* @details
|
||||
* Additional information: https://www.freertos.org/RTOS-task-notifications.html
|
||||
* and general semaphore documentation.
|
||||
*/
|
||||
class BinarySemaphoreUsingTask: public SemaphoreIF,
|
||||
public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||
|
||||
//! @brief Default ctor
|
||||
BinarySemaphoreUsingTask();
|
||||
//! @brief Default dtor
|
||||
virtual~ BinarySemaphoreUsingTask();
|
||||
|
||||
ReturnValue_t acquire(TimeoutType timeoutType = TimeoutType::BLOCKING,
|
||||
uint32_t timeoutMs = portMAX_DELAY) override;
|
||||
ReturnValue_t release() override;
|
||||
uint8_t getSemaphoreCounter() const override;
|
||||
static uint8_t getSemaphoreCounter(TaskHandle_t taskHandle);
|
||||
static uint8_t getSemaphoreCounterFromISR(TaskHandle_t taskHandle,
|
||||
BaseType_t* higherPriorityTaskWoken);
|
||||
|
||||
/**
|
||||
* Same as acquire() with timeout in FreeRTOS ticks.
|
||||
* @param timeoutTicks
|
||||
* @return - @c RETURN_OK on success
|
||||
* - @c RETURN_FAILED on failure
|
||||
*/
|
||||
ReturnValue_t acquireWithTickTimeout(
|
||||
TimeoutType timeoutType = TimeoutType::BLOCKING,
|
||||
TickType_t timeoutTicks = portMAX_DELAY);
|
||||
|
||||
/**
|
||||
* Get handle to the task related to the semaphore.
|
||||
* @return
|
||||
*/
|
||||
TaskHandle_t getTaskHandle();
|
||||
|
||||
/**
|
||||
* Wrapper function to give back semaphore from handle
|
||||
* @param semaphore
|
||||
* @return - @c RETURN_OK on success
|
||||
* - @c RETURN_FAILED on failure
|
||||
*/
|
||||
static ReturnValue_t release(TaskHandle_t taskToNotify);
|
||||
|
||||
/**
|
||||
* Wrapper function to give back semaphore from handle when called from an ISR
|
||||
* @param semaphore
|
||||
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with
|
||||
* a higher priority was unblocked. A context switch should be requested
|
||||
* from an ISR if this is the case (see TaskManagement functions)
|
||||
* @return - @c RETURN_OK on success
|
||||
* - @c RETURN_FAILED on failure
|
||||
*/
|
||||
static ReturnValue_t releaseFromISR(TaskHandle_t taskToNotify,
|
||||
BaseType_t * higherPriorityTaskWoken);
|
||||
|
||||
protected:
|
||||
TaskHandle_t handle;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_ */
|
||||
|
@ -1,108 +1,108 @@
|
||||
#include "../../osal/FreeRTOS/BinarySemaphore.h"
|
||||
#include "../../osal/FreeRTOS/TaskManagement.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
BinarySemaphore::BinarySemaphore() {
|
||||
handle = xSemaphoreCreateBinary();
|
||||
if(handle == nullptr) {
|
||||
sif::error << "Semaphore: Binary semaph creation failure" << std::endl;
|
||||
}
|
||||
// Initiated semaphore must be given before it can be taken.
|
||||
xSemaphoreGive(handle);
|
||||
}
|
||||
|
||||
BinarySemaphore::~BinarySemaphore() {
|
||||
vSemaphoreDelete(handle);
|
||||
}
|
||||
|
||||
BinarySemaphore::BinarySemaphore(BinarySemaphore&& s) {
|
||||
handle = xSemaphoreCreateBinary();
|
||||
if(handle == nullptr) {
|
||||
sif::error << "Binary semaphore creation failure" << std::endl;
|
||||
}
|
||||
xSemaphoreGive(handle);
|
||||
}
|
||||
|
||||
BinarySemaphore& BinarySemaphore::operator =(
|
||||
BinarySemaphore&& s) {
|
||||
if(&s != this) {
|
||||
handle = xSemaphoreCreateBinary();
|
||||
if(handle == nullptr) {
|
||||
sif::error << "Binary semaphore creation failure" << std::endl;
|
||||
}
|
||||
xSemaphoreGive(handle);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphore::acquire(TimeoutType timeoutType,
|
||||
uint32_t timeoutMs) {
|
||||
TickType_t timeout = 0;
|
||||
if(timeoutType == TimeoutType::POLLING) {
|
||||
timeout = 0;
|
||||
}
|
||||
else if(timeoutType == TimeoutType::WAITING){
|
||||
timeout = pdMS_TO_TICKS(timeoutMs);
|
||||
}
|
||||
else {
|
||||
timeout = portMAX_DELAY;
|
||||
}
|
||||
return acquireWithTickTimeout(timeoutType, timeout);
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphore::acquireWithTickTimeout(TimeoutType timeoutType,
|
||||
TickType_t timeoutTicks) {
|
||||
if(handle == nullptr) {
|
||||
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||
}
|
||||
|
||||
BaseType_t returncode = xSemaphoreTake(handle, timeoutTicks);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphore::release() {
|
||||
return release(handle);
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphore::release(SemaphoreHandle_t semaphore) {
|
||||
if (semaphore == nullptr) {
|
||||
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||
}
|
||||
BaseType_t returncode = xSemaphoreGive(semaphore);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t BinarySemaphore::getSemaphoreCounter() const {
|
||||
return uxSemaphoreGetCount(handle);
|
||||
}
|
||||
|
||||
SemaphoreHandle_t BinarySemaphore::getSemaphore() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
// Be careful with the stack size here. This is called from an ISR!
|
||||
ReturnValue_t BinarySemaphore::releaseFromISR(
|
||||
SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) {
|
||||
if (semaphore == nullptr) {
|
||||
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||
}
|
||||
BaseType_t returncode = xSemaphoreGiveFromISR(semaphore,
|
||||
higherPriorityTaskWoken);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||
}
|
||||
}
|
||||
#include "../../osal/FreeRTOS/BinarySemaphore.h"
|
||||
#include "../../osal/FreeRTOS/TaskManagement.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
BinarySemaphore::BinarySemaphore() {
|
||||
handle = xSemaphoreCreateBinary();
|
||||
if(handle == nullptr) {
|
||||
sif::error << "Semaphore: Binary semaph creation failure" << std::endl;
|
||||
}
|
||||
// Initiated semaphore must be given before it can be taken.
|
||||
xSemaphoreGive(handle);
|
||||
}
|
||||
|
||||
BinarySemaphore::~BinarySemaphore() {
|
||||
vSemaphoreDelete(handle);
|
||||
}
|
||||
|
||||
BinarySemaphore::BinarySemaphore(BinarySemaphore&& s) {
|
||||
handle = xSemaphoreCreateBinary();
|
||||
if(handle == nullptr) {
|
||||
sif::error << "Binary semaphore creation failure" << std::endl;
|
||||
}
|
||||
xSemaphoreGive(handle);
|
||||
}
|
||||
|
||||
BinarySemaphore& BinarySemaphore::operator =(
|
||||
BinarySemaphore&& s) {
|
||||
if(&s != this) {
|
||||
handle = xSemaphoreCreateBinary();
|
||||
if(handle == nullptr) {
|
||||
sif::error << "Binary semaphore creation failure" << std::endl;
|
||||
}
|
||||
xSemaphoreGive(handle);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphore::acquire(TimeoutType timeoutType,
|
||||
uint32_t timeoutMs) {
|
||||
TickType_t timeout = 0;
|
||||
if(timeoutType == TimeoutType::POLLING) {
|
||||
timeout = 0;
|
||||
}
|
||||
else if(timeoutType == TimeoutType::WAITING){
|
||||
timeout = pdMS_TO_TICKS(timeoutMs);
|
||||
}
|
||||
else {
|
||||
timeout = portMAX_DELAY;
|
||||
}
|
||||
return acquireWithTickTimeout(timeoutType, timeout);
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphore::acquireWithTickTimeout(TimeoutType timeoutType,
|
||||
TickType_t timeoutTicks) {
|
||||
if(handle == nullptr) {
|
||||
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||
}
|
||||
|
||||
BaseType_t returncode = xSemaphoreTake(handle, timeoutTicks);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphore::release() {
|
||||
return release(handle);
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphore::release(SemaphoreHandle_t semaphore) {
|
||||
if (semaphore == nullptr) {
|
||||
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||
}
|
||||
BaseType_t returncode = xSemaphoreGive(semaphore);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t BinarySemaphore::getSemaphoreCounter() const {
|
||||
return uxSemaphoreGetCount(handle);
|
||||
}
|
||||
|
||||
SemaphoreHandle_t BinarySemaphore::getSemaphore() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
// Be careful with the stack size here. This is called from an ISR!
|
||||
ReturnValue_t BinarySemaphore::releaseFromISR(
|
||||
SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) {
|
||||
if (semaphore == nullptr) {
|
||||
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||
}
|
||||
BaseType_t returncode = xSemaphoreGiveFromISR(semaphore,
|
||||
higherPriorityTaskWoken);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||
}
|
||||
}
|
||||
|
@ -1,107 +1,107 @@
|
||||
#ifndef FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_
|
||||
#define FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_
|
||||
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../../tasks/SemaphoreIF.h"
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h>
|
||||
|
||||
/**
|
||||
* @brief OS Tool to achieve synchronization of between tasks or between
|
||||
* task and ISR. The default semaphore implementation creates a
|
||||
* binary semaphore, which can only be taken once.
|
||||
* @details
|
||||
* Documentation: https://www.freertos.org/Embedded-RTOS-Binary-Semaphores.html
|
||||
*
|
||||
* Please note that if the semaphore implementation is only related to
|
||||
* the synchronization of one task, the new task notifications can be used,
|
||||
* also see the BinSemaphUsingTask and CountingSemaphUsingTask classes.
|
||||
* These use the task notification value instead of a queue and are
|
||||
* faster and more efficient.
|
||||
*
|
||||
* @author R. Mueller
|
||||
* @ingroup osal
|
||||
*/
|
||||
class BinarySemaphore: public SemaphoreIF,
|
||||
public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||
|
||||
//! @brief Default ctor
|
||||
BinarySemaphore();
|
||||
//! @brief Copy ctor, deleted explicitely.
|
||||
BinarySemaphore(const BinarySemaphore&) = delete;
|
||||
//! @brief Copy assignment, deleted explicitely.
|
||||
BinarySemaphore& operator=(const BinarySemaphore&) = delete;
|
||||
//! @brief Move ctor
|
||||
BinarySemaphore (BinarySemaphore &&);
|
||||
//! @brief Move assignment
|
||||
BinarySemaphore & operator=(BinarySemaphore &&);
|
||||
//! @brief Destructor
|
||||
virtual ~BinarySemaphore();
|
||||
|
||||
uint8_t getSemaphoreCounter() const override;
|
||||
|
||||
/**
|
||||
* Take the binary semaphore.
|
||||
* If the semaphore has already been taken, the task will be blocked
|
||||
* for a maximum of #timeoutMs or until the semaphore is given back,
|
||||
* for example by an ISR or another task.
|
||||
* @param timeoutMs
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||
*/
|
||||
ReturnValue_t acquire(TimeoutType timeoutType =
|
||||
TimeoutType::BLOCKING, uint32_t timeoutMs = portMAX_DELAY) override;
|
||||
|
||||
/**
|
||||
* Same as lockBinarySemaphore() with timeout in FreeRTOS ticks.
|
||||
* @param timeoutTicks
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||
*/
|
||||
ReturnValue_t acquireWithTickTimeout(TimeoutType timeoutType =
|
||||
TimeoutType::BLOCKING, TickType_t timeoutTicks = portMAX_DELAY);
|
||||
|
||||
/**
|
||||
* Release the binary semaphore.
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||
* already available.
|
||||
*/
|
||||
ReturnValue_t release() override;
|
||||
|
||||
/**
|
||||
* Get Handle to the semaphore.
|
||||
* @return
|
||||
*/
|
||||
SemaphoreHandle_t getSemaphore();
|
||||
|
||||
/**
|
||||
* Wrapper function to give back semaphore from handle
|
||||
* @param semaphore
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||
* already available.
|
||||
*/
|
||||
static ReturnValue_t release(SemaphoreHandle_t semaphore);
|
||||
|
||||
/**
|
||||
* Wrapper function to give back semaphore from handle when called from an ISR
|
||||
* @param semaphore
|
||||
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with
|
||||
* a higher priority was unblocked. A context switch from an ISR should
|
||||
* then be requested (see TaskManagement functions)
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||
* already available.
|
||||
*/
|
||||
static ReturnValue_t releaseFromISR(SemaphoreHandle_t semaphore,
|
||||
BaseType_t * higherPriorityTaskWoken);
|
||||
|
||||
protected:
|
||||
SemaphoreHandle_t handle;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */
|
||||
#ifndef FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_
|
||||
#define FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_
|
||||
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../../tasks/SemaphoreIF.h"
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h>
|
||||
|
||||
/**
|
||||
* @brief OS Tool to achieve synchronization of between tasks or between
|
||||
* task and ISR. The default semaphore implementation creates a
|
||||
* binary semaphore, which can only be taken once.
|
||||
* @details
|
||||
* Documentation: https://www.freertos.org/Embedded-RTOS-Binary-Semaphores.html
|
||||
*
|
||||
* Please note that if the semaphore implementation is only related to
|
||||
* the synchronization of one task, the new task notifications can be used,
|
||||
* also see the BinSemaphUsingTask and CountingSemaphUsingTask classes.
|
||||
* These use the task notification value instead of a queue and are
|
||||
* faster and more efficient.
|
||||
*
|
||||
* @author R. Mueller
|
||||
* @ingroup osal
|
||||
*/
|
||||
class BinarySemaphore: public SemaphoreIF,
|
||||
public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||
|
||||
//! @brief Default ctor
|
||||
BinarySemaphore();
|
||||
//! @brief Copy ctor, deleted explicitely.
|
||||
BinarySemaphore(const BinarySemaphore&) = delete;
|
||||
//! @brief Copy assignment, deleted explicitely.
|
||||
BinarySemaphore& operator=(const BinarySemaphore&) = delete;
|
||||
//! @brief Move ctor
|
||||
BinarySemaphore (BinarySemaphore &&);
|
||||
//! @brief Move assignment
|
||||
BinarySemaphore & operator=(BinarySemaphore &&);
|
||||
//! @brief Destructor
|
||||
virtual ~BinarySemaphore();
|
||||
|
||||
uint8_t getSemaphoreCounter() const override;
|
||||
|
||||
/**
|
||||
* Take the binary semaphore.
|
||||
* If the semaphore has already been taken, the task will be blocked
|
||||
* for a maximum of #timeoutMs or until the semaphore is given back,
|
||||
* for example by an ISR or another task.
|
||||
* @param timeoutMs
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||
*/
|
||||
ReturnValue_t acquire(TimeoutType timeoutType =
|
||||
TimeoutType::BLOCKING, uint32_t timeoutMs = portMAX_DELAY) override;
|
||||
|
||||
/**
|
||||
* Same as lockBinarySemaphore() with timeout in FreeRTOS ticks.
|
||||
* @param timeoutTicks
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||
*/
|
||||
ReturnValue_t acquireWithTickTimeout(TimeoutType timeoutType =
|
||||
TimeoutType::BLOCKING, TickType_t timeoutTicks = portMAX_DELAY);
|
||||
|
||||
/**
|
||||
* Release the binary semaphore.
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||
* already available.
|
||||
*/
|
||||
ReturnValue_t release() override;
|
||||
|
||||
/**
|
||||
* Get Handle to the semaphore.
|
||||
* @return
|
||||
*/
|
||||
SemaphoreHandle_t getSemaphore();
|
||||
|
||||
/**
|
||||
* Wrapper function to give back semaphore from handle
|
||||
* @param semaphore
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||
* already available.
|
||||
*/
|
||||
static ReturnValue_t release(SemaphoreHandle_t semaphore);
|
||||
|
||||
/**
|
||||
* Wrapper function to give back semaphore from handle when called from an ISR
|
||||
* @param semaphore
|
||||
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with
|
||||
* a higher priority was unblocked. A context switch from an ISR should
|
||||
* then be requested (see TaskManagement functions)
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||
* already available.
|
||||
*/
|
||||
static ReturnValue_t releaseFromISR(SemaphoreHandle_t semaphore,
|
||||
BaseType_t * higherPriorityTaskWoken);
|
||||
|
||||
protected:
|
||||
SemaphoreHandle_t handle;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */
|
||||
|
@ -1,114 +1,114 @@
|
||||
#include "../../osal/FreeRTOS/CountingSemaphUsingTask.h"
|
||||
#include "../../osal/FreeRTOS/TaskManagement.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
CountingSemaphoreUsingTask::CountingSemaphoreUsingTask(const uint8_t maxCount,
|
||||
uint8_t initCount): maxCount(maxCount) {
|
||||
if(initCount > maxCount) {
|
||||
sif::error << "CountingSemaphoreUsingTask: Max count bigger than "
|
||||
"intial cout. Setting initial count to max count." << std::endl;
|
||||
initCount = maxCount;
|
||||
}
|
||||
|
||||
handle = TaskManagement::getCurrentTaskHandle();
|
||||
if(handle == nullptr) {
|
||||
sif::error << "CountingSemaphoreUsingTask: Could not retrieve task "
|
||||
"handle. Please ensure the constructor was called inside a "
|
||||
"task." << std::endl;
|
||||
}
|
||||
|
||||
uint32_t oldNotificationValue;
|
||||
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite,
|
||||
&oldNotificationValue);
|
||||
if(oldNotificationValue != 0) {
|
||||
sif::warning << "CountinSemaphoreUsingTask: Semaphore initiated but "
|
||||
"current notification value is not 0. Please ensure the "
|
||||
"notification value is not used for other purposes!" << std::endl;
|
||||
}
|
||||
for(int i = 0; i < initCount; i++) {
|
||||
xTaskNotifyGive(handle);
|
||||
}
|
||||
}
|
||||
|
||||
CountingSemaphoreUsingTask::~CountingSemaphoreUsingTask() {
|
||||
// Clear notification value on destruction.
|
||||
// If this is not desired, don't call the destructor
|
||||
// (or implement a boolean which disables the reset)
|
||||
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite, nullptr);
|
||||
}
|
||||
|
||||
ReturnValue_t CountingSemaphoreUsingTask::acquire(TimeoutType timeoutType,
|
||||
uint32_t timeoutMs) {
|
||||
TickType_t timeout = 0;
|
||||
if(timeoutType == TimeoutType::POLLING) {
|
||||
timeout = 0;
|
||||
}
|
||||
else if(timeoutType == TimeoutType::WAITING){
|
||||
timeout = pdMS_TO_TICKS(timeoutMs);
|
||||
}
|
||||
else {
|
||||
timeout = portMAX_DELAY;
|
||||
}
|
||||
return acquireWithTickTimeout(timeoutType, timeout);
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t CountingSemaphoreUsingTask::acquireWithTickTimeout(
|
||||
TimeoutType timeoutType, TickType_t timeoutTicks) {
|
||||
// Decrement notfication value without resetting it.
|
||||
BaseType_t oldCount = ulTaskNotifyTake(pdFALSE, timeoutTicks);
|
||||
if (getSemaphoreCounter() == oldCount - 1) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t CountingSemaphoreUsingTask::release() {
|
||||
if(getSemaphoreCounter() == maxCount) {
|
||||
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||
}
|
||||
return release(handle);
|
||||
}
|
||||
|
||||
ReturnValue_t CountingSemaphoreUsingTask::release(
|
||||
TaskHandle_t taskToNotify) {
|
||||
BaseType_t returncode = xTaskNotifyGive(taskToNotify);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
// This should never happen.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t CountingSemaphoreUsingTask::getSemaphoreCounter() const {
|
||||
uint32_t notificationValue = 0;
|
||||
xTaskNotifyAndQuery(handle, 0, eNoAction, ¬ificationValue);
|
||||
return notificationValue;
|
||||
}
|
||||
|
||||
TaskHandle_t CountingSemaphoreUsingTask::getTaskHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
ReturnValue_t CountingSemaphoreUsingTask::releaseFromISR(
|
||||
TaskHandle_t taskToNotify, BaseType_t* higherPriorityTaskWoken) {
|
||||
vTaskNotifyGiveFromISR(taskToNotify, higherPriorityTaskWoken);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
uint8_t CountingSemaphoreUsingTask::getSemaphoreCounterFromISR(
|
||||
TaskHandle_t task, BaseType_t* higherPriorityTaskWoken) {
|
||||
uint32_t notificationValue;
|
||||
xTaskNotifyAndQueryFromISR(task, 0, eNoAction, ¬ificationValue,
|
||||
higherPriorityTaskWoken);
|
||||
return notificationValue;
|
||||
}
|
||||
|
||||
uint8_t CountingSemaphoreUsingTask::getMaxCount() const {
|
||||
return maxCount;
|
||||
}
|
||||
#include "../../osal/FreeRTOS/CountingSemaphUsingTask.h"
|
||||
#include "../../osal/FreeRTOS/TaskManagement.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
CountingSemaphoreUsingTask::CountingSemaphoreUsingTask(const uint8_t maxCount,
|
||||
uint8_t initCount): maxCount(maxCount) {
|
||||
if(initCount > maxCount) {
|
||||
sif::error << "CountingSemaphoreUsingTask: Max count bigger than "
|
||||
"intial cout. Setting initial count to max count." << std::endl;
|
||||
initCount = maxCount;
|
||||
}
|
||||
|
||||
handle = TaskManagement::getCurrentTaskHandle();
|
||||
if(handle == nullptr) {
|
||||
sif::error << "CountingSemaphoreUsingTask: Could not retrieve task "
|
||||
"handle. Please ensure the constructor was called inside a "
|
||||
"task." << std::endl;
|
||||
}
|
||||
|
||||
uint32_t oldNotificationValue;
|
||||
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite,
|
||||
&oldNotificationValue);
|
||||
if(oldNotificationValue != 0) {
|
||||
sif::warning << "CountinSemaphoreUsingTask: Semaphore initiated but "
|
||||
"current notification value is not 0. Please ensure the "
|
||||
"notification value is not used for other purposes!" << std::endl;
|
||||
}
|
||||
for(int i = 0; i < initCount; i++) {
|
||||
xTaskNotifyGive(handle);
|
||||
}
|
||||
}
|
||||
|
||||
CountingSemaphoreUsingTask::~CountingSemaphoreUsingTask() {
|
||||
// Clear notification value on destruction.
|
||||
// If this is not desired, don't call the destructor
|
||||
// (or implement a boolean which disables the reset)
|
||||
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite, nullptr);
|
||||
}
|
||||
|
||||
ReturnValue_t CountingSemaphoreUsingTask::acquire(TimeoutType timeoutType,
|
||||
uint32_t timeoutMs) {
|
||||
TickType_t timeout = 0;
|
||||
if(timeoutType == TimeoutType::POLLING) {
|
||||
timeout = 0;
|
||||
}
|
||||
else if(timeoutType == TimeoutType::WAITING){
|
||||
timeout = pdMS_TO_TICKS(timeoutMs);
|
||||
}
|
||||
else {
|
||||
timeout = portMAX_DELAY;
|
||||
}
|
||||
return acquireWithTickTimeout(timeoutType, timeout);
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t CountingSemaphoreUsingTask::acquireWithTickTimeout(
|
||||
TimeoutType timeoutType, TickType_t timeoutTicks) {
|
||||
// Decrement notfication value without resetting it.
|
||||
BaseType_t oldCount = ulTaskNotifyTake(pdFALSE, timeoutTicks);
|
||||
if (getSemaphoreCounter() == oldCount - 1) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t CountingSemaphoreUsingTask::release() {
|
||||
if(getSemaphoreCounter() == maxCount) {
|
||||
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||
}
|
||||
return release(handle);
|
||||
}
|
||||
|
||||
ReturnValue_t CountingSemaphoreUsingTask::release(
|
||||
TaskHandle_t taskToNotify) {
|
||||
BaseType_t returncode = xTaskNotifyGive(taskToNotify);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
// This should never happen.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t CountingSemaphoreUsingTask::getSemaphoreCounter() const {
|
||||
uint32_t notificationValue = 0;
|
||||
xTaskNotifyAndQuery(handle, 0, eNoAction, ¬ificationValue);
|
||||
return notificationValue;
|
||||
}
|
||||
|
||||
TaskHandle_t CountingSemaphoreUsingTask::getTaskHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
ReturnValue_t CountingSemaphoreUsingTask::releaseFromISR(
|
||||
TaskHandle_t taskToNotify, BaseType_t* higherPriorityTaskWoken) {
|
||||
vTaskNotifyGiveFromISR(taskToNotify, higherPriorityTaskWoken);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
uint8_t CountingSemaphoreUsingTask::getSemaphoreCounterFromISR(
|
||||
TaskHandle_t task, BaseType_t* higherPriorityTaskWoken) {
|
||||
uint32_t notificationValue;
|
||||
xTaskNotifyAndQueryFromISR(task, 0, eNoAction, ¬ificationValue,
|
||||
higherPriorityTaskWoken);
|
||||
return notificationValue;
|
||||
}
|
||||
|
||||
uint8_t CountingSemaphoreUsingTask::getMaxCount() const {
|
||||
return maxCount;
|
||||
}
|
||||
|
@ -1,102 +1,102 @@
|
||||
#ifndef FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_
|
||||
#define FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_
|
||||
|
||||
#include "../../osal/FreeRTOS/CountingSemaphUsingTask.h"
|
||||
#include "../../tasks/SemaphoreIF.h"
|
||||
|
||||
extern "C" {
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Couting Semaphore implementation which uses the notification value
|
||||
* of the task. The notification value should therefore not be used
|
||||
* for other purposes.
|
||||
* @details
|
||||
* Additional information: https://www.freertos.org/RTOS-task-notifications.html
|
||||
* and general semaphore documentation.
|
||||
*/
|
||||
class CountingSemaphoreUsingTask: public SemaphoreIF {
|
||||
public:
|
||||
CountingSemaphoreUsingTask(const uint8_t maxCount, uint8_t initCount);
|
||||
virtual ~CountingSemaphoreUsingTask();
|
||||
|
||||
/**
|
||||
* Acquire the counting semaphore.
|
||||
* If no semaphores are available, the task will be blocked
|
||||
* for a maximum of #timeoutMs or until one is given back,
|
||||
* for example by an ISR or another task.
|
||||
* @param timeoutMs
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||
*/
|
||||
ReturnValue_t acquire(TimeoutType timeoutType = TimeoutType::BLOCKING,
|
||||
uint32_t timeoutMs = portMAX_DELAY) override;
|
||||
|
||||
/**
|
||||
* Release a semaphore, increasing the number of available counting
|
||||
* semaphores up to the #maxCount value.
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if #maxCount semaphores are
|
||||
* already available.
|
||||
*/
|
||||
ReturnValue_t release() override;
|
||||
|
||||
uint8_t getSemaphoreCounter() const override;
|
||||
/**
|
||||
* Get the semaphore counter from an ISR.
|
||||
* @param task
|
||||
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with
|
||||
* a higher priority was unblocked. A context switch should be requested
|
||||
* from an ISR if this is the case (see TaskManagement functions)
|
||||
* @return
|
||||
*/
|
||||
static uint8_t getSemaphoreCounterFromISR(TaskHandle_t task,
|
||||