xFSTK  1.8.1-17.9
Intel SoC Cross Platform Firmware & Software Tool Kit
Typedefs | Functions | Variables
dynamic-load/xfstk-dldr-example-parallel.cpp File Reference
#include "xfstk-dldr-example-parallel.h"
#include <dlfcn.h>
Include dependency graph for dynamic-load/xfstk-dldr-example-parallel.cpp:

Typedefs

typedef xfstkdldrapi *(* PXFSTKALLOC )()
 
typedef void(* PXFSTKDEALLOC )(xfstkdldrapi *)
 

Functions

void status (char *message, void *clientdata)
 
bool IsContains (list< void * > *list_checking, string *usbsn)
 
void Sleepms (int delay)
 
int main (int argc, char *argv[])
 

Variables

QMutex ghMutex
 
QMutex ghListMutex
 
void * hinstLib
 
PXFSTKALLOC xfstkalloc
 
PXFSTKDEALLOC xfstkdealloc
 
list< string > list_usbsn
 
list< string >::iterator it_usbsn
 
list< void * > list_running
 
list< void * > list_done
 
list< void * >::iterator it_running
 
list< void * >::iterator it_done
 
int totaltargets = 7
 
int donetargets = 0
 
int failtargets = 0
 

Typedef Documentation

typedef xfstkdldrapi*( * PXFSTKALLOC)()
typedef void( * PXFSTKDEALLOC)(xfstkdldrapi *)

Function Documentation

void status ( char *  message,
void *  clientdata 
)

References ghMutex.

39 {
40  ghMutex.lock();
41  printf(message);
42  ghMutex.unlock();
43 }
QMutex ghMutex
Definition: xfstk-dldr-example-parallel.cpp:25
bool IsContains ( list< void * > *  list_checking,
string *  usbsn 
)

References ghListMutex, and thread_rectype::usbsn.

131 {
132  bool ret = false;
133  ghListMutex.lock();
134  for (list<void*>::iterator it=list_checking->begin(); it!=list_checking->end(); it++) {
135  thread_rectype *trd = (thread_rectype *)*it;
136  if(trd->usbsn == *usbsn) {
137  ret = true;
138  break;
139  }
140  }
141  ghListMutex.unlock();
142  return ret;
143 }
Definition: xfstk-dldr-example-parallel.h:48
string usbsn
Definition: xfstk-dldr-example-parallel.h:50
QMutex ghListMutex
Definition: xfstk-dldr-example-parallel.cpp:26
void Sleepms ( int  delay)
146 {
147 #if defined XFSTK_OS_WIN
148  Sleep(delay);
149 #else
150  usleep(1000*delay);
151 #endif
152 }
int main ( int  argc,
char *  argv[] 
)

References DlThreadObj::Arg(), donetargets, failtargets, arg_type::fwdnx, arg_type::fwimage, xfstkdldrapi::getavailabletargets(), ghListMutex, arg_type::gpflags, hinstLib, thread_rectype::hthread, IsContains(), it_done, it_running, it_usbsn, list_done, list_running, list_usbsn, arg_type::osdnx, arg_type::osimage, Dlthread::setobj(), Sleepms(), status(), arg_type::statuscallback, thread_rectype::threadobj, totaltargets, arg_type::usbsn, thread_rectype::usbsn, xfstkalloc, and xfstkdealloc.

