##// END OF EJS Templates
An other Win32 dirty fix tentative.
Jeandet Alexis -
r5:15c638a85130 default
parent child
Show More
@@ -1,188 +1,199
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) 2013, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2013, Laboratory of Plasmas Physic - 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 "APBUARTPLUGIN.h"
22 #include "APBUARTPLUGIN.h"
23 #include <socexplorerengine.h>
23 #include <socexplorerengine.h>
24
24
25
25
26 ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent)
26 ApbUartPlugin::ApbUartPlugin(QWidget *parent):socexplorerplugin(parent)
27 {
27 {
28 this->UI = new ApbUartPluginUi();
28 this->UI = new ApbUartPluginUi();
29 this->setWindowTitle(tr("APBUART"));
29 this->setWindowTitle(tr("APBUART"));
30 this->setWidget((QWidget*)this->UI);
30 this->setWidget((QWidget*)this->UI);
31 this->useLoopBack = false;
31 this->useLoopBack = false;
32 connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int)));
32 connect(this->UI,SIGNAL(loopbackChkBxStateChanged(int)),this,SLOT(loopbackChangeState(int)));
33 connect(this,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
33 connect(this,SIGNAL(apbUartTextReceived(QString)),this->UI,SIGNAL(apbUartTextReceived(QString)));
34 connect(&this->loopBackTimer,SIGNAL(timeout()),this,SLOT(uartReadout()));
34 connect(&this->loopBackTimer,SIGNAL(timeout()),this,SLOT(uartReadout()));
35 }
35 }
36
36
37
37
38 ApbUartPlugin::~ApbUartPlugin()
38 ApbUartPlugin::~ApbUartPlugin()
39 {
39 {
40
40
41 }
41 }
42
42
43 void ApbUartPlugin::closeMe()
43 void ApbUartPlugin::closeMe()
44 {
44 {
45 emit this->closePlugin(this);
45 emit this->closePlugin(this);
46 }
46 }
47
47
48 void ApbUartPlugin::postInstantiationTrigger()
48 void ApbUartPlugin::postInstantiationTrigger()
49 {
49 {
50 if(this->isEnabled())
50 if(this->isEnabled())
51 {
51 {
52 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
52 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
53 loopbackChangeState(Qt::Checked);
53 loopbackChangeState(Qt::Checked);
54 }
54 }
55 }
55 }
56
56
57 void ApbUartPlugin::loopbackChangeState(int state)
57 void ApbUartPlugin::loopbackChangeState(int state)
58 {
58 {
59 if(state==Qt::Checked)
59 if(state==Qt::Checked)
60 {
60 {
61 enableLoopback();
61 enableLoopback();
62 }
62 }
63 else
63 else
64 {
64 {
65 disableLoopback();
65 disableLoopback();
66 }
66 }
67 }
67 }
68
68
69 void ApbUartPlugin::uartReadout()
69 void ApbUartPlugin::uartReadout()
70 {
70 {
71 #ifdef WIN32
72 int readcnt=0;
73 #endif
71 if(this->isEnabled() && parent!=NULL)
74 if(this->isEnabled() && parent!=NULL)
72 {
75 {
73 if(this->useLoopBack)
76 if(this->useLoopBack)
74 {
77 {
75 if(this->baseAddress()!=-1)
78 if(this->baseAddress()!=-1)
76 {
79 {
77 this->loopBackTimer.stop();
80 this->loopBackTimer.stop();
78 unsigned int status_reg,data;
81 unsigned int status_reg,data;
79 char ch;
82 char ch;
80 QString printdata="";
83 QString printdata="";
81 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
84 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
82 while ((status_reg&4)==0) {
85 while ((status_reg&4)==0) {
83 parent->Read(&data,1,this->baseAddress()+APB_UART_FIFO_DEBUG_REG);
86 parent->Read(&data,1,this->baseAddress()+APB_UART_FIFO_DEBUG_REG);
84 ch = (char)(0xff & data);
87 ch = (char)(0xff & data);
85 printdata+=ch;
88 printdata+=ch;
89 #ifdef WIN32
90 readcnt++;
91 if(readcnt>=32)
92 {
93 qApp->processEvents();
94 break;
95 }
96 #endif
86 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
97 parent->Read(&status_reg,1,this->baseAddress()+APB_UART_STATUS_REG);
87 }
98 }
88 if(printdata!="")
99 if(printdata!="")
89 emit apbUartTextReceived(printdata);
100 emit apbUartTextReceived(printdata);
90 this->loopBackTimer.start();
101 this->loopBackTimer.start(200);
91 }
102 }
92 else
103 else
93 {
104 {
94 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
105 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
95 this->enableLoopback();
106 this->enableLoopback();
96 }
107 }
97 }
108 }
98 }
109 }
99 }
110 }
100
111
101 void ApbUartPlugin::activate(bool flag)
112 void ApbUartPlugin::activate(bool flag)
102 {
113 {
103 this->setEnabled(flag);
114 this->setEnabled(flag);
104 emit this->activateSig(flag);
115 emit this->activateSig(flag);
105 if(this->isEnabled())
116 if(this->isEnabled())
106 {this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
117 {this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
107
118
108 loopbackChangeState(Qt::Checked);
119 loopbackChangeState(Qt::Checked);
109 }
120 }
110 }
121 }
111
122
112 void ApbUartPlugin::activateScan(bool flag)
123 void ApbUartPlugin::activateScan(bool flag)
113 {
124 {
114 if(flag)
125 if(flag)
115 this->loopBackTimer.start(200);
126 this->loopBackTimer.start(200);
116 else
127 else
117 this->loopBackTimer.stop();
128 this->loopBackTimer.stop();
118 }
129 }
119
130
120 int ApbUartPlugin::enableLoopback()
131 int ApbUartPlugin::enableLoopback()
121 {
132 {
122
133
123 this->useLoopBack = true;
134 this->useLoopBack = true;
124 this->loopBackTimer.start(200);
135 this->loopBackTimer.start(200);
125 SocExplorerEngine::message(this,"Set FiFo debug mode mode");
136 SocExplorerEngine::message(this,"Set FiFo debug mode mode");
126 if(parent==NULL)
137 if(parent==NULL)
127 {
138 {
128 SocExplorerEngine::message(this,"Can't set FiFo debug mode no parent driver accessible");
139 SocExplorerEngine::message(this,"Can't set FiFo debug mode no parent driver accessible");
129 return -1;
140 return -1;
130 }
141 }
131 if(this->baseAddress()==-1)
142 if(this->baseAddress()==-1)
132 {
143 {
133 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
144 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
134 if(this->baseAddress()==-1)
145 if(this->baseAddress()==-1)
135 return -1;
146 return -1;
136 }
147 }
137 unsigned int ctrl_reg= 0x843;
148 unsigned int ctrl_reg= 0x843;
138 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
149 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
139 return 0;
150 return 0;
140 }
151 }
141
152
142 int ApbUartPlugin::disableLoopback()
153 int ApbUartPlugin::disableLoopback()
143 {
154 {
144 SocExplorerEngine::message(this,"Disable FiFo debug mode mode");
155 SocExplorerEngine::message(this,"Disable FiFo debug mode mode");
145 if(parent==NULL)
156 if(parent==NULL)
146 {
157 {
147 SocExplorerEngine::message(this,"Can't disable FiFo debug mode no parent driver accessible");
158 SocExplorerEngine::message(this,"Can't disable FiFo debug mode no parent driver accessible");
148 return -1;
159 return -1;
149 }
160 }
150 if(this->baseAddress()==-1)
161 if(this->baseAddress()==-1)
151 {
162 {
152 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
163 this->setBaseAddress(SocExplorerEngine::self()->getEnumDeviceBaseAddress(this,this->VID(),this->PID(),0));
153 if(this->baseAddress()==-1)
164 if(this->baseAddress()==-1)
154 return -1;
165 return -1;
155 }
166 }
156 unsigned int ctrl_reg;
167 unsigned int ctrl_reg;
157 this->loopBackTimer.stop();
168 this->loopBackTimer.stop();
158 /* Firts get Control reg value*/
169 /* Firts get Control reg value*/
159 parent->Read(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
170 parent->Read(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
160 ctrl_reg = ctrl_reg & (~(1<<11));
171 ctrl_reg = ctrl_reg & (~(1<<11));
161 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
172 parent->Write(&ctrl_reg,1,this->baseAddress()+APB_UART_CONTROL_REG);
162 this->useLoopBack = false;
173 this->useLoopBack = false;
163 return 0;
174 return 0;
164 }
175 }
165
176
166
177
167 unsigned int ApbUartPlugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
178 unsigned int ApbUartPlugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
168 {
179 {
169 if(parent!=NULL)
180 if(parent!=NULL)
170 return parent->Read(Value,count,address);
181 return parent->Read(Value,count,address);
171 return 0;
182 return 0;
172 }
183 }
173
184
174
185
175 unsigned int ApbUartPlugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
186 unsigned int ApbUartPlugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
176 {
187 {
177 if(parent!=NULL)
188 if(parent!=NULL)
178 return parent->Write(Value,count,address);
189 return parent->Write(Value,count,address);
179 return 0;
190 return 0;
180 }
191 }
181
192
182
193
183
194
184
195
185
196
186
197
187
198
188
199
@@ -1,459 +1,468
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, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - 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 this->setWindowTitle(tr("AHB UART"));
42 this->setWindowTitle(tr("AHB UART"));
43 QObject::connect(this,SIGNAL(activateSig(bool)),this->UI,SLOT(setConnected(bool)));
43 QObject::connect(this,SIGNAL(activateSig(bool)),this->UI,SLOT(setConnected(bool)));
44 QObject::connect(this->UI,SIGNAL(connectPortsig(QString,int)),this,SLOT(togglePort(QString,int)));
44 QObject::connect(this->UI,SIGNAL(connectPortsig(QString,int)),this,SLOT(togglePort(QString,int)));
45 this->pyObject = new ahbuartPywrapper(this);
45 this->pyObject = new ahbuartPywrapper(this);
46 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(open(QString,int)),this,SLOT(open(QString,int)));
46 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(open(QString,int)),this,SLOT(open(QString,int)));
47 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(close()),this,SLOT(close()));
47 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(close()),this,SLOT(close()));
48 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(ReadBytes(uint,uint)),this,SLOT(ReadBytes(uint,uint)));
48 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(ReadBytes(uint,uint)),this,SLOT(ReadBytes(uint,uint)));
49 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(WriteBytes(uint,QList<QVariant>)),this,SLOT(WriteBytes(uint,QList<QVariant>)));
49 QObject::connect(((ahbuartPywrapper*)this->pyObject),SIGNAL(WriteBytes(uint,QList<QVariant>)),this,SLOT(WriteBytes(uint,QList<QVariant>)));
50 QObject::connect(this->UI,SIGNAL(rescanPorts()),this,SLOT(updatePortList()));
50 QObject::connect(this->UI,SIGNAL(rescanPorts()),this,SLOT(updatePortList()));
51 this->portListcompleter = NULL;
51 this->portListcompleter = NULL;
52 this->scanDone = false;
52 this->scanDone = false;
53 updatePortList();
53 updatePortList();
54 }
54 }
55
55
56
56
57 ahbuartplugin::~ahbuartplugin()
57 ahbuartplugin::~ahbuartplugin()
58 {
58 {
59 if(this->port!=(rs232port_t)NULL)
59 if(this->port!=(rs232port_t)NULL)
60 {
60 {
61 rs232close(this->port);
61 rs232close(this->port);
62 this->port = (rs232port_t)NULL;
62 this->port = (rs232port_t)NULL;
63 }
63 }
64 this->UI->close();
64 this->UI->close();
65 this->UI->~ahbUartPluginUI();
65 this->UI->~ahbUartPluginUI();
66 }
66 }
67
67
68
68
69 void ahbuartplugin::closeMe()
69 void ahbuartplugin::closeMe()
70 {
70 {
71 if(this->port!=(rs232port_t)NULL)
71 if(this->port!=(rs232port_t)NULL)
72 {
72 {
73 rs232close(this->port);
73 rs232close(this->port);
74 this->port = (rs232port_t)NULL;
74 this->port = (rs232port_t)NULL;
75 }
75 }
76 emit this->closePlugin(this);
76 emit this->closePlugin(this);
77 }
77 }
78
78
79 int ahbuartplugin::registermenu(QMainWindow *menuHolder)
79 int ahbuartplugin::registermenu(QMainWindow *menuHolder)
80 {
80 {
81 this->menu = menuHolder->menuBar()->addMenu(tr("&AHB UART"));
81 this->menu = menuHolder->menuBar()->addMenu(tr("&AHB UART"));
82 this->closeAction = this->menu->addAction(tr("Close plugin"));
82 this->closeAction = this->menu->addAction(tr("Close plugin"));
83 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
83 QObject::connect(this->closeAction,SIGNAL(triggered()),this,SLOT(closeMe()));
84 return 1;
84 return 1;
85 }
85 }
86
86
87
87
88
88
89
89
90 bool ahbuartplugin::checkConnection()
90 bool ahbuartplugin::checkConnection()
91 {
91 {
92 QTime timeout;
92 QTime timeout;
93 char test[5] ={(char)0x80,(char)0x80,(char)0,(char)0,(char)0};
93 char test[5] ={(char)0x80,(char)0x80,(char)0,(char)0,(char)0};
94 char test2[1024];
94 char test2[1024];
95 int writen =0;
95 int writen =0;
96 int read = 0;
96 int read = 0;
97 timeout.start();
97 timeout.start();
98 SocExplorerEngine::message(this,"Check connection",2);
98 SocExplorerEngine::message(this,"Check connection",2);
99 while(writen!=5)
99 while(writen!=5)
100 {
100 {
101 writen+=rs232write(this->port,test+writen,5-writen);
101 writen+=rs232write(this->port,test+writen,5-writen);
102 if(timeout.elapsed()>1000)
102 if(timeout.elapsed()>1000)
103 {
103 {
104 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);
105 return false;
105 return false;
106 }
106 }
107 }
107 }
108 #ifdef WIN32
109 usleep(1000);
110 #endif
108 timeout.restart();
111 timeout.restart();
109 while(read!=4)
112 while(read!=4)
110 {
113 {
111 read += rs232read(this->port,test2,4-read);
114 read += rs232read(this->port,test2,4-read);
112 if(timeout.elapsed()>1000) break;
115 if(timeout.elapsed()>1000) break;
113 }
116 }
114 if(read>0)
117 if(read>0)
115 {
118 {
116 SocExplorerEngine::message(this,"Connection Ok",2);
119 SocExplorerEngine::message(this,"Connection Ok",2);
117 return true;
120 return true;
118 }
121 }
119 else
122 else
120 {
123 {
121 SocExplorerEngine::message(this,"Connection Error",2);
124 SocExplorerEngine::message(this,"Connection Error",2);
122 return false;
125 return false;
123 }
126 }
124
127
125 }
128 }
126
129
127 void ahbuartplugin::connectPort(QString PortName, int baudrate)
130 void ahbuartplugin::connectPort(QString PortName, int baudrate)
128 {
131 {
129 QTime timeout;
132 QTime timeout;
130 SocExplorerEngine::message(this,"Try to connect to port "+PortName,2);
133 SocExplorerEngine::message(this,"Try to connect to port "+PortName,2);
131 timeout.start();
134 timeout.start();
132 if(this->port==(rs232port_t)NULL)
135 if(this->port==(rs232port_t)NULL)
133 {
136 {
134 SocExplorerEngine::message(this,"Open port "+PortName,2);
137 SocExplorerEngine::message(this,"Open port "+PortName,2);
135 this->port=rs232open((char*)PortName.toStdString().c_str());
138 this->port=rs232open((char*)PortName.toStdString().c_str());
136 }
139 }
137 if(this->port!=badPortValue)
140 if(this->port!=badPortValue)
138 {
141 {
139 SocExplorerEngine::message(this,"Port opened "+PortName,2);
142 SocExplorerEngine::message(this,"Port opened "+PortName,2);
140 SocExplorerEngine::message(this,"Configure port "+PortName,2);
143 SocExplorerEngine::message(this,"Configure port "+PortName,2);
141 rs232setup(this->port,8,baudrate,rs232parityNo,rs232OneStop);
144 rs232setup(this->port,8,baudrate,rs232parityNo,rs232OneStop);
142 char test[7] ={(char)0x55,(char)0x51,(char)0x80,(char)0x80,(char)0x0,(char)0x0,(char)0x14};
145 char test[7] ={(char)0x55,(char)0x51,(char)0x80,(char)0x80,(char)0x0,(char)0x0,(char)0x14};
143 char test2[1024];
146 char test2[1024];
144 SAFEWRITE(test,1,timeout,2000,return);
147 SAFEWRITE(test,1,timeout,2000,return);
145 SAFEWRITE((test+1),1,timeout,2000,return);
148 SAFEWRITE((test+1),1,timeout,2000,return);
146 APPENDTOLOG(QString("Flush port "));
149 APPENDTOLOG(QString("Flush port "));
147 rs232read(this->port,test2,512);
150 rs232read(this->port,test2,512);
148 int read = 0;
151 int read = 0;
149 for(int i=0;i<10;i++)
152 for(int i=0;i<10;i++)
150 {
153 {
151 SocExplorerEngine::message(this,"Send test patern :0x55,0x55,0x80,0x80,0x0,0x0,0x14",2);
154 SocExplorerEngine::message(this,"Send test patern :0x55,0x55,0x80,0x80,0x0,0x0,0x14",2);
152 SAFEWRITE(test+2,5,timeout,2000,return);
155 SAFEWRITE(test+2,5,timeout,2000,return);
153 SocExplorerEngine::message(this,"Read Result",2);
156 SocExplorerEngine::message(this,"Read Result",2);
154 read=rs232read(this->port,test2+read,16);
157 read=rs232read(this->port,test2+read,16);
155 SocExplorerEngine::message(this,QString("Get ") + QString::number(read) + " bytes",2);
158 SocExplorerEngine::message(this,QString("Get ") + QString::number(read) + " bytes",2);
156 if(read>0)
159 if(read>0)
157 {
160 {
158 SocExplorerEngine::message(this,"Flush port ",2);
161 SocExplorerEngine::message(this,"Flush port ",2);
159 while(rs232read(this->port,test2,1)>0);
162 while(rs232read(this->port,test2,1)>0);
160 this->Connected = true;
163 this->Connected = true;
161 SocExplorerEngine::message(this,QString("Connection success on ")+PortName,2);
164 SocExplorerEngine::message(this,QString("Connection success on ")+PortName,2);
162 emit this->activate(true);
165 emit this->activate(true);
163 if(this->scanDone==false)
166 if(this->scanDone==false)
164 {
167 {
165 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
168 socexplorerproxy::loadChildSysDriver(this,"AMBA_PLUGIN");
166 this->scanDone=true;
169 this->scanDone=true;
167 }
170 }
168 break;
171 break;
169 }
172 }
170 }
173 }
171 }
174 }
172 else
175 else
173 {
176 {
174 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
177 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
175 this->port = (rs232port_t)NULL;
178 this->port = (rs232port_t)NULL;
176 this->Connected = false;
179 this->Connected = false;
177 emit this->activateSig(false);
180 emit this->activateSig(false);
178 return;
181 return;
179 }
182 }
180 if(this->Connected == false)
183 if(this->Connected == false)
181 {
184 {
182 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
185 SocExplorerEngine::message(this,QString("Port not opened ")+PortName,2);
183 rs232close(this->port);
186 rs232close(this->port);
184 this->port = (rs232port_t)NULL;
187 this->port = (rs232port_t)NULL;
185 emit this->activateSig(false);
188 emit this->activateSig(false);
186 }
189 }
187
190
188 }
191 }
189
192
190 bool ahbuartplugin::open(QString PortName,int baudrate)
193 bool ahbuartplugin::open(QString PortName,int baudrate)
191 {
194 {
192 if(this->port!=(rs232port_t)NULL)
195 if(this->port!=(rs232port_t)NULL)
193 this->close();
196 this->close();
194 this->UI->setconfig(PortName,baudrate);
197 this->UI->setconfig(PortName,baudrate);
195 this->connectPort(PortName,baudrate);
198 this->connectPort(PortName,baudrate);
196 return (this->port!=(rs232port_t)NULL);
199 return (this->port!=(rs232port_t)NULL);
197 }
200 }
198
201
199 void ahbuartplugin::close()
202 void ahbuartplugin::close()
200 {
203 {
201 if(this->port!=(rs232port_t)NULL)
204 if(this->port!=(rs232port_t)NULL)
202 {
205 {
203 rs232close(this->port);
206 rs232close(this->port);
204 this->port = (rs232port_t)NULL;
207 this->port = (rs232port_t)NULL;
205 this->Connected = false;
208 this->Connected = false;
206 emit this->activateSig(false);
209 emit this->activateSig(false);
207 }
210 }
208 }
211 }
209
212
210 void ahbuartplugin::togglePort(QString PortName,int baudrate)
213 void ahbuartplugin::togglePort(QString PortName,int baudrate)
211 {
214 {
212 if(this->port!=(rs232port_t)NULL)
215 if(this->port!=(rs232port_t)NULL)
213 {
216 {
214 this->close();
217 this->close();
215 }
218 }
216 else
219 else
217 {
220 {
218 this->connectPort(PortName,baudrate);
221 this->connectPort(PortName,baudrate);
219 }
222 }
220 }
223 }
221
224
222
225
223 unsigned int ahbuartplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
226 unsigned int ahbuartplugin::Read(unsigned int *Value,unsigned int count,unsigned int address)
224 {
227 {
225 QTime timeout;
228 QTime timeout;
226 timeout.start();
229 timeout.start();
227 unsigned int read=0;
230 unsigned int read=0;
228 unsigned int cnt=count;
231 unsigned int cnt=count;
229 unsigned int nextUpdateTrig=0,updateStep=512;
232 unsigned int nextUpdateTrig=0,updateStep=512;
230 SocExplorerEngine::message(this,QString("Read ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
233 SocExplorerEngine::message(this,QString("Read ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
231 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
234 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
232 {
235 {
233 if(!this->portMutex->tryLock())
236 if(!this->portMutex->tryLock())
234 return 0;
237 return 0;
235 if(!this->checkConnection())
238 if(!this->checkConnection())
236 {
239 {
237 this->Connected = false;
240 this->Connected = false;
238 emit this->activateSig(false);
241 emit this->activateSig(false);
239 this->portMutex->unlock();
242 this->portMutex->unlock();
240 return 0;
243 return 0;
241 }
244 }
242 QProgressBar* progress=NULL;
245 QProgressBar* progress=NULL;
243 if(cnt>128)
246 if(cnt>128)
244 progress= SocExplorerEngine::getProgressBar("Reading on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
247 progress= SocExplorerEngine::getProgressBar("Reading on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
245 char CMD[5];
248 char CMD[5];
246 char* result = (char*)malloc(count*4);
249 char* result = (char*)malloc(count*4);
247 while(count>32)
250 while(count>32)
248 {
251 {
249 CMD[0] = 0x80 | (32-1);
252 CMD[0] = 0x80 | (32-1);
250 CMD[1] = (char)((address>>24)&0xFF);
253 CMD[1] = (char)((address>>24)&0xFF);
251 CMD[2] = (char)((address>>16)&0xFF);
254 CMD[2] = (char)((address>>16)&0xFF);
252 CMD[3] = (char)((address>>8)&0xFF);
255 CMD[3] = (char)((address>>8)&0xFF);
253 CMD[4] = (char)((address)&0xFF);
256 CMD[4] = (char)((address)&0xFF);
254 // APENDTABLETOLOG(CMD,5,logmessage,"Write CMD : ");
257 // APENDTABLETOLOG(CMD,5,logmessage,"Write CMD : ");
255 SAFEWRITE(CMD,5,timeout,1000,return 0);
258 SAFEWRITE(CMD,5,timeout,1000,return 0);
259 #ifdef WIN32
260 usleep(1000);
261 #endif
256 SAFEREAD(result+((cnt-count)*4),32*4,timeout,1000,return 0);
262 SAFEREAD(result+((cnt-count)*4),32*4,timeout,1000,return 0);
257 // APENDTABLETOLOG((result+((cnt-count)*4)),32*4,logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
263 // APENDTABLETOLOG((result+((cnt-count)*4)),32*4,logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
258 count-=32;
264 count-=32;
259 address+=32*4;
265 address+=32*4;
260 if(cnt>128)
266 if(cnt>128)
261 {
267 {
262
268
263 if((cnt-count)>=nextUpdateTrig)
269 if((cnt-count)>=nextUpdateTrig)
264 {
270 {
265 progress->setValue(cnt-count);
271 progress->setValue(cnt-count);
266 qApp->processEvents();
272 qApp->processEvents();
267 nextUpdateTrig+=updateStep;
273 nextUpdateTrig+=updateStep;
268 }
274 }
269 }
275 }
270 }
276 }
271 if(count>0)
277 if(count>0)
272 {
278 {
273 CMD[0] = 0x80 | (count-1);
279 CMD[0] = 0x80 | (count-1);
274 CMD[1] = (char)((address>>24)&0xFF);
280 CMD[1] = (char)((address>>24)&0xFF);
275 CMD[2] = (char)((address>>16)&0xFF);
281 CMD[2] = (char)((address>>16)&0xFF);
276 CMD[3] = (char)((address>>8)&0xFF);
282 CMD[3] = (char)((address>>8)&0xFF);
277 CMD[4] = (char)((address)&0xFF);
283 CMD[4] = (char)((address)&0xFF);
278 SAFEWRITE(CMD,5,timeout,1000,return 0);
284 SAFEWRITE(CMD,5,timeout,1000,return 0);
285 #ifdef WIN32
286 usleep(1000);
287 #endif
279 SAFEREAD(result+((cnt-count)*4),(count*4),timeout,1000,return 0);
288 SAFEREAD(result+((cnt-count)*4),(count*4),timeout,1000,return 0);
280 // APENDTABLETOLOG((result+((cnt-count)*4)),(count*4),logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
289 // APENDTABLETOLOG((result+((cnt-count)*4)),(count*4),logmessage, QString("Get ") + QString::number(32*4) + " Bytes : ");
281 }
290 }
282 if(cnt>128)
291 if(cnt>128)
283 {
292 {
284 progress->setValue(cnt-count);
293 progress->setValue(cnt-count);
285 qApp->processEvents();
294 qApp->processEvents();
286 }
295 }
287 for(int i=0;(unsigned int)i<cnt;i++)
296 for(int i=0;(unsigned int)i<cnt;i++)
288 {
297 {
289 for(int j =0;j<4;j++)
298 for(int j =0;j<4;j++)
290 {
299 {
291 Value[i]= ((unsigned char)(result[i*4+j])) + Value[i]*256;
300 Value[i]= ((unsigned char)(result[i*4+j])) + Value[i]*256;
292 }
301 }
293 read = cnt*4;
302 read = cnt*4;
294
303
295 }
304 }
296 if(cnt>128)
305 if(cnt>128)
297 SocExplorerEngine::deleteProgressBar(progress);
306 SocExplorerEngine::deleteProgressBar(progress);
298 free(result);
307 free(result);
299 this->portMutex->unlock();
308 this->portMutex->unlock();
300 }
309 }
301 return read/4;
310 return read/4;
302 }
311 }
303
312
304 unsigned int ahbuartplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
313 unsigned int ahbuartplugin::Write(unsigned int *Value,unsigned int count, unsigned int address)
305 {
314 {
306 QTime timeout;
315 QTime timeout;
307 timeout.start();
316 timeout.start();
308 unsigned int writen=0;
317 unsigned int writen=0;
309 unsigned int nextUpdateTrig=0,updateStep=512;
318 unsigned int nextUpdateTrig=0,updateStep=512;
310 SocExplorerEngine::message(this,QString("Write ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
319 SocExplorerEngine::message(this,QString("Write ")+ QString::number(count) + QString(" words @0x")+ QString::number(address,16),2);
311 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
320 if((this->port!= badPortValue)||(this->port!=(rs232port_t)NULL))
312 {
321 {
313 if(!this->portMutex->tryLock())
322 if(!this->portMutex->tryLock())
314 return 0;
323 return 0;
315 if(!this->checkConnection())
324 if(!this->checkConnection())
316 {
325 {
317 emit this->activateSig(false);
326 emit this->activateSig(false);
318 this->Connected = false;
327 this->Connected = false;
319 this->portMutex->unlock();
328 this->portMutex->unlock();
320 return 0;
329 return 0;
321 }
330 }
322 QProgressBar* progress = NULL;
331 QProgressBar* progress = NULL;
323 if(count>128)
332 if(count>128)
324 progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
333 progress = SocExplorerEngine::getProgressBar("Writing on uart @0x"+QString::number(address,16)+" %v of "+QString::number(count)+" words ",count);
325 int offset = 0;
334 int offset = 0;
326 char* CMD= (char*)malloc((32*4)+5);
335 char* CMD= (char*)malloc((32*4)+5);
327 while(count>32)
336 while(count>32)
328 {
337 {
329 writen=0;
338 writen=0;
330 CMD[0] = 0xC0 | (32-1);
339 CMD[0] = 0xC0 | (32-1);
331 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
340 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
332 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
341 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
333 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
342 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
334 CMD[4] = (char)(((unsigned int)address)&0xFF);
343 CMD[4] = (char)(((unsigned int)address)&0xFF);
335 for(int i=0;i<32;i++)
344 for(int i=0;i<32;i++)
336 {
345 {
337 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
346 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
338 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
347 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
339 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
348 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
340 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
349 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
341 }
350 }
342 SAFEWRITE(CMD,((32*4)+5),timeout,1000,return 0);
351 SAFEWRITE(CMD,((32*4)+5),timeout,1000,return 0);
343 writen+=32;
352 writen+=32;
344 count-=32;
353 count-=32;
345 offset+=32;
354 offset+=32;
346 address+=32*4;
355 address+=32*4;
347 if(offset>=nextUpdateTrig && progress!=NULL)
356 if(offset>=nextUpdateTrig && progress!=NULL)
348 {
357 {
349 progress->setValue(offset);
358 progress->setValue(offset);
350 qApp->processEvents();
359 qApp->processEvents();
351 nextUpdateTrig +=updateStep;
360 nextUpdateTrig +=updateStep;
352 }
361 }
353
362
354 }
363 }
355 if(count>0)
364 if(count>0)
356 {
365 {
357 CMD[0] = 0xC0 | (count-1);
366 CMD[0] = 0xC0 | (count-1);
358 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
367 CMD[1] = (char)(((unsigned int)address>>24)&0xFF);
359 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
368 CMD[2] = (char)(((unsigned int)address>>16)&0xFF);
360 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
369 CMD[3] = (char)(((unsigned int)address>>8)&0xFF);
361 CMD[4] = (char)(((unsigned int)address)&0xFF);
370 CMD[4] = (char)(((unsigned int)address)&0xFF);
362 for(int i=0;(unsigned int) i<(count);i++)
371 for(int i=0;(unsigned int) i<(count);i++)
363 {
372 {
364 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
373 CMD[(i*4)+5] = (char)(((unsigned int)Value[i+offset]>>24)&0xFF);
365 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
374 CMD[(i*4)+6] = (char)(((unsigned int)Value[i+offset]>>16)&0xFF);
366 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
375 CMD[(i*4)+7] = (char)(((unsigned int)Value[i+offset]>>8)&0xFF);
367 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
376 CMD[(i*4)+8] = (char)(((unsigned int)Value[i+offset])&0xFF);
368 }
377 }
369 SAFEWRITE(CMD,((count*4)+5),timeout,1000,return 0);
378 SAFEWRITE(CMD,((count*4)+5),timeout,1000,return 0);
370 writen+=count;
379 writen+=count;
371 }
380 }
372 if(progress!=NULL)
381 if(progress!=NULL)
373 {
382 {
374 progress->setValue(writen);
383 progress->setValue(writen);
375 qApp->processEvents();
384 qApp->processEvents();
376 SocExplorerEngine::deleteProgressBar(progress);
385 SocExplorerEngine::deleteProgressBar(progress);
377 }
386 }
378 free(CMD);
387 free(CMD);
379 this->portMutex->unlock();
388 this->portMutex->unlock();
380 return writen;
389 return writen;
381 }
390 }
382 return 0;
391 return 0;
383 }
392 }
384
393
385
394
386
395
387
396
388 void ahbuartplugin::updatePortList()
397 void ahbuartplugin::updatePortList()
389 {
398 {
390 if(this->portListcompleter==(QCompleter*)NULL)
399 if(this->portListcompleter==(QCompleter*)NULL)
391 {
400 {
392 this->portListcompleter=new QCompleter(this);
401 this->portListcompleter=new QCompleter(this);
393 this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive);
402 this->portListcompleter->setCaseSensitivity(Qt::CaseInsensitive);
394 this->portListcompleterModel = new QStringListModel(this);
403 this->portListcompleterModel = new QStringListModel(this);
395 this->portListcompleter->setModel(this->portListcompleterModel);
404 this->portListcompleter->setModel(this->portListcompleterModel);
396 this->UI->setCompleter(this->portListcompleter);
405 this->UI->setCompleter(this->portListcompleter);
397 }
406 }
398 rs232portslist_t* portlist = rs232getportlist();
407 rs232portslist_t* portlist = rs232getportlist();
399 rs232portslist_t* portlistenum = portlist;
408 rs232portslist_t* portlistenum = portlist;
400 QStringList wordList;
409 QStringList wordList;
401 while(portlistenum!=NULL)
410 while(portlistenum!=NULL)
402 {
411 {
403 wordList << portlistenum->name;
412 wordList << portlistenum->name;
404 portlistenum = portlistenum->next;
413 portlistenum = portlistenum->next;
405 }
414 }
406 rs232deleteportlist(portlist);
415 rs232deleteportlist(portlist);
407 this->portListcompleterModel->setStringList(wordList);
416 this->portListcompleterModel->setStringList(wordList);
408 }
417 }
409
418
410 QVariantList ahbuartplugin::ReadBytes(unsigned int address, unsigned int count)
419 QVariantList ahbuartplugin::ReadBytes(unsigned int address, unsigned int count)
411 {
420 {
412 unsigned int data[(count/4)+1];
421 unsigned int data[(count/4)+1];
413 QVariantList result;
422 QVariantList result;
414 this->Read(data,(count/4)+1,address);
423 this->Read(data,(count/4)+1,address);
415 for(unsigned int i = 0;i<count/4;i++)
424 for(unsigned int i = 0;i<count/4;i++)
416 {
425 {
417 result.append(QVariant((int)(0x0FF&(data[i]>>24))));
426 result.append(QVariant((int)(0x0FF&(data[i]>>24))));
418 result.append(QVariant((int)(0x0FF&(data[i]>>16))));
427 result.append(QVariant((int)(0x0FF&(data[i]>>16))));
419 result.append(QVariant((int)(0x0FF&(data[i]>>8))));
428 result.append(QVariant((int)(0x0FF&(data[i]>>8))));
420 result.append(QVariant((int)(0x0FF&(data[i]))));
429 result.append(QVariant((int)(0x0FF&(data[i]))));
421 }
430 }
422
431
423 for(int i=0;i<(count%4);i++)
432 for(int i=0;i<(count%4);i++)
424 {
433 {
425 result.append(QVariant((int)(0x0FF&(data[count/4]>>((3-i)*8)))));
434 result.append(QVariant((int)(0x0FF&(data[count/4]>>((3-i)*8)))));
426 }
435 }
427
436
428 return result;
437 return result;
429 }
438 }
430
439
431 void ahbuartplugin::WriteBytes(unsigned int address, QList<QVariant> dataList)
440 void ahbuartplugin::WriteBytes(unsigned int address, QList<QVariant> dataList)
432 {
441 {
433 unsigned int data[dataList.count()/4];
442 unsigned int data[dataList.count()/4];
434 for(int i = 0;i<(dataList.count()/4);i++)
443 for(int i = 0;i<(dataList.count()/4);i++)
435 {
444 {
436 data[i] = 0x0FF & ((unsigned int)dataList.at(4*i).toUInt());
445 data[i] = 0x0FF & ((unsigned int)dataList.at(4*i).toUInt());
437 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)+1).toUInt()));
438 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)+2).toUInt()));
439 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+3).toUInt()));
448 data[i] = (data[i]<<8) + (0x0FF & ((unsigned int)dataList.at((4*i)+3).toUInt()));
440 }
449 }
441 this->Write(data,dataList.count()/4,address);
450 this->Write(data,dataList.count()/4,address);
442 }
451 }
443
452
444
453
445
454
446
455
447
456
448
457
449
458
450
459
451
460
452
461
453
462
454
463
455
464
456
465
457
466
458
467
459
468
General Comments 0
You need to be logged in to leave comments. Login now