xFSTK  0.0.0
Intel SoC Cross Platform Firmware & Software Tool Kit
Functions | Variables
xfstk-dldr-example-parallel.cpp File Reference
#include "xfstk-dldr-example-parallel.h"
#include <stdio.h>
Include dependency graph for xfstk-dldr-example-parallel.cpp:

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
 
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 = 6
 
int donetargets = 0
 
int failtargets = 0
 

Function Documentation

◆ status()

void status ( char *  message,
void *  clientdata 
)

References ghMutex.

Referenced by main().

29 {
30  ghMutex.lock();
31  printf(message);
32  ghMutex.unlock();
33 }
QMutex ghMutex
Definition: xfstk-dldr-example-parallel.cpp:25
Here is the caller graph for this function:

◆ IsContains()

bool IsContains ( list< void *> *  list_checking,
string *  usbsn 
)

References ghListMutex, and thread_rectype::usbsn.

Referenced by main().

116 {
117  bool ret = false;
118  ghListMutex.lock();
119  for (list<void*>::iterator it=list_checking->begin(); it!=list_checking->end(); it++) {
120  thread_rectype *trd = (thread_rectype *)*it;
121  if(trd->usbsn == *usbsn) {
122  ret = true;
123  break;
124  }
125  }
126  ghListMutex.unlock();
127  return ret;
128 }
string usbsn
Definition: xfstk-dldr-example-parallel.h:50
QMutex ghListMutex
Definition: xfstk-dldr-example-parallel.cpp:26
Definition: xfstk-dldr-example-parallel.h:48
Here is the caller graph for this function:

◆ Sleepms()

void Sleepms ( int  delay)

Referenced by main().

131 {
132 #if defined XFSTK_OS_WIN
133  Sleep(delay);
134 #else
135  usleep(1000*delay);
136 #endif
137 }
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

References DlThreadObj::Arg(), Dlthread::Dlthread(), donetargets, failtargets, arg_type::fwdnx, arg_type::fwimage, xfstkdldrapi::getavailabletargets(), ghListMutex, arg_type::gpflags, 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, and thread_rectype::usbsn.

