@@ -1,201 +1,201 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SocExplorer Software |
|
2 | -- This file is a part of the SocExplorer Software | |
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
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 <socexplorerengine.h> |
|
23 | #include <socexplorerengine.h> | |
24 |
|
24 | |||
25 | UARTPollingThread::UARTPollingThread(socexplorerplugin *parent) : |
|
25 | UARTPollingThread::UARTPollingThread(socexplorerplugin *parent) : | |
26 | QThread((QObject*)parent) |
|
26 | QThread((QObject*)parent) | |
27 | { |
|
27 | { | |
28 | this->plugin = parent; |
|
28 | this->plugin = parent; | |
29 | uartMutex = new QMutex(); |
|
29 | uartMutex = new QMutex(); | |
30 | uartOpened = false; |
|
30 | uartOpened = false; | |
31 | fifoDebugConfigured = false; |
|
31 | fifoDebugConfigured = false; | |
32 | fifoDebugEnabled = false; |
|
32 | fifoDebugEnabled = false; | |
33 | this->moveToThread(this); |
|
33 | this->moveToThread(this); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | UARTPollingThread::~UARTPollingThread() |
|
36 | UARTPollingThread::~UARTPollingThread() | |
37 | { |
|
37 | { | |
38 | this->requestInterruption(); |
|
38 | this->requestInterruption(); | |
39 | while(isRunning()); |
|
39 | while(isRunning()); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | void UARTPollingThread::run() |
|
42 | void UARTPollingThread::run() | |
43 | { |
|
43 | { | |
44 |
|
44 | |||
45 | SocExplorerEngine::message(this->plugin,"Entering APB UART polling thread",3); |
|
45 | SocExplorerEngine::message(this->plugin,"Entering APB UART polling thread",3); | |
46 | while (!this->isInterruptionRequested()) |
|
46 | while (!this->isInterruptionRequested()) | |
47 | { |
|
47 | { | |
48 | if(fifoDebugEnabled) |
|
48 | if(fifoDebugEnabled) | |
49 | { |
|
49 | { | |
50 | if(fifoDebugConfigured) |
|
50 | if(fifoDebugConfigured) | |
51 | { |
|
51 | { | |
52 | if(this->plugin->baseAddress()!=-1) |
|
52 | if(this->plugin->baseAddress()!=-1) | |
53 | { |
|
53 | { | |
54 | unsigned int status_reg,data; |
|
54 | unsigned int status_reg,data; | |
55 | char ch; |
|
55 | char ch; | |
56 | QString printdata=""; |
|
56 | QString printdata=""; | |
57 | plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG); |
|
57 | plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG); | |
58 | while ((status_reg&4)==0) { |
|
58 | while ((status_reg&4)==0) { | |
59 | plugin->parent->Read(&data,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG); |
|
59 | plugin->parent->Read(&data,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG); | |
60 | ch = (char)(0xff & data); |
|
60 | ch = (char)(0xff & data); | |
61 | printdata+=ch; |
|
61 | printdata+=ch; | |
62 | plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG); |
|
62 | plugin->parent->Read(&status_reg,1,this->plugin->baseAddress()+APB_UART_STATUS_REG); | |
63 | } |
|
63 | } | |
64 | if(printdata!="") |
|
64 | if(printdata!="") | |
65 | emit apbUartTextReceived(printdata); |
|
65 | emit apbUartTextReceived(printdata); | |
66 | } |
|
66 | } | |
67 | else |
|
67 | else | |
68 | { |
|
68 | { | |
69 | this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0)); |
|
69 | this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0)); | |
70 | } |
|
70 | } | |
71 | } |
|
71 | } | |
72 | else |
|
72 | else | |
73 | { |
|
73 | { | |
74 | configFifoDebug(true); |
|
74 | configFifoDebug(true); | |
75 | } |
|
75 | } | |
76 | } |
|
76 | } | |
77 | else |
|
77 | else | |
78 | { |
|
78 | { | |
79 | int read =0; |
|
79 | int read =0; | |
80 | char ch[1]; |
|
80 | char ch[1]; | |
81 | uartMutex->lock(); |
|
81 | uartMutex->lock(); | |
82 | if(uartOpened) |
|
82 | if(uartOpened) | |
83 | { |
|
83 | { | |
84 | read =rs232read(this->uart,ch,1); |
|
84 | read =rs232read(this->uart,ch,1); | |
85 | SocExplorerEngine::message(this->plugin,QString("Read %1 bytes on uart").arg(read),3); |
|
85 | SocExplorerEngine::message(this->plugin,QString("Read %1 bytes on uart").arg(read),3); | |
86 | } |
|
86 | } | |
87 | uartMutex->unlock(); |
|
87 | uartMutex->unlock(); | |
88 | if(read>=1) |
|
88 | if(read>=1) | |
89 | { |
|
89 | { | |
90 | SocExplorerEngine::message(this->plugin,QString("Received one char from APBUART"),3); |
|
90 | SocExplorerEngine::message(this->plugin,QString("Received one char from APBUART"),3); | |
91 | emit this->apbUartTextReceived(QString(ch[0])); |
|
91 | emit this->apbUartTextReceived(QString(ch[0])); | |
92 | } |
|
92 | } | |
93 | msleep(1); |
|
93 | msleep(10); | |
94 | } |
|
94 | } | |
95 | } |
|
95 | } | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void UARTPollingThread::sendChar(char c) |
|
98 | void UARTPollingThread::sendChar(char c) | |
99 | { |
|
99 | { | |
100 | if(fifoDebugEnabled) |
|
100 | if(fifoDebugEnabled) | |
101 | { |
|
101 | { | |
102 | if(this->plugin->baseAddress()!=-1) |
|
102 | if(this->plugin->baseAddress()!=-1) | |
103 | { |
|
103 | { | |
104 | unsigned int i=0x0FF & c; |
|
104 | unsigned int i=0x0FF & c; | |
105 | plugin->parent->Write(&i,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG); |
|
105 | plugin->parent->Write(&i,1,this->plugin->baseAddress()+APB_UART_FIFO_DEBUG_REG); | |
106 | } |
|
106 | } | |
107 | } |
|
107 | } | |
108 | else |
|
108 | else | |
109 | { |
|
109 | { | |
110 | uartMutex->lock(); |
|
110 | uartMutex->lock(); | |
111 | rs232write(this->uart,&c,1); |
|
111 | rs232write(this->uart,&c,1); | |
112 | uartMutex->unlock(); |
|
112 | uartMutex->unlock(); | |
113 | } |
|
113 | } | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | bool UARTPollingThread::openUart() |
|
116 | bool UARTPollingThread::openUart() | |
117 | { |
|
117 | { | |
118 | uartMutex->lock(); |
|
118 | uartMutex->lock(); | |
119 | if(uartOpened) |
|
119 | if(uartOpened) | |
120 | { |
|
120 | { | |
121 | closeUart(); |
|
121 | closeUart(); | |
122 | } |
|
122 | } | |
123 | SocExplorerEngine::message(this->plugin,"Opening UART "+this->portName,3); |
|
123 | SocExplorerEngine::message(this->plugin,"Opening UART "+this->portName,3); | |
124 | this->uart = rs232open((char*)this->portName.toStdString().c_str()); |
|
124 | this->uart = rs232open((char*)this->portName.toStdString().c_str()); | |
125 | if(this->uart!=badPortValue) |
|
125 | if(this->uart!=badPortValue) | |
126 | { |
|
126 | { | |
127 | SocExplorerEngine::message(this->plugin,QString("Configuring UART, speed =%1").arg(this->uartSpeed),3); |
|
127 | SocExplorerEngine::message(this->plugin,QString("Configuring UART, speed =%1").arg(this->uartSpeed),3); | |
128 | rs232setup(this->uart,8,this->uartSpeed,rs232parityNo,rs232OneStop); |
|
128 | rs232setup(this->uart,8,this->uartSpeed,rs232parityNo,rs232OneStop); | |
129 | uartOpened = true; |
|
129 | uartOpened = true; | |
130 | } |
|
130 | } | |
131 | uartMutex->unlock(); |
|
131 | uartMutex->unlock(); | |
132 | return uartOpened; |
|
132 | return uartOpened; | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | void UARTPollingThread::closeUart() |
|
135 | void UARTPollingThread::closeUart() | |
136 | { |
|
136 | { | |
137 | uartMutex->lock(); |
|
137 | uartMutex->lock(); | |
138 | rs232close(this->uart); |
|
138 | rs232close(this->uart); | |
139 | uartOpened = false; |
|
139 | uartOpened = false; | |
140 | uartMutex->unlock(); |
|
140 | uartMutex->unlock(); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void UARTPollingThread::setPortName(QString name) |
|
143 | void UARTPollingThread::setPortName(QString name) | |
144 | { |
|
144 | { | |
145 | SocExplorerEngine::message(this->plugin,"Changing UART port Name: "+name,3); |
|
145 | SocExplorerEngine::message(this->plugin,"Changing UART port Name: "+name,3); | |
146 | this->portName = name; |
|
146 | this->portName = name; | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | void UARTPollingThread::setPortSpeedStr(QString speed) |
|
149 | void UARTPollingThread::setPortSpeedStr(QString speed) | |
150 | { |
|
150 | { | |
151 | SocExplorerEngine::message(this->plugin,"Changing UART speed: "+speed,3); |
|
151 | SocExplorerEngine::message(this->plugin,"Changing UART speed: "+speed,3); | |
152 | this->uartSpeed = speed.toInt(); |
|
152 | this->uartSpeed = speed.toInt(); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void UARTPollingThread::setPortSpeed(int speed) |
|
155 | void UARTPollingThread::setPortSpeed(int speed) | |
156 | { |
|
156 | { | |
157 | SocExplorerEngine::message(this->plugin,QString("Changing UART speed: %1").arg(speed),3); |
|
157 | SocExplorerEngine::message(this->plugin,QString("Changing UART speed: %1").arg(speed),3); | |
158 | this->uartSpeed = speed; |
|
158 | this->uartSpeed = speed; | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void UARTPollingThread::setFifoDebugEable(bool enable) |
|
161 | void UARTPollingThread::setFifoDebugEable(bool enable) | |
162 | { |
|
162 | { | |
163 | if(enable) |
|
163 | if(enable) | |
164 | SocExplorerEngine::message(this->plugin,"Enabling APB UART FIFO debug mode",3); |
|
164 | SocExplorerEngine::message(this->plugin,"Enabling APB UART FIFO debug mode",3); | |
165 | else |
|
165 | else | |
166 | SocExplorerEngine::message(this->plugin,"Disabling APB UART FIFO debug mode",3); |
|
166 | SocExplorerEngine::message(this->plugin,"Disabling APB UART FIFO debug mode",3); | |
167 | if(uartOpened && enable) |
|
167 | if(uartOpened && enable) | |
168 | { |
|
168 | { | |
169 | closeUart(); |
|
169 | closeUart(); | |
170 | } |
|
170 | } | |
171 | this->fifoDebugConfigured = false; |
|
171 | this->fifoDebugConfigured = false; | |
172 | configFifoDebug(enable); |
|
172 | configFifoDebug(enable); | |
173 | this->fifoDebugEnabled = enable; |
|
173 | this->fifoDebugEnabled = enable; | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void UARTPollingThread::configFifoDebug(bool enable) |
|
176 | void UARTPollingThread::configFifoDebug(bool enable) | |
177 | { |
|
177 | { | |
178 | SocExplorerEngine::message(this->plugin,"Configuring APB UART in FIFO debug mode",3); |
|
178 | SocExplorerEngine::message(this->plugin,"Configuring APB UART in FIFO debug mode",3); | |
179 | if(this->plugin->baseAddress()==-1) |
|
179 | if(this->plugin->baseAddress()==-1) | |
180 | { |
|
180 | { | |
181 | this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0)); |
|
181 | this->plugin->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this->plugin,this->plugin->VID(),this->plugin->PID(),0)); | |
182 | } |
|
182 | } | |
183 | if(this->plugin->baseAddress()!=-1) |
|
183 | if(this->plugin->baseAddress()!=-1) | |
184 | { |
|
184 | { | |
185 | if(enable) |
|
185 | if(enable) | |
186 | { |
|
186 | { | |
187 | unsigned int ctrl_reg= 0x843; |
|
187 | unsigned int ctrl_reg= 0x843; | |
188 | this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG); |
|
188 | this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG); | |
189 | this->fifoDebugConfigured = true; |
|
189 | this->fifoDebugConfigured = true; | |
190 | } |
|
190 | } | |
191 | else |
|
191 | else | |
192 | { |
|
192 | { | |
193 | unsigned int ctrl_reg; |
|
193 | unsigned int ctrl_reg; | |
194 | /* Firts get Control reg value*/ |
|
194 | /* Firts get Control reg value*/ | |
195 | this->plugin->parent->Read(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG); |
|
195 | this->plugin->parent->Read(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG); | |
196 | ctrl_reg = ctrl_reg & (~(1<<11)); |
|
196 | ctrl_reg = ctrl_reg & (~(1<<11)); | |
197 | this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG); |
|
197 | this->plugin->parent->Write(&ctrl_reg,1,this->plugin->baseAddress()+APB_UART_CONTROL_REG); | |
198 | this->fifoDebugConfigured = true; |
|
198 | this->fifoDebugConfigured = true; | |
199 | } |
|
199 | } | |
200 | } |
|
200 | } | |
201 | } |
|
201 | } |
@@ -1,467 +1,471 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SocExplorer Software |
|
2 | -- This file is a part of the SocExplorer Software | |
3 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr |
|
20 | -- Mail : alexis.jeandet@lpp.polytechnique.fr | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include <socexplorerengine.h> |
|
22 | #include <socexplorerengine.h> | |
23 | #include "ahbuartplugin.h" |
|
23 | #include "ahbuartplugin.h" | |
24 | #include <unistd.h> |
|
24 | #include <unistd.h> | |
25 | #include <errno.h> |
|
25 | #include <errno.h> | |
26 | #include <QApplication> |
|
26 | #include <QApplication> | |
27 | #include <QProgressBar> |
|
27 | #include <QProgressBar> | |
28 | #include <stdio.h> |
|
28 | #include <stdio.h> | |
29 | #include <QThread> |
|
29 | #include <QThread> | |
30 | #include "ahbuartpywrapper.h" |
|
30 | #include "ahbuartpywrapper.h" | |
31 | #include <QCompleter> |
|
31 | #include <QCompleter> | |
32 | #include <QStringList> |
|
32 | #include <QStringList> | |
33 | #include <QLineEdit> |
|
33 | #include <QLineEdit> | |
34 | #include <socexplorerproxy.h> |
|
34 | #include <socexplorerproxy.h> | |
35 |
|
35 | |||
36 | ahbuartplugin::ahbuartplugin(QWidget *parent):socexplorerplugin(parent,false) |
|
36 | ahbuartplugin::ahbuartplugin(QWidget *parent):socexplorerplugin(parent,false) | |
37 | { |
|
37 | { | |
38 | this->port =(rs232port_t)NULL; |
|
38 | this->port =(rs232port_t)NULL; | |
39 | this->portMutex = new QMutex(QMutex::Recursive); |
|
39 | this->portMutex = new QMutex(QMutex::Recursive); | |
40 | this->UI = new ahbUartPluginUI(); |
|
40 | this->UI = new ahbUartPluginUI(); | |
41 | this->setWidget((QWidget*)this->UI); |
|
41 | this->setWidget((QWidget*)this->UI); | |
42 | QObject::connect(this,SIGNAL(activateSig(bool)),this->UI,SLOT(setConnected(bool))); |
|
42 | QObject::connect(this,SIGNAL(activateSig(bool)),this->UI,SLOT(setConnected(bool))); | |
43 | QObject::connect(this->UI,SIGNAL(connectPortsig(QString,int)),this,SLOT(togglePort(QString,int))); |
|
43 | QObject::connect(this->UI,SIGNAL(connectPortsig(QString,int)),this,SLOT(togglePort(QString,int))); | |
44 | this->pyObject = new ahbuartPywrapper(this); |
|
44 | this->pyObject = new ahbuartPywrapper(this); | |
45 | QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(open(QString,int)),this,SLOT(open(QString,int))); |
|
45 | QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(open(QString,int)),this,SLOT(open(QString,int))); | |
46 | QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(close()),this,SLOT(close())); |
|
46 | QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(close()),this,SLOT(close())); | |
47 | QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(ReadBytes(uint,uint)),this,SLOT(ReadBytes(uint,uint))); |
|
47 | QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(ReadBytes(uint,uint)),this,SLOT(ReadBytes(uint,uint))); | |
48 | QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(WriteBytes(uint,QList<QVariant>)),this,SLOT(WriteBytes(uint,QList<QVariant>))); |
|
48 | QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(WriteBytes(uint,QList<QVariant>)),this,SLOT(WriteBytes(uint,QList<QVariant>))); | |
49 | QObject::connect(this->UI,SIGNAL(rescanPorts()),this,SLOT(updatePortList())); |
|
49 | QObject::connect(this->UI,SIGNAL(rescanPorts()),this,SLOT(updatePortList())); | |
50 | this->portListcompleter = NULL; |
|
50 | this->portListcompleter = NULL; | |
51 | this->scanDone = false; |
|
51 | this->scanDone = false; | |
52 | updatePortList(); |
|
52 | updatePortList(); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | ahbuartplugin::~ahbuartplugin() |
|
56 | ahbuartplugin::~ahbuartplugin() | |
57 | { |
|
57 | { | |
58 | if(this->port!=(rs232port_t)NULL) |
|
58 | if(this->port!=(rs232port_t)NULL) | |
59 | { |
|
59 | { | |
60 | rs232close(this->port); |
|
60 | rs232close(this->port); | |
61 | this->port = (rs232port_t)NULL; |
|
61 | this->port = (rs232port_t)NULL; | |
62 | } |
|
62 | } | |
63 | this->UI->close(); |
|
63 | this->UI->close(); | |
64 | this->UI->~ahbUartPluginUI(); |
|
64 | this->UI->~ahbUartPluginUI(); | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 |
|
67 | |||
68 | void ahbuartplugin::closeMe() |
|
68 | void ahbuartplugin::closeMe() | |
69 | { |
|
69 | { | |
70 | if(this->port!=(rs232port_t)NULL) |
|
70 | if(this->port!=(rs232port_t)NULL) | |
71 | { |
|
71 | { | |
72 | rs232close(this->port); |
|
72 | rs232close(this->port); | |
73 | this->port = (rs232port_t)NULL; |
|
73 | this->port = (rs232port_t)NULL; | |
74 | } |
|
74 | } | |
75 | emit this->closePlugin(this); |
|
75 | emit this->closePlugin(this); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | int ahbuartplugin::registermenu(QMainWindow *menuHolder) |
|
78 | int ahbuartplugin::registermenu(QMainWindow *menuHolder) | |
79 | { |
|
79 | { | |
80 | this->menu = menuHolder->menuBar()->addMenu(tr("&AHB UART")); |
|
80 | this->menu = menuHolder->menuBar()->addMenu(tr("&AHB UART")); | |
81 | this->closeAction = this->menu->addAction(tr("Close plugin")); |
|
81 | this->closeAction = this->menu->addAction(tr("Close plugin")); | |
82 | QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe())); |
|
82 | QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe())); | |
83 | return 1; |
|
83 | return 1; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 |
|
86 | |||
87 |
|
87 | |||
88 |
|
88 | |||
89 | bool ahbuartplugin::checkConnection() |
|
89 | bool ahbuartplugin::checkConnection() | |
90 | { |
|
90 | { | |
91 | QTime timeout; |
|
91 | QTime timeout; | |
92 | char test[5] ={(char)0x80,(char)0x80,(char)0,(char)0,(char)0}; |
|
92 | char test[5] ={(char)0x80,(char)0x80,(char)0,(char)0,(char)0}; | |
93 | char test2[1024]; |
|
93 | char test2[1024]; | |
94 | int writen =0; |
|
94 | int writen =0; | |
95 | int read = 0; |
|
95 | int read = 0; | |
96 | timeout.start(); |
|
96 | timeout.start(); | |
97 | SocExplorerEngine::message(this,"Check connection",2); |
|
97 | SocExplorerEngine::message(this,"Check connection",2); | |
|
98 | QMutexLocker lock(portMutex); | |||
98 | while(writen!=5) |
|
99 | while(writen!=5) | |
99 | { |
|
100 | { | |
100 | writen+=rs232write(this->port,test+writen,5-writen); |
|
101 | writen+=rs232write(this->port,test+writen,5-writen); | |
101 | if(timeout.elapsed()>1000) |
|
102 | if(timeout.elapsed()>1000) | |
102 | { |
|
103 | { | |
103 | SocExplorerEngine::message(this,"Can't write any data on serial port",2); |
|
104 | SocExplorerEngine::message(this,"Can't write any data on serial port",2); | |
104 | return false; |
|
105 | return false; | |
105 | } |
|
106 | } | |
106 | } |
|
107 | } | |
107 | #ifdef WIN32 |
|
108 | #ifdef WIN32 | |
108 | usleep(1000); |
|
109 | usleep(1000); | |
109 | #endif |
|
110 | #endif | |
110 | timeout.restart(); |
|
111 | timeout.restart(); | |
111 | while(read!=4) |
|
112 | while(read!=4) | |
112 | { |
|
113 | { | |
113 | read += rs232read(this->port,test2,4-read); |
|
114 | read += rs232read(this->port,test2,4-read); | |
114 | if(timeout.elapsed()>1000) break; |
|
115 | if(timeout.elapsed()>1000) break; | |
115 | } |
|
116 | } | |
116 | if(read>0) |
|
117 | if(read>0) | |
117 | { |
|
118 | { | |
118 | SocExplorerEngine::message(this,"Connection Ok",2); |
|
119 | SocExplorerEngine::message(this,"Connection Ok",2); | |
119 | return true; |
|
120 | return true; | |
120 | } |
|
121 | } | |
121 | else |
|
122 | else | |
122 | { |
|
123 | { | |
123 | SocExplorerEngine::message(this,"Connection Error",2); |
|
124 | SocExplorerEngine::message(this,"Connection Error",2); | |
124 | return false; |
|
125 | return false; | |
125 | } |
|
126 | } | |
126 |
|
127 | |||
127 | } |
|
128 | } | |
128 |
|
129 | |||
129 | void ahbuartplugin::connectPort(QString PortName, int baudrate) |
|
130 | void ahbuartplugin::connectPort(QString PortName, int baudrate) | |
130 | { |
|
131 | { | |
131 | QTime timeout; |
|
132 | QTime timeout; | |
132 | SocExplorerEngine::message(this,"Try to connect to port "+PortName,2); |
|
133 | SocExplorerEngine::message(this,"Try to connect to port "+PortName,2); | |
133 | timeout.start(); |
|
134 | timeout.start(); | |
|
135 | QMutexLocker lock(portMutex); | |||
134 | if(this->port==(rs232port_t)NULL) |
|
136 | if(this->port==(rs232port_t)NULL) | |
135 | { |
|
137 | { | |
136 | SocExplorerEngine::message(this,"Open port "+PortName,2); |
|
138 | SocExplorerEngine::message(this,"Open port "+PortName,2); | |
137 | this->port=rs232open((char*)PortName.toStdString().c_str()); |
|
139 | this->port=rs232open((char*)PortName.toStdString().c_str()); | |
138 | } |
|
140 | } | |
139 | if(this->port!=badPortValue) |
|
141 | if(this->port!=badPortValue) | |
140 | { |
|
142 | { | |
141 | SocExplorerEngine::message(this,"Port opened "+PortName,2); |
|
143 | SocExplorerEngine::message(this,"Port opened "+PortName,2); | |
142 | SocExplorerEngine::message(this,"Configure port "+PortName,2); |
|
144 | SocExplorerEngine::message(this,"Configure port "+PortName,2); | |
143 | rs232setup(this->port,8,baudrate,rs232parityNo,rs232OneStop); |
|
145 | rs232setup(this->port,8,baudrate,rs232parityNo,rs232OneStop); | |
144 | char test[7] ={(char)0x55,(char)0x51,(char)0x80,(char)0x80,(char)0x0,(char)0x0,(char)0x14}; |
|
146 | char test[7] ={(char)0x55,(char)0x51,(char)0x80,(char)0x80,(char)0x0,(char)0x0,(char)0x14}; | |
145 | char test2[1024]; |
|
147 | char test2[1024]; | |
146 | SAFEWRITE(test,1,timeout,2000,return); |
|
148 | SAFEWRITE(test,1,timeout,2000,return); | |
147 | SAFEWRITE((test+1),1,timeout,2000,return); |
|
149 | SAFEWRITE((test+1),1,timeout,2000,return); | |
148 | APPENDTOLOG(QString("Flush port ")); |
|
150 | APPENDTOLOG(QString("Flush port ")); | |
149 | rs232read(this->port,test2,512); |
|
151 | rs232read(this->port,test2,512); | |
150 | int read = 0; |
|
152 | int read = 0; | |
151 | for(int i=0;i<10;i++) |
|
153 | for(int i=0;i<10;i++) | |
152 | { |
|
154 | { | |
153 | SocExplorerEngine::message(this,"Send test patern :0x55,0x55,0x80,0x80,0x0,0x0,0x14",2); |
|
155 | SocExplorerEngine::message(this,"Send test patern :0x55,0x55,0x80,0x80,0x0,0x0,0x14",2); | |
154 | SAFEWRITE(test+2,5,timeout,2000,return); |
|
156 | SAFEWRITE(test+2,5,timeout,2000,return); | |
155 | SocExplorerEngine::message(this,"Read Result",2); |
|
157 | SocExplorerEngine::message(this,"Read Result",2); | |
156 | read=rs232read(this->port,test2+read,16); |
|
158 | read=rs232read(this->port,test2+read,16); | |
157 | SocExplorerEngine::message(this,QString("Get ") + QString::number(read) + " bytes",2); |
|
159 | SocExplorerEngine::message(this,QString("Get ") + QString::number(read) + " bytes",2); | |
158 | if(read>0) |
|
160 | if(read>0) | |
159 | { |
|
161 | { | |
160 | SocExplorerEngine::message(this,"Flush port ",2); |
|
162 | SocExplorerEngine::message(this,"Flush port ",2); | |
161 | while(rs232read(this->port,test2,1)>0); |
|
163 | while(rs232read(this->port,test2,1)>0); | |
162 | this->Connected = true; |
|
164 | this->Connected = true; | |
163 | SocExplorerEngine::message(this,QString("Connection success on ")+PortName,2); |
|
165 | SocExplorerEngine::message(this,QString("Connection success on ")+PortName,2); | |
164 | emit this->activate(true); |
|
166 | emit this->activate(true); | |
165 | if(this->scanDone==false) |
|
167 | if(this->scanDone==false) | |
166 | { |
|
168 | { | |
167 | socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN"); |
|
169 | socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN"); | |
168 | this->scanDone=true; |
|
170 | this->scanDone=true; | |
169 | } |
|
171 | } | |
170 | break; |
|
172 | break; | |
171 | } |
|
173 | } | |
172 | } |
|
174 | } | |
173 | } |
|
175 | } | |
174 | else |
|
176 | else | |
175 | { |
|
177 | { | |
176 | SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2); |
|
178 | SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2); | |
177 | this->port = (rs232port_t)NULL; |
|
179 | this->port = (rs232port_t)NULL; | |
178 | this->Connected = false; |
|
180 | this->Connected = false; | |
179 | emit this->activateSig(false); |
|
181 | emit this->activateSig(false); | |
180 | return; |
|
182 | return; | |
181 | } |
|
183 | } | |
182 | if(this->Connected == false) |
|
184 | if(this->Connected == false) | |
183 | { |
|
185 | { | |
184 | SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2); |
|
186 | SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2); | |
185 | rs232close(this->port); |
|
187 | rs232close(this->port); | |
186 | this->port = (rs232port_t)NULL; |
|
188 | this->port = (rs232port_t)NULL; | |
187 | emit this->activateSig(false); |
|
189 | emit this->activateSig(false); | |
188 | } |
|
190 | } | |
189 |
|
191 | |||
190 | } |
|
192 | } | |
191 |
|
193 | |||
192 | bool ahbuartplugin::open(QString PortName,int baudrate) |
|
194 | bool ahbuartplugin::open(QString PortName,int baudrate) | |
193 | { |
|
195 | { | |
194 | if(this->port!=(rs232port_t)NULL) |
|
196 | if(this->port!=(rs232port_t)NULL) | |
195 | this->close(); |
|
197 | this->close(); | |
196 | this->UI->setconfig(PortName,baudrate); |
|
198 | this->UI->setconfig(PortName,baudrate); | |
197 | this->connectPort(PortName,baudrate); |
|
199 | this->connectPort(PortName,baudrate); | |
198 | return (this->port!=(rs232port_t)NULL); |
|
200 | return (this->port!=(rs232port_t)NULL); | |
199 | } |
|
201 | } | |
200 |
|
202 | |||
201 | void ahbuartplugin::close() |
|
203 | void ahbuartplugin::close() | |
202 | { |
|
204 | { | |
203 | if(this->port!=(rs232port_t)NULL) |
|
205 | if(this->port!=(rs232port_t)NULL) | |
204 | { |
|
206 | { | |
205 | rs232close(this->port); |
|
207 | rs232close(this->port); | |
206 | this->port = (rs232port_t)NULL; |
|
208 | this->port = (rs232port_t)NULL; | |
207 | this->Connected = false; |
|
209 | this->Connected = false; | |
208 | emit this->activateSig(false); |
|
210 | emit this->activateSig(false); | |
209 | } |
|
211 | } | |
210 | } |
|
212 | } | |
211 |
|
213 | |||
212 | void ahbuartplugin::togglePort(QString PortName,int baudrate) |
|
214 | void ahbuartplugin::togglePort(QString PortName,int baudrate) | |
213 | { |
|
215 | { | |
214 | if(this->port!=(rs232port_t)NULL) |
|
216 | if(this->port!=(rs232port_t)NULL) | |
215 | { |
|
217 | { | |
216 | this->close(); |
|
218 | this->close(); | |
217 | } |
|
219 | } | |
218 | else |
|
220 | else | |
219 | { |
|
221 | { | |
220 | this->connectPort(PortName,baudrate); |
|
222 | this->connectPort(PortName,baudrate); | |
221 | } |
|
223 | } | |
222 | } |
|
224 | } | |
223 |
|
225 | |||
224 |
|
226 | |||
225 | unsigned int ahbuartplugin::Read(unsigned int *Value,unsigned int count,unsigned int address) |
|
227 | unsigned int ahbuartplugin::Read(unsigned int *Value,unsigned int count,unsigned int address) | |
226 | { |
|
228 | { | |
227 | QTime timeout; |
|
229 | QTime timeout; | |
228 | timeout.start(); |
|
230 | timeout.start(); | |
229 | unsigned int read=0; |
|
231 | unsigned int read=0; | |
230 | unsigned int cnt=count; |
|
232 | unsigned int cnt=count; | |
231 | unsigned int nextUpdateTrig=0,updateStep=512; |
|
233 | unsigned int nextUpdateTrig=0,updateStep=512; | |
232 | SocExplorerEngine::message(this,QString("Read ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2); |
|
234 | SocExplorerEngine::message(this,QString("Read ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2); | |
233 | if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL)) |
|
235 | if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL)) | |
234 | { |
|
236 | { | |
235 | if(!this->portMutex->tryLock()) |
|
237 | QMutexLocker lock(portMutex); | |
236 | return 0; |
|
238 | // if(!this->portMutex->tryLock()) | |
|
239 | // return 0; | |||
237 | if(!this->checkConnection()) |
|
240 | if(!this->checkConnection()) | |
238 | { |
|
241 | { | |
239 | this->Connected = false; |
|
242 | this->Connected = false; | |
240 | emit this->activateSig(false); |
|
243 | emit this->activateSig(false); | |
241 | this->portMutex->unlock(); |
|
244 | this->portMutex->unlock(); | |
242 | return 0; |
|
245 | return 0; | |
243 | } |
|
246 | } | |
244 | QProgressBar* progress=NULL; |
|
247 | QProgressBar* progress=NULL; | |
245 | if(cnt>128) |
|
248 | if(cnt>128) | |
246 | progress= SocExplorerEngine::getProgressBar("Reading on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count); |
|
249 | progress= SocExplorerEngine::getProgressBar("Reading on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count); | |
247 | char CMD[5]; |
|
250 | char CMD[5]; | |
248 | char* result = (char*)malloc(count*4); |
|
251 | char* result = (char*)malloc(count*4); | |
249 | while(count>32) |
|
252 | while(count>32) | |
250 | { |
|
253 | { | |
251 | CMD[0] = 0x80 | (32-1); |
|
254 | CMD[0] = 0x80 | (32-1); | |
252 | CMD[1] = (char)((address>>24)&0xFF); |
|
255 | CMD[1] = (char)((address>>24)&0xFF); | |
253 | CMD[2] = (char)((address>>16)&0xFF); |
|
256 | CMD[2] = (char)((address>>16)&0xFF); | |
254 | CMD[3] = (char)((address>>8)&0xFF); |
|
257 | CMD[3] = (char)((address>>8)&0xFF); | |
255 | CMD[4] = (char)((address)&0xFF); |
|
258 | CMD[4] = (char)((address)&0xFF); | |
256 | // APENDTABLETOLOG(CMD,5,logmessage,"Write CMD : "); |
|
259 | // APENDTABLETOLOG(CMD,5,logmessage,"Write CMD : "); | |
257 | SAFEWRITE(CMD,5,timeout,1000,return 0); |
|
260 | SAFEWRITE(CMD,5,timeout,1000,return 0); | |
258 | #ifdef WIN32 |
|
261 | #ifdef WIN32 | |
259 | usleep(1000); |
|
262 | usleep(1000); | |
260 | #endif |
|
263 | #endif | |
261 | SAFEREAD(result+((cnt-count)*4),32*4,timeout,1000,return 0); |
|
264 | SAFEREAD(result+((cnt-count)*4),32*4,timeout,1000,return 0); | |
262 | // APENDTABLETOLOG((result+((cnt-count)*4)),32*4,logmessage, QString("Get ") + QString::number(32*4) + " Bytes : "); |
|
265 | // APENDTABLETOLOG((result+((cnt-count)*4)),32*4,logmessage, QString("Get ") + QString::number(32*4) + " Bytes : "); | |
263 | count-=32; |
|
266 | count-=32; | |
264 | address+=32*4; |
|
267 | address+=32*4; | |
265 | if(cnt>128) |
|
268 | if(cnt>128) | |
266 | { |
|
269 | { | |
267 |
|
270 | |||
268 | if((cnt-count)>=nextUpdateTrig) |
|
271 | if((cnt-count)>=nextUpdateTrig) | |
269 | { |
|
272 | { | |
270 | progress->setValue(cnt-count); |
|
273 | progress->setValue(cnt-count); | |
271 | qApp->processEvents(); |
|
274 | qApp->processEvents(); | |
272 | nextUpdateTrig+=updateStep; |
|
275 | nextUpdateTrig+=updateStep; | |
273 | } |
|
276 | } | |
274 | } |
|
277 | } | |
275 | } |
|
278 | } | |
276 | if(count>0) |
|
279 | if(count>0) | |
277 | { |
|
280 | { | |
278 | CMD[0] = 0x80 | (count-1); |
|
281 | CMD[0] = 0x80 | (count-1); | |
279 | CMD[1] = (char)((address>>24)&0xFF); |
|
282 | CMD[1] = (char)((address>>24)&0xFF); | |
280 | CMD[2] = (char)((address>>16)&0xFF); |
|
283 | CMD[2] = (char)((address>>16)&0xFF); | |
281 | CMD[3] = (char)((address>>8)&0xFF); |
|
284 | CMD[3] = (char)((address>>8)&0xFF); | |
282 | CMD[4] = (char)((address)&0xFF); |
|
285 | CMD[4] = (char)((address)&0xFF); | |
283 | SAFEWRITE(CMD,5,timeout,1000,return 0); |
|
286 | SAFEWRITE(CMD,5,timeout,1000,return 0); | |
284 | #ifdef WIN32 |
|
287 | #ifdef WIN32 | |
285 | usleep(1000); |
|
288 | usleep(1000); | |
286 | #endif |
|
289 | #endif | |
287 | SAFEREAD(result+((cnt-count)*4),(count*4),timeout,1000,return 0); |
|
290 | SAFEREAD(result+((cnt-count)*4),(count*4),timeout,1000,return 0); | |
288 | // APENDTABLETOLOG((result+((cnt-count)*4)),(count*4),logmessage, QString("Get ") + QString::number(32*4) + " Bytes : "); |
|
291 | // APENDTABLETOLOG((result+((cnt-count)*4)),(count*4),logmessage, QString("Get ") + QString::number(32*4) + " Bytes : "); | |
289 | } |
|
292 | } | |
290 | if(cnt>128) |
|
293 | if(cnt>128) | |
291 | { |
|
294 | { | |
292 | progress->setValue(cnt-count); |
|
295 | progress->setValue(cnt-count); | |
293 | qApp->processEvents(); |
|
296 | qApp->processEvents(); | |
294 | } |
|
297 | } | |
295 | for(int i=0;(unsigned int)i<cnt;i++) |
|
298 | for(int i=0;(unsigned int)i<cnt;i++) | |
296 | { |
|
299 | { | |
297 | for(int j =0;j<4;j++) |
|
300 | for(int j =0;j<4;j++) | |
298 | { |
|
301 | { | |
299 | Value[i]= ((unsigned char)(result[i*4+j])) + Value[i]*256; |
|
302 | Value[i]= ((unsigned char)(result[i*4+j])) + Value[i]*256; | |
300 | } |
|
303 | } | |
301 | read = cnt*4; |
|
304 | read = cnt*4; | |
302 |
|
305 | |||
303 | } |
|
306 | } | |
304 | if(cnt>128) |
|
307 | if(cnt>128) | |
305 | SocExplorerEngine::deleteProgressBar(progress); |
|
308 | SocExplorerEngine::deleteProgressBar(progress); | |
306 | free(result); |
|
309 | free(result); | |
307 | this->portMutex->unlock(); |
|
310 | // this->portMutex->unlock(); | |
308 | } |
|
311 | } | |
309 | return read/4; |
|
312 | return read/4; | |
310 | } |
|
313 | } | |
311 |
|
314 | |||
312 | unsigned int ahbuartplugin::Write(unsigned int *Value,unsigned int count, unsigned int address) |
|
315 | unsigned int ahbuartplugin::Write(unsigned int *Value,unsigned int count, unsigned int address) | |
313 | { |
|
316 | { | |
314 | QTime timeout; |
|
317 | QTime timeout; | |
315 | timeout.start(); |
|
318 | timeout.start(); | |
316 | unsigned int writen=0; |
|
319 | unsigned int writen=0; | |
317 | unsigned int nextUpdateTrig=0,updateStep=512; |
|
320 | unsigned int nextUpdateTrig=0,updateStep=512; | |
318 | SocExplorerEngine::message(this,QString("Write ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2); |
|
321 | SocExplorerEngine::message(this,QString("Write ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2); | |
319 | if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL)) |
|
322 | if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL)) | |
320 | { |
|
323 | { | |
321 | if(!this->portMutex->tryLock()) |
|
324 | QMutexLocker lock(portMutex); | |
322 | return 0; |
|
325 | // if(!this->portMutex->tryLock()) | |
|
326 | // return 0; | |||
323 | if(!this->checkConnection()) |
|
327 | if(!this->checkConnection()) | |
324 | { |
|
328 | { | |
325 | emit this->activateSig(false); |
|
329 | emit this->activateSig(false); | |
326 | this->Connected = false; |
|
330 | this->Connected = false; | |
327 | this->portMutex->unlock(); |
|
331 | this->portMutex->unlock(); | |
328 | return 0; |
|
332 | return 0; | |
329 | } |
|
333 | } | |
330 | QProgressBar* progress = NULL; |
|
334 | QProgressBar* progress = NULL; | |
331 | if(count>128) |
|
335 | if(count>128) | |
332 | progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count); |
|
336 | progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count); | |
333 | int offset = 0; |
|
337 | int offset = 0; | |
334 | char* CMD= (char*)malloc((32*4)+5); |
|
338 | char* CMD= (char*)malloc((32*4)+5); | |
335 | while(count>32) |
|
339 | while(count>32) | |
336 | { |
|
340 | { | |
337 | writen=0; |
|
341 | writen=0; | |
338 | CMD[0] = 0xC0 | (32-1); |
|
342 | CMD[0] = 0xC0 | (32-1); | |
339 | CMD[1] = (char)(((unsigned int)address>>24)&0xFF); |
|
343 | CMD[1] = (char)(((unsigned int)address>>24)&0xFF); | |
340 | CMD[2] = (char)(((unsigned int)address>>16)&0xFF); |
|
344 | CMD[2] = (char)(((unsigned int)address>>16)&0xFF); | |
341 | CMD[3] = (char)(((unsigned int)address>>8)&0xFF); |
|
345 | CMD[3] = (char)(((unsigned int)address>>8)&0xFF); | |
342 | CMD[4] = (char)(((unsigned int)address)&0xFF); |
|
346 | CMD[4] = (char)(((unsigned int)address)&0xFF); | |
343 | for(int i=0;i<32;i++) |
|
347 | for(int i=0;i<32;i++) | |
344 | { |
|
348 | { | |
345 | CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF); |
|
349 | CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF); | |
346 | CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF); |
|
350 | CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF); | |
347 | CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF); |
|
351 | CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF); | |
348 | CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF); |
|
352 | CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF); | |
349 | } |
|
353 | } | |
350 | SAFEWRITE(CMD,((32*4)+5),timeout,1000,return 0); |
|
354 | SAFEWRITE(CMD,((32*4)+5),timeout,1000,return 0); | |
351 | writen+=32; |
|
355 | writen+=32; | |
352 | count-=32; |
|
356 | count-=32; | |
353 | offset+=32; |
|
357 | offset+=32; | |
354 | address+=32*4; |
|
358 | address+=32*4; | |
355 | if(offset>=nextUpdateTrig && progress!=NULL) |
|
359 | if(offset>=nextUpdateTrig && progress!=NULL) | |
356 | { |
|
360 | { | |
357 | progress->setValue(offset); |
|
361 | progress->setValue(offset); | |
358 | qApp->processEvents(); |
|
362 | qApp->processEvents(); | |
359 | nextUpdateTrig +=updateStep; |
|
363 | nextUpdateTrig +=updateStep; | |
360 | } |
|
364 | } | |
361 |
|
365 | |||
362 | } |
|
366 | } | |
363 | if(count>0) |
|
367 | if(count>0) | |
364 | { |
|
368 | { | |
365 | CMD[0] = 0xC0 | (count-1); |
|
369 | CMD[0] = 0xC0 | (count-1); | |
366 | CMD[1] = (char)(((unsigned int)address>>24)&0xFF); |
|
370 | CMD[1] = (char)(((unsigned int)address>>24)&0xFF); | |
367 | CMD[2] = (char)(((unsigned int)address>>16)&0xFF); |
|
371 | CMD[2] = (char)(((unsigned int)address>>16)&0xFF); | |
368 | CMD[3] = (char)(((unsigned int)address>>8)&0xFF); |
|
372 | CMD[3] = (char)(((unsigned int)address>>8)&0xFF); | |
369 | CMD[4] = (char)(((unsigned int)address)&0xFF); |
|
373 | CMD[4] = (char)(((unsigned int)address)&0xFF); | |
370 | for(int i=0;(unsigned int) i<(count);i++) |
|
374 | for(int i=0;(unsigned int) i<(count);i++) | |
371 | { |
|
375 | { | |
372 | CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF); |
|
376 | CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF); | |
373 | CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF); |
|
377 | CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF); | |
374 | CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF); |
|
378 | CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF); | |
375 | CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF); |
|
379 | CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF); | |
376 | } |
|
380 | } | |
377 | SAFEWRITE(CMD,((count*4)+5),timeout,1000,return 0); |
|
381 | SAFEWRITE(CMD,((count*4)+5),timeout,1000,return 0); | |
378 | writen+=count; |
|
382 | writen+=count; | |
379 | } |
|
383 | } | |
380 | if(progress!=NULL) |
|
384 | if(progress!=NULL) | |
381 | { |
|
385 | { | |
382 | progress->setValue(writen); |
|
386 | progress->setValue(writen); | |
383 | qApp->processEvents(); |
|
387 | qApp->processEvents(); | |
384 | SocExplorerEngine::deleteProgressBar(progress); |
|
388 | SocExplorerEngine::deleteProgressBar(progress); | |
385 | } |
|
389 | } | |
386 | free(CMD); |
|
390 | free(CMD); | |
387 | this->portMutex->unlock(); |
|
391 | // this->portMutex->unlock(); | |
388 | return writen; |
|
392 | return writen; | |
389 | } |
|
393 | } | |
390 | return 0; |
|
394 | return 0; | |
391 | } |
|
395 | } | |
392 |
|
396 | |||
393 |
|
397 | |||
394 |
|
398 | |||
395 |
|
399 | |||
396 | void ahbuartplugin::updatePortList() |
|
400 | void ahbuartplugin::updatePortList() | |
397 | { |
|
401 | { | |
398 | if(this->portListcompleter==(QCompleter*)NULL) |
|
402 | if(this->portListcompleter==(QCompleter*)NULL) | |
399 | { |
|
403 | { | |
400 | this->portListcompleter=new QCompleter(this); |
|
404 | this->portListcompleter=new QCompleter(this); | |
401 | this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive); |
|
405 | this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive); | |
402 | this->portListcompleterModel = new QStringListModel(this); |
|
406 | this->portListcompleterModel = new QStringListModel(this); | |
403 | this->portListcompleter->setModel(this->portListcompleterModel); |
|
407 | this->portListcompleter->setModel(this->portListcompleterModel); | |
404 | this->UI->setCompleter(this->portListcompleter); |
|
408 | this->UI->setCompleter(this->portListcompleter); | |
405 | } |
|
409 | } | |
406 | rs232portslist_t* portlist = rs232getportlist(); |
|
410 | rs232portslist_t* portlist = rs232getportlist(); | |
407 | rs232portslist_t* portlistenum = portlist; |
|
411 | rs232portslist_t* portlistenum = portlist; | |
408 | QStringList wordList; |
|
412 | QStringList wordList; | |
409 | while(portlistenum!=NULL) |
|
413 | while(portlistenum!=NULL) | |
410 | { |
|
414 | { | |
411 | wordList << portlistenum->name; |
|
415 | wordList << portlistenum->name; | |
412 | portlistenum = portlistenum->next; |
|
416 | portlistenum = portlistenum->next; | |
413 | } |
|
417 | } | |
414 | rs232deleteportlist(portlist); |
|
418 | rs232deleteportlist(portlist); | |
415 | this->portListcompleterModel->setStringList(wordList); |
|
419 | this->portListcompleterModel->setStringList(wordList); | |
416 | } |
|
420 | } | |
417 |
|
421 | |||
418 | QVariantList ahbuartplugin::ReadBytes(unsigned int address, unsigned int count) |
|
422 | QVariantList ahbuartplugin::ReadBytes(unsigned int address, unsigned int count) | |
419 | { |
|
423 | { | |
420 | unsigned int data[(count/4)+1]; |
|
424 | unsigned int data[(count/4)+1]; | |
421 | QVariantList result; |
|
425 | QVariantList result; | |
422 | this->Read(data,(count/4)+1,address); |
|
426 | this->Read(data,(count/4)+1,address); | |
423 | for(unsigned int i = 0;i<count/4;i++) |
|
427 | for(unsigned int i = 0;i<count/4;i++) | |
424 | { |
|
428 | { | |
425 | result.append(QVariant((int)(0x0FF&(data[i]>>24)))); |
|
429 | result.append(QVariant((int)(0x0FF&(data[i]>>24)))); | |
426 | result.append(QVariant((int)(0x0FF&(data[i]>>16)))); |
|
430 | result.append(QVariant((int)(0x0FF&(data[i]>>16)))); | |
427 | result.append(QVariant((int)(0x0FF&(data[i]>>8)))); |
|
431 | result.append(QVariant((int)(0x0FF&(data[i]>>8)))); | |
428 | result.append(QVariant((int)(0x0FF&(data[i])))); |
|
432 | result.append(QVariant((int)(0x0FF&(data[i])))); | |
429 | } |
|
433 | } | |
430 |
|
434 | |||
431 | for(int i=0;i<(count%4);i++) |
|
435 | for(int i=0;i<(count%4);i++) | |
432 | { |
|
436 | { | |
433 | result.append(QVariant((int)(0x0FF&(data[count/4]>>((3-i)*8))))); |
|
437 | result.append(QVariant((int)(0x0FF&(data[count/4]>>((3-i)*8))))); | |
434 | } |
|
438 | } | |
435 |
|
439 | |||
436 | return result; |
|
440 | return result; | |
437 | } |
|
441 | } | |
438 |
|
442 | |||
439 | void ahbuartplugin::WriteBytes(unsigned int address, QList<QVariant> dataList) |
|
443 | void ahbuartplugin::WriteBytes(unsigned int address, QList<QVariant> dataList) | |
440 | { |
|
444 | { | |
441 | unsigned int data[dataList.count()/4]; |
|
445 | unsigned int data[dataList.count()/4]; | |
442 | for(int i = 0;i<(dataList.count()/4);i++) |
|
446 | for(int i = 0;i<(dataList.count()/4);i++) | |
443 | { |
|
447 | { | |
444 | data[i] = 0x0FF & ((unsigned int)dataList.at(4*i).toUInt()); |
|
448 | data[i] = 0x0FF & ((unsigned int)dataList.at(4*i).toUInt()); | |
445 | data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+1).toUInt())); |
|
449 | data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+1).toUInt())); | |
446 | data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+2).toUInt())); |
|
450 | data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+2).toUInt())); | |
447 | data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+3).toUInt())); |
|
451 | data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+3).toUInt())); | |
448 | } |
|
452 | } | |
449 | this->Write(data,dataList.count()/4,address); |
|
453 | this->Write(data,dataList.count()/4,address); | |
450 | } |
|
454 | } | |
451 |
|
455 | |||
452 |
|
456 | |||
453 |
|
457 | |||
454 |
|
458 | |||
455 |
|
459 | |||
456 |
|
460 | |||
457 |
|
461 | |||
458 |
|
462 | |||
459 |
|
463 | |||
460 |
|
464 | |||
461 |
|
465 | |||
462 |
|
466 | |||
463 |
|
467 | |||
464 |
|
468 | |||
465 |
|
469 | |||
466 |
|
470 | |||
467 |
|
471 |
General Comments 0
You need to be logged in to leave comments.
Login now