##// END OF EJS Templates
APB UART PLUGIN rework in progress;
jeandet -
r28:0f22f4cfd076 default
parent child
Show More
@@ -1,199 +1,102
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "APBUARTPLUGIN.h"
23 23 #include <socexplorerengine.h>
24 24
25 25 ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent)
26 26 {
27 this->setBaseAddress(-1);
27 28 this->UI = new APBUART_Plugin_ui();
28 29 this->setWidget((QWidget*)this->UI);
29 this->useLoopBack = false;
30 this->uartConnected = false;
31 this->UartThread = new UARTPollingThread(this);
30 32 connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int)));
31 connect(this,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
32 connect(&this->loopBackTimer,SIGNAL(timeout()),this,SLOT(uartReadout()));
33 connect(this->UartThread,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
34 connect(this->UI,SIGNAL(connectPort()),this,SLOT(toggleUartState()));
35 connect(this->UI,SIGNAL(sendChar(char)),this->UartThread,SLOT(sendChar(char)));
36 connect(this->UI,SIGNAL(PortNameChanged(QString)),this->UartThread,SLOT(setPortName(QString)));
37 connect(this->UI,SIGNAL(UartSpeedChanged(QString)),this->UartThread,SLOT(setPortSpeedStr(QString)));
38 this->UartThread->start();
33 39 }
34 40
35 41
36 42 ApbUartPlugin::~ApbUartPlugin()
37 43 {
38 44
39 45 }
40 46
41 47 void ApbUartPlugin::closeMe()
42 48 {
43 49 emit this->closePlugin(this);
44 50 }
45 51
46 void ApbUartPlugin::postInstantiationTrigger()
52 void ApbUartPlugin::toggleUartState()
47 53 {
48 if(this->isEnabled())
54 if(!uartConnected)
49 55 {
50 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
51 loopbackChangeState(Qt::Checked);
56 uartConnected = this->UartThread->openUart();
52 57 }
58 else
59 {
60 this->UartThread->closeUart();
61 this->uartConnected = false;
62 }
63 this->UI->setUartConnected(uartConnected);
53 64 }
54 65
55 66 void ApbUartPlugin::loopbackChangeState(int state)
56 67 {
57 68 if(state==Qt::Checked)
58 69 {
59 enableLoopback();
70 this->UI->setEnableForLoopBack(false);
71 this->UartThread->setFifoDebugEable(true);
60 72 }
61 73 else
62 74 {
63 disableLoopback();
64 }
65 }
66
67 void ApbUartPlugin::uartReadout()
68 {
69 #ifdef WIN32
70 int readcnt=0;
71 #endif
72 if(this->isEnabled() && parent!=NULL)
73 {
74 if(this->useLoopBack)
75 {
76 if(this->baseAddress()!=-1)
77 {
78 this->loopBackTimer.stop();
79 unsigned int status_reg,data;
80 char ch;
81 QString printdata="";
82 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
83 while ((status_reg&4)==0) {
84 parent->Read(&data,1,this->baseAddress()+APB_UART_FIFO_DEBUG_REG);
85 ch = (char)(0xff & data);
86 printdata+=ch;
87 #ifdef WIN32
88 readcnt++;
89 if(readcnt>=32)
90 {
91 qApp->processEvents();
92 break;
93 }
94 #endif
95 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
96 }
97 if(printdata!="")
98 emit apbUartTextReceived(printdata);
99 this->loopBackTimer.start(200);
100 }
101 else
102 {
103 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
104 this->enableLoopback();
105 }
106 }
107 }
108 }
109
110 void ApbUartPlugin::activate(bool flag)
111 {
112 this->setEnabled(flag);
113 emit this->activateSig(flag);
114 if(this->isEnabled())
115 {this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
116
117 loopbackChangeState(Qt::Checked);
75 this->UI->setEnableForLoopBack(true);
76 this->UartThread->setFifoDebugEable(false);
118 77 }
119 78 }
120 79
121 void ApbUartPlugin::activateScan(bool flag)
122 {
123 if(flag)
124 this->loopBackTimer.start(200);
125 else
126 this->loopBackTimer.stop();
127 }
128
129 int ApbUartPlugin::enableLoopback()
130 {
131
132 this->useLoopBack = true;
133 this->loopBackTimer.start(200);
134 SocExplorerEngine::message(this,"Set FiFo debug mode mode");
135 if(parent==NULL)
136 {
137 SocExplorerEngine::message(this,"Can't set FiFo debug mode no parent driver accessible");
138 return -1;
139 }
140 if(this->baseAddress()==-1)
141 {
142 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
143 if(this->baseAddress()==-1)
144 return -1;
145 }
146 unsigned int ctrl_reg= 0x843;
147 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
148 this->UI->setEnableForLoopBack(false);
149 return 0;
150 }
151
152 int ApbUartPlugin::disableLoopback()
153 {
154 SocExplorerEngine::message(this,"Disable FiFo debug mode mode");
155 if(parent==NULL)
156 {
157 SocExplorerEngine::message(this,"Can't disable FiFo debug mode no parent driver accessible");
158 return -1;
159 }
160 if(this->baseAddress()==-1)
161 {
162 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
163 if(this->baseAddress()==-1)
164 return -1;
165 }
166 unsigned int ctrl_reg;
167 this->loopBackTimer.stop();
168 /* Firts get Control reg value*/
169 parent->Read(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
170 ctrl_reg = ctrl_reg & (~(1<<11));
171 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
172 this->useLoopBack = false;
173 this->UI->setEnableForLoopBack(true);
174 return 0;
175 }
176
177 80
178 81 unsigned int ApbUartPlugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
179 82 {
180 83 if(parent!=NULL)
181 84 return parent->Read(Value,count,address);
182 85 return 0;
183 86 }
184 87
185 88
186 89 unsigned int ApbUartPlugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
187 90 {
188 91 if(parent!=NULL)
189 92 return parent->Write(Value,count,address);
190 93 return 0;
191 94 }
192 95
193 96
194 97
195 98
196 99
197 100
198 101
199 102
@@ -1,68 +1,65
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef APBUARTPLUGIN_H
23 23 #define APBUARTPLUGIN_H
24 24 #include <QMenuBar>
25 25 #include <QMenu>
26 26 #include <QAction>
27 27 #include <QLayout>
28 28
29 29 #include <socexplorerplugin.h>
30 30 #include <QTimer>
31 31 #include "apbuart_plugin_ui.h"
32 32 #include "uartpollingthread.h"
33 33 #define APB_UART_DATA_REG 0x0
34 34 #define APB_UART_STATUS_REG 0x4
35 35 #define APB_UART_CONTROL_REG 0x8
36 36 #define APB_UART_SCALE_REG 0xC
37 37 #define APB_UART_FIFO_DEBUG_REG 0x10
38 38
39 39 class ApbUartPlugin : public socexplorerplugin
40 40 {
41 41 Q_OBJECT
42 42 public:
43 43 explicit ApbUartPlugin(QWidget *parent = 0);
44 44 ~ApbUartPlugin();
45 45 int VID(){return driver_VID;}
46 46 int PID(){return driver_PID;}
47 47
48 48 public slots:
49 49 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
50 50 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
51 void loopbackChangeState(int state);
51 52 void closeMe();
52 void postInstantiationTrigger();
53 void loopbackChangeState( int state );
54 void uartReadout();
55 void activateScan(bool flag);
56 void activate(bool flag);
53 void toggleUartState();
57 54 signals:
58 void apbUartTextReceived(QString text);
55
59 56 private:
60 57 APBUART_Plugin_ui* UI;
61 bool useLoopBack;
62 QTimer loopBackTimer;
58 bool uartConnected;
59 UARTPollingThread* UartThread;
63 60 int enableLoopback();
64 61 int disableLoopback();
65 62 };
66 63
67 64 #endif // APBUARTPLUGIN_H
68 65
@@ -1,44 +1,64
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "apbuart_plugin_ui.h"
23 23 #include "ui_apbuart_plugin_ui.h"
24 #include "apbuartterminal.h"
24 25
25 26 APBUART_Plugin_ui::APBUART_Plugin_ui(QWidget *parent) :
26 27 QWidget(parent),
27 28 ui(new Ui::APBUART_Plugin_ui)
28 29 {
29 30 ui->setupUi(this);
30 31 connect(this->ui->FIFODebugChkBx,SIGNAL(stateChanged(int)),this,SIGNAL(loopbackChkBxStateChanged(int)));
31 32 connect(this,SIGNAL(apbUartTextReceived(QString)),this->ui->UART_TERM,SLOT(append(QString)));
33 connect(this->ui->ConnectQpb,SIGNAL(clicked()),this,SIGNAL(connectPort()));
34 connect(this->ui->UART_TERM,SIGNAL(sendChar(char)),this,SIGNAL(sendChar(char)));
35 connect(this->ui->PortNameLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(PortNameChanged(QString)));
36 connect(this->ui->UartSpeedLineEdit,SIGNAL(textChanged(QString)),this,SIGNAL(UartSpeedChanged(QString)));
32 37 }
33 38
34 39 APBUART_Plugin_ui::~APBUART_Plugin_ui()
35 40 {
36 41 delete ui;
37 42 }
38 43
39 44 void APBUART_Plugin_ui::setEnableForLoopBack(bool enable)
40 45 {
41 46 this->ui->PortNameLineEdit->setEnabled(enable);
42 47 this->ui->ConnectQpb->setEnabled(enable);
43 48 this->ui->UartSpeedLineEdit->setEnabled(enable);
44 49 }
50
51 void APBUART_Plugin_ui::setUartConnected(bool enable)
52 {
53 this->ui->PortNameLineEdit->setDisabled(enable);
54 this->ui->UartSpeedLineEdit->setDisabled(enable);
55 this->ui->FIFODebugChkBx->setDisabled(enable);
56 if(enable)
57 {
58 this->ui->ConnectQpb->setText("Close Port");
59 }
60 else
61 {
62 this->ui->ConnectQpb->setText("Open Port");
63 }
64 }
@@ -1,49 +1,53
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef APBUART_PLUGIN_UI_H
23 23 #define APBUART_PLUGIN_UI_H
24 24
25 25 #include <QWidget>
26 26
27 27 namespace Ui {
28 28 class APBUART_Plugin_ui;
29 29 }
30 30
31 31 class APBUART_Plugin_ui : public QWidget
32 32 {
33 33 Q_OBJECT
34 34
35 35 public:
36 36 explicit APBUART_Plugin_ui(QWidget *parent = 0);
37 37 ~APBUART_Plugin_ui();
38 38
39 39 public slots:
40 40 void setEnableForLoopBack(bool enable);
41 void setUartConnected(bool enable);
41 42 signals:
42 43 void loopbackChkBxStateChanged( int state );
43 44 void apbUartTextReceived(QString text);
44
45 void connectPort();
46 void sendChar(char c);
47 void UartSpeedChanged(QString text);
48 void PortNameChanged(QString text);
45 49 private:
46 50 Ui::APBUART_Plugin_ui *ui;
47 51 };
48 52
49 53 #endif // APBUART_PLUGIN_UI_H
@@ -1,82 +1,89
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>APBUART_Plugin_ui</class>
4 4 <widget class="QWidget" name="APBUART_Plugin_ui">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>400</width>
10 10 <height>300</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 16 <layout class="QVBoxLayout" name="verticalLayout">
17 17 <item>
18 18 <widget class="QTabWidget" name="TabWidget">
19 19 <property name="currentIndex">
20 <number>0</number>
20 <number>1</number>
21 21 </property>
22 22 <widget class="QWidget" name="Config">
23 23 <attribute name="title">
24 24 <string>Configuration</string>
25 25 </attribute>
26 26 <layout class="QGridLayout" name="gridLayout">
27 27 <item row="1" column="1">
28 28 <widget class="QLineEdit" name="PortNameLineEdit"/>
29 29 </item>
30 30 <item row="0" column="0" colspan="2">
31 31 <widget class="QCheckBox" name="FIFODebugChkBx">
32 32 <property name="text">
33 33 <string>Enable FIFO debug mode</string>
34 34 </property>
35 35 <property name="checked">
36 36 <bool>true</bool>
37 37 </property>
38 38 </widget>
39 39 </item>
40 40 <item row="1" column="0">
41 41 <widget class="QLabel" name="PortNameLbl">
42 42 <property name="text">
43 43 <string>Port Name</string>
44 44 </property>
45 45 </widget>
46 46 </item>
47 47 <item row="3" column="0">
48 48 <widget class="QLabel" name="UartSpeedLbl">
49 49 <property name="text">
50 50 <string>Uart Speed</string>
51 51 </property>
52 52 </widget>
53 53 </item>
54 54 <item row="4" column="1">
55 55 <widget class="QPushButton" name="ConnectQpb">
56 56 <property name="text">
57 57 <string>Open Port</string>
58 58 </property>
59 59 </widget>
60 60 </item>
61 61 <item row="3" column="1">
62 62 <widget class="QLineEdit" name="UartSpeedLineEdit"/>
63 63 </item>
64 64 </layout>
65 65 </widget>
66 66 <widget class="QWidget" name="Terminal">
67 67 <attribute name="title">
68 68 <string>Terminal</string>
69 69 </attribute>
70 70 <layout class="QVBoxLayout" name="verticalLayout_2">
71 71 <item>
72 <widget class="QTextEdit" name="UART_TERM"/>
72 <widget class="ApbUartTerminal" name="UART_TERM"/>
73 73 </item>
74 74 </layout>
75 75 </widget>
76 76 </widget>
77 77 </item>
78 78 </layout>
79 79 </widget>
80 <customwidgets>
81 <customwidget>
82 <class>ApbUartTerminal</class>
83 <extends>QTextEdit</extends>
84 <header>apbuartterminal.h</header>
85 </customwidget>
86 </customwidgets>
80 87 <resources/>
81 88 <connections/>
82 89 </ui>
@@ -1,28 +1,35
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "apbuartterminal.h"
23 23
24 24 ApbUartTerminal::ApbUartTerminal(QWidget *parent) :
25 25 QTextEdit(parent)
26 26 {
27 27 connect(this,SIGNAL(apbUartTextReceived(QString)),this,SLOT(append(QString)));
28 setReadOnly(true);
28 29 }
30
31 void ApbUartTerminal::keyPressEvent(QKeyEvent *e)
32 {
33 emit this->sendChar((char)e->key());
34 e->accept();
35 }
@@ -1,41 +1,45
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef APBUARTTERMINAL_H
23 23 #define APBUARTTERMINAL_H
24 24
25 25 #include <QWidget>
26 26 #include <QTextEdit>
27
27 #include <QKeyEvent>
28 28
29 29 class ApbUartTerminal : public QTextEdit
30 30 {
31 31 Q_OBJECT
32 32 public:
33 33 explicit ApbUartTerminal(QWidget *parent = 0);
34
34
35 protected:
36 void keyPressEvent(QKeyEvent * e);
37
35 38 signals:
36 39 void apbUartTextReceived(QString text);
40 void sendChar(char c);
37 41 public slots:
38
42
39 43 };
40 44
41 45 #endif // APBUARTTERMINAL_H
@@ -1,70 +1,185
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "uartpollingthread.h"
23 #include <RS232.h>
24 23 #include <socexplorerengine.h>
25 24
26 25 UARTPollingThread::UARTPollingThread(socexplorerplugin *parent) :
27 26 QThread((QObject*)parent)
28 27 {
29 28 this->plugin = parent;
30 rs232open("/dev/ttyUS0");
29 uartMutex = new QMutex();
30 uartOpened = false;
31 fifoDebugConfigured = false;
32 this->moveToThread(this);
31 33 }
32 34
33 35 void UARTPollingThread::run()
34 36 {
37
38 SocExplorerEngine::message(this->plugin,"Entering APB UART polling thread",3);
35 39 while (!this->isInterruptionRequested())
36 40 {
37 41 if(fifoDebugEnabled)
38 42 {
39 if(this->plugin->baseAddress()!=-1)
43 if(fifoDebugConfigured)
40 44 {
41 unsigned int status_reg,data;
42 char ch;
43 QString printdata="";
44 plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG);
45 while ((status_reg&4)==0) {
46 plugin->parent->Read(&data,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG);
47 ch = (char)(0xff & data);
48 printdata+=ch;
45 if(this->plugin->baseAddress()!=-1)
46 {
47 unsigned int status_reg,data;
48 char ch;
49 QString printdata="";
49 50 plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG);
51 while ((status_reg&4)==0) {
52 plugin->parent->Read(&data,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG);
53 ch = (char)(0xff & data);
54 printdata+=ch;
55 plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG);
56 }
57 if(printdata!="")
58 emit apbUartTextReceived(printdata);
50 59 }
51 if(printdata!="")
52 emit apbUartTextReceived(printdata);
60 else
61 {
62 this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0));
63 }
53 64 }
54 65 else
55 66 {
56 this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0));
67 configFifoDebug(true);
57 68 }
58 69 }
59 if(uartOpened)
70 else
60 71 {
61
72 int read =0;
73 char ch;
74 uartMutex->lock();
75 if(uartOpened)
76 {
77 read =rs232read(this->uart,&ch,1);
78 }
79 uartMutex->unlock();
80 if(read==1)
81 {
82 emit this->sendChar(ch);
83 }
62 84 }
63 85 msleep(100);
64 86 }
65 87 }
66 88
67 89 void UARTPollingThread::sendChar(char c)
68 90 {
91 if(fifoDebugEnabled)
92 {
93 if(this->plugin->baseAddress()!=-1)
94 {
95 unsigned int i=0x0FF & c;
96 plugin->parent->Write(&i,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG);
97 }
98 }
99 else
100 {
101 uartMutex->lock();
102 rs232write(this->uart,&c,1);
103 uartMutex->unlock();
104 }
105 }
69 106
107 bool UARTPollingThread::openUart()
108 {
109 if(uartOpened)
110 {
111 closeUart();
112 }
113 this->uart = rs232open((char*)this->portName.toStdString().c_str());
114 if(this->uart!=badPortValue)
115 {
116 rs232setup(this->uart,8,this->uartSpeed,rs232parityNo,rs232OneStop);
117 uartOpened = true;
118 }
119 return uartOpened;
70 120 }
121
122 void UARTPollingThread::closeUart()
123 {
124 uartMutex->lock();
125 rs232close(this->uart);
126 uartOpened = false;
127 uartMutex->unlock();
128 }
129
130 void UARTPollingThread::setPortName(QString name)
131 {
132 this->portName = name;
133 }
134
135 void UARTPollingThread::setPortSpeedStr(QString speed)
136 {
137 this->uartSpeed = speed.toInt();
138 }
139
140 void UARTPollingThread::setPortSpeed(int speed)
141 {
142 this->uartSpeed = speed;
143 }
144
145 void UARTPollingThread::setFifoDebugEable(bool enable)
146 {
147 if(enable)
148 SocExplorerEngine::message(this->plugin,"Enabling APB UART FIFO debug mode",3);
149 else
150 SocExplorerEngine::message(this->plugin,"Disabling APB UART FIFO debug mode",3);
151 if(uartOpened && enable)
152 {
153 closeUart();
154 }
155 this->fifoDebugConfigured = false;
156 configFifoDebug(enable);
157 this->fifoDebugEnabled = enable;
158 }
159
160 void UARTPollingThread::configFifoDebug(bool enable)
161 {
162 SocExplorerEngine::message(this->plugin,"Configuring APB UART in FIFO debug mode",3);
163 if(this->plugin->baseAddress()==-1)
164 {
165 this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0));
166 }
167 if(this->plugin->baseAddress()!=-1)
168 {
169 if(enable)
170 {
171 unsigned int ctrl_reg= 0x843;
172 this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
173 this->fifoDebugConfigured = true;
174 }
175 else
176 {
177 unsigned int ctrl_reg;
178 /* Firts get Control reg value*/
179 this->plugin->parent->Read(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
180 ctrl_reg = ctrl_reg & (~(1<<11));
181 this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG);
182 this->fifoDebugConfigured = true;
183 }
184 }
185 }
@@ -1,53 +1,65
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef UARTPOLLINGTHREAD_H
23 23 #define UARTPOLLINGTHREAD_H
24 24
25 25 #include <QObject>
26 26 #include <QThread>
27 27 #include <socexplorerplugin.h>
28 #include <RS232.h>
29 #include <QMutex>
28 30
29 31 #define APB_UART_DATA_REG 0x0
30 32 #define APB_UART_STATUS_REG 0x4
31 33 #define APB_UART_CONTROL_REG 0x8
32 34 #define APB_UART_SCALE_REG 0xC
33 35 #define APB_UART_FIFO_DEBUG_REG 0x10
34 36
35 37 class UARTPollingThread : public QThread
36 38 {
37 39 Q_OBJECT
38 40 public:
39 41 explicit UARTPollingThread(socexplorerplugin *parent = 0);
40 42 void run();
41 43 signals:
42 44 void apbUartTextReceived(QString text);
43 45 public slots:
44 46 void sendChar(char c);
47 bool openUart();
48 void closeUart();
49 void setPortName(QString name);
50 void setPortSpeedStr(QString speed);
51 void setPortSpeed(int speed);
52 void setFifoDebugEable(bool enable);
45 53 private:
54 void configFifoDebug(bool enable);
46 55 bool fifoDebugEnabled;
56 bool fifoDebugConfigured;
47 57 QString portName;
48 58 int uartSpeed;
49 59 bool uartOpened;
50 60 socexplorerplugin* plugin;
61 rs232port_t uart;
62 QMutex* uartMutex;
51 63 };
52 64
53 65 #endif // UARTPOLLINGTHREAD_H
General Comments 0
You need to be logged in to leave comments. Login now