-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add examples/redpitaya/fft * jquery.flot.canvas in downloads * add fft in build_examples.sh [ci skip]
- Loading branch information
Showing
25 changed files
with
1,719 additions
and
534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,4 +96,3 @@ web: | |
- ./web/clock-generator.ts | ||
- ./web/index.html | ||
- ./web/main.css | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/// demodulator driver | ||
/// | ||
/// (c) Koheron | ||
|
||
#ifndef __DRIVERS_DEMODULATOR_HPP__ | ||
#define __DRIVERS_DEMODULATOR_HPP__ | ||
|
||
#include <context.hpp> | ||
|
||
#include <array> | ||
|
||
// http://www.xilinx.com/support/documentation/ip_documentation/axi_fifo_mm_s/v4_1/pg080-axi-fifo-mm-s.pdf | ||
namespace Fifo_regs { | ||
constexpr uint32_t rdfr = 0x18; | ||
constexpr uint32_t rdfo = 0x1C; | ||
constexpr uint32_t rdfd = 0x20; | ||
constexpr uint32_t rlr = 0x24; | ||
} | ||
|
||
constexpr uint32_t fifo_buff_size = 8192 * 256; | ||
|
||
class Demodulator | ||
{ | ||
public: | ||
Demodulator(Context& _ctx) | ||
: ctx(_ctx) | ||
, ctl(ctx.mm.get<mem::control>()) | ||
, adc_fifo_map(_ctx.mm.get<mem::adc_fifo>()) | ||
{ | ||
start_fifo_acquisition(); | ||
} | ||
|
||
~Demodulator() { | ||
fifo_acquisition_started = false; | ||
fifo_thread.join(); | ||
} | ||
|
||
void reset_fifo() {adc_fifo_map.write<Fifo_regs::rdfr>(0x000000A5);} | ||
int32_t read_fifo() {return adc_fifo_map.read<Fifo_regs::rdfd>();} | ||
uint32_t get_fifo_length() {return (adc_fifo_map.read<Fifo_regs::rlr>() & 0x3FFFFF) >> 2;} | ||
|
||
std::vector<int32_t>& get_vector(uint32_t n_pts) { | ||
last_buffer_vect.resize(n_pts); | ||
std::lock_guard<std::mutex> lock(mutex); | ||
uint32_t start_idx = fifo_buff_idx - (fifo_buff_idx % 2); | ||
for (uint32_t i = 0; i < n_pts; i++) { | ||
last_buffer_vect[n_pts - 1 - i] = fifo_buffer[(start_idx - 1 - i) % fifo_buff_size]; | ||
} | ||
return last_buffer_vect; | ||
} | ||
|
||
void start_fifo_acquisition(); | ||
|
||
private: | ||
Context& ctx; | ||
Memory<mem::control>& ctl; | ||
Memory<mem::adc_fifo>& adc_fifo_map; | ||
|
||
std::mutex mutex; | ||
|
||
std::atomic<bool> fifo_acquisition_started{false}; | ||
std::atomic<uint32_t> fifo_buff_idx{0}; | ||
std::array<int32_t, fifo_buff_size> fifo_buffer; | ||
|
||
std::vector<int32_t> last_buffer_vect; | ||
std::thread fifo_thread; | ||
void fifo_acquisition_thread(); | ||
|
||
}; | ||
|
||
inline void Demodulator::start_fifo_acquisition() { | ||
if (! fifo_acquisition_started) { | ||
fifo_buffer.fill(0); | ||
fifo_thread = std::thread{&Demodulator::fifo_acquisition_thread, this}; | ||
fifo_thread.detach(); | ||
} | ||
} | ||
|
||
inline void Demodulator::fifo_acquisition_thread() | ||
{ | ||
using namespace std::chrono_literals; | ||
fifo_acquisition_started = true; | ||
while (fifo_acquisition_started) { | ||
{ | ||
std::lock_guard<std::mutex> lock(mutex); | ||
const uint32_t n_pts = get_fifo_length(); | ||
ctx.log<INFO>("fifo_length: %d \n", n_pts); | ||
for (size_t i = 0; i < n_pts; i++) { | ||
fifo_buffer[fifo_buff_idx] = read_fifo(); | ||
fifo_buff_idx = (fifo_buff_idx + 1) % fifo_buff_size; | ||
} | ||
} | ||
std::this_thread::sleep_for(10ms); | ||
} | ||
} | ||
|
||
|
||
#endif // __DRIVERS_DEMODULATOR_HPP__ |
Oops, something went wrong.