Skip to content

Commit

Permalink
Refactored to encapsulate all device-specific knowledge into the Device
Browse files Browse the repository at this point in the history
class including flash creation to prevent Samba from being a dumping
ground for miscellaneous device features.

Removed serial port auto scan since it is unreliable and potentially
dangerous.  Instead the first serial port in the system is used by
default.

Made all serial port factories inherit from the ABC as designed.

Removed chip ID display since not all devices support it.

Read now defaults to read the rest of the device when an offset is
specified.

Cleaned up the chip ID and device ID logic to identify the device.

Changed the force USB option to conform to standard conventions.

Removed Arduino-specific reset in the normal path.  Board-specific
behavior should be enabled with an option.

waitFSR now takes an optional wait time parameter to handle cases like
chip erase when an operation can take a long time to finish
  • Loading branch information
shumatech committed May 21, 2017
1 parent 2615437 commit ee5a651
Show file tree
Hide file tree
Showing 35 changed files with 594 additions and 963 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WXVERSION=3.0
#
# Source files
#
COMMON_SRCS=Samba.cpp Flash.cpp NvmFlash.cpp EfcFlash.cpp EefcFlash.cpp FlashFactory.cpp Applet.cpp WordCopyApplet.cpp Flasher.cpp
COMMON_SRCS=Samba.cpp Flash.cpp NvmFlash.cpp EfcFlash.cpp EefcFlash.cpp Applet.cpp WordCopyApplet.cpp Flasher.cpp Device.cpp
APPLET_SRCS=WordCopyArm.asm
BOSSA_SRCS=BossaForm.cpp BossaWindow.cpp BossaAbout.cpp BossaApp.cpp BossaBitmaps.cpp BossaInfo.cpp BossaThread.cpp BossaProgress.cpp
BOSSA_BMPS=BossaLogo.bmp BossaIcon.bmp ShumaTechLogo.bmp
Expand Down
3 changes: 2 additions & 1 deletion src/BSDPortFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ BSDPortFactory::next()
std::string
BSDPortFactory::end()
{
return std::string();
return std::string("/dev/cuaU0");
}

6 changes: 4 additions & 2 deletions src/BSDPortFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@
#ifndef _BSDPORTFACTORY_H
#define _BSDPORTFACTORY_H

#include "SerialPort.h"
class BSDPortFactory;
#include "PortFactory.h"

#include <sys/types.h>
#include <dirent.h>

#include <string>


class BSDPortFactory
class BSDPortFactory : public PortFactoryBase
{
public:
BSDPortFactory();
Expand All @@ -46,6 +47,7 @@ class BSDPortFactory
virtual std::string begin();
virtual std::string end();
virtual std::string next();
virtual std::string def();

virtual SerialPort::Ptr create(const std::string& name);
virtual SerialPort::Ptr create(const std::string& name, bool isUsb);
Expand Down
2 changes: 1 addition & 1 deletion src/BossaApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
///////////////////////////////////////////////////////////////////////////////
#include "BossaApp.h"

BossaApp::BossaApp() : config(_("Bossa"))
BossaApp::BossaApp() : config(_("Bossa")), device(samba)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/BossaApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class BossaApp : public wxApp
public:
BossaApp();

wxConfig config;
PortFactory portFactory;
Samba samba;
BossaBitmaps bitmaps;
Flash::Ptr flash;
wxConfig config;
Device device;

private:
bool OnInit();
Expand Down
18 changes: 3 additions & 15 deletions src/BossaForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,13 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co
_portComboBox = new wxComboBox( _portBoxSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY );
_portBoxSizer->Add( _portComboBox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );

_refreshButton = new wxButton( _portBoxSizer->GetStaticBox(), wxID_ANY, wxT("Refresh"), wxDefaultPosition, wxDefaultSize, 0 );
_refreshButton->SetToolTip( wxT("Refresh the list of available serial ports") );

_portBoxSizer->Add( _refreshButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );


_portBoxSizer->Add( 0, 0, 1, wxEXPAND, 5 );

_autoScanButton = new wxButton( _portBoxSizer->GetStaticBox(), wxID_ANY, wxT("Auto-Scan"), wxDefaultPosition, wxDefaultSize, 0 );
_autoScanButton->SetToolTip( wxT("Scan all serial ports for a processor") );
_refreshButton = new wxButton( _portBoxSizer->GetStaticBox(), wxID_ANY, wxT("Refresh"), wxDefaultPosition, wxDefaultSize, 0 );
_refreshButton->SetToolTip( wxT("Refresh the list of available serial ports") );

_portBoxSizer->Add( _autoScanButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
_portBoxSizer->Add( _refreshButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );


_topBoxSizer->Add( _portBoxSizer, 3, wxALL|wxEXPAND, 5 );
Expand Down Expand Up @@ -347,13 +342,6 @@ InfoDialog::InfoDialog( wxWindow* parent, wxWindowID id, const wxString& title,
_deviceTextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
_deviceBoxSizer->Add( _deviceTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );

_chipIdStaticText = new wxStaticText( this, wxID_ANY, wxT("Chip ID:"), wxDefaultPosition, wxDefaultSize, 0 );
_chipIdStaticText->Wrap( -1 );
_deviceBoxSizer->Add( _chipIdStaticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );

_chipIdTextCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
_deviceBoxSizer->Add( _chipIdTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );


_topBoxSizer->Add( _deviceBoxSizer, 0, wxALL|wxEXPAND, 5 );

Expand Down
268 changes: 3 additions & 265 deletions src/BossaForm.fbp

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions src/BossaForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class MainFrame : public wxFrame
wxButton* _aboutButton;
wxComboBox* _portComboBox;
wxButton* _refreshButton;
wxButton* _autoScanButton;
wxFilePickerCtrl* _filePicker;
wxCheckBox* _eraseCheckBox;
wxCheckBox* _bootCheckBox;
Expand Down Expand Up @@ -136,8 +135,6 @@ class InfoDialog : public wxDialog
protected:
wxStaticText* _deviceStaticText;
wxTextCtrl* _deviceTextCtrl;
wxStaticText* _chipIdStaticText;
wxTextCtrl* _chipIdTextCtrl;
wxStaticText* _versionStaticText;
wxTextCtrl* _versionTextCtrl;
wxStaticText* _pagesStaticText;
Expand Down
6 changes: 1 addition & 5 deletions src/BossaInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@
BossaInfo::BossaInfo(wxWindow* parent) : InfoDialog(parent)
{
Samba& samba = wxGetApp().samba;
Flash::Ptr& flash = wxGetApp().flash;
uint32_t chipId;
uint32_t extChipId;
Device::FlashPtr& flash = wxGetApp().device.getFlash();

_deviceTextCtrl->SetValue(wxString(flash->name().c_str(), wxConvUTF8));
samba.chipId(chipId, extChipId);
_chipIdTextCtrl->SetValue(wxString::Format(wxT("%08x"), chipId));
_versionTextCtrl->SetValue(wxString(samba.version().c_str(), wxConvUTF8));

_pagesTextCtrl->SetValue(wxString::Format(wxT("%d"), flash->numPages()));
Expand Down
13 changes: 7 additions & 6 deletions src/BossaThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ WriteThread::WriteThread(wxEvtHandler* parent,
wxThread::ExitCode
WriteThread::Entry()
{
Flash::Ptr& flash = wxGetApp().flash;
Device& device = wxGetApp().device;
Device::FlashPtr& flash = device.getFlash();
Samba& samba = wxGetApp().samba;

try
{
ThreadObserver observer(this, "Writing");
Flasher flasher(samba, flash, observer);
Flasher flasher(samba, device, observer);

if (_eraseAll)
{
Expand Down Expand Up @@ -159,15 +160,15 @@ VerifyThread::VerifyThread(wxEvtHandler* parent, const wxString& filename, uint3
wxThread::ExitCode
VerifyThread::Entry()
{
Flash::Ptr& flash = wxGetApp().flash;
Device& device = wxGetApp().device;
Samba& samba = wxGetApp().samba;
uint32_t pageErrors;
uint32_t totalErrors;

try
{
ThreadObserver observer(this, "Verifying");
Flasher flasher(samba, flash, observer);
Flasher flasher(samba, device, observer);

if (!flasher.verify(_filename.mb_str(), pageErrors, totalErrors, _offset))
{
Expand Down Expand Up @@ -199,13 +200,13 @@ ReadThread::ReadThread(wxEvtHandler* parent, const wxString& filename, size_t si
wxThread::ExitCode
ReadThread::Entry()
{
Flash::Ptr& flash = wxGetApp().flash;
Device& device = wxGetApp().device;
Samba& samba = wxGetApp().samba;

try
{
ThreadObserver observer(this, "Reading");
Flasher flasher(samba, flash, observer);
Flasher flasher(samba, device, observer);

flasher.read(_filename.mb_str(), _size, _offset);

Expand Down
67 changes: 15 additions & 52 deletions src/BossaWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "BossaAbout.h"
#include "BossaInfo.h"

#include "FlashFactory.h"
#include "Device.h"

#include <string>

Expand All @@ -54,10 +54,6 @@ BossaWindow::BossaWindow() : MainFrame(NULL)
wxCommandEventHandler(BossaWindow::OnSerial),
NULL, this);

_autoScanButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(BossaWindow::OnAutoScan),
NULL, this);

_writeButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(BossaWindow::OnWrite),
NULL, this);
Expand Down Expand Up @@ -112,7 +108,7 @@ BossaWindow::BossaWindow() : MainFrame(NULL)

if (samba.connect(portFactory.create(std::string(port.mb_str()))))
{
CreateFlash();
CreateDevice();
}
}
}
Expand Down Expand Up @@ -174,16 +170,16 @@ BossaWindow::OnRefresh(wxCommandEvent& event)
void
BossaWindow::Connected()
{
Flash& flash = *wxGetApp().flash;
Device::FlashPtr& flash = wxGetApp().device.getFlash();
Samba& samba = wxGetApp().samba;
const SerialPort& port = samba.getSerialPort();

_statusBar->SetStatusText(wxT("Connected"), 0);
_statusBar->SetStatusText(wxString::Format(wxT("Device: %s"), flash.name().c_str()), 1);
_statusBar->SetStatusText(wxString::Format(wxT("Device: %s"), flash->name().c_str()), 1);
_portComboBox->SetStringSelection(wxString(port.name().c_str(), wxConvUTF8));
_bootCheckBox->Enable(flash.canBootFlash());
_bodCheckBox->Enable(flash.canBod());
_borCheckBox->Enable(flash.canBor());
_bootCheckBox->Enable(flash->canBootFlash());
_bodCheckBox->Enable(flash->canBod());
_borCheckBox->Enable(flash->canBor());
_writeButton->Enable(true);
_verifyButton->Enable(true);
_readButton->Enable(true);
Expand Down Expand Up @@ -257,15 +253,13 @@ BossaWindow::Question(const wxString& message)
}

void
BossaWindow::CreateFlash()
BossaWindow::CreateDevice()
{
Samba& samba = wxGetApp().samba;
Flash::Ptr& flash = wxGetApp().flash;
FlashFactory flashFactory;
Device& device = wxGetApp().device;

try
{
flash = flashFactory.create(samba);
device.create();
}
catch (exception& e)
{
Expand All @@ -274,14 +268,7 @@ BossaWindow::CreateFlash()
return;
}

if (flash.get() == NULL)
{
Disconnected();
Error(wxT("Device is not supported"));
return;
}

_statusBar->SetStatusText(wxString::Format(wxT("Device: %s"), flash->name().c_str()), 1);
_statusBar->SetStatusText(wxString::Format(wxT("Device: %s"), device.getFlash()->name().c_str()), 1);
Connected();
}

Expand All @@ -299,31 +286,7 @@ BossaWindow::OnSerial(wxCommandEvent& event)
return;
}

CreateFlash();
}

void
BossaWindow::OnAutoScan(wxCommandEvent& event)
{
string port;
PortFactory& portFactory = wxGetApp().portFactory;
Samba& samba = wxGetApp().samba;

RefreshSerial();

for (port = portFactory.begin();
port != portFactory.end();
port = portFactory.next())
{
if (samba.connect(portFactory.create(port)))
{
CreateFlash();
return;
}
}

Disconnected();
Error(wxString(wxT("Could not find a device")));
CreateDevice();
}

bool
Expand All @@ -350,7 +313,7 @@ BossaWindow::GetOffset(uint32_t& offset)
void
BossaWindow::OnWrite(wxCommandEvent& event)
{
Flash& flash = *wxGetApp().flash;
Device::FlashPtr& flash = wxGetApp().device.getFlash();
uint32_t offset;

if (_filePicker->GetPath().IsEmpty())
Expand All @@ -370,12 +333,12 @@ BossaWindow::OnWrite(wxCommandEvent& event)

try
{
if (flash.isLocked())
if (flash->isLocked())
{
if (!Question(wxT("The flash is currently locked. Do you want to unlock it and proceed with the write?")))
return;

flash.unlockAll();
flash->unlockAll();
}
}
catch(exception& e)
Expand Down
3 changes: 1 addition & 2 deletions src/BossaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BossaWindow : public MainFrame
BossaProgress* _progress;

void RefreshSerial();
void CreateFlash();
void CreateDevice();
void Connected();
void Disconnected();

Expand All @@ -60,7 +60,6 @@ class BossaWindow : public MainFrame
void OnAbout(wxCommandEvent& event);
void OnRefresh(wxCommandEvent& event);
void OnSerial(wxCommandEvent& event);
void OnAutoScan(wxCommandEvent& event);

void OnWrite(wxCommandEvent& event);
void OnVerify(wxCommandEvent& event);
Expand Down
Loading

0 comments on commit ee5a651

Please sign in to comment.