|
|
@@ -1,6 +1,6 @@
|
|
|
/* ----------------------------------------------------------------------
|
|
|
* Project: CMSIS DSP Library
|
|
|
- * Title: Sched.h
|
|
|
+ * Title: GenericNodes.h
|
|
|
* Description: C++ support templates for the compute graph with static scheduler
|
|
|
*
|
|
|
* $Date: 29 July 2021
|
|
|
@@ -9,7 +9,7 @@
|
|
|
* Target Processor: Cortex-M and Cortex-A cores
|
|
|
* -------------------------------------------------------------------- */
|
|
|
/*
|
|
|
- * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
|
|
|
+ * Copyright (C) 2010-2022 ARM Limited or its affiliates. All rights reserved.
|
|
|
*
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
*
|
|
|
@@ -31,10 +31,20 @@
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
+/*
|
|
|
+Defined in cg_status.h by default but user
|
|
|
+may want to use a different header to define the
|
|
|
+error codes of the application
|
|
|
+*/
|
|
|
+#define CG_SKIP_EXECUTION_ID_CODE (-5)
|
|
|
+#define CG_BUFFER_ERROR_ID_CODE (-6)
|
|
|
+
|
|
|
// FIFOS
|
|
|
|
|
|
#ifdef DEBUGSCHED
|
|
|
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
template<typename T>
|
|
|
struct debugtype{
|
|
|
typedef T type;
|
|
|
@@ -55,23 +65,29 @@ class FIFOBase{
|
|
|
public:
|
|
|
virtual T* getWriteBuffer(int nb)=0;
|
|
|
virtual T* getReadBuffer(int nb)=0;
|
|
|
+ virtual bool willUnderflowWith(int nb)=0;
|
|
|
+ virtual bool willOverflowWith(int nb)=0;
|
|
|
+
|
|
|
};
|
|
|
|
|
|
+template<typename T, int length, int isArray=0, int isAsync = 0>
|
|
|
+class FIFO;
|
|
|
|
|
|
-template<typename T, int length, int isArray=0>
|
|
|
-class FIFO: public FIFOBase<T>
|
|
|
+/* Real FIFO, Synchronous */
|
|
|
+template<typename T, int length>
|
|
|
+class FIFO<T,length,0,0>: public FIFOBase<T>
|
|
|
{
|
|
|
public:
|
|
|
FIFO(T *buffer,int delay=0):mBuffer(buffer),readPos(0),writePos(delay) {};
|
|
|
FIFO(uint8_t *buffer,int delay=0):mBuffer((T*)buffer),readPos(0),writePos(delay) {};
|
|
|
|
|
|
+ /* Not used in synchronous mode */
|
|
|
+ bool willUnderflowWith(int nb) override {return false;};
|
|
|
+ bool willOverflowWith(int nb) override {return false;};
|
|
|
+
|
|
|
T * getWriteBuffer(int nb) override
|
|
|
{
|
|
|
- if (isArray==1)
|
|
|
- {
|
|
|
- return(mBuffer);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
T *ret;
|
|
|
if (readPos > 0)
|
|
|
{
|
|
|
@@ -87,24 +103,148 @@ class FIFO: public FIFOBase<T>
|
|
|
|
|
|
T* getReadBuffer(int nb) override
|
|
|
{
|
|
|
- if (isArray==1)
|
|
|
+
|
|
|
+ T *ret = mBuffer + readPos;
|
|
|
+ readPos += nb;
|
|
|
+ return(ret);
|
|
|
+ }
|
|
|
+
|
|
|
+ #ifdef DEBUGSCHED
|
|
|
+ void dump()
|
|
|
+ {
|
|
|
+ int nb=0;
|
|
|
+ std::cout << std::endl;
|
|
|
+ for(int i=0; i < length ; i++)
|
|
|
{
|
|
|
- return(mBuffer);
|
|
|
+ std::cout << (typename Debug<T>::type)mBuffer[i] << " ";
|
|
|
+ nb++;
|
|
|
+ if (nb == 10)
|
|
|
+ {
|
|
|
+ nb=0;
|
|
|
+ std::cout << std::endl;
|
|
|
+ }
|
|
|
}
|
|
|
+ std::cout << std::endl;
|
|
|
+ std::cout << std::endl;
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+
|
|
|
+ protected:
|
|
|
+ T *mBuffer;
|
|
|
+ int readPos,writePos;
|
|
|
+};
|
|
|
+
|
|
|
+/* Buffer, Synchronous */
|
|
|
+template<typename T, int length>
|
|
|
+class FIFO<T,length,1,0>: public FIFOBase<T>
|
|
|
+{
|
|
|
+ public:
|
|
|
+ FIFO(T *buffer,int delay=0):mBuffer(buffer),readPos(0),writePos(delay) {};
|
|
|
+ FIFO(uint8_t *buffer,int delay=0):mBuffer((T*)buffer),readPos(0),writePos(delay) {};
|
|
|
+
|
|
|
+ bool willUnderflowWith(int nb) override {return false;};
|
|
|
+ bool willOverflowWith(int nb) override {return false;};
|
|
|
+
|
|
|
+ T * getWriteBuffer(int nb) override
|
|
|
+ {
|
|
|
+ return(mBuffer);
|
|
|
+ };
|
|
|
+
|
|
|
+ T* getReadBuffer(int nb) override
|
|
|
+ {
|
|
|
+ return(mBuffer);
|
|
|
+ }
|
|
|
+
|
|
|
+ #ifdef DEBUGSCHED
|
|
|
+ void dump()
|
|
|
+ {
|
|
|
+ int nb=0;
|
|
|
+ std::cout << std::endl;
|
|
|
+ for(int i=0; i < length ; i++)
|
|
|
+ {
|
|
|
+ std::cout << (typename Debug<T>::type)mBuffer[i] << " ";
|
|
|
+ nb++;
|
|
|
+ if (nb == 10)
|
|
|
+ {
|
|
|
+ nb=0;
|
|
|
+ std::cout << std::endl;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ std::cout << std::endl;
|
|
|
+ std::cout << std::endl;
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+
|
|
|
+ protected:
|
|
|
+ T *mBuffer;
|
|
|
+ int readPos,writePos;
|
|
|
+};
|
|
|
+
|
|
|
+/* Real FIFO, Asynchronous */
|
|
|
+template<typename T, int length>
|
|
|
+class FIFO<T,length,0,1>: public FIFOBase<T>
|
|
|
+{
|
|
|
+ public:
|
|
|
+ FIFO(T *buffer,int delay=0):mBuffer(buffer),readPos(0),writePos(delay),nbSamples(delay) {};
|
|
|
+ FIFO(uint8_t *buffer,int delay=0):mBuffer((T*)buffer),readPos(0),writePos(delay),nbSamples(delay) {};
|
|
|
+
|
|
|
+ /*
|
|
|
+
|
|
|
+ Check for overflow must have been done
|
|
|
+ before using this function
|
|
|
+
|
|
|
+ */
|
|
|
+ T * getWriteBuffer(int nb) override
|
|
|
+ {
|
|
|
|
|
|
+ T *ret;
|
|
|
+ if (readPos > 0)
|
|
|
+ {
|
|
|
+ memcpy((void*)mBuffer,(void*)(mBuffer+readPos),(writePos-readPos)*sizeof(T));
|
|
|
+ writePos -= readPos;
|
|
|
+ readPos = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ ret = mBuffer + writePos;
|
|
|
+ writePos += nb;
|
|
|
+ nbSamples += nb;
|
|
|
+ return(ret);
|
|
|
+ };
|
|
|
+
|
|
|
+ /*
|
|
|
+
|
|
|
+ Check for undeflow must have been done
|
|
|
+ before using this function
|
|
|
+
|
|
|
+ */
|
|
|
+ T* getReadBuffer(int nb) override
|
|
|
+ {
|
|
|
+
|
|
|
T *ret = mBuffer + readPos;
|
|
|
readPos += nb;
|
|
|
+ nbSamples -= nb;
|
|
|
return(ret);
|
|
|
}
|
|
|
|
|
|
+ bool willUnderflowWith(int nb) override
|
|
|
+ {
|
|
|
+ return((nbSamples - nb)<0);
|
|
|
+ }
|
|
|
+
|
|
|
+ bool willOverflowWith(int nb) override
|
|
|
+ {
|
|
|
+ return((nbSamples + nb)>length);
|
|
|
+ }
|
|
|
+
|
|
|
#ifdef DEBUGSCHED
|
|
|
void dump()
|
|
|
{
|
|
|
int nb=0;
|
|
|
std::cout << std::endl;
|
|
|
+ std::cout << "FIFO nb samples = " << nbSamples << std::endl;
|
|
|
for(int i=0; i < length ; i++)
|
|
|
{
|
|
|
- std::cout << (Debug<T>::type)mBuffer[i] << " ";
|
|
|
+ std::cout << (typename Debug<T>::type)mBuffer[i] << " ";
|
|
|
nb++;
|
|
|
if (nb == 10)
|
|
|
{
|
|
|
@@ -120,6 +260,7 @@ class FIFO: public FIFOBase<T>
|
|
|
protected:
|
|
|
T *mBuffer;
|
|
|
int readPos,writePos;
|
|
|
+ int nbSamples;
|
|
|
};
|
|
|
|
|
|
// GENERIC NODES
|
|
|
@@ -128,6 +269,7 @@ class NodeBase
|
|
|
{
|
|
|
public:
|
|
|
virtual int run()=0;
|
|
|
+ virtual int prepareForRunning()=0;
|
|
|
};
|
|
|
|
|
|
template<typename IN, int inputSize,typename OUT, int outputSize>
|
|
|
@@ -140,6 +282,9 @@ protected:
|
|
|
OUT * getWriteBuffer(int nb = outputSize){return mDst.getWriteBuffer(nb);};
|
|
|
IN * getReadBuffer(int nb = inputSize){return mSrc.getReadBuffer(nb);};
|
|
|
|
|
|
+ bool willOverflow(int nb = outputSize){return mDst.willOverflowWith(nb);};
|
|
|
+ bool willUnderflow(int nb = inputSize){return mSrc.willUnderflowWith(nb);};
|
|
|
+
|
|
|
private:
|
|
|
FIFOBase<IN> &mSrc;
|
|
|
FIFOBase<OUT> &mDst;
|
|
|
@@ -157,6 +302,11 @@ protected:
|
|
|
OUT2 * getWriteBuffer2(int nb=output2Size){return mDst2.getWriteBuffer(nb);};
|
|
|
IN * getReadBuffer(int nb=inputSize){return mSrc.getReadBuffer(nb);};
|
|
|
|
|
|
+ bool willOverflow1(int nb = output1Size){return mDst1.willOverflowWith(nb);};
|
|
|
+ bool willOverflow2(int nb = output2Size){return mDst2.willOverflowWith(nb);};
|
|
|
+
|
|
|
+ bool willUnderflow(int nb = inputSize){return mSrc.willUnderflowWith(nb);};
|
|
|
+
|
|
|
private:
|
|
|
FIFOBase<IN> &mSrc;
|
|
|
FIFOBase<OUT1> &mDst1;
|
|
|
@@ -184,6 +334,12 @@ protected:
|
|
|
|
|
|
IN * getReadBuffer(int nb=inputSize){return mSrc.getReadBuffer(nb);};
|
|
|
|
|
|
+ bool willOverflow1(int nb = output1Size){return mDst1.willOverflowWith(nb);};
|
|
|
+ bool willOverflow2(int nb = output2Size){return mDst2.willOverflowWith(nb);};
|
|
|
+ bool willOverflow3(int nb = output3Size){return mDst3.willOverflowWith(nb);};
|
|
|
+
|
|
|
+ bool willUnderflow(int nb = inputSize){return mSrc.willUnderflowWith(nb);};
|
|
|
+
|
|
|
private:
|
|
|
FIFOBase<IN> &mSrc;
|
|
|
FIFOBase<OUT1> &mDst1;
|
|
|
@@ -205,6 +361,10 @@ protected:
|
|
|
IN1 * getReadBuffer1(int nb=input1Size){return mSrc1.getReadBuffer(nb);};
|
|
|
IN2 * getReadBuffer2(int nb=input2Size){return mSrc2.getReadBuffer(nb);};
|
|
|
|
|
|
+ bool willOverflow(int nb = outputSize){return mDst.willOverflowWith(nb);};
|
|
|
+ bool willUnderflow1(int nb = input1Size){return mSrc1.willUnderflowWith(nb);};
|
|
|
+ bool willUnderflow2(int nb = input2Size){return mSrc2.willUnderflowWith(nb);};
|
|
|
+
|
|
|
private:
|
|
|
FIFOBase<IN1> &mSrc1;
|
|
|
FIFOBase<IN2> &mSrc2;
|
|
|
@@ -222,6 +382,8 @@ public:
|
|
|
protected:
|
|
|
OUT * getWriteBuffer(int nb=outputSize){return mDst.getWriteBuffer(nb);};
|
|
|
|
|
|
+ bool willOverflow(int nb = outputSize){return mDst.willOverflowWith(nb);};
|
|
|
+
|
|
|
private:
|
|
|
FIFOBase<OUT> &mDst;
|
|
|
};
|
|
|
@@ -235,6 +397,8 @@ public:
|
|
|
protected:
|
|
|
IN * getReadBuffer(int nb=inputSize){return mSrc.getReadBuffer(nb);};
|
|
|
|
|
|
+ bool willUnderflow(int nb = inputSize){return mSrc.willUnderflowWith(nb);};
|
|
|
+
|
|
|
private:
|
|
|
FIFOBase<IN> &mSrc;
|
|
|
};
|
|
|
@@ -253,7 +417,19 @@ public:
|
|
|
Duplicate2(FIFOBase<IN> &src,FIFOBase<IN> &dst1,FIFOBase<IN> &dst2):
|
|
|
GenericNode12<IN,inputSize,IN,inputSize,IN,inputSize>(src,dst1,dst2){};
|
|
|
|
|
|
- int run(){
|
|
|
+ int prepareForRunning() override
|
|
|
+ {
|
|
|
+ if (this->willUnderflow() ||
|
|
|
+ this->willOverflow1() ||
|
|
|
+ this->willOverflow2())
|
|
|
+ {
|
|
|
+ return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
|
|
|
+ }
|
|
|
+
|
|
|
+ return(0);
|
|
|
+ };
|
|
|
+
|
|
|
+ int run() override {
|
|
|
IN *a=this->getReadBuffer();
|
|
|
IN *b1=this->getWriteBuffer1();
|
|
|
IN *b2=this->getWriteBuffer2();
|
|
|
@@ -293,7 +469,21 @@ public:
|
|
|
IN,inputSize,
|
|
|
IN,inputSize>(src,dst1,dst2,dst3){};
|
|
|
|
|
|
- int run(){
|
|
|
+ int prepareForRunning() override
|
|
|
+ {
|
|
|
+ if (this->willUnderflow() ||
|
|
|
+ this->willOverflow1() ||
|
|
|
+ this->willOverflow2() ||
|
|
|
+ this->willOverflow3()
|
|
|
+ )
|
|
|
+ {
|
|
|
+ return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
|
|
|
+ }
|
|
|
+
|
|
|
+ return(0);
|
|
|
+ };
|
|
|
+
|
|
|
+ int run() override {
|
|
|
IN *a=this->getReadBuffer();
|
|
|
IN *b1=this->getWriteBuffer1();
|
|
|
IN *b2=this->getWriteBuffer2();
|