139 {
140  QCoreApplication a(argc, argv);
141  int y = 0;
142  int pass = 0;
143  int fail = 0;
144  xfstkdldrapi xfstktest;
145 
146  it_running = list_running.begin();
147  it_done = list_done.begin();
148  it_usbsn = list_usbsn.begin();
149 
150  //Here populate list_usbsn for simulate the SCU device dection
151  //Remeber replace the ussn string with the ones from your devices
152  list_usbsn.push_back ("175D126E48335F80");
153  list_usbsn.push_back ("BDA397C26EA8035B");
154  list_usbsn.push_back ("3183CBBBDA014AF1");
155  list_usbsn.push_back ("E7C123BC1EA72083");
156  list_usbsn.push_back ("B9AD3AC29A0BDF5E");
157  list_usbsn.push_back ("9724D645A3D7E902");
158 
159  //Wait to see if there is a new device arrived
160  while(1) {
161  if(xfstktest.getavailabletargets() == totaltargets) {
162  printf("\n\nXFSTK INFO: Found SCU %d devices.\n",xfstktest.getavailabletargets());
163  break;
164  }
165 
166  //Sleep one second and scan a again
167  printf("\n\nXFSTK INFO: Wait One seconds and scan for SCU device again\n");
168  Sleepms(1000);//(1000);
169  }
170 
171  while(1) {
172  //In your App, need to use winddk USB enumeration to detect SCU devices
173  //here only use populated list_usbsn to simulate
174  for (it_usbsn=list_usbsn.begin(); it_usbsn!=list_usbsn.end(); it_usbsn++) {
175  if(!IsContains(&list_running,&*it_usbsn) ){
176  thread_rectype * thread_rec = new thread_rectype;
177  DlThreadObj* downloader = new DlThreadObj;
178  Dlthread *dlthread = new Dlthread;
179  thread_rec->threadobj = (void*)downloader;
180  thread_rec->usbsn = *it_usbsn;
181 
182  ghListMutex.lock();
183  list_running.push_back((void*)thread_rec);
184  ghListMutex.unlock();
185 
186  arg_type * myarg = new arg_type;
187  myarg->fwdnx = "//tmp//fwdnx.bin";
188  myarg->fwimage = "//tmp//fwimage.bin";
189  myarg->osdnx = "//tmp//osdnx.bin";
190  myarg->osimage = "//tmp//osimage.bin";
191  myarg->gpflags = "80000045";
192  myarg->usbsn = *it_usbsn;
193  myarg->statuscallback = status;
194  cout << "Starting thread on USBSN: " + *it_usbsn << "\n";
195  downloader->Arg(myarg);
196  thread_rec->hthread = (void*)dlthread;
197  dlthread->setobj(downloader);
198  dlthread->start();
199  //Wait 200ms to let the thread to start
200  Sleepms(200);//(200);
201  }
202  }
203 
204 
205  //If done clear up all resources
206  if(donetargets >= totaltargets) {
207  ghListMutex.lock();
208  while (!list_done.empty()) {
209  thread_rectype *trd = (thread_rectype *)list_done.front();
210  list_done.pop_front();
211  delete (Dlthread*)trd->hthread;
212  delete (DlThreadObj*)trd->threadobj;
213  delete trd;
214  }
215  list_done.clear();
216  list_running.clear();
217 
218  if(failtargets > 0) {
219  fail += failtargets;
220  pass += donetargets;
221  pass -= failtargets;
222  printf("\n\nXFSTK ERROR: %d devices failed out of %d\n",fail, donetargets);
223  } else {
224  pass += donetargets;
225  printf("\n\nXFSTK INFO: %d devices soccessful out of %d\n",pass, donetargets);
226  }
227  //clear the variables for next round of run
228  donetargets = failtargets = 0;
229  ghListMutex.unlock();
230  //break;
231  }
232 
233  //wait one second to check if threads are done
234  Sleepms(200);
235 
236  }
237 
238  exit(0);
239 }
list< void * >::iterator it_running
Definition: xfstk-dldr-example-parallel.cpp:41
list< void * >::iterator it_done
Definition: xfstk-dldr-example-parallel.cpp:42
string fwimage
Definition: xfstk-dldr-example-parallel.h:39
string usbsn
Definition: xfstk-dldr-example-parallel.h:43
void status(char *message, void *clientdata)
Definition: xfstk-dldr-example-parallel.cpp:28
string fwdnx
Definition: xfstk-dldr-example-parallel.h:38
void * Arg() const
Definition: xfstk-dldr-example-parallel.h:60
bool IsContains(list< void *> *list_checking, string *usbsn)
Definition: xfstk-dldr-example-parallel.cpp:115
void setobj(DlThreadObj *obj)
Definition: xfstk-dldr-example-parallel.cpp:104
int failtargets
Definition: xfstk-dldr-example-parallel.cpp:45
list< string > list_usbsn
Definition: xfstk-dldr-example-parallel.cpp:37
string usbsn
Definition: xfstk-dldr-example-parallel.h:50
int donetargets
Definition: xfstk-dldr-example-parallel.cpp:44
Definition: xfstk-dldr-example-parallel.h:69
void * threadobj
Definition: xfstk-dldr-example-parallel.h:49
string gpflags
Definition: xfstk-dldr-example-parallel.h:42
list< void * > list_running
Definition: xfstk-dldr-example-parallel.cpp:39
list< void * > list_done
Definition: xfstk-dldr-example-parallel.cpp:40
void Sleepms(int delay)
Definition: xfstk-dldr-example-parallel.cpp:130
list< string >::iterator it_usbsn
Definition: xfstk-dldr-example-parallel.cpp:38
Definition: xfstk-dldr-example-parallel.h:37
void * hthread
Definition: xfstk-dldr-example-parallel.h:51
QMutex ghListMutex
Definition: xfstk-dldr-example-parallel.cpp:26
int totaltargets
Definition: xfstk-dldr-example-parallel.cpp:43
string osimage
Definition: xfstk-dldr-example-parallel.h:41
virtual int getavailabletargets()
Reports the number of available targets connected to the host system.
Definition: xfstk-dldr-example-parallel.h:54
This interface enables the development of Intel SoC firmware/operating system provisioning applicatio...
Definition: xfstkdldrapi.h:124
string osdnx
Definition: xfstk-dldr-example-parallel.h:40
xfstkstatuspfn statuscallback
Definition: xfstk-dldr-example-parallel.h:45
Definition: xfstk-dldr-example-parallel.h:48
Here is the call graph for this function:

Variable Documentation

◆ ghMutex

QMutex ghMutex

Referenced by status().

◆ ghListMutex

QMutex ghListMutex

◆ list_usbsn

list<string> list_usbsn

Referenced by main().

◆ it_usbsn

list<string>::iterator it_usbsn

Referenced by main().

◆ list_running

list<void*> list_running

Referenced by DlThreadObj::DldrRun(), and main().

◆ list_done

list<void*> list_done

Referenced by DlThreadObj::DldrRun(), and main().

◆ it_running

list<void*>::iterator it_running

Referenced by main().

◆ it_done

list<void*>::iterator it_done

Referenced by main().

◆ totaltargets

int totaltargets = 6

Referenced by main().

◆ donetargets

int donetargets = 0

Referenced by DlThreadObj::DldrRun(), and main().

◆ failtargets

int failtargets = 0

Referenced by DlThreadObj::DldrRun(), and main().