void InitSoraRx(BlinkParams *params) { HRESULT hr; ULONG nRxBufSize = 0; // Map Rx Buffer hr = SoraURadioMapRxSampleBuf( params->radioParams.radioId, ¶ms->pRxBuf, & nRxBufSize); if ( FAILED (hr) ) { fprintf (stderr, "Error: Fail to map Sora Rx buffer!\n" ); exit(1); } // Generate a sample stream from mapped Rx buffer params->radioParams.dev = (SoraRadioParam *)inmem_malloc(sizeof(SoraRadioParam)); SoraURadioAllocRxStream(&(params->radioParams.dev->RxStream), params->radioParams.radioId, (PUCHAR)params->pRxBuf, nRxBufSize); }
void InitSoraRx(BlinkParams *params) { HRESULT hr; ULONG nRxBufSize = 0; readSoraCtx *rctx = (readSoraCtx *)inmem_malloc(sizeof(readSoraCtx)); params->TXBuffer = (PVOID)rctx; // Create queue between worker and RX // (only used if READ_IN_WORKER_THREAD defined) size_t size = 28*sizeof(complex16); rctx->readQueue = s_ts_init(1, &size); // Map Rx Buffer hr = SoraURadioMapRxSampleBuf( params->radioParams.radioId, ¶ms->pRxBuf, & nRxBufSize); if ( FAILED (hr) ) { fprintf (stderr, "Error: Fail to map Sora Rx buffer!\n" ); exit(1); } // Generate a sample stream from mapped Rx buffer params->radioParams.dev = (SoraRadioParam *)inmem_malloc(sizeof(SoraRadioParam)); SoraURadioAllocRxStream(&(params->radioParams.dev->RxStream), params->radioParams.radioId, (PUCHAR)params->pRxBuf, nRxBufSize); }
int __cdecl main(int argc, const char *argv[]) { HRESULT hr; if ( ParseCmdLine (argc, argv) == false ) { usage(); return 0; } // init DebugPlot library DebugPlotInit(); // init sora timestamp library InitializeTimestampInfo ( &tsinfo, false ); do { // begin receive or transmit packets if (!SoraUInitUserExtension("\\\\.\\HWTest")) { printf ( "Error: fail to find the hwtest driver!\n" ); break; } // start UMX // Map Rx Sample Buffer hr = SoraURadioMapRxSampleBuf(TARGET_RADIO, &RxBuffer, &RxBufferSize); if (FAILED(hr)) { printf ( "Fail to map rx buffer!\n" ); break; } // Alloc Tx Sample Buffer SampleBuffer = SoraUAllocBuffer(SampleSize); if (!SampleBuffer) { printf ( "Fail to allocate Tx buffer!\n" ); break; } hr = SoraURadioAllocRxStream(&RxStream, TARGET_RADIO, (PUCHAR)RxBuffer, RxBufferSize); if (FAILED(hr)) { printf ( "Fail to allocate a RX stream!\n" ); break; } printf ( "Configure radio...\n" ); // configure radio parameters properly ConfigureRadio (); if ( sine.Create ( SampleBuffer, SampleSize ) ) { printf ("Sine source starts...\n" ); sine.Start (); } // enter the message loop process_kb (); } while (false); sine.Stop (); SoraURadioReleaseRxStream(&RxStream, TARGET_RADIO); if (SampleBuffer) { SoraUReleaseBuffer(SampleBuffer); SampleBuffer = NULL; } if (RxBuffer) { hr = SoraURadioUnmapRxSampleBuf(TARGET_RADIO, RxBuffer); } SoraUCleanUserExtension(); DebugPlotDeinit(); return 0; }
void DoDump(HANDLE hDevice, ULONG* RadioNo, ULONG Count, char UseTimeStamp, PCSTR szDumpFileName) { ULONG mask = 0; ULONG i; HRESULT err = S_OK; PVOID buf[MAX_RADIO_NUMBER] = { 0 }; ULONG len[MAX_RADIO_NUMBER] = { 0 }; SORA_RADIO_RX_STREAM RxStream[MAX_RADIO_NUMBER] = { 0 }; do { if (!SoraUInitUserExtension("\\\\.\\HWTest")) { err = E_FAIL; break; } for(i=0; i < Count; i++) { if (mask & RadioNo[i]) { err = E_FAIL; break; } if (SoraURadioMapRxSampleBuf(RadioNo[i], &buf[i], &len[i]) != S_OK) { err = E_FAIL; break; } if (SoraURadioAllocRxStream(&RxStream[i], RadioNo[i], buf[i], len[i]) != S_OK) { err = E_FAIL; break; } } if (err == S_OK) { // raise to realtime to dump char** dump_buf = __MALLOC(sizeof(char*) * Count); memset(dump_buf, 0, sizeof(char*) * Count); for(i=0; i < Count; i++) { dump_buf[i] = __MALLOC(DUMP_BUFFER_SIZE); if (!dump_buf[i]) { err = E_FAIL; break; } } SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); if (err == S_OK) { ULONG max_timestamp; ULONG last_timestamp = 0; ULONG clear_count = 0; #if 1 if (UseTimeStamp) { for(clear_count=0; clear_count < 2; clear_count++) { for(i=0; i < Count; i++) { last_timestamp = ClearRxBuf(&RxStream[i]); printf("radio: %d, last_timestamp: 0x%08x\n", RadioNo[i], last_timestamp); if (i) { if (last_timestamp > max_timestamp) { if (last_timestamp - max_timestamp > 0x7fffffff) { // timestamp overflow !!! max_timestamp is still the max, do nothing } else max_timestamp = last_timestamp; } else if (max_timestamp > last_timestamp) { if (max_timestamp - last_timestamp > 0x7fffffff) { // timestamp overflow !!! max_timestamp = last_timestamp; } } } else max_timestamp = last_timestamp; } } printf("max_timestamp: 0x%08x\n", max_timestamp); DumpFromTimeStamp(RadioNo, RxStream, dump_buf, Count, max_timestamp + DUMP_BUFFER_DELAY_TIMESTAMP, UseTimeStamp, szDumpFileName); } else { last_timestamp = ClearRxBuf(&RxStream[0]); DumpFromTimeStamp(RadioNo, RxStream, dump_buf, Count, 0, UseTimeStamp, szDumpFileName); } } #endif #if 0 timestamp_for_dump: for(i=0; i < Count; i++) { last_timestamp = ClearRxBuf(&RxStream[i]); printf("last_timestamp: 0x%08x\n", last_timestamp); if (i) { if (last_timestamp > max_timestamp) { if (last_timestamp - max_timestamp > 0x7fffffff) { // timestamp overflow !!! printf("timestamp overflow, retry...\n"); goto timestamp_for_dump; } max_timestamp = last_timestamp; } else if (max_timestamp > last_timestamp) { if (max_timestamp - last_timestamp > 0x7fffffff) { // timestamp overflow !!! printf("timestamp overflow, retry...\n"); goto timestamp_for_dump; } } else if (last_timestamp < min_timestamp) min_timestamp = last_timestamp; } else { min_timestamp = last_timestamp; max_timestamp = last_timestamp; } } printf("max_timestamp: 0x%08x, min_timestamp: 0x%08x\n", max_timestamp, min_timestamp); if ((max_timestamp - min_timestamp) > (DUMP_BUFFER_SIZE/sizeof(RX_BLOCK))/2) { printf("prevent out of sync, retry...\n"); goto timestamp_for_dump; } DumpFromTimeStamp(RadioNo, RxStream, dump_buf, Count, max_timestamp + DUMP_BUFFER_DELAY_TIMESTAMP); } #endif SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); for(i=0; i < Count; i++) if (!dump_buf[i]) __FREE(dump_buf[i]); __FREE(dump_buf); } } while(0); for(i=0; i < Count; i++) { if (RxStream[i].__VStreamMask) SoraURadioReleaseRxStream(&RxStream[i], RadioNo[i]); if (buf[i]) SoraURadioUnmapRxSampleBuf(RadioNo[i], buf[i]); } SoraUCleanUserExtension(); }