##// END OF EJS Templates
An other Win32 dirty fix tentative.
An other Win32 dirty fix tentative.

File last commit:

r5:15c638a85130 default
r5:15c638a85130 default
Show More
APBUARTPLUGIN.cpp
199 lines | 5.8 KiB | text/x-c | CppLexer
/*------------------------------------------------------------------------------
-- This file is a part of the SocExplorer Software
-- Copyright (C) 2013, Laboratory of Plasmas Physic - 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 "APBUARTPLUGIN.h"
#include <socexplorerengine.h>
ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent)
{
this->UI = new ApbUartPluginUi();
this->setWindowTitle(tr("APBUART"));
this->setWidget((QWidget*)this->UI);
this->useLoopBack = false;
connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int)));
connect(this,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
connect(&this->loopBackTimer,SIGNAL(timeout()),this,SLOT(uartReadout()));
}
ApbUartPlugin::~ApbUartPlugin()
{
}
void ApbUartPlugin::closeMe()
{
emit this->closePlugin(this);
}
void ApbUartPlugin::postInstantiationTrigger()
{
if(this->isEnabled())
{
this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
loopbackChangeState(Qt::Checked);
}
}
void ApbUartPlugin::loopbackChangeState(int state)
{
if(state==Qt::Checked)
{
enableLoopback();
}
else
{
disableLoopback();
}
}
void ApbUartPlugin::uartReadout()
{
#ifdef WIN32
int readcnt=0;
#endif
if(this->isEnabled() && parent!=NULL)
{
if(this->useLoopBack)
{
if(this->baseAddress()!=-1)
{
this->loopBackTimer.stop();
unsigned int status_reg,data;
char ch;
QString printdata="";
parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
while ((status_reg&4)==0) {
parent->Read(&data,1,this->baseAddress()+APB_UART_FIFO_DEBUG_REG);
ch = (char)(0xff & data);
printdata+=ch;
#ifdef WIN32
readcnt++;
if(readcnt>=32)
{
qApp->processEvents();
break;
}
#endif
parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
}
if(printdata!="")
emit apbUartTextReceived(printdata);
this->loopBackTimer.start(200);
}
else
{
this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
this->enableLoopback();
}
}
}
}
void ApbUartPlugin::activate(bool flag)
{
this->setEnabled(flag);
emit this->activateSig(flag);
if(this->isEnabled())
{this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
loopbackChangeState(Qt::Checked);
}
}
void ApbUartPlugin::activateScan(bool flag)
{
if(flag)
this->loopBackTimer.start(200);
else
this->loopBackTimer.stop();
}
int ApbUartPlugin::enableLoopback()
{
this->useLoopBack = true;
this->loopBackTimer.start(200);
SocExplorerEngine::message(this,"Set FiFo debug mode mode");
if(parent==NULL)
{
SocExplorerEngine::message(this,"Can't set FiFo debug mode no parent driver accessible");
return -1;
}
if(this->baseAddress()==-1)
{
this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
if(this->baseAddress()==-1)
return -1;
}
unsigned int ctrl_reg= 0x843;
parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
return 0;
}
int ApbUartPlugin::disableLoopback()
{
SocExplorerEngine::message(this,"Disable FiFo debug mode mode");
if(parent==NULL)
{
SocExplorerEngine::message(this,"Can't disable FiFo debug mode no parent driver accessible");
return -1;
}
if(this->baseAddress()==-1)
{
this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
if(this->baseAddress()==-1)
return -1;
}
unsigned int ctrl_reg;
this->loopBackTimer.stop();
/* Firts get Control reg value*/
parent->Read(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
ctrl_reg = ctrl_reg & (~(1<<11));
parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
this->useLoopBack = false;
return 0;
}
unsigned int ApbUartPlugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
{
if(parent!=NULL)
return parent->Read(Value,count,address);
return 0;
}
unsigned int ApbUartPlugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
{
if(parent!=NULL)
return parent->Write(Value,count,address);
return 0;
}