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

View File

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

View File

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

View File

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

View File

@ -23,6 +23,7 @@
#define __PORTAPACK_SHARED_MEMORY_H__
#include <cstdint>
#include <cstddef>
#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 */
struct SharedMemory {
MessageQueue<12> baseband_queue;
MessageQueue<11> application_queue;
static constexpr size_t baseband_queue_k = 12;
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
// acquiring ADC samples.
@ -44,8 +50,12 @@ extern SharedMemory& shared_memory;
#if defined(LPC43XX_M0)
inline void init_message_queues() {
new (&shared_memory.baseband_queue) MessageQueue<12>();
new (&shared_memory.application_queue) MessageQueue<11>();
new (&shared_memory.baseband_queue) MessageQueue(
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