Remove "K" parameter from FIFO template.

This commit is contained in:
Jared Boone 2016-02-10 10:41:06 -08:00
parent dfbcf5bc75
commit d125a5c662
5 changed files with 39 additions and 15 deletions

View File

@ -35,7 +35,8 @@
class SpectrumCollector { class SpectrumCollector {
public: public:
constexpr SpectrumCollector( constexpr SpectrumCollector(
) : channel_spectrum_decimator { 1 } ) : channel_spectrum_decimator { 1 },
fifo { fifo_data, ChannelSpectrumConfigMessage::fifo_k }
{ {
} }
@ -52,6 +53,7 @@ public:
private: private:
BlockDecimator<complex16_t, 256> channel_spectrum_decimator; BlockDecimator<complex16_t, 256> channel_spectrum_decimator;
ChannelSpectrumFIFO fifo; ChannelSpectrumFIFO fifo;
ChannelSpectrum fifo_data[1 << ChannelSpectrumConfigMessage::fifo_k];
volatile bool channel_spectrum_request_update { false }; volatile bool channel_spectrum_request_update { false };
bool streaming { false }; bool streaming { false };

View File

@ -22,18 +22,24 @@
#ifndef __FIFO_H__ #ifndef __FIFO_H__
#define __FIFO_H__ #define __FIFO_H__
#include <cstddef>
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <memory>
#include <hal.h> #include <hal.h>
/* FIFO implementation inspired by Linux kfifo. */ /* FIFO implementation inspired by Linux kfifo. */
template<typename T, size_t K> template<typename T>
class FIFO { class FIFO {
public: public:
constexpr FIFO( constexpr FIFO(
) : _in { 0 }, T* data,
size_t k
) : _data { data },
_size { 1U << k },
_in { 0 },
_out { 0 } _out { 0 }
{ {
} }
@ -150,15 +156,15 @@ public:
} }
private: private:
static constexpr size_t size() { size_t size() const {
return (1UL << K); return _size;
} }
static constexpr size_t esize() { static constexpr size_t esize() {
return sizeof(T); return sizeof(T);
} }
static constexpr size_t mask() { size_t mask() const {
return size() - 1; return size() - 1;
} }
@ -224,7 +230,8 @@ private:
return buf_len; return buf_len;
} }
T _data[size()]; T* const _data;
const size_t _size;
volatile size_t _in; volatile size_t _in;
volatile size_t _out; volatile size_t _out;
}; };

View File

@ -244,10 +244,12 @@ struct ChannelSpectrum {
uint32_t channel_filter_stop_frequency { 0 }; uint32_t channel_filter_stop_frequency { 0 };
}; };
using ChannelSpectrumFIFO = FIFO<ChannelSpectrum, 2>; using ChannelSpectrumFIFO = FIFO<ChannelSpectrum>;
class ChannelSpectrumConfigMessage : public Message { class ChannelSpectrumConfigMessage : public Message {
public: public:
static constexpr size_t fifo_k = 2;
constexpr ChannelSpectrumConfigMessage( constexpr ChannelSpectrumConfigMessage(
ChannelSpectrumFIFO* fifo ChannelSpectrumFIFO* fifo
) : Message { ID::ChannelSpectrumConfig }, ) : Message { ID::ChannelSpectrumConfig },

View File

@ -32,10 +32,13 @@ using namespace lpc43xx;
#include <ch.h> #include <ch.h>
template<size_t K>
class MessageQueue { class MessageQueue {
public: public:
MessageQueue() { MessageQueue(
uint8_t* const data,
size_t k
) : fifo { data, k }
{
chMtxInit(&mutex_write); chMtxInit(&mutex_write);
} }
@ -80,7 +83,7 @@ public:
} }
private: private:
FIFO<uint8_t, K> fifo; FIFO<uint8_t> fifo;
Mutex mutex_write; Mutex mutex_write;
bool push(const void* const buf, const size_t len) { bool push(const void* const buf, const size_t len) {

View File

@ -23,6 +23,7 @@
#define __PORTAPACK_SHARED_MEMORY_H__ #define __PORTAPACK_SHARED_MEMORY_H__
#include <cstdint> #include <cstdint>
#include <cstddef>
#include "message_queue.hpp" #include "message_queue.hpp"
@ -32,8 +33,13 @@ struct TouchADCFrame {
/* NOTE: These structures must be located in the same location in both M4 and M0 binaries */ /* NOTE: These structures must be located in the same location in both M4 and M0 binaries */
struct SharedMemory { struct SharedMemory {
MessageQueue<12> baseband_queue; static constexpr size_t baseband_queue_k = 12;
MessageQueue<11> application_queue; static constexpr size_t application_queue_k = 11;
MessageQueue baseband_queue;
uint8_t baseband_queue_data[1 << baseband_queue_k];
MessageQueue application_queue;
uint8_t application_queue_data[1 << application_queue_k];
// TODO: M0 should directly configure and control DMA channel that is // TODO: M0 should directly configure and control DMA channel that is
// acquiring ADC samples. // acquiring ADC samples.
@ -44,8 +50,12 @@ extern SharedMemory& shared_memory;
#if defined(LPC43XX_M0) #if defined(LPC43XX_M0)
inline void init_message_queues() { inline void init_message_queues() {
new (&shared_memory.baseband_queue) MessageQueue<12>(); new (&shared_memory.baseband_queue) MessageQueue(
new (&shared_memory.application_queue) MessageQueue<11>(); shared_memory.baseband_queue_data, SharedMemory::baseband_queue_k
);
new (&shared_memory.application_queue) MessageQueue(
shared_memory.application_queue_data, SharedMemory::application_queue_k
);
} }
#endif #endif