Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug trace FX3 via USB #195

Merged
merged 3 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/FX3Class.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class fx3class
virtual bool Control(FX3Command command, uint64_t data) = 0;
virtual bool SetArgument(uint16_t index, uint16_t value) = 0;
virtual bool GetHardwareInfo(uint32_t* data) = 0;

virtual bool ReadDebugTrace(uint8_t* pdata, uint8_t len) = 0;
virtual void StartStream(const std::function<void( void* )> &f, size_t readsize, int numofblock) = 0;
virtual void StopStream() = 0;

Expand Down
28 changes: 28 additions & 0 deletions Core/RadioHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void RadioHandlerClass::OnDataPacket(void* buf)
}

RadioHandlerClass::RadioHandlerClass() :
DbgPrintFX3(nullptr),
run(false),
pga(false),
dither(false),
Expand Down Expand Up @@ -342,6 +343,11 @@ void RadioHandlerClass::CaculateStats()

BytesXferred = 0;
SamplesXIF = 0;

uint16_t maxlen = 64;
uint8_t debdata[64];
memset(debdata, 0, maxlen);

auto StartingTime = high_resolution_clock::now();

while (run) {
Expand All @@ -359,7 +365,29 @@ void RadioHandlerClass::CaculateStats()
SamplesXIF = 0;

StartingTime = high_resolution_clock::now();

#ifdef _DEBUG
int nt = 5;
while (nt-- > 0)
{
std::this_thread::sleep_for(0.1s);

if (hardware->ReadDebugTrace(debdata, maxlen) == true) // there are message from FX3 ?
{
int len = strlen((char*)debdata);
if (len > maxlen - 1) len = maxlen - 1;
debdata[len] = 0;
if ((len > 0)&&(DbgPrintFX3 != nullptr))
{
DbgPrintFX3("%s\n", (char*)debdata);
memset(debdata, 0, sizeof(debdata));
}
}

}
#else
std::this_thread::sleep_for(0.5s);
#endif
}
return;
}
Expand Down
7 changes: 7 additions & 0 deletions Core/RadioHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class RadioHandlerClass {

void uptLed(int led, bool on);

void EnableDebug(void (*dbgprintFX3)(const char* fmt, ...)) { this->DbgPrintFX3 = dbgprintFX3; };

bool ReadDebugTrace(uint8_t* pdata, uint8_t len) { return fx3->ReadDebugTrace(pdata, len); }

private:
void AdcSamplesProcess();
void AbortXferLoop(int qidx);
Expand All @@ -68,6 +72,7 @@ class RadioHandlerClass {
r2iqControlClass* r2iqCntrl;

void (*Callback)(float *data, uint32_t length);
void (*DbgPrintFX3)(const char* fmt, ...);

bool run;
unsigned long count; // absolute index
Expand Down Expand Up @@ -126,6 +131,8 @@ class RadioHardware {
bool FX3producerOn() { return Fx3->Control(STARTFX3); }
bool FX3producerOff() { return Fx3->Control(STOPFX3); }

bool ReadDebugTrace(uint8_t* pdata, uint8_t len) { return Fx3->ReadDebugTrace(pdata, len); }

bool FX3SetGPIO(uint32_t mask);
bool FX3UnsetGPIO(uint32_t mask);

Expand Down
7 changes: 6 additions & 1 deletion Core/arch/linux/FX3handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ void fx3handler::PacketRead(uint32_t data_size, uint8_t *data, void *context)
fx3handler *handler = (fx3handler*)context;

handler->Callback(data);
}
}

bool fx3handler::ReadDebugTrace(uint8_t* pdata, uint8_t len)
{
return true;
}
2 changes: 1 addition & 1 deletion Core/arch/linux/FX3handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class fx3handler : public fx3class
bool Control(FX3Command command, uint64_t data) override;
bool SetArgument(uint16_t index, uint16_t value) override;
bool GetHardwareInfo(uint32_t* data) override;

bool ReadDebugTrace(uint8_t* pdata, uint8_t len);
void StartStream(const std::function<void( void* )> &callback, size_t readsize, int numofblock) override;
void StopStream() override;

Expand Down
29 changes: 27 additions & 2 deletions Core/arch/win32/FX3handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ bool fx3handler::Open(uint8_t* fw_data, uint32_t fw_size) {
if (n == 0) return r; // return if no devices connected
if (!GetFx3Device()) return r; // NO FX3 device connected

#ifdef _DEBUG
if (!fx3dev->IsBootLoaderRunning()) { // if not bootloader device
Control(RESETFX3); // reset the fx3 firmware via CyU3PDeviceReset(false)
DbgPrintf("DEBUG - Reset Firmware\n");
Sleep(300);
fx3dev->Close(); // close class
delete fx3dev; // destroy class
Sleep(300);
fx3dev = new CCyFX3Device; // create class
GetFx3Device(); // open class
}
#endif

FX3_FWDWNLOAD_ERROR_CODE dlf = SUCCESS;
if (fx3dev->IsBootLoaderRunning())
{
Expand Down Expand Up @@ -224,9 +237,12 @@ bool fx3handler::GetHardwareInfo(UINT32* data) { // firmware control BBRF
long lgt = 4;

fx3dev->ControlEndPt->ReqCode = TESTFX3;
fx3dev->ControlEndPt->Value = (USHORT)0;
#ifdef _DEBUG
fx3dev->ControlEndPt->Value = (USHORT) 1;
#else
fx3dev->ControlEndPt->Value = (USHORT) 0;
#endif
fx3dev->ControlEndPt->Index = (USHORT)0;
lgt = 4; // TESTFX3 len
bool r = fx3dev->ControlEndPt->Read((PUCHAR)data, lgt);
DbgPrintf("GetHardwareInfo %x .%x %x\n", r, TESTFX3, *data);
if (r == false)
Expand All @@ -237,6 +253,15 @@ bool fx3handler::GetHardwareInfo(UINT32* data) { // firmware control BBRF

}

bool fx3handler::ReadDebugTrace(uint8_t* pdata, uint8_t len)
{
long lgt = len;
bool r;
fx3dev->ControlEndPt->ReqCode = READINFODEBUG;
r = fx3dev->ControlEndPt->Read((PUCHAR)pdata, lgt);
return r;
}

bool fx3handler::SendI2cbytes(UINT8 i2caddr, UINT8 regaddr, PUINT8 pdata, UINT8 len)
{
bool r = false;
Expand Down
2 changes: 1 addition & 1 deletion Core/arch/win32/FX3handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class fx3handler : public fx3class
bool Control(FX3Command command, uint64_t data);
bool SetArgument(uint16_t index, uint16_t value);
bool GetHardwareInfo(uint32_t* data);

bool ReadDebugTrace(uint8_t* pdata, uint8_t len);
void StartStream(const std::function<void( void* )> &callback, size_t readsize, int numofblock);
void StopStream();

Expand Down
29 changes: 28 additions & 1 deletion ExtIO_sddc/ExtIO_sddc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ double FreqCorrectionFactor()
return 1.0 + gfFreqCorrectionPpm / 1E6;
}

std::mutex mtx_print; // mutex for critical section

// printf console from ExtIO debug
void dbgprintf(const char* fmt, ...) {
mtx_print.lock();
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
mtx_print.unlock();
}
// printf console from FX3 via USB callback
static void printf_USB_cb(const char* fmt, ...) {
mtx_print.lock();
SetConsoleColorTXT(TXT_CYAN);
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
SetConsoleColorTXT(TXT_GREEN);
mtx_print.unlock();
}

//---------------------------------------------------------------------------

Expand Down Expand Up @@ -123,6 +145,7 @@ bool __declspec(dllexport) __stdcall InitHW(char *name, char *model, int& type)
SetWindowPos(Hconsole, HWND_TOPMOST, rect.right - 800, 24, 800, 420, SWP_SHOWWINDOW);
DbgPrintf((char *) "Oscar Steila IK1XPV fecit MMXVIII - MMXX\n");
MakeWindowTransparent(Hconsole, 0xC0);
SetConsoleColorTXT(TXT_GREEN);
}
#endif
EnterFunction(); // now works
Expand Down Expand Up @@ -152,7 +175,11 @@ bool __declspec(dllexport) __stdcall InitHW(char *name, char *model, int& type)

auto Fx3 = CreateUsbHandler();
gbInitHW = Fx3->Open(res_data, res_size) &&
RadioHandler.Init(Fx3, Callback); // Check if it there hardware
RadioHandler.Init(Fx3, Callback ); // Check if it there hardware
#ifdef _DEBUG
RadioHandler.EnableDebug( printf_USB_cb );
#endif

if (!gbInitHW)
{
MessageBox(NULL, "Is SDR powered on and connected ?\r\n\r\nPlease start HDSDR again",
Expand Down
1 change: 0 additions & 1 deletion ExtIO_sddc/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#define IDB_BITMAP2 106
#define IDD_DLG_HDSDR 107
#define IDD_DLG_HDSDR281 108
#define DIALOGH 80
#define IDC_LW 1001
#define IDC_HF 1002
#define IDC_VHF 1003
Expand Down
14 changes: 13 additions & 1 deletion ExtIO_sddc/uti.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


/**************************************************************
* MakeWindowTrasparent(window, factor)
*
Expand All @@ -12,7 +14,10 @@

#define LWA_COLORKEY 0x00000001
#define LWA_ALPHA 0x00000002


#include <windows.h>
#include "uti.h"

typedef DWORD(WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD);

Expand Down Expand Up @@ -86,4 +91,11 @@ bool GetStateButton(HWND hWnd, int controlID)
void Command(HWND hwnd, int controlID, int command)
{
SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(controlID, command), (LPARAM)0);
}
}


void SetConsoleColorTXT(console_color c)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
}

22 changes: 21 additions & 1 deletion ExtIO_sddc/uti.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,24 @@ void SendF4();
bool GetStateButton(HWND hwnd, int controlID);
void Command(HWND hwnd, int controlID, int command);

#endif // _UTIH_
/*
#define FOREGROUND_BLUE 1 // Text color contains blue.
#define FOREGROUND_GREEN 2 // Text color contains green.
#define FOREGROUND_RED 4 // Text color contains red.
#define FOREGROUND_INTENSITY 8 // Text color is intensified.
#define BACKGROUND_BLUE 10 // Background color contains blue.
#define BACKGROUND_GREEN 20 // Background color contains green.
#define BACKGROUND_RED 40 // Background color contains red.
#define BACKGROUND_INTENSITY 80 // Background color is intensifie
*/

enum console_color {
TXT_CYAN = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
TXT_GREEN = FOREGROUND_GREEN | FOREGROUND_INTENSITY,
TXT_YELLOW = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
TXT_RED = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY
};

void SetConsoleColorTXT(console_color c);

#endif
4 changes: 4 additions & 0 deletions Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ enum FX3Command {
// Tune 4351 to a frequency
// WRITE: UINT64
AD4351TUNE = 0xB9,

// Read Debug string if any
// READ:
READINFODEBUG = 0xBA,
};

#define OUTXIO0 (1U << 0) // ATT_LE
Expand Down
Binary file modified SDDC_FX3.img
Binary file not shown.
11 changes: 7 additions & 4 deletions SDDC_FX3/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "cyu3externcstart.h"
#include "i2cmodule.h"

#define TRACESERIAL /* enable the trace to serial port*/
#define MAXLEN 64 // max buffer debug len

#define FIFO_DMA_RX_SIZE (0) /* DMA transfer size is set to infinite */
#define FIFO_THREAD_STACK (0x400) /* application thread stack size */
Expand Down Expand Up @@ -65,11 +65,14 @@
#define INFINITE_TRANSFER_SIZE (0)

#define APP_THREADS (1)
// void null_func(uint8_t, ...) // redefine DebugPrint if required
#define DebugPrint (CyU3PDebugPrint)
// void null_func(uint8_t, ...) // redefine DebugPrint if required
#define DebugPrint CyU3PDebugPrint

extern void DebugPrint2USB ( uint8_t priority, char *msg, ...);
#define DebugUSB DebugPrint2USB

// detect pin for HF103
#define LED_KIT (54) // This is also UART_CTS
#define LED_KIT (54) // This is also UART_CTS
#define GPIO52 (52) // sense RXLUCY
#define GPIO53 (53) // sense RXLUCY

Expand Down
Loading