Skip to content
Snippets Groups Projects
Commit 3054912e authored by Alain Carlucci's avatar Alain Carlucci
Browse files

[DMA] Enabled FIFO and added FIFO queue status monitor

parent 521ac229
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ using namespace miosix; ...@@ -30,6 +30,7 @@ using namespace miosix;
int main() int main()
{ {
printf("\n");
Leds::init(); Leds::init();
Leds::set(0); Leds::set(0);
Log::getInstance(); Log::getInstance();
...@@ -38,6 +39,9 @@ int main() ...@@ -38,6 +39,9 @@ int main()
const std::vector<SingleSensor>& data = sBoard->debugGetSensors(); const std::vector<SingleSensor>& data = sBoard->debugGetSensors();
int ctr=0; int ctr=0;
char buf[128] = {0};
const SPIDriver& spi = SPIDriver::instance();
while(1) while(1)
{ {
for(const auto& s : data) for(const auto& s : data)
...@@ -54,8 +58,13 @@ int main() ...@@ -54,8 +58,13 @@ int main()
break; break;
} }
} }
DMAFIFOStatus tx = spi.getTxFIFOStatus();
DMAFIFOStatus rx = spi.getRxFIFOStatus();
Thread::sleep(10); if(tx > -1) sLog->logLimitedInt(17, DFS_EE, DFS_100, tx);
if(rx > -1) sLog->logLimitedInt(18, DFS_EE, DFS_100, rx);
Thread::sleep(1);
} }
// NOT EXECUTED // NOT EXECUTED
......
...@@ -183,6 +183,11 @@ void SPIRequest::IRQbeginTransaction() ...@@ -183,6 +183,11 @@ void SPIRequest::IRQbeginTransaction()
DMA2_Stream0->PAR = reinterpret_cast<unsigned int>(&SPI1->DR); DMA2_Stream0->PAR = reinterpret_cast<unsigned int>(&SPI1->DR);
DMA2_Stream0->M0AR = reinterpret_cast<unsigned int>(fromPeripheral.data()); DMA2_Stream0->M0AR = reinterpret_cast<unsigned int>(fromPeripheral.data());
DMA2_Stream0->NDTR = fromPeripheral.size(); 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 DMA2_Stream0->CR = DMA_SxCR_CHSEL_1 | DMA_SxCR_CHSEL_0 // Channel 3
| DMA_SxCR_PL_1 //High priority because fifo disabled | DMA_SxCR_PL_1 //High priority because fifo disabled
| DMA_SxCR_MINC //Increment memory pointer | DMA_SxCR_MINC //Increment memory pointer
...@@ -191,11 +196,17 @@ void SPIRequest::IRQbeginTransaction() ...@@ -191,11 +196,17 @@ void SPIRequest::IRQbeginTransaction()
| DMA_SxCR_DMEIE //Interrupt on direct mode error | DMA_SxCR_DMEIE //Interrupt on direct mode error
| DMA_SxCR_EN; //Start DMA | DMA_SxCR_EN; //Start DMA
// Tx // Tx
DMA2_Stream5->CR = 0; DMA2_Stream5->CR = 0;
DMA2_Stream5->PAR = reinterpret_cast<unsigned int>(&SPI1->DR); DMA2_Stream5->PAR = reinterpret_cast<unsigned int>(&SPI1->DR);
DMA2_Stream5->M0AR = reinterpret_cast<unsigned int>(toPeripheral.data()); DMA2_Stream5->M0AR = reinterpret_cast<unsigned int>(toPeripheral.data());
DMA2_Stream5->NDTR = toPeripheral.size(); 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 DMA2_Stream5->CR = DMA_SxCR_CHSEL_1 | DMA_SxCR_CHSEL_0 // Channel 3
| DMA_SxCR_PL_1 //High priority because fifo disabled | DMA_SxCR_PL_1 //High priority because fifo disabled
| DMA_SxCR_MINC //Increment memory pointer | DMA_SxCR_MINC //Increment memory pointer
......
...@@ -27,6 +27,17 @@ ...@@ -27,6 +27,17 @@
class SPIRequest; 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 class SPIDriver
{ {
public: public:
...@@ -34,6 +45,16 @@ public: ...@@ -34,6 +45,16 @@ public:
bool transaction(std::vector<SPIRequest>& requests); 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: private:
SPIDriver(); SPIDriver();
...@@ -50,6 +71,21 @@ private: ...@@ -50,6 +71,21 @@ private:
{ {
SPI1->CR2 = 0; 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; pthread_mutex_t mutex;
}; };
......
...@@ -20,6 +20,7 @@ class Log : public Singleton<Log>, ActiveObject ...@@ -20,6 +20,7 @@ class Log : public Singleton<Log>, ActiveObject
DATA_FLOAT = 2, DATA_FLOAT = 2,
DATA_INT = 3, DATA_INT = 3,
DATA_STRING = 4, DATA_STRING = 4,
DATA_LIMITED_INT = 5,
}; };
friend class Singleton<Log>; friend class Singleton<Log>;
...@@ -49,6 +50,19 @@ public: ...@@ -49,6 +50,19 @@ public:
queue(std::move(buf)); 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) void logSensorVec3(uint8_t id, const Vec3& data)
{ {
float tmp; float tmp;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment