##// END OF EJS Templates
Removed APBUartPlugin bug (when switching between debug and non debug link)....
Removed APBUartPlugin bug (when switching between debug and non debug link). Added APBUart Python wrapper.

File last commit:

r34:ccd56e93ef09 default
r34:ccd56e93ef09 default
Show More
uartpollingthread.cpp
222 lines | 7.2 KiB | text/x-c | CppLexer
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 /*------------------------------------------------------------------------------
-- 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 "uartpollingthread.h"
#include <socexplorerengine.h>
UARTPollingThread::UARTPollingThread(socexplorerplugin *parent) :
QThread((QObject*)parent)
{
this->plugin = parent;
APB UART PLUGIN rework in progress;
r28 uartMutex = new QMutex();
uartOpened = false;
fifoDebugConfigured = false;
Removed APBUartPlugin bug (when switching between debug and non debug link)....
r34 p_fifoDebugEnabled = false;
APB UART PLUGIN rework in progress;
r28 this->moveToThread(this);
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 }
Jeandet Alexis
APBUART Working, need some cosmetic now.
r29 UARTPollingThread::~UARTPollingThread()
{
this->requestInterruption();
while(isRunning());
}
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 void UARTPollingThread::run()
{
APB UART PLUGIN rework in progress;
r28
Improved APB UART Plugin, now check how many bytes are available on uart...
r32 char ch[4097];
int timeout =10;
APB UART PLUGIN rework in progress;
r28 SocExplorerEngine::message(this->plugin,"Entering APB UART polling thread",3);
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 while (!this->isInterruptionRequested())
{
Removed APBUartPlugin bug (when switching between debug and non debug link)....
r34 if(p_fifoDebugEnabled)
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 {
APB UART PLUGIN rework in progress;
r28 if(fifoDebugConfigured)
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 {
APB UART PLUGIN rework in progress;
r28 if(this->plugin->baseAddress()!=-1)
{
unsigned int status_reg,data;
char ch;
QString printdata="";
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG);
Removed APBUartPlugin bug (when switching between debug and non debug link)....
r34 while ((status_reg & 4)==0) {
APB UART PLUGIN rework in progress;
r28 plugin->parent->Read(&data,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG);
ch = (char)(0xff & data);
printdata+=ch;
plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG);
}
if(printdata!="")
emit apbUartTextReceived(printdata);
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 }
APB UART PLUGIN rework in progress;
r28 else
{
this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0));
}
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 }
else
{
APB UART PLUGIN rework in progress;
r28 configFifoDebug(true);
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 }
}
APB UART PLUGIN rework in progress;
r28 else
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 {
Improved APB UART Plugin, now check how many bytes are available on uart...
r32 int read =0,avail=0;
APB UART PLUGIN rework in progress;
r28 uartMutex->lock();
if(uartOpened)
{
Improved APB UART Plugin, now check how many bytes are available on uart...
r32 avail = rs232availablebytes(this->uart);
SocExplorerEngine::message(this->plugin,QString("%1 available bytes on uart").arg(read),3);
if(avail)
{
if(avail>=4096)
{
read = rs232read(this->uart,ch,4096);
timeout = 0;
}
else
{
read = rs232read(this->uart,ch,avail);
timeout = 10;
}
SocExplorerEngine::message(this->plugin,QString("Read %1 bytes on uart").arg(read),3);
ch[read]='\0';
}
APB UART PLUGIN rework in progress;
r28 }
uartMutex->unlock();
Jeandet Alexis
APBUART Working, need some cosmetic now.
r29 if(read>=1)
APB UART PLUGIN rework in progress;
r28 {
Improved APB UART Plugin, now check how many bytes are available on uart...
r32 SocExplorerEngine::message(this->plugin,QString("Received %1 char(s) from APBUART").arg(read),3);
emit this->apbUartTextReceived(QString(ch));
APB UART PLUGIN rework in progress;
r28 }
Improved APB UART Plugin, now check how many bytes are available on uart...
r32 msleep(timeout);
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 }
}
}
void UARTPollingThread::sendChar(char c)
{
Removed APBUartPlugin bug (when switching between debug and non debug link)....
r34 if(p_fifoDebugEnabled)
APB UART PLUGIN rework in progress;
r28 {
if(this->plugin->baseAddress()!=-1)
{
unsigned int i=0x0FF & c;
plugin->parent->Write(&i,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG);
}
}
else
{
uartMutex->lock();
rs232write(this->uart,&c,1);
uartMutex->unlock();
}
}
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27
APB UART PLUGIN rework in progress;
r28 bool UARTPollingThread::openUart()
{
Jeandet Alexis
APBUART Working, need some cosmetic now.
r29 uartMutex->lock();
APB UART PLUGIN rework in progress;
r28 if(uartOpened)
{
closeUart();
}
Jeandet Alexis
APBUART Working, need some cosmetic now.
r29 SocExplorerEngine::message(this->plugin,"Opening UART "+this->portName,3);
APB UART PLUGIN rework in progress;
r28 this->uart = rs232open((char*)this->portName.toStdString().c_str());
if(this->uart!=badPortValue)
{
Jeandet Alexis
APBUART Working, need some cosmetic now.
r29 SocExplorerEngine::message(this->plugin,QString("Configuring UART, speed =%1").arg(this->uartSpeed),3);
APB UART PLUGIN rework in progress;
r28 rs232setup(this->uart,8,this->uartSpeed,rs232parityNo,rs232OneStop);
uartOpened = true;
}
Jeandet Alexis
APBUART Working, need some cosmetic now.
r29 uartMutex->unlock();
APB UART PLUGIN rework in progress;
r28 return uartOpened;
Jeandet Alexis
Removed lppserial from ahbuart now uses the one provided by socexplorercommon.
r27 }
APB UART PLUGIN rework in progress;
r28
void UARTPollingThread::closeUart()
{
uartMutex->lock();
rs232close(this->uart);
uartOpened = false;
uartMutex->unlock();
}
void UARTPollingThread::setPortName(QString name)
{
Jeandet Alexis
APBUART Working, need some cosmetic now.
r29 SocExplorerEngine::message(this->plugin,"Changing UART port Name: "+name,3);
APB UART PLUGIN rework in progress;
r28 this->portName = name;
}
void UARTPollingThread::setPortSpeedStr(QString speed)
{
Jeandet Alexis
APBUART Working, need some cosmetic now.
r29 SocExplorerEngine::message(this->plugin,"Changing UART speed: "+speed,3);
APB UART PLUGIN rework in progress;
r28 this->uartSpeed = speed.toInt();
}
void UARTPollingThread::setPortSpeed(int speed)
{
Jeandet Alexis
APBUART Working, need some cosmetic now.
r29 SocExplorerEngine::message(this->plugin,QString("Changing UART speed: %1").arg(speed),3);
APB UART PLUGIN rework in progress;
r28 this->uartSpeed = speed;
}
void UARTPollingThread::setFifoDebugEable(bool enable)
{
if(enable)
SocExplorerEngine::message(this->plugin,"Enabling APB UART FIFO debug mode",3);
else
SocExplorerEngine::message(this->plugin,"Disabling APB UART FIFO debug mode",3);
if(uartOpened && enable)
{
closeUart();
}
this->fifoDebugConfigured = false;
configFifoDebug(enable);
Removed APBUartPlugin bug (when switching between debug and non debug link)....
r34 this->p_fifoDebugEnabled = enable;
}
bool UARTPollingThread::fifoDebugEnabled()
{
return p_fifoDebugEnabled;
APB UART PLUGIN rework in progress;
r28 }
void UARTPollingThread::configFifoDebug(bool enable)
{
SocExplorerEngine::message(this->plugin,"Configuring APB UART in FIFO debug mode",3);
if(this->plugin->baseAddress()==-1)
{
this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0));
}
if(this->plugin->baseAddress()!=-1)
{
if(enable)
{
unsigned int ctrl_reg= 0x843;
this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
this->fifoDebugConfigured = true;
}
else
{
unsigned int ctrl_reg;
/* Firts get Control reg value*/
this->plugin->parent->Read(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
ctrl_reg = ctrl_reg & (~(1<<11));
this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
this->fifoDebugConfigured = true;
}
}
}