Skip to content

Commit

Permalink
fQ returned back
Browse files Browse the repository at this point in the history
  • Loading branch information
WeSpeakEnglish committed Jul 22, 2024
1 parent 4f2c8be commit b97d722
Showing 1 changed file with 99 additions and 54 deletions.
153 changes: 99 additions & 54 deletions antirtos.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,77 +10,33 @@
#ifndef antirtos_h
#define antirtos_h

/// @brief delayed functional pointers queue without parameters, only time delay parameter
class del_fQ{
/// @brief class for finctional pointers queue without parameters
class fQ {
private:
int first;
volatile int last;
int length;
unsigned int time;
typedef void(*fP)(void);
typedef void(*fP)(void);
fP * fQueue;
fP * del_fQueue; // delayed functions
bool * execArr; //is need to be executed?
unsigned int * execTime; //execution time arr
int push(fP);
public:
del_fQ(int sizeQ);
~del_fQ();
int push_delayed(fP pointerF, unsigned int delayTime);
void tick(void);
fQ(int sizeQ);
~fQ();
int push(fP);
int pull(void);
};

del_fQ::del_fQ(int sizeQ){ // initialization of Queue
fQ::fQ(int sizeQ){ // initialization of Queue
fQueue = new fP[sizeQ];
del_fQueue = new fP[sizeQ];
execArr = new bool[sizeQ];
execTime = new unsigned int[sizeQ];
last = 0;
first = 0;
time = 0;
for(unsigned int i = 0; i < sizeQ; i++){
execArr[i] = false;
}
length = sizeQ;
};

del_fQ::~del_fQ(){ // initialization of Queue
fQ::~fQ(){ // initialization of Queue
delete [] fQueue;
delete [] del_fQueue;
delete [] execArr;
delete [] execTime;
};

int del_fQ::push_delayed(fP pointerF, unsigned int delayTime){ // push element from the queue

bool fullQ = true; // is Queue full?
for(unsigned int i = 0; i < length; i++){
if (!execArr[i] ){
del_fQueue[i] = pointerF; // put pointer into exec queue
execArr[i] = true; // true flag for execution
execTime[i] = time + delayTime; //calc execution time, no worry if overload
fullQ = false;
break;
}
}
if (fullQ) return 1;
return 0;
};

void del_fQ::tick(void){
static unsigned int i = 0 ; //uses in search cycle every tick
for(i=0; i < length; i++){
if(execTime[i] == time)
if(execArr[i]){
push(del_fQueue[i]); // bump into normal queue part of delayed Queue
execArr[i] = false;
}
}
time++;
}

int del_fQ::push(fP pointerF){ // push element from the queue
int fQ::push(fP pointerF){ // push element from the queue
if ((last+1)%length == first){
return 1;
}
Expand All @@ -89,7 +45,7 @@ int del_fQ::push(fP pointerF){ // push element from the queue
return 0;
};

int del_fQ::pull(void){ // pull element from the queue
int fQ::pull(void){ // pull element from the queue
if (last != first){
fQueue[first++]();
first = first%length;
Expand Down Expand Up @@ -157,4 +113,93 @@ int fQP<T>::pull() {
}
}

/// @brief delayed functional pointers queue without parameters, only time delay parameter
class del_fQ{
private:
int first;
volatile int last;
int length;
unsigned int time;
typedef void(*fP)(void);
fP * fQueue;
fP * del_fQueue; // delayed functions
bool * execArr; //is need to be executed?
unsigned int * execTime; //execution time arr
int push(fP);
public:
del_fQ(int sizeQ);
~del_fQ();
int push_delayed(fP pointerF, unsigned int delayTime);
void tick(void);
int pull(void);
};

del_fQ::del_fQ(int sizeQ){ // initialization of Queue
fQueue = new fP[sizeQ];
del_fQueue = new fP[sizeQ];
execArr = new bool[sizeQ];
execTime = new unsigned int[sizeQ];
last = 0;
first = 0;
time = 0;
for(unsigned int i = 0; i < sizeQ; i++){
execArr[i] = false;
}
length = sizeQ;
};

del_fQ::~del_fQ(){ // initialization of Queue
delete [] fQueue;
delete [] del_fQueue;
delete [] execArr;
delete [] execTime;
};

int del_fQ::push_delayed(fP pointerF, unsigned int delayTime){ // push element from the queue

bool fullQ = true; // is Queue full?
for(unsigned int i = 0; i < length; i++){
if (!execArr[i] ){
del_fQueue[i] = pointerF; // put pointer into exec queue
execArr[i] = true; // true flag for execution
execTime[i] = time + delayTime; //calc execution time, no worry if overload
fullQ = false;
break;
}
}
if (fullQ) return 1;
return 0;
};

void del_fQ::tick(void){
static unsigned int i = 0 ; //uses in search cycle every tick
for(i=0; i < length; i++){
if(execTime[i] == time)
if(execArr[i]){
push(del_fQueue[i]); // bump into normal queue part of delayed Queue
execArr[i] = false;
}
}
time++;
}

int del_fQ::push(fP pointerF){ // push element from the queue
if ((last+1)%length == first){
return 1;
}
fQueue[last++] = pointerF;
last = last%length;
return 0;
};

int del_fQ::pull(void){ // pull element from the queue
if (last != first){
fQueue[first++]();
first = first%length;
return 0;
}
else{
return 1;
}
};
#endif

0 comments on commit b97d722

Please sign in to comment.