void * __REALLOC( void *addr, size_t size, int type, int flags, vm_allocation_site_t *site) { struct _mhead *hdr; void *newaddr; size_t alloc; /* realloc(NULL, ...) is equivalent to malloc(...) */ if (addr == NULL) return (__MALLOC(size, type, flags, site)); /* Allocate a new, bigger (or smaller) block */ if ((newaddr = __MALLOC(size, type, flags, site)) == NULL) return (NULL); hdr = addr; --hdr; alloc = hdr->mlen - sizeof (*hdr); /* Copy over original contents */ bcopy(addr, newaddr, MIN(size, alloc)); _FREE(addr, type); return (newaddr); }
void DutWriteRegister(HANDLE hDevice, ULONG Offset, ULONG Value) { OFFSET_VALUE Input; PDEV_RET pOut = (PDEV_RET)__MALLOC(sizeof(DEV_RET)); BOOL ret; ULONG nWritten; Input.Offset = Offset; Input.Value = Value; ret = DeviceIoControl ( hDevice, DUT_IO_CODE(CMD_WR_REG), &Input, sizeof(Input), pOut, sizeof(DEV_RET), &nWritten, NULL); if (nWritten != sizeof(DEV_RET)) { printf("Write register failed, %d, %d\n", nWritten, ret); } else { printf("Ret:0x%08x\n", pOut->hResult); } __FREE(pOut); }
void DutStartRadio(HANDLE hDevice, ULONG RadioNo) { PDEV_RET pOut = (PDEV_RET)__MALLOC(sizeof(DEV_RET)); ULONG nWritten = 0; START_RADIO start_radio; start_radio.RadioNo = RadioNo; DeviceIoControl ( hDevice, DUT_IO_CODE(CMD_START_RADIO), &start_radio, sizeof(START_RADIO), pOut, sizeof(DEV_RET), &nWritten, NULL); if (nWritten != sizeof(DEV_RET)) { printf("Start Radio fails\n"); } else { printf("Ret: 0x%08x\n", pOut->hResult); } __FREE(pOut); }
void DutGetRxBuffer(HANDLE hDevice) { PDEV_RET pOut = (PDEV_RET)__MALLOC(sizeof(DEV_RET) + sizeof(HWT_DMA_RET)); ULONG nWritten = 0; DeviceIoControl ( hDevice, DUT_IO_CODE(CMD_DMA), NULL, 0, pOut, sizeof(DEV_RET) + sizeof(HWT_DMA_RET), &nWritten, NULL); if (nWritten != sizeof(DEV_RET) + sizeof(HWT_DMA_RET)) { printf("Input error!\n"); } else { PULONG p = (PULONG)(((PHWT_DMA_RET)(pOut->data))->UserVA); printf("Ret: 0x%08x\n", pOut->hResult); printf("RX Buffer: 0x%08x\n", p); printf("RX Size: 0x%08x\n", ((PHWT_DMA_RET)(pOut->data))->Size); printf("content: %08X, %08X, %08X, %08X", p[0], p[1], p[2], p[3]); p[0] = 0; } }
void * _MALLOC_external( size_t size, int type, int flags) { static vm_allocation_site_t site = { VM_KERN_MEMORY_KALLOC, VM_TAG_BT }; return (__MALLOC(size, type, flags, &site)); }
void DutTransferSignals(HANDLE hDevice, PCSTR szSigFileName) { ULONG nWritten; DEV_RET Out; size_t len; PWSTR wszFileName = (PWSTR)__MALLOC(SYM_FILE_MAX_PATH_LENGTH * sizeof(WCHAR)); PSTR szFileName = (PSTR) __MALLOC(SYM_FILE_MAX_PATH_LENGTH * sizeof(CHAR)); szFileName[0] = '\0'; assert(strlen(szSigFileName) + strlen(FILE_OBJ_NAME_PREFIX) < SYM_FILE_MAX_PATH_LENGTH); strcat_s(szFileName, SYM_FILE_MAX_PATH_LENGTH, FILE_OBJ_NAME_PREFIX); strcat_s(szFileName, SYM_FILE_MAX_PATH_LENGTH, szSigFileName); len = Str2WStr(szFileName, wszFileName , SYM_FILE_MAX_PATH_LENGTH); if (len == 0) { printf("Please specify a signal file (name length no more than 100)\n"); return; } DeviceIoControl ( hDevice, DUT_IO_CODE(CMD_TRANSFER), wszFileName, SYM_FILE_MAX_PATH_LENGTH * sizeof(WCHAR), &Out, sizeof(DEV_RET), &nWritten, NULL); if (nWritten != sizeof(DEV_RET)) printf("Input error!\n"); else printf("Ret:0x%08x\n", Out.hResult); __FREE(wszFileName); __FREE(szFileName); }
void DutGetFwVersion(HANDLE hDevice) { ULONG nWritten; PDEV_RET pOut = (PDEV_RET)__MALLOC(sizeof(DEV_RET) + sizeof(HWT_FW_VERSION)); DeviceIoControl ( hDevice, DUT_IO_CODE(CMD_FW_VERSION), NULL, 0, pOut, sizeof(DEV_RET) + sizeof(HWT_FW_VERSION), &nWritten, NULL); printf("firmware version: 0x%08x\n", ((HWT_FW_VERSION*)pOut->data)->m_fw_version); __FREE(pOut); }
void DutGetInfo(HANDLE hDevice) { ULONG nWritten; PDEV_RET pOut = (PDEV_RET)__MALLOC(sizeof(DEV_RET) + sizeof(HWT_DETAIL_INFO)); DeviceIoControl ( hDevice, DUT_IO_CODE(CMD_INFO), NULL, 0, pOut, sizeof(DEV_RET) + sizeof(HWT_DETAIL_INFO), &nWritten, NULL); if (nWritten != sizeof(DEV_RET) + sizeof(HWT_DETAIL_INFO)) printf("Information unvailable %d\n", nWritten); else PrintHwtInfo((PHWT_DETAIL_INFO)pOut->data); __FREE(pOut); }
void DutReadRegister(HANDLE hDevice, ULONG Offset) { ULONG OutLen = sizeof(DEV_RET) + sizeof(ULONG); PDEV_RET pOut = (PDEV_RET)__MALLOC(OutLen); ULONG nWritten = 0; BOOL ret = DeviceIoControl ( hDevice, DUT_IO_CODE(CMD_RD_REG), &Offset, sizeof(Offset), pOut, OutLen, &nWritten, NULL); if (nWritten != OutLen) { printf("Read register failed\n"); } else { printf("Ret: 0x%08x\n", pOut->hResult); printf("Content: 0x%08x\n", *(PULONG)(pOut->data)); } __FREE(pOut); }
void DutDump(HANDLE hDevice, ULONG* RadioNo, ULONG Count, PCSTR szDumpFileName) { ULONG nWritten; PDEV_RET pOutInfo = (PDEV_RET)__MALLOC(sizeof(DEV_RET) + sizeof(HWT_DETAIL_INFO)); DeviceIoControl ( hDevice, DUT_IO_CODE(CMD_INFO), NULL, 0, pOutInfo, sizeof(DEV_RET) + sizeof(HWT_DETAIL_INFO), &nWritten, NULL); if (nWritten != sizeof(DEV_RET) + sizeof(HWT_DETAIL_INFO)) printf("Get Radio Mask failed.\n"); else { ULONG nWritten; PDEV_RET pOutVer = (PDEV_RET)__MALLOC(sizeof(DEV_RET) + sizeof(HWT_FW_VERSION)); DeviceIoControl ( hDevice, DUT_IO_CODE(CMD_FW_VERSION), NULL, 0, pOutVer, sizeof(DEV_RET) + sizeof(HWT_FW_VERSION), &nWritten, NULL); if (nWritten != sizeof(DEV_RET) + sizeof(HWT_FW_VERSION)) printf("Get Firmware version failed.\n"); else { if (((HWT_FW_VERSION*)pOutVer->data)->m_fw_version >= 0x02000000) { PHWT_DETAIL_INFO hwt_detail_info; ULONG i; HRESULT r = S_OK; hwt_detail_info = (PHWT_DETAIL_INFO)pOutInfo->data; if (Count) { for(i=0; i < Count; i++) { if (hwt_detail_info->RadioMask & (1 << RadioNo[i])) continue; printf("Radio is not ready.\n"); r = E_FAIL; break; } if (r == S_OK) DoDump(hDevice, RadioNo, Count, TRUE, szDumpFileName); } else { ULONG RadioNo[MAX_RADIO_NUMBER] = { 0 }; ULONG Count = 0; for(i=0; i < MAX_RADIO_NUMBER; i++) { if (hwt_detail_info->RadioMask & (1 << i)) { RadioNo[Count] = i; Count++; } } DoDump(hDevice, RadioNo, Count, TRUE, szDumpFileName); } } else { ULONG RadioNo = 0; ULONG Count = 1; DoDump(hDevice, &RadioNo, Count, FALSE, szDumpFileName); } } __FREE(pOutVer); } __FREE(pOutInfo); }
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(); }