Commit 3b5ed783 authored by David Košenina's avatar David Košenina

eeprom read

parent f1418d2b
......@@ -69,6 +69,18 @@ int fileLoad(const char* fileName, char** buffer, ilarge* bufferSize)
return 0;
}
int fileSize(const char* fileName, ilarge* bufferSize)
{
SDL_RWops* ctx = SDL_RWFromFile(fileName, "rb");
if (!ctx)
{
return 1;
}
*bufferSize = SDL_RWsize(ctx);
SDL_RWclose(ctx);
return 0;
}
int fileLoadPtr(const char* fileName, char* buffer, ilarge* bufferSize)
{
SDL_RWops* ctx = SDL_RWFromFile(fileName, "rb");
......
......@@ -25,6 +25,7 @@ int fileLoadString(const char* fileName, char** string, ilarge* stringSize);
int fileSaveString(const char* fileName, char* string);
int fileLoad(const char* fileName, char** buffer, ilarge* bufferSize);
int fileSize(const char* fileName, ilarge* bufferSize);
int fileLoadPtr(const char* fileName, char* buffer, ilarge* bufferSize);
int fileSave(const char* fileName, char* buffer, ilarge bufferSize);
......
......@@ -203,15 +203,31 @@ int usbFx3ReadEEPROM(UsbContext* ctx, unsigned char* buffer, int size, int reada
if(usbFxxIsConnected(ctx))
{
// bReqType: 0xC0, bRequest : 0xBB, wLength - MAX : 0x1000
int ret = libusb_control_transfer((libusb_device_handle*)ctx->device,
0xC0,
0xBB,
(readadress >> 16) & 0xffff,
(readadress) & 0xffff,
buffer,
size,
100000);
if(ret == size)
int packet = 1024;
int count = size / packet;
int left = size % packet;
int read = 0;
for (int i = 0; i < count; i++)
{
read += libusb_control_transfer((libusb_device_handle*)ctx->device,
0xC0,
0xBB,
(readadress >> 16) & 0xffff,
(readadress) & 0xffff,
buffer + i * packet,
packet,
100000);
readadress += packet;
}
read += libusb_control_transfer((libusb_device_handle*)ctx->device,
0xC0,
0xBB,
(readadress >> 16) & 0xffff,
(readadress) & 0xffff,
buffer + count * packet,
left,
100000);
if(read == size)
{
return PUREUSB_SUCCESS;
}
......
......@@ -2217,11 +2217,23 @@ void OsciloskopOsciloskop::m_menuItemReadEEPROMOnMenuSelection(wxCommandEvent& e
{
pDebug->Clear();
FORMAT_BUFFER();
for(int i = 0; i < EEPROM_BYTE_COUNT; i++)
int count = min(16,size / EEPROM_BYTE_COUNT);
int left = size % EEPROM_BYTE_COUNT;
for(int i=0;i<count;i++)
{
for(int j = 0; j < EEPROM_BYTE_COUNT; j++)
{
byte byteToPrint = eeprom.data.bytes[i*EEPROM_BYTE_COUNT +j];
FORMAT("%02x ", byteToPrint);
pDebug->AppendText(wxString::FromAscii(formatBuffer));
}
pDebug->AppendText(wxString::FromAscii("\n"));
}
for (int j = 0; j < left; j++)
{
byte byteToPrint = eeprom.data.bytes[i];
FORMAT("%02x ", byteToPrint);
pDebug->AppendText(wxString::FromAscii(formatBuffer));
byte byteToPrint = eeprom.data.bytes[count*EEPROM_BYTE_COUNT + j];
FORMAT("%02x ", byteToPrint);
pDebug->AppendText(wxString::FromAscii(formatBuffer));
}
}
}
......
......@@ -4377,7 +4377,7 @@ Info::~Info()
Debug::Debug( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxSize( -1,-1 ), wxDefaultSize );
this->SetSizeHints( wxSize( -1,-1 ), wxSize( -1,-1 ) );
wxBoxSizer* bSizer55;
bSizer55 = new wxBoxSizer( wxVERTICAL );
......
......@@ -993,7 +993,7 @@ class Debug : public wxDialog
public:
wxTextCtrl* m_textCtrl41;
Debug( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Debug"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,500 ), long style = wxDEFAULT_DIALOG_STYLE );
Debug( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Debug"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 750,500 ), long style = wxDEFAULT_DIALOG_STYLE );
~Debug();
};
......
......@@ -30873,7 +30873,7 @@
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size">-1,-1</property>
<property name="minimum_size">500,500</property>
<property name="name">Debug</property>
<property name="pos"></property>
<property name="size">500,500</property>
......@@ -162,10 +162,10 @@ ThreadApi::ThreadApi()
////////////////////////////////////////////////////////////////////////////////
void ThreadApi::function(EThreadApiFunction f)
{
SDL_AtomicSet(&sync, 1);
SDL_AtomicLock(&lock);
func.pushBack(f);
SDL_AtomicUnlock(&lock);
SDL_AtomicSet(&sync, 1);
}
void ThreadApi::wait()
......@@ -216,6 +216,10 @@ void ThreadApi::update()
sfSetTimeOut(getCtx(), timeout);
SDL_AtomicUnlock(&lock);
break;
case afIsOpened:
iret += sfHardwareIsOpened(getCtx(), &iopened);
SDL_AtomicSet(&open, iopened);
break;
case afOpenUsb:
SDL_AtomicLock(&lock);
iret += sfHardwareOpen(getCtx(), &usbData, SDL_AtomicGet(&version));
......@@ -622,6 +626,8 @@ int ThreadApi::readUsbFromEEPROM(OscHardware* hw)
SUsb usb = hw->getUSB();
setUSB(&usb);
function(EThreadApiFunction::afOpenUsb);
function(EThreadApiFunction::afIsOpened);
wait();
}
if (SDL_AtomicGet(&open) > 0)
......@@ -635,24 +641,23 @@ int ThreadApi::readUsbFromEEPROM(OscHardware* hw)
}
if (iversion == HARDWARE_VERSION_2)
{
eepromSize = sizeof(SEeprom);
ilarge size = 0;
fileSize(hw->usbFirmware.asChar(), &size);
eepromSize = size;
eepromOffset = 0;
}
SDL_AtomicUnlock(&lock);
function(EThreadApiFunction::afEEPROMRead);
wait();
SDL_AtomicLock(&lock);
SDL_memcpy((char*)hw, (char*)&eepromData, eepromSize);
SDL_AtomicUnlock(&lock);
}
int iret = SDL_AtomicGet(&ret);
if (iret == SCOPEFUN_SUCCESS)
{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Success", "Read callibration data from EEPROM was successfull.", 0);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Success", "Read usb data from EEPROM was successfull.", 0);
}
else
{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Read callibration data from EEPROM failed.", 0);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Read usb data from EEPROM failed.", 0);
}
return iret;
}
......
......@@ -788,6 +788,7 @@ public:
enum EThreadApiFunction {
afInit,
afIsOpened,
afOpenUsb,
afUploadFpga,
afUploadFxx,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment