// ================================================================================================ // FUNCTION : CalcEVM() // ------------------------------------------------------------------------------------------------ // Purpose : This is the top-level interface function accessed by wiPHY // ================================================================================================ wiStatus CalcEVM(int command, void *pdata) { if (Verbose) wiPrintf(" CalcEVM(0x%08X, @x%08X)\n",command,pdata); switch (command & 0xFFFF0000) { case WIPHY_WRITE_CONFIG: { wiMessageFn MsgFunc = (wiMessageFn)*((wiFunction *)pdata); XSTATUS(CalcEVM_WriteConfig(MsgFunc)); } break; case WIPHY_ADD_METHOD: { wiPhyMethod_t *method = (wiPhyMethod_t *)pdata; method->TxFn = CalcEVM_TX; method->RxFn = CalcEVM_RX; State.UseMojaveTX = 1; State.UseMojaveRX = 0; XSTATUS(wiParse_AddMethod(CalcEVM_ParseLine)); XSTATUS(CalcEVM_OFDM_Init()); } break; case WIPHY_REMOVE_METHOD: XSTATUS(wiParse_RemoveMethod(CalcEVM_ParseLine)); WIFREE( State.TX.s[0] ); WIFREE( State.EVM.x ); WIFREE( State.EVM.u ); XSTATUS(CalcEVM_OFDM_Close()); break; case WIPHY_SET_DATA : return WI_WARN_METHOD_UNHANDLED_PARAMETER; break; case WIPHY_GET_DATA : return WI_WARN_METHOD_UNHANDLED_PARAMETER; break; default: return STATUS(WI_WARN_METHOD_UNHANDLED_COMMAND); } return WI_SUCCESS; }
// ================================================================================================ // FUNCTION : wiProcess_ReleaseThreadIndex() // ------------------------------------------------------------------------------------------------ // ================================================================================================ wiStatus wiProcess_ReleaseThreadIndex(unsigned ThreadIndex) { if (InvalidRange(ThreadIndex, 1, WISE_MAX_THREADINDEX)) return WI_ERROR_PARAMETER1; #if defined WISE_USE_PTHREADS { void *lpvData = pthread_getspecific(wiProcessKey); WIFREE(lpvData); pthread_setspecific(wiProcessKey, NULL); return WI_SUCCESS; } #elif defined WIN32 { LPVOID lpvData; lpvData = TlsGetValue(dwTlsIndex); LocalFree((HLOCAL)lpvData); return WI_SUCCESS; } #else return STATUS(WI_ERROR_NO_MULTITHREAD_SUPPORT); #endif }
// ================================================================================================ // FUNCTION : CalcEVM_EVM_Sensitivity() // ------------------------------------------------------------------------------------------------ // Purpose : Meaure sensitivity of EVM to a paramter, (SNR in this case) // Parameters: none // ================================================================================================ wiStatus CalcEVM_EVM_Sensitivity(int paramtype, char paramstr[], double x1, double dx, double x2) { wiUInt n, Init,GoodPackets, done=0; double x, Se2, EVMdB, N, minSe2, maxSe2, minEVMdB, maxEVMdB, pktSe2; double W_EVM=0.0, W_EVMdB; char paramset[256]; wiInt N_SYM = 0; //local N_SYM variable; CalcEVM_OFDM_RxState_t *pRX = CalcEVM_OFDM_RxState(); wiTest_State_t *pState = wiTest_State(); XSTATUS( wiTest_StartTest("CalcEVM_EVM_Sensitivity()") ); switch (paramtype) { case 1: wiTestWr(" Parameter Sweep: %s = %d:%d:%d\n",paramstr,(int)x1,(int)dx,(int)x2); break; case 2: wiTestWr(" Parameter Sweep: %s = %8.4e:%8.4e:%8.4e\n",paramstr,x1,dx,x2); break; case 3: wiTestWr(" Parameter Sweep: %s = %d:%d (%d)\n",paramstr,(int)x1,(int)x2,(int)dx); break; case 4: wiTestWr(" Parameter Sweep: %s = %8.4e:%8.4e:%8.4e\n",paramstr,x1,dx,x2); break; default: return WI_ERROR_PARAMETER1; } wiTestWr("\n"); wiTestWr(" SNR EVM W_EVM min max TotalPackets GoodPackets BER PER \n"); wiTestWr(" ----- ------- ------- ------- ------- -------------- ------------ ------- -------\n"); for (x=x1; !done; ) { switch (paramtype) { case 1: sprintf(paramset,"%s = %d",paramstr, (int)x); break; case 2: sprintf(paramset,"%s = %8.12e",paramstr, x); break; case 3: sprintf(paramset,"%s = %d",paramstr, (int)x); break; case 4: sprintf(paramset,"%s = %8.12e",paramstr, x); break; } XSTATUS( wiParse_Line(paramset) ); XSTATUS( wiTest_ClearCounters() ); Se2 = 0.0; W_EVM=0.0; Init=0; //For the first nonfault packet, initialize minSe2 and maxSe2; minSe2=0.0; maxSe2=0.0; GoodPackets=0; //# of non-fault packets; for (n=0; n<pState->MaxPackets; n++) { XSTATUS( wiTest_TxRxPacket(0, pState->MinSNR, pState->DataRate, pState->Length) ); if (!pRX->Fault) { N_SYM=State.EVM.N_SYM; N = 48.0 * State.EVM.N_SYM; pktSe2 = min(N, State.EVM.Se2); // clamp EVM at 100% (0 dB) Se2 = Se2 + pktSe2; W_EVM+=pow(10.0,State.EVM.W_EVMdB/10.0); GoodPackets+=1; if (Init) { minSe2 = min(minSe2, pktSe2); maxSe2 = max(maxSe2, pktSe2); } else {minSe2 = pktSe2; maxSe2 = pktSe2; Init=1;} } } if (GoodPackets) { N = 48.0 * N_SYM; minEVMdB = minSe2? 10*log10(minSe2/N) : 0.0; maxEVMdB = minSe2? 10*log10(maxSe2/N) : 0.0; N = 48.0 * N_SYM * GoodPackets; //only count the good packets; EVMdB = (Se2 && N)? 10*log10(Se2/N) :0.0; W_EVMdB=10*log10(W_EVM/GoodPackets); } else { minEVMdB=0.0; maxEVMdB=0.0; EVMdB=0.0; W_EVMdB=0.0; } switch (paramtype) { case 1: case 3: wiPrintf(" %s =% 6d: EVM = %4.2f dB Weighted EVM=%4.2f dB BER=%.5f PER=%.5f \n", paramstr, (int)x, EVMdB,W_EVMdB,pState->BER, pState->PER); break; case 2: case 4: wiPrintf(" %s =% 8.4e: EVM = %4.2f dB Weighted EVM=%4.2f dB BER=%.5f PER=%.5f \n", paramstr, x, EVMdB, W_EVMdB,pState->BER, pState->PER); break; } switch (paramtype) { case 1: wiTestWr(" % 5d % 7.2f %7.2f % 7.2f % 7.2f %12d %12d %7.4f %7.4f\n", (int)x, EVMdB, W_EVMdB,minEVMdB, maxEVMdB, pState->MaxPackets, GoodPackets, pState->BER, pState->PER); break; case 2: wiTestWr("% 13.4e % 7.2f %7.2f % 7.2f % 7.2f %12d %12d %7.4f %7.4f \n", x, EVMdB, W_EVMdB, minEVMdB, maxEVMdB,pState->MaxPackets, GoodPackets,pState->BER, pState->PER); break; case 3: wiTestWr(" % 5d % 7.2f %7.2f % 7.2f % 7.2f %12d %12d %7.4f %7.4f\n", (int)x, EVMdB, W_EVMdB, minEVMdB, maxEVMdB,pState->MaxPackets, GoodPackets,pState->BER, pState->PER); break; case 4: wiTestWr("% 13.4e % 7.2f %7.2f % 7.2f % 7.2f %12d %12d %7.4f %7.4f \n", x, EVMdB, W_EVMdB, minEVMdB, maxEVMdB,pState->MaxPackets, GoodPackets,pState->BER, pState->PER); break; } switch (paramtype) { case 1: done = (dx<0)? (x+dx<x2):(x+dx>x2); x += dx; break; case 2: done = (dx<0)? (x+dx<x2):(x+dx>x2); x += dx; break; case 3: done = (x*dx>x2); x *= dx; break; case 4: done = (x*dx>x2); x *= dx; break; } } WIFREE( pRX->trace_r ); XSTATUS(wiTest_EndTest()); return WI_SUCCESS; }
struct datrietree_s* loaddatrie_bindict(const char* dictname) { FILE* fd = NULL; int magiclen; char version; char* buff[1024]; struct datrietree_s* datrietree = NULL; struct wordimage_s* wdimg = NULL; struct datrie_s* datrie = NULL; int as; int r; if (dictname == NULL) return NULL; fd = fopen(dictname, "rb"); if (fd == NULL) return 0; magiclen = strlen(DATRIE_MAGIC); r = fread(buff, sizeof(char), magiclen, fd); buff[magiclen] = '\0'; /* Magic */ if (strncmp(DATRIE_MAGIC, (const char*)buff, magiclen) != 0) goto failed; /* Version */ r = fread(&version, sizeof(char), 1, fd); if (version != DATRIE_VERSION_1_0) goto failed; fdmalloc(datrietree, struct datrietree_s*, sizeof(struct datrietree_s)); if (datrietree == NULL) { LDMEMOUT; LDMEMOUT_EXIT(NULL); } wdimg = (struct wordimage_s*)WIMALLOC(sizeof(struct wordimage_s)); if (wdimg == NULL) goto failed; wdimg->wordimage = NULL; /* Wsize */ r = fread(&(wdimg->size), sizeof(int), 1, fd); /* Id */ r = fread(&(wdimg->id), sizeof(int), 1, fd); /* wordimage */ wdimg->wordimage = (int*)WIMALLOC(sizeof(int) * wdimg->size); r = fread(wdimg->wordimage, sizeof(int), wdimg->size, fd); datrie = (struct datrie_s*)DATMALLOC(sizeof(struct datrie_s)); if (datrie == NULL) { DATMEMOUT; DATMEMOUT_EXIT(NULL); } datrie->wordimage = wdimg; datrie->encodesize = 0; datrie->scantype = 0; datrie->lastk = 0; datrie->array = NULL; /* As */ r = fread(&as, sizeof(int), 1, fd); datrie->size = as; /* Array */ datrie->array = (struct array_s*)DATMALLOC(sizeof(struct array_s) * as); memset(datrie->array, 0, sizeof(struct array_s) * as); r = fread(datrie->array, sizeof(struct array_s), as, fd); datrietree->wordimage = wdimg; datrietree->trie = NULL; datrietree->datrie = datrie; goto success; failed: if (datrietree != NULL) { fdfree(datrietree); datrietree = NULL; } if (wdimg != NULL) { if (wdimg->wordimage != NULL) { WIFREE(wdimg->wordimage); wdimg->wordimage = NULL; } WIFREE(wdimg); wdimg = NULL; } if (datrie != NULL) { if (datrie->array != NULL) { DATFREE(datrie->array); datrie->array = NULL; } DATFREE(datrie); datrie = NULL; } success: fclose(fd); return datrietree; }