##// END OF EJS Templates
APB UART PLUGIN rework in progress;
jeandet -
r28:0f22f4cfd076 default
parent child
Show More
@@ -24,12 +24,18
24
24
25 ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent)
25 ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent)
26 {
26 {
27 this->setBaseAddress(-1);
27 this->UI = new APBUART_Plugin_ui();
28 this->UI = new APBUART_Plugin_ui();
28 this->setWidget((QWidget*)this->UI);
29 this->setWidget((QWidget*)this->UI);
29 this->useLoopBack = false;
30 this->uartConnected = false;
31 this->UartThread = new UARTPollingThread(this);
30 connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int)));
32 connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int)));
31 connect(this,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
33 connect(this->UartThread,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
32 connect(&this->loopBackTimer,SIGNAL(timeout()),this,SLOT(uartReadout()));
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
@@ -43,135 +49,32 void ApbUartPlugin::closeMe()
43 emit this->closePlugin(this);
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));
56 uartConnected = this->UartThread->openUart();
51 loopbackChangeState(Qt::Checked);
52 }
57 }
58 else
59 {
60 this->UartThread->closeUart();
61 this->uartConnected = false;
62 }
63 this->UI->setUartConnected(uartConnected);
53 }
64 }
54
65
55 void ApbUartPlugin::loopbackChangeState(int state)
66 void ApbUartPlugin::loopbackChangeState(int state)
56 {
67 {
57 if(state==Qt::Checked)
68 if(state==Qt::Checked)
58 {
69 {
59 enableLoopback();
70 this->UI->setEnableForLoopBack(false);
60 }
71 this->UartThread->setFifoDebugEable(true);
61 else
62 {
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 }
72 }
101 else
73 else
102 {
74 {
103 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
75 this->UI->setEnableForLoopBack(true);
104 this->enableLoopback();
76 this->UartThread->setFifoDebugEable(false);
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);
118 }
119 }
120
121 void ApbUartPlugin::activateScan(bool flag)
122 {
123 if(flag)
124 this->loopBackTimer.start(200);
125 else
126 this->loopBackTimer.stop();
127 }
77 }
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 }
78 }
176
79
177
80
@@ -48,18 +48,15 public:
48 public slots:
48 public slots:
49 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
49 unsigned int Write(unsigned int *Value,unsigned int count, unsigned int address=0);
50 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
50 unsigned int Read(unsigned int *Value,unsigned int count, unsigned int address=0);
51 void loopbackChangeState(int state);
51 void closeMe();
52 void closeMe();
52 void postInstantiationTrigger();
53 void toggleUartState();
53 void loopbackChangeState( int state );
54 void uartReadout();
55 void activateScan(bool flag);
56 void activate(bool flag);
57 signals:
54 signals:
58 void apbUartTextReceived(QString text);
55
59 private:
56 private:
60 APBUART_Plugin_ui* UI;
57 APBUART_Plugin_ui* UI;
61 bool useLoopBack;
58 bool uartConnected;
62 QTimer loopBackTimer;
59 UARTPollingThread* UartThread;
63 int enableLoopback();
60 int enableLoopback();
64 int disableLoopback();
61 int disableLoopback();
65 };
62 };
@@ -21,6 +21,7
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "apbuart_plugin_ui.h"
22 #include "apbuart_plugin_ui.h"
23 #include "ui_apbuart_plugin_ui.h"
23 #include "ui_apbuart_plugin_ui.h"
24 #include "apbuartterminal.h"
24
25
25 APBUART_Plugin_ui::APBUART_Plugin_ui(QWidget *parent) :
26 APBUART_Plugin_ui::APBUART_Plugin_ui(QWidget *parent) :
26 QWidget(parent),
27 QWidget(parent),
@@ -29,6 +30,10 APBUART_Plugin_ui::APBUART_Plugin_ui(QWi
29 ui->setupUi(this);
30 ui->setupUi(this);
30 connect(this->ui->FIFODebugChkBx,SIGNAL(stateChanged(int)),this,SIGNAL(loopbackChkBxStateChanged(int)));
31 connect(this->ui->FIFODebugChkBx,SIGNAL(stateChanged(int)),this,SIGNAL(loopbackChkBxStateChanged(int)));
31 connect(this,SIGNAL(apbUartTextReceived(QString)),this->ui->UART_TERM,SLOT(append(QString)));
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 APBUART_Plugin_ui::~APBUART_Plugin_ui()
39 APBUART_Plugin_ui::~APBUART_Plugin_ui()
@@ -42,3 +47,18 void APBUART_Plugin_ui::setEnableForLoop
42 this->ui->ConnectQpb->setEnabled(enable);
47 this->ui->ConnectQpb->setEnabled(enable);
43 this->ui->UartSpeedLineEdit->setEnabled(enable);
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 }
@@ -38,10 +38,14 public:
38
38
39 public slots:
39 public slots:
40 void setEnableForLoopBack(bool enable);
40 void setEnableForLoopBack(bool enable);
41 void setUartConnected(bool enable);
41 signals:
42 signals:
42 void loopbackChkBxStateChanged( int state );
43 void loopbackChkBxStateChanged( int state );
43 void apbUartTextReceived(QString text);
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 private:
49 private:
46 Ui::APBUART_Plugin_ui *ui;
50 Ui::APBUART_Plugin_ui *ui;
47 };
51 };
@@ -17,7 +17,7
17 <item>
17 <item>
18 <widget class="QTabWidget" name="TabWidget">
18 <widget class="QTabWidget" name="TabWidget">
19 <property name="currentIndex">
19 <property name="currentIndex">
20 <number>0</number>
20 <number>1</number>
21 </property>
21 </property>
22 <widget class="QWidget" name="Config">
22 <widget class="QWidget" name="Config">
23 <attribute name="title">
23 <attribute name="title">
@@ -69,7 +69,7
69 </attribute>
69 </attribute>
70 <layout class="QVBoxLayout" name="verticalLayout_2">
70 <layout class="QVBoxLayout" name="verticalLayout_2">
71 <item>
71 <item>
72 <widget class="QTextEdit" name="UART_TERM"/>
72 <widget class="ApbUartTerminal" name="UART_TERM"/>
73 </item>
73 </item>
74 </layout>
74 </layout>
75 </widget>
75 </widget>
@@ -77,6 +77,13
77 </item>
77 </item>
78 </layout>
78 </layout>
79 </widget>
79 </widget>
80 <customwidgets>
81 <customwidget>
82 <class>ApbUartTerminal</class>
83 <extends>QTextEdit</extends>
84 <header>apbuartterminal.h</header>
85 </customwidget>
86 </customwidgets>
80 <resources/>
87 <resources/>
81 <connections/>
88 <connections/>
82 </ui>
89 </ui>
@@ -25,4 +25,11 ApbUartTerminal::ApbUartTerminal(QWidget
25 QTextEdit(parent)
25 QTextEdit(parent)
26 {
26 {
27 connect(this,SIGNAL(apbUartTextReceived(QString)),this,SLOT(append(QString)));
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 }
@@ -24,7 +24,7
24
24
25 #include <QWidget>
25 #include <QWidget>
26 #include <QTextEdit>
26 #include <QTextEdit>
27
27 #include <QKeyEvent>
28
28
29 class ApbUartTerminal : public QTextEdit
29 class ApbUartTerminal : public QTextEdit
30 {
30 {
@@ -32,8 +32,12 class ApbUartTerminal : public QTextEdit
32 public:
32 public:
33 explicit ApbUartTerminal(QWidget *parent = 0);
33 explicit ApbUartTerminal(QWidget *parent = 0);
34
34
35 protected:
36 void keyPressEvent(QKeyEvent * e);
37
35 signals:
38 signals:
36 void apbUartTextReceived(QString text);
39 void apbUartTextReceived(QString text);
40 void sendChar(char c);
37 public slots:
41 public slots:
38
42
39 };
43 };
@@ -20,22 +20,28
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "uartpollingthread.h"
22 #include "uartpollingthread.h"
23 #include <RS232.h>
24 #include <socexplorerengine.h>
23 #include <socexplorerengine.h>
25
24
26 UARTPollingThread::UARTPollingThread(socexplorerplugin *parent) :
25 UARTPollingThread::UARTPollingThread(socexplorerplugin *parent) :
27 QThread((QObject*)parent)
26 QThread((QObject*)parent)
28 {
27 {
29 this->plugin = parent;
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 void UARTPollingThread::run()
35 void UARTPollingThread::run()
34 {
36 {
37
38 SocExplorerEngine::message(this->plugin,"Entering APB UART polling thread",3);
35 while (!this->isInterruptionRequested())
39 while (!this->isInterruptionRequested())
36 {
40 {
37 if(fifoDebugEnabled)
41 if(fifoDebugEnabled)
38 {
42 {
43 if(fifoDebugConfigured)
44 {
39 if(this->plugin->baseAddress()!=-1)
45 if(this->plugin->baseAddress()!=-1)
40 {
46 {
41 unsigned int status_reg,data;
47 unsigned int status_reg,data;
@@ -56,9 +62,25 void UARTPollingThread::run()
56 this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0));
62 this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0));
57 }
63 }
58 }
64 }
65 else
66 {
67 configFifoDebug(true);
68 }
69 }
70 else
71 {
72 int read =0;
73 char ch;
74 uartMutex->lock();
59 if(uartOpened)
75 if(uartOpened)
60 {
76 {
61
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 msleep(100);
85 msleep(100);
64 }
86 }
@@ -66,5 +88,98 void UARTPollingThread::run()
66
88
67 void UARTPollingThread::sendChar(char c)
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();
70 }
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;
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 }
@@ -25,6 +25,8
25 #include <QObject>
25 #include <QObject>
26 #include <QThread>
26 #include <QThread>
27 #include <socexplorerplugin.h>
27 #include <socexplorerplugin.h>
28 #include <RS232.h>
29 #include <QMutex>
28
30
29 #define APB_UART_DATA_REG 0x0
31 #define APB_UART_DATA_REG 0x0
30 #define APB_UART_STATUS_REG 0x4
32 #define APB_UART_STATUS_REG 0x4
@@ -42,12 +44,22 signals:
42 void apbUartTextReceived(QString text);
44 void apbUartTextReceived(QString text);
43 public slots:
45 public slots:
44 void sendChar(char c);
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 private:
53 private:
54 void configFifoDebug(bool enable);
46 bool fifoDebugEnabled;
55 bool fifoDebugEnabled;
56 bool fifoDebugConfigured;
47 QString portName;
57 QString portName;
48 int uartSpeed;
58 int uartSpeed;
49 bool uartOpened;
59 bool uartOpened;
50 socexplorerplugin* plugin;
60 socexplorerplugin* plugin;
61 rs232port_t uart;
62 QMutex* uartMutex;
51 };
63 };
52
64
53 #endif // UARTPOLLINGTHREAD_H
65 #endif // UARTPOLLINGTHREAD_H
General Comments 0
You need to be logged in to leave comments. Login now