##// END OF EJS Templates
First init /!\ outdated spwplugin!
First init /!\ outdated spwplugin!

File last commit:

r0:2d12462f4460 default
r0:2d12462f4460 default
Show More
APBUARTPLUGIN.cpp
185 lines | 5.5 KiB | text/x-c | CppLexer
/*------------------------------------------------------------------------------ -- This file is a part of the LPPMON 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 3 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()
{
if(this->isEnabled() && parent!=NULL)
{
if(this->useLoopBack)
{
if(this->baseAddress()!=-1)
{
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;
parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
}
if(printdata!="")
emit apbUartTextReceived(printdata);
}
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(100);
else
this->loopBackTimer.stop();
}
int ApbUartPlugin::enableLoopback()
{
this->useLoopBack = true;
this->loopBackTimer.start(100);
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;
}