2016-10-06 16:38:56 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
|
|
|
|
#include "message.hpp"
|
|
|
|
#include "fifo.hpp"
|
|
|
|
#include "io.hpp"
|
|
|
|
|
|
|
|
class BufferExchange {
|
|
|
|
public:
|
|
|
|
BufferExchange(CaptureConfig* const config);
|
2017-04-19 17:05:16 -04:00
|
|
|
BufferExchange(ReplayConfig* const config);
|
2016-10-06 16:38:56 -04:00
|
|
|
~BufferExchange();
|
|
|
|
|
2016-11-26 19:52:57 -05:00
|
|
|
BufferExchange(const BufferExchange&) = delete;
|
|
|
|
BufferExchange(BufferExchange&&) = delete;
|
|
|
|
BufferExchange& operator=(const BufferExchange&) = delete;
|
|
|
|
BufferExchange& operator=(BufferExchange&&) = delete;
|
|
|
|
|
2016-10-06 16:38:56 -04:00
|
|
|
#if defined(LPC43XX_M0)
|
|
|
|
bool empty() const {
|
|
|
|
return fifo_buffers_for_application->is_empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamBuffer* get() {
|
|
|
|
return get(fifo_buffers_for_application);
|
|
|
|
}
|
2017-12-06 08:20:51 -05:00
|
|
|
|
|
|
|
StreamBuffer* get_prefill() {
|
|
|
|
return get_prefill(fifo_buffers_for_application);
|
|
|
|
}
|
2016-10-06 16:38:56 -04:00
|
|
|
|
|
|
|
bool put(StreamBuffer* const p) {
|
|
|
|
return fifo_buffers_for_baseband->in(p);
|
|
|
|
}
|
2017-12-06 08:20:51 -05:00
|
|
|
|
|
|
|
bool put_app(StreamBuffer* const p) {
|
|
|
|
return fifo_buffers_for_application->in(p);
|
|
|
|
}
|
2016-10-06 16:38:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(LPC43XX_M4)
|
|
|
|
bool empty() const {
|
|
|
|
return fifo_buffers_for_baseband->is_empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamBuffer* get() {
|
|
|
|
return get(fifo_buffers_for_baseband);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool put(StreamBuffer* const p) {
|
|
|
|
return fifo_buffers_for_application->in(p);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void handle_isr() {
|
|
|
|
if( obj ) {
|
|
|
|
obj->check_fifo_isr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-04-19 17:05:16 -04:00
|
|
|
//CaptureConfig* const config_capture;
|
|
|
|
//ReplayConfig* const config_replay;
|
2016-11-26 19:50:44 -05:00
|
|
|
FIFO<StreamBuffer*>* fifo_buffers_for_baseband { nullptr };
|
|
|
|
FIFO<StreamBuffer*>* fifo_buffers_for_application { nullptr };
|
|
|
|
Thread* thread { nullptr };
|
2016-10-06 16:38:56 -04:00
|
|
|
static BufferExchange* obj;
|
2017-04-19 17:05:16 -04:00
|
|
|
|
|
|
|
enum {
|
|
|
|
CAPTURE,
|
|
|
|
REPLAY
|
|
|
|
} direction { };
|
2016-10-06 16:38:56 -04:00
|
|
|
|
|
|
|
void check_fifo_isr() {
|
2017-04-19 17:05:16 -04:00
|
|
|
if (!empty())
|
2016-10-06 16:38:56 -04:00
|
|
|
wakeup_isr();
|
|
|
|
}
|
|
|
|
|
|
|
|
void wakeup_isr() {
|
|
|
|
auto thread_tmp = thread;
|
|
|
|
if( thread_tmp ) {
|
|
|
|
thread = nullptr;
|
|
|
|
chSchReadyI(thread_tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamBuffer* get(FIFO<StreamBuffer*>* fifo);
|
2017-12-06 08:20:51 -05:00
|
|
|
|
|
|
|
StreamBuffer* get_prefill(FIFO<StreamBuffer*>* fifo);
|
2016-10-06 16:38:56 -04:00
|
|
|
};
|