156 {
157  QCoreApplication a(argc, argv);
158  int y = 0;
159  int pass = 0;
160  int fail = 0;
161  hinstLib = dlopen("./libxfstk-dldr-api.so", RTLD_LAZY);
162  if (!hinstLib)
163  {
164  printf("%s\n", dlerror());
165  exit(1);
166  }
167 
168  xfstkalloc = (PXFSTKALLOC)dlsym(hinstLib, "xfstkdldrapi_alloc");
169 
170  if (xfstkalloc == NULL)
171  {
172  printf("%s\n", dlerror());
173  exit(1);
174  }
175 
176  xfstkdealloc = (PXFSTKDEALLOC)dlsym(hinstLib, "xfstkdldrapi_dealloc");
177  if (xfstkdealloc == NULL)
178  {
179  printf("%s\n", dlerror());
180  exit(1);
181  }
182 
183  xfstkdldrapi* xfstktest = xfstkalloc();
184 
185  if(xfstktest == NULL)
186  exit(1);
187 
188  int retrycount = 20;
189 
190  bool provisioningok = false;
191 
192  it_running = list_running.begin();
193  it_done = list_done.begin();
194  it_usbsn = list_usbsn.begin();
195 
196  //Here populate list_usbsn for simulate the SCU device dection
197  //Remeber replace the ussn string with the ones from your devices
198  list_usbsn.push_back ("175D126E48335F80");
199  list_usbsn.push_back ("BDA397C26EA8035B");
200  list_usbsn.push_back ("3183CBBBDA014AF1");
201  list_usbsn.push_back ("E7C123BC1EA72083");
202  list_usbsn.push_back ("B9AD3AC29A0BDF5E");
203  list_usbsn.push_back ("4EC224787F0ECABB");
204  list_usbsn.push_back ("9724D645A3D7E902");
205 
206  //Wait to see if there is a new device arrived
207  while(1) {
208  if(xfstktest->getavailabletargets() > 0) {
209  printf("\n\nXFSTK INFO: Found SCU %d devices.\n",xfstktest->getavailabletargets());
210  break;
211  }
212 
213  //Sleep one second and scan a again
214  printf("\n\nXFSTK INFO: Wait One seconds and scan for SCU device again\n");
215  Sleepms(1000);//(1000);
216  }
217 
218  while(1) {
219  //In your App, need to use winddk USB enumeration to detect SCU devices
220  //here only use populated list_usbsn to simulate
221  for (it_usbsn=list_usbsn.begin(); it_usbsn!=list_usbsn.end(); it_usbsn++) {
222  //cout << "USBSN: \n" << *it_usbsn;
223  if(!IsContains(&list_running,&*it_usbsn) ){
224  thread_rectype * thread_rec = new thread_rectype;
225  DlThreadObj* downloader = new DlThreadObj;
226  Dlthread *dlthread = new Dlthread;
227  thread_rec->threadobj = (void*)downloader;
228  thread_rec->usbsn = *it_usbsn;
229 
230  ghListMutex.lock();
231  list_running.push_back((void*)thread_rec);
232  ghListMutex.unlock();
233 
234  arg_type * myarg = new arg_type;
235  myarg->fwdnx = "C:\\tmp\\fwdnx.bin";
236  myarg->fwimage = "C:\\tmp\\fwimage.bin";
237  myarg->osdnx = "C:\\tmp\\osdnx.bin";
238  myarg->osimage = "C:\\tmp\\osimage.bin";
239  myarg->gpflags = "80000041";
240  myarg->usbsn = *it_usbsn;
241  myarg->statuscallback = status;
242  cout << "Starting thread on USBSN: " + *it_usbsn << "\n";
243  downloader->Arg(myarg);
244  thread_rec->hthread = (void*)dlthread;
245  dlthread->setobj(downloader);
246  dlthread->start();
247  //Wait 200ms to let the thread to start
248  Sleepms(200);//(200);
249  }
250  }
251 
252  //If done clear up all resources
253  if(donetargets >= totaltargets) {
254  ghListMutex.lock();
255 
256  while (!list_done.empty()) {
257  thread_rectype *trd = (thread_rectype *)list_done.front();
258  list_done.pop_front();
259  delete (Dlthread *)trd->hthread;
260  delete (DlThreadObj*)trd->threadobj;
261  delete trd;
262  }
263  list_done.clear();
264  list_running.clear();
265 
266  if(failtargets > 0) {
267  fail += failtargets;
268  pass += donetargets;
269  pass -= failtargets;
270  printf("\n\nXFSTK ERROR: %d devices failed out of %d\n",failtargets, donetargets);
271  } else {
272  pass += donetargets;
273  printf("\n\nXFSTK INFO: %d devices soccessful out of %d\n",pass, donetargets);
274  }
275  //clear the variables for next round of run
276  donetargets = failtargets = 0;
277  ghListMutex.unlock();
278  break;
279  }
280 
281  //wait one second to check if threads are done
282  Sleepms(1000);
283 
284  }
285 
286  cout << "Press any key to terminate this program. " ;// getch();
287  xfstkdealloc(xfstktest);
288  dlclose(hinstLib);
289  exit(0);
290 }
Definition: xfstk-dldr-example-parallel.h:48
string usbsn
Definition: xfstk-dldr-example-parallel.h:43
void * Arg() const
Definition: xfstk-dldr-example-parallel.h:60
void(* PXFSTKDEALLOC)(xfstkdldrapi *)
Definition: dynamic-load/xfstk-dldr-example-parallel.cpp:31
string usbsn
Definition: xfstk-dldr-example-parallel.h:50
string fwimage
Definition: xfstk-dldr-example-parallel.h:39
PXFSTKDEALLOC xfstkdealloc
Definition: dynamic-load/xfstk-dldr-example-parallel.cpp:35
list< string >::iterator it_usbsn
Definition: xfstk-dldr-example-parallel.cpp:38
This interface enables the development of Intel SoC firmware/operating system provisioning applicatio...
Definition: xfstkdldrapi.h:124
void * hinstLib
Definition: dynamic-load/xfstk-dldr-example-parallel.cpp:33
list< void * > list_running
Definition: xfstk-dldr-example-parallel.cpp:39
Definition: xfstk-dldr-example-parallel.h:54
int donetargets
Definition: xfstk-dldr-example-parallel.cpp:44
string fwdnx
Definition: xfstk-dldr-example-parallel.h:38
PXFSTKALLOC xfstkalloc
Definition: dynamic-load/xfstk-dldr-example-parallel.cpp:34
string osdnx
Definition: xfstk-dldr-example-parallel.h:40
list< void * > list_done
Definition: xfstk-dldr-example-parallel.cpp:40
string gpflags
Definition: xfstk-dldr-example-parallel.h:42
string osimage
Definition: xfstk-dldr-example-parallel.h:41
QMutex ghListMutex
Definition: xfstk-dldr-example-parallel.cpp:26
Definition: xfstk-dldr-example-parallel.h:69
bool IsContains(list< void * > *list_checking, string *usbsn)
Definition: xfstk-dldr-example-parallel.cpp:115
virtual int getavailabletargets()
Reports the number of available targets connected to the host system.
void * hthread
Definition: xfstk-dldr-example-parallel.h:51
void status(char *message, void *clientdata)
Definition: xfstk-dldr-example-parallel.cpp:28
xfstkstatuspfn statuscallback
Definition: xfstk-dldr-example-parallel.h:45
list< void * >::iterator it_running
Definition: xfstk-dldr-example-parallel.cpp:41
int totaltargets
Definition: xfstk-dldr-example-parallel.cpp:43
list< void * >::iterator it_done
Definition: xfstk-dldr-example-parallel.cpp:42
xfstkdldrapi *(* PXFSTKALLOC)()
Definition: dynamic-load/xfstk-dldr-example-parallel.cpp:30
void * threadobj
Definition: xfstk-dldr-example-parallel.h:49
Definition: xfstk-dldr-example-parallel.h:37
int failtargets
Definition: xfstk-dldr-example-parallel.cpp:45
void setobj(DlThreadObj *obj)
Definition: xfstk-dldr-example-parallel.cpp:104
void Sleepms(int delay)
Definition: xfstk-dldr-example-parallel.cpp:130
list< string > list_usbsn
Definition: xfstk-dldr-example-parallel.cpp:37

Here is the call graph for this function:

Variable Documentation

QMutex ghMutex
QMutex ghListMutex
void* hinstLib

Referenced by main().

PXFSTKALLOC xfstkalloc

Referenced by main().

PXFSTKDEALLOC xfstkdealloc

Referenced by main().

list<string> list_usbsn
list<string>::iterator it_usbsn
list<void*> list_running
list<void*> list_done
list<void*>::iterator it_running
list<void*>::iterator it_done
int totaltargets = 7
int donetargets = 0
int failtargets = 0