diff --git a/APBUARTPLUGIN/APBUARTPLUGIN.cpp b/APBUARTPLUGIN/APBUARTPLUGIN.cpp --- a/APBUARTPLUGIN/APBUARTPLUGIN.cpp +++ b/APBUARTPLUGIN/APBUARTPLUGIN.cpp @@ -21,20 +21,31 @@ ----------------------------------------------------------------------------*/ #include "APBUARTPLUGIN.h" #include +#include -ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent) +ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent,false) { this->setBaseAddress(-1); + this->p_curentAPBUart = 0; this->UI = new APBUART_Plugin_ui(); this->setWidget((QWidget*)this->UI); this->uartConnected = false; this->UartThread = new UARTPollingThread(this); - connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int))); + this->pyObject = new APBUartPyWrapper(this); + connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(fifoDebugChangeState(int))); connect(this->UartThread,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString))); connect(this->UI,SIGNAL(connectPort()),this,SLOT(toggleUartState())); connect(this->UI,SIGNAL(sendChar(char)),this->UartThread,SLOT(sendChar(char))); connect(this->UI,SIGNAL(PortNameChanged(QString)),this->UartThread,SLOT(setPortName(QString))); connect(this->UI,SIGNAL(UartSpeedChanged(QString)),this->UartThread,SLOT(setPortSpeedStr(QString))); + connect(this->UI,SIGNAL(updateAPBUartsList()),this,SLOT(updateAPBUartsList())); + connect(this->UI,SIGNAL(curentAPBUartChanged(int)),this,SLOT(setCurentAPBUart(int))); + connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(openUart()),this,SLOT(openUart())); + connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(closeUart()),this,SLOT(closeUart())); + connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(setFifoDebugEnabled(bool)),this,SLOT(setFifoDebugEnabled(bool))); + connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(setUARTPortNane(QString)),this,SLOT(setUARTPortNane(QString))); + connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(setUARTPortSpeed(int)),this,SLOT(setUARTPortSpeed(int))); + connect(((APBUartPyWrapper*)this->pyObject),SIGNAL(updateAPBUartsList()),this,SLOT(updateAPBUartsList())); this->UartThread->start(); } @@ -44,6 +55,11 @@ ApbUartPlugin::~ApbUartPlugin() } +int ApbUartPlugin::curentAPBUart() +{ + return p_curentAPBUart; +} + void ApbUartPlugin::closeMe() { emit this->closePlugin(this); @@ -53,27 +69,86 @@ void ApbUartPlugin::toggleUartState() { if(!uartConnected) { - uartConnected = this->UartThread->openUart(); + this->openUart(); } else { - this->UartThread->closeUart(); - this->uartConnected = false; + this->closeUart(); } +} + +void ApbUartPlugin::activate(bool flag) +{ + socexplorerplugin::activate(flag); + this->updateAPBUartsList(); +} + +void ApbUartPlugin::updateAPBUartsList() +{ + QList addresses; + int count = SocExplorerEngine::self()->getEnumDeviceCount(this,this->VID(),this->PID()); + for(int i=0;igetEnumDeviceBaseAddress(this,this->VID(),this->PID(),i)); + } + this->UI->updateAPBUartList(addresses); +} + +void ApbUartPlugin::setCurentAPBUart(int index) +{ + this->p_curentAPBUart = index; + this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),index)); +} + +void ApbUartPlugin::openUart() +{ + if(this->UartThread->fifoDebugEnabled()) + setFifoDebugEnabled(false); + if(!uartConnected) + uartConnected = this->UartThread->openUart(); this->UI->setUartConnected(uartConnected); } -void ApbUartPlugin::loopbackChangeState(int state) +void ApbUartPlugin::closeUart() +{ + if(uartConnected) + this->UartThread->closeUart(); + this->uartConnected = false; + this->UI->setUartConnected(uartConnected); +} + +void ApbUartPlugin::setFifoDebugEnabled(bool enable) +{ + if(uartConnected) + closeUart(); + this->UI->setEnableForLoopBack(!enable); + this->UartThread->setFifoDebugEable(enable); +} + +void ApbUartPlugin::setAPBUartIndex(int index) +{ + this->UI->setAPBUartIndex(index); +} + +void ApbUartPlugin::setUARTPortNane(QString name) +{ + this->UI->setUartPortName(name); +} + +void ApbUartPlugin::setUARTPortSpeed(int speed) +{ + this->UI->setUartSpeed(speed); +} + +void ApbUartPlugin::fifoDebugChangeState(int state) { if(state==Qt::Checked) { - this->UI->setEnableForLoopBack(false); - this->UartThread->setFifoDebugEable(true); + this->setFifoDebugEnabled(true); } else { - this->UI->setEnableForLoopBack(true); - this->UartThread->setFifoDebugEable(false); + this->setFifoDebugEnabled(false); } } diff --git a/APBUARTPLUGIN/APBUARTPLUGIN.h b/APBUARTPLUGIN/APBUARTPLUGIN.h --- a/APBUARTPLUGIN/APBUARTPLUGIN.h +++ b/APBUARTPLUGIN/APBUARTPLUGIN.h @@ -44,18 +44,29 @@ public: ~ApbUartPlugin(); int VID(){return driver_VID;} int PID(){return driver_PID;} - + int curentAPBUart(); + public slots: unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0); unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0); - void loopbackChangeState(int state); + void fifoDebugChangeState(int state); void closeMe(); void toggleUartState(); + void activate(bool flag); + void updateAPBUartsList(); + void setCurentAPBUart(int index); + void openUart(); + void closeUart(); + void setFifoDebugEnabled(bool enable); + void setAPBUartIndex(int index); + void setUARTPortNane(QString name); + void setUARTPortSpeed(int speed); signals: private: APBUART_Plugin_ui* UI; bool uartConnected; + int p_curentAPBUart; UARTPollingThread* UartThread; int enableLoopback(); int disableLoopback(); diff --git a/APBUARTPLUGIN/APBUARTPLUGIN.pro b/APBUARTPLUGIN/APBUARTPLUGIN.pro --- a/APBUARTPLUGIN/APBUARTPLUGIN.pro +++ b/APBUARTPLUGIN/APBUARTPLUGIN.pro @@ -4,6 +4,7 @@ #------------------------------------------------- CONFIG += socexplorerplugin + win32:CONFIG += dll win32:CONFIG -= static @@ -35,14 +36,16 @@ HEADERS += \ APBUARTPLUGIN.h \ apbuartterminal.h \ apbuart_plugin_ui.h \ - uartpollingthread.h + uartpollingthread.h \ + apbuartpywrapper.h SOURCES += \ APBUARTPLUGIN.cpp \ apbuartterminal.cpp \ apbuart_plugin_ui.cpp \ - uartpollingthread.cpp + uartpollingthread.cpp \ + apbuartpywrapper.cpp FORMS += \ apbuart_plugin_ui.ui diff --git a/APBUARTPLUGIN/apbuart_plugin_ui.cpp b/APBUARTPLUGIN/apbuart_plugin_ui.cpp --- a/APBUARTPLUGIN/apbuart_plugin_ui.cpp +++ b/APBUARTPLUGIN/apbuart_plugin_ui.cpp @@ -22,6 +22,7 @@ #include "apbuart_plugin_ui.h" #include "ui_apbuart_plugin_ui.h" #include "apbuartterminal.h" +#include APBUART_Plugin_ui::APBUART_Plugin_ui(QWidget *parent) : QWidget(parent), @@ -35,6 +36,8 @@ APBUART_Plugin_ui::APBUART_Plugin_ui(QWi connect(this->ui->PortNameLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(PortNameChanged(QString))); connect(this->ui->UartSpeedLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(UartSpeedChanged(QString))); connect(this->ui->rescanQpb,SIGNAL(clicked()),this,SLOT(updatePortList())); + connect(this->ui->APBUartsUpdateQpb,SIGNAL(clicked()),this,SIGNAL(updateAPBUartsList())); + connect(this->ui->UARTSelector,SIGNAL(currentIndexChanged(int)),this,SIGNAL(curentAPBUartChanged(int))); this->portListcompleter = NULL; this->updatePortList(); } @@ -44,11 +47,22 @@ APBUART_Plugin_ui::~APBUART_Plugin_ui() delete ui; } +int APBUART_Plugin_ui::curentAPBUart() +{ + return this->ui->UARTSelector->currentIndex(); +} + void APBUART_Plugin_ui::setEnableForLoopBack(bool enable) { this->ui->PortNameLineEdit->setEnabled(enable); this->ui->ConnectQpb->setEnabled(enable); this->ui->UartSpeedLineEdit->setEnabled(enable); + this->ui->APBUartsUpdateQpb->setEnabled(enable); + this->ui->rescanQpb->setEnabled(enable); + this->ui->UARTSelector->setEnabled(enable); + if(this->ui->FIFODebugChkBx->isChecked()==enable) + this->ui->FIFODebugChkBx->toggle(); + } void APBUART_Plugin_ui::setUartConnected(bool enable) @@ -56,6 +70,9 @@ void APBUART_Plugin_ui::setUartConnected this->ui->PortNameLineEdit->setDisabled(enable); this->ui->UartSpeedLineEdit->setDisabled(enable); this->ui->FIFODebugChkBx->setDisabled(enable); + this->ui->APBUartsUpdateQpb->setDisabled(enable); + this->ui->rescanQpb->setDisabled(enable); + this->ui->UARTSelector->setDisabled(enable); if(enable) { this->ui->ConnectQpb->setText("Close Port"); @@ -90,6 +107,32 @@ void APBUART_Plugin_ui::updatePortList() this->portListcompleterModel->setStringList(wordList); } +void APBUART_Plugin_ui::updateAPBUartList(QList addresses) +{ + this->ui->UARTSelector->clear(); + for(int i=0;iui->UARTSelector->addItem(QString("APBUart %1 @0x%2").arg(i).arg(addresses.at(i),8,16)); + } + if(addresses.count()==0) + this->ui->UARTSelector->addItem("None"); +} + +void APBUART_Plugin_ui::setUartSpeed(int speed) +{ + this->ui->UartSpeedLineEdit->setText(QString::number(speed)); +} + +void APBUART_Plugin_ui::setUartPortName(QString name) +{ + this->ui->PortNameLineEdit->setText(name); +} + +void APBUART_Plugin_ui::setAPBUartIndex(int index) +{ + if((indexui->UARTSelector->count()) && (index>0) ) + this->ui->UARTSelector->setCurrentIndex(index); +} @@ -98,3 +141,5 @@ void APBUART_Plugin_ui::updatePortList() + + diff --git a/APBUARTPLUGIN/apbuart_plugin_ui.h b/APBUARTPLUGIN/apbuart_plugin_ui.h --- a/APBUARTPLUGIN/apbuart_plugin_ui.h +++ b/APBUARTPLUGIN/apbuart_plugin_ui.h @@ -37,18 +37,26 @@ class APBUART_Plugin_ui : public QWidget public: explicit APBUART_Plugin_ui(QWidget *parent = 0); ~APBUART_Plugin_ui(); - + int curentAPBUart(); public slots: void setEnableForLoopBack(bool enable); void setUartConnected(bool enable); void updatePortList(); + void updateAPBUartList(QList addresses); + void setUartSpeed(int speed); + void setUartPortName(QString name); + void setAPBUartIndex(int index); +private slots: + signals: + void curentAPBUartChanged(int index); void loopbackChkBxStateChanged( int state ); void apbUartTextReceived(QString text); void connectPort(); void sendChar(char c); void UartSpeedChanged(QString text); void PortNameChanged(QString text); + void updateAPBUartsList(); private: Ui::APBUART_Plugin_ui *ui; QCompleter *portListcompleter; diff --git a/APBUARTPLUGIN/apbuart_plugin_ui.ui b/APBUARTPLUGIN/apbuart_plugin_ui.ui --- a/APBUARTPLUGIN/apbuart_plugin_ui.ui +++ b/APBUARTPLUGIN/apbuart_plugin_ui.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 608 + 319 @@ -24,48 +24,80 @@ Configuration - - - - - - - Enable FIFO debug mode - - - false - - - - - - - Port Name + + + + APB UART Config - - - - - - Uart Speed - - - - - - - Rescan ports - - - - - - - - - - Open Port - + + + + + Port Name + + + + + + + Uart Speed + + + + + + + Enable FIFO debug mode + + + false + + + + + + + Update + + + + + + + + + + Rescan ports + + + + + + + + + + + None + + + + + + + + Chose UART + + + + + + + Open Port + + + + diff --git a/APBUARTPLUGIN/apbuartpywrapper.cpp b/APBUARTPLUGIN/apbuartpywrapper.cpp new file mode 100644 --- /dev/null +++ b/APBUARTPLUGIN/apbuartpywrapper.cpp @@ -0,0 +1,27 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#include "apbuartpywrapper.h" + +APBUartPyWrapper::APBUartPyWrapper(socexplorerplugin *parent) : + genericPySysdriver(parent) +{ +} diff --git a/APBUARTPLUGIN/apbuartpywrapper.h b/APBUARTPLUGIN/apbuartpywrapper.h new file mode 100644 --- /dev/null +++ b/APBUARTPLUGIN/apbuartpywrapper.h @@ -0,0 +1,46 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the SocExplorer Software +-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#ifndef APBUARTPYWRAPPER_H +#define APBUARTPYWRAPPER_H +#include +#include +#include + +class APBUartPyWrapper : public genericPySysdriver +{ + Q_OBJECT +public: + explicit APBUartPyWrapper(socexplorerplugin *parent = 0); + +signals: + void setFifoDebugEnabled(bool enable); + void setAPBUartIndex(int index); + void setUARTPortNane(QString name); + void setUARTPortSpeed(int speed); + void updateAPBUartsList(); + void openUart(); + void closeUart(); +public slots: + +}; + +#endif // APBUARTPYWRAPPER_H diff --git a/APBUARTPLUGIN/uartpollingthread.cpp b/APBUARTPLUGIN/uartpollingthread.cpp --- a/APBUARTPLUGIN/uartpollingthread.cpp +++ b/APBUARTPLUGIN/uartpollingthread.cpp @@ -29,7 +29,7 @@ UARTPollingThread::UARTPollingThread(soc uartMutex = new QMutex(); uartOpened = false; fifoDebugConfigured = false; - fifoDebugEnabled = false; + p_fifoDebugEnabled = false; this->moveToThread(this); } @@ -47,7 +47,7 @@ void UARTPollingThread::run() SocExplorerEngine::message(this->plugin,"Entering APB UART polling thread",3); while (!this->isInterruptionRequested()) { - if(fifoDebugEnabled) + if(p_fifoDebugEnabled) { if(fifoDebugConfigured) { @@ -57,7 +57,7 @@ void UARTPollingThread::run() char ch; QString printdata=""; plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG); - while ((status_reg&4)==0) { + while ((status_reg & 4)==0) { plugin->parent->Read(&data,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG); ch = (char)(0xff & data); printdata+=ch; @@ -113,7 +113,7 @@ void UARTPollingThread::run() void UARTPollingThread::sendChar(char c) { - if(fifoDebugEnabled) + if(p_fifoDebugEnabled) { if(this->plugin->baseAddress()!=-1) { @@ -186,7 +186,12 @@ void UARTPollingThread::setFifoDebugEabl } this->fifoDebugConfigured = false; configFifoDebug(enable); - this->fifoDebugEnabled = enable; + this->p_fifoDebugEnabled = enable; +} + +bool UARTPollingThread::fifoDebugEnabled() +{ + return p_fifoDebugEnabled; } void UARTPollingThread::configFifoDebug(bool enable) diff --git a/APBUARTPLUGIN/uartpollingthread.h b/APBUARTPLUGIN/uartpollingthread.h --- a/APBUARTPLUGIN/uartpollingthread.h +++ b/APBUARTPLUGIN/uartpollingthread.h @@ -51,9 +51,10 @@ public slots: void setPortSpeedStr(QString speed); void setPortSpeed(int speed); void setFifoDebugEable(bool enable); + bool fifoDebugEnabled(); private: void configFifoDebug(bool enable); - bool fifoDebugEnabled; + bool p_fifoDebugEnabled; bool fifoDebugConfigured; QString portName; int uartSpeed; diff --git a/ahbuartplugin/ahbuartplugin.cpp b/ahbuartplugin/ahbuartplugin.cpp --- a/ahbuartplugin/ahbuartplugin.cpp +++ b/ahbuartplugin/ahbuartplugin.cpp @@ -86,8 +86,6 @@ int ahbuartplugin::registermenu(QMainWin } - - bool ahbuartplugin::checkConnection() { QTime timeout; @@ -357,9 +355,9 @@ unsigned int ahbuartplugin::Write(unsign progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count); int offset = 0; char* CMD= (char*)malloc((32*4)+5); + writen=0; while(count>32) { - writen=0; CMD[0] = 0xC0 | (32-1); CMD[1] = (char)(((unsigned int)address>>24)&0xFF); CMD[2] = (char)(((unsigned int)address>>16)&0xFF); @@ -409,7 +407,7 @@ unsigned int ahbuartplugin::Write(unsign SocExplorerEngine::deleteProgressBar(progress); } free(CMD); - emit this->addWritenBytes(writen); + emit this->addWritenBytes(writen*4); return writen; } return 0; diff --git a/ahbuartplugin/ahbuartpywrapper.h b/ahbuartplugin/ahbuartpywrapper.h --- a/ahbuartplugin/ahbuartpywrapper.h +++ b/ahbuartplugin/ahbuartpywrapper.h @@ -1,7 +1,9 @@ #ifndef AHBUARTPYWRAPPER_H #define AHBUARTPYWRAPPER_H +#include #include #include +#include class ahbuartPywrapper : public genericPySysdriver {