43#include <condition_variable>
46#define TIME_WIDTH 10e-6
48#define BLOCK 60000*CHANNEL_NUM*10
61 std::unique_lock<std::mutex> lock(mutex_);
64 condition_.notify_one();
69 std::unique_lock<std::mutex> lock(mutex_);
70 condition_.wait(lock, [
this] {
return !queue_.empty(); });
71 auto value = (T *)queue_.front();
77 std::queue<T *> queue_;
79 std::condition_variable condition_;
119 uint32_t points = timeWidth * fs *
sizeof(T)*2;
120 double step = freq/(double )fs;
121 const uint32_t type_max = ((1 << (
sizeof(T) * 8 - 1)) - 1);
123 for(uint32_t i=0; i<points; i=i+2) {
124 buffer[i] =
static_cast<T
>(cos(2 * M_PI * i * step)*type_max);
125 buffer[i+1] =
static_cast<T
>(sin(2 * M_PI * i * step)*type_max);
142 uint32_t points = timeWidth * fs *
sizeof(T)*2;
143 double step = freq/(double )fs;
144 const uint32_t type_max = ((1 << (
sizeof(T) * 8 - 1)) - 1);
146 for(uint32_t i=0; i<points; i=i+2) {
147 buffer[i] =
static_cast<T
>(sin(2 * M_PI * i * step)*type_max);
148 buffer[i+1] =
static_cast<T
>(cos(2 * M_PI * i * step)*type_max);
165 std::unique_lock<std::mutex> *lock;
186 auto s = _kit->
open_send(0, mem, block, 0);
188 std::cout <<
"Establish CS and CR connections: " << std::endl;
189 std::cout <<
"Failed to enable data uplink " <<
nsukit::status2_string(s) <<
", currently uplinked: " << current << std::endl;
193 std::this_thread::sleep_for(std::chrono::milliseconds(10));
203 lock =
new std::unique_lock<std::mutex>(*mu);
219 uint32_t total_sampling_points, uint32_t sampling_rate, uint32_t signal_frequency) {
224 auto st = std::chrono::steady_clock::now();
225 unsigned int current;
229 uint32_t points_align = std::ceil(points/(
float)pack_len)*pack_len;
230 auto signal = (int8_t *)malloc(points_align);
231 generate_signal_iq_reverse<int8_t>(
TIME_WIDTH, signal_frequency, sampling_rate, signal);
232 uint32_t last_offset = 0;
234 std::cout <<
TIME_WIDTH <<
" " << sampling_rate <<
" " << points_align*
CHANNEL_NUM <<
" " << pack_len << std::endl;
238 auto lock = std::unique_lock<std::mutex>(*mu);
242 buffer = (int8_t *)_kit->
get_buffer(mem, block);
247 for (offset=last_offset;offset<points_align;offset+=pack_len) {
250 memcpy(buffer+mem_offset+ch*pack_len, signal+offset, pack_len);
255 last_offset = offset+pack_len;
256 if(last_offset >= points_align) last_offset = 0;
259 int _len = block-current;
261 for(offset=last_offset;offset<last_offset+_len/
CHANNEL_NUM;offset+=pack_len) {
262 uint32_t mem_offset = current+offset;
264 memcpy(buffer+mem_offset+ch*pack_len, signal+offset, pack_len);
266 last_offset = offset+pack_len;
267 if(last_offset >= points_align) last_offset = 0;
271 speed_count += block;
274 auto count = std::chrono::steady_clock::now() - st;
275 std::cout << std::flush <<
'\r' <<
"当前数据生成速度: " << speed_count*1000./(count.count()) <<
"MB/s" << std::endl;
280 std::cout << std::endl;
284int main(
int argc,
char *argv[]) {
289 nsukit::NSUSoc <nsukit::PCIECmdUItf, nsukit::PCIECmdUItf, nsukit::PCIEStreamUItf> kit{};
292 std::cout <<
"Unsupported parameter passing method" << std::endl;
294 std::cout << argv[0] <<
" {DDR total depth} {total sampling points} {sampling rate} {signal frequency}" << std::endl;
304 int total_sampling_points = std::atoi(argv[2]);
305 int sampling_rate = std::atoi(argv[3]);
306 int signal_frequency = std::atoi(argv[4]);
308 unsigned int ds_block =
BLOCK;
315 int total_len = total_sampling_points * 2;
322 auto res = kit.link_stream(¶m);
328 for (
int i=0; i<10; i++) {
341 std::thread up_trd(
download_thread, &kit, &q, ds_block, total_len, &mu, total_DDR_depth);
343 std::thread generate_trd(
data_generate, &kit, &q, ds_block, &mu, total_sampling_points, sampling_rate, signal_frequency);
354 std::cout <<
"Data download completed" << std::endl;
virtual nsuVoidBuf_p get_buffer(nsuMemory_p fd, nsuStreamLen_t length=0)
virtual nsukitStatus_t open_send(nsuChnlNum_t chnl, nsuMemory_p fd, nsuStreamLen_t length, nsuStreamLen_t offset=0)
virtual nsukitStatus_t wait_stream(nsuMemory_p fd, float timeout=0.)
std::string NSU_DLLEXPORT status2_string(nsukitStatus_t status)
bool generate_signal_iq_reverse(float timeWidth, uint32_t freq, uint32_t fs, T *buffer)
void data_generate(nsukit::BaseKit *_kit, Deque *q, nsuSize_t block, std::mutex *mu, uint32_t total_sampling_points, uint32_t sampling_rate, uint32_t signal_frequency)
void download_thread(nsukit::BaseKit *_kit, Deque *q, nsuSize_t block, nsuSize_t total, std::mutex *mu, nsuRegAddr_t total_DDR_depth)
ThreadSafeQueue< void > memQueue
bool generate_signal_iq(float timeWidth, uint32_t freq, uint32_t fs, T *buffer)
nsuBoardNum_t stream_board
@ NSUKIT_STATUS_STREAM_RUNNING
DLLEXTERN typedef size_t nsuSize_t
DLLEXTERN typedef void * nsuMemory_p
DLLEXTERN typedef uint32_t nsuRegValue_t
DLLEXTERN typedef uint32_t nsuRegAddr_t