diff --git a/src/entrypoints/anakin-test-dma.cpp b/src/entrypoints/anakin-test-dma.cpp
index 7f7505acc5383ba0a46c06a0cd613377c6804862..72350005f70eb4d065bfa89f2d1978a53085ce28 100644
--- a/src/entrypoints/anakin-test-dma.cpp
+++ b/src/entrypoints/anakin-test-dma.cpp
@@ -30,6 +30,7 @@ using namespace miosix;
int main()
{
+ printf("\n");
Leds::init();
Leds::set(0);
Log::getInstance();
@@ -38,6 +39,9 @@ int main()
const std::vector<SingleSensor>& data = sBoard->debugGetSensors();
int ctr=0;
+ char buf[128] = {0};
+
+ const SPIDriver& spi = SPIDriver::instance();
while(1)
{
for(const auto& s : data)
@@ -54,8 +58,13 @@ int main()
break;
}
}
+ DMAFIFOStatus tx = spi.getTxFIFOStatus();
+ DMAFIFOStatus rx = spi.getRxFIFOStatus();
+
+ if(tx > -1) sLog->logLimitedInt(17, DFS_EE, DFS_100, tx);
+ if(rx > -1) sLog->logLimitedInt(18, DFS_EE, DFS_100, rx);
- Thread::sleep(10);
+ Thread::sleep(1);
}
// NOT EXECUTED
diff --git a/src/shared/DMA/DMA.cpp b/src/shared/DMA/DMA.cpp
index 2f14f41d1bc0b4aa0d19225620e28b38abb051cf..3545107cce6ebc7e78f1b913cdad120d89eaa833 100644
--- a/src/shared/DMA/DMA.cpp
+++ b/src/shared/DMA/DMA.cpp
@@ -183,6 +183,11 @@ void SPIRequest::IRQbeginTransaction()
DMA2_Stream0->PAR = reinterpret_cast<unsigned int>(&SPI1->DR);
DMA2_Stream0->M0AR = reinterpret_cast<unsigned int>(fromPeripheral.data());
DMA2_Stream0->NDTR = fromPeripheral.size();
+
+ DMA2_Stream0->FCR = DMA_SxFCR_FEIE //Enable interrupt on FIFO error
+ | DMA_SxFCR_FTH_0 //FTH = 11 -> Full FIFO
+ | DMA_SxFCR_FTH_1;
+
DMA2_Stream0->CR = DMA_SxCR_CHSEL_1 | DMA_SxCR_CHSEL_0 // Channel 3
| DMA_SxCR_PL_1 //High priority because fifo disabled
| DMA_SxCR_MINC //Increment memory pointer
@@ -190,12 +195,18 @@ void SPIRequest::IRQbeginTransaction()
| DMA_SxCR_TEIE //Interrupt on transfer error
| DMA_SxCR_DMEIE //Interrupt on direct mode error
| DMA_SxCR_EN; //Start DMA
+
// Tx
DMA2_Stream5->CR = 0;
DMA2_Stream5->PAR = reinterpret_cast<unsigned int>(&SPI1->DR);
DMA2_Stream5->M0AR = reinterpret_cast<unsigned int>(toPeripheral.data());
DMA2_Stream5->NDTR = toPeripheral.size();
+
+ DMA2_Stream5->FCR = DMA_SxFCR_FEIE //Enable interrupt on FIFO error
+ | DMA_SxFCR_FTH_0 //FTH = 11 -> Full FIFO
+ | DMA_SxFCR_FTH_1;
+
DMA2_Stream5->CR = DMA_SxCR_CHSEL_1 | DMA_SxCR_CHSEL_0 // Channel 3
| DMA_SxCR_PL_1 //High priority because fifo disabled
| DMA_SxCR_MINC //Increment memory pointer
diff --git a/src/shared/DMA/DMA.h b/src/shared/DMA/DMA.h
index 58e9a89bc593490a9221e6f4ca09fe7e2be9dfde..f5f929e407303add384847fb2fe9cac67defd093 100644
--- a/src/shared/DMA/DMA.h
+++ b/src/shared/DMA/DMA.h
@@ -27,13 +27,34 @@
class SPIRequest;
+enum DMAFIFOStatus
+{
+ DFS_UNK = -1,// Unk
+ DFS_EE = 0, // x == 0
+ DFS_10 = 1, // 0 < x < 25
+ DFS_25 = 2, // 25 <= x < 50
+ DFS_50 = 3, // 50 <= x < 75
+ DFS_75 = 4, // 75 <= x < 100
+ DFS_100 = 5, // x == 100
+};
+
class SPIDriver
{
public:
static SPIDriver& instance();
bool transaction(std::vector<SPIRequest>& requests);
-
+
+ DMAFIFOStatus getTxFIFOStatus() const
+ {
+ return intToFIFOStatus((DMA2_Stream5->FCR & DMA_SxFCR_FS) >> 3);
+ }
+
+ DMAFIFOStatus getRxFIFOStatus() const
+ {
+ return intToFIFOStatus((DMA2_Stream0->FCR & DMA_SxFCR_FS) >> 3);
+ }
+
private:
SPIDriver();
@@ -50,6 +71,21 @@ private:
{
SPI1->CR2 = 0;
}
+
+ inline DMAFIFOStatus intToFIFOStatus(uint8_t s) const
+ {
+ switch(s)
+ {
+ case 0: return DFS_10;
+ case 1: return DFS_25;
+ case 2: return DFS_50;
+ case 3: return DFS_75;
+ case 4: return DFS_EE;
+ case 5: return DFS_100;
+ }
+ return DFS_UNK;
+ }
+
pthread_mutex_t mutex;
};
diff --git a/src/shared/log/Log.h b/src/shared/log/Log.h
index 3be1e16ffdc9add2275d41651034f5e51f7f2f1d..e16f217a52c27c3a47a53e237746ba86de8f1b3b 100644
--- a/src/shared/log/Log.h
+++ b/src/shared/log/Log.h
@@ -20,6 +20,7 @@ class Log : public Singleton<Log>, ActiveObject
DATA_FLOAT = 2,
DATA_INT = 3,
DATA_STRING = 4,
+ DATA_LIMITED_INT = 5,
};
friend class Singleton<Log>;
@@ -49,6 +50,19 @@ public:
queue(std::move(buf));
}
+ void logLimitedInt(uint8_t id, int min, int max, int data)
+ {
+ assert(max > min);
+ uint32_t v = (data - min) * 256 / (max - min);
+
+ std::vector<uint8_t> buf(2 + 1);
+ buf[0] = DATA_LIMITED_INT;
+ buf[1] = id;
+ buf[2] = v & 0xff;
+
+ queue(std::move(buf));
+ }
+
void logSensorVec3(uint8_t id, const Vec3& data)
{
float tmp;