Semihosting.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: Semihosting.cpp
  4. * Description: Semihosting io
  5. *
  6. * IO for a platform supporting semihosting.
  7. * (Several input and output files)
  8. *
  9. * $Date: 20. June 2019
  10. * $Revision: V1.0.0
  11. *
  12. * Target Processor: Cortex-M cores
  13. * -------------------------------------------------------------------- */
  14. /*
  15. * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved.
  16. *
  17. * SPDX-License-Identifier: Apache-2.0
  18. *
  19. * Licensed under the Apache License, Version 2.0 (the License); you may
  20. * not use this file except in compliance with the License.
  21. * You may obtain a copy of the License at
  22. *
  23. * www.apache.org/licenses/LICENSE-2.0
  24. *
  25. * Unless required by applicable law or agreed to in writing, software
  26. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  27. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  28. * See the License for the specific language governing permissions and
  29. * limitations under the License.
  30. */
  31. #include "Test.h"
  32. #include <string>
  33. #include <cstddef>
  34. #include "Semihosting.h"
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include "Generators.h"
  38. namespace Client
  39. {
  40. struct pathOrGen {
  41. int kind;
  42. std::string path;
  43. Testing::param_t *data;
  44. Testing::nbSamples_t nbInputSamples;
  45. Testing::nbSamples_t nbOutputSamples;
  46. int dimensions;
  47. };
  48. Semihosting::Semihosting(std::string path,std::string patternRootPath,std::string outputRootPath,std::string parameterRootPath)
  49. {
  50. // Open the driver file
  51. this->infile=fopen(path.c_str(), "r");
  52. this->path=new std::vector<std::string>();
  53. this->patternRootPath=patternRootPath;
  54. this->outputRootPath=outputRootPath;
  55. this->parameterRootPath=parameterRootPath;
  56. this->patternFilenames=new std::vector<std::string>();
  57. this->outputNames=new std::vector<std::string>();
  58. this->parameterNames=new std::vector<struct pathOrGen>();
  59. this->m_hasParam = false;
  60. }
  61. void Semihosting::DeleteParams()
  62. {
  63. for (std::vector<struct pathOrGen>::iterator it = this->parameterNames->begin() ; it != this->parameterNames->end(); ++it)
  64. {
  65. if (it->kind==1)
  66. {
  67. if (it->data)
  68. {
  69. free(it->data);
  70. it->data = NULL;
  71. }
  72. }
  73. }
  74. }
  75. Semihosting::~Semihosting()
  76. {
  77. fclose(this->infile);
  78. delete(this->path);
  79. delete(this->patternFilenames);
  80. delete(this->outputNames);
  81. this->DeleteParams();
  82. delete(this->parameterNames);
  83. }
  84. /**
  85. Read the list of patterns from the driver file.
  86. This list is for the current suite.
  87. */
  88. void Semihosting::ReadPatternList()
  89. {
  90. char tmp[256];
  91. int nbPatterns;
  92. fscanf(this->infile,"%d\n",&nbPatterns);
  93. // Reset the list for the current suite
  94. this->patternFilenames->clear();
  95. std::string tmpstr;
  96. for(int i=0;i<nbPatterns;i++)
  97. {
  98. fgets(tmp,256,this->infile);
  99. // Remove end of line
  100. if (tmp[strlen(tmp)-1] == '\n')
  101. {
  102. tmp[strlen(tmp)-1]=0;
  103. }
  104. tmpstr.assign(tmp);
  105. this->patternFilenames->push_back(tmpstr);
  106. }
  107. }
  108. /**
  109. Read the list of parameters from the driver file.
  110. This list is for the current suite.
  111. */
  112. void Semihosting::ReadParameterList(Testing::nbParameters_t nbParams)
  113. {
  114. char tmp[256];
  115. char paramKind;
  116. std::string tmpstr;
  117. // It is the number of samples in the file.
  118. // Not the number of parameters controlling the function
  119. int nbValues;
  120. fscanf(this->infile,"%d\n",&nbValues);
  121. // Reset the list for the current suite
  122. this->DeleteParams();
  123. this->parameterNames->clear();
  124. for(int i=0;i<nbValues;i++)
  125. {
  126. fscanf(this->infile,"%c\n",&paramKind);
  127. struct pathOrGen gen;
  128. if (paramKind == 'p')
  129. {
  130. fgets(tmp,256,this->infile);
  131. // Remove end of line
  132. if (tmp[strlen(tmp)-1] == '\n')
  133. {
  134. tmp[strlen(tmp)-1]=0;
  135. }
  136. tmpstr.assign(tmp);
  137. std::string tmp;
  138. tmp += this->parameterRootPath;
  139. tmp += this->testDir;
  140. tmp += "/";
  141. tmp += tmpstr;
  142. gen.kind=0;
  143. gen.path=tmp;
  144. gen.nbInputSamples = this->GetFileSize(tmp);
  145. gen.dimensions = nbParams;
  146. }
  147. // Generator
  148. // Generator kind (only 1 = cartesian product generator)
  149. // Number of samples generated when run
  150. // Number of dimensions
  151. // For each dimension
  152. // Length
  153. // Samples
  154. else
  155. {
  156. int kind,nbInputSamples,nbOutputSamples,dimensions,len,sample;
  157. Testing::param_t *p,*current;
  158. size_t length;
  159. // Generator kind. Not yet used since there is only one kind of generator
  160. fscanf(this->infile,"%d\n",&kind);
  161. // Input data in config file
  162. fscanf(this->infile,"%d\n",&nbInputSamples);
  163. // Number of output combinations
  164. // And each output has dimensions parameters
  165. fscanf(this->infile,"%d\n",&nbOutputSamples);
  166. fscanf(this->infile,"%d\n",&dimensions);
  167. p=(Testing::param_t*)malloc(sizeof(Testing::param_t)*(nbInputSamples));
  168. current=p;
  169. for(int i=0;i < nbInputSamples; i ++)
  170. {
  171. fscanf(this->infile,"%d\n",&sample);
  172. *current++ = (Testing::param_t)sample;
  173. }
  174. gen.kind=1;
  175. gen.data=p;
  176. gen.nbInputSamples = nbInputSamples;
  177. gen.nbOutputSamples = nbOutputSamples;
  178. gen.dimensions = dimensions;
  179. }
  180. this->parameterNames->push_back(gen);
  181. }
  182. }
  183. /**
  184. Read the list of output from the driver file.
  185. This list is for the current suite.
  186. */
  187. void Semihosting::ReadOutputList()
  188. {
  189. char tmp[256];
  190. int nbOutputs;
  191. fscanf(this->infile,"%d\n",&nbOutputs);
  192. // Reset the list for the current suite
  193. this->outputNames->clear();
  194. std::string tmpstr;
  195. for(int i=0;i<nbOutputs;i++)
  196. {
  197. fgets(tmp,256,this->infile);
  198. // Remove end of line
  199. if (tmp[strlen(tmp)-1] == '\n')
  200. {
  201. tmp[strlen(tmp)-1]=0;
  202. }
  203. tmpstr.assign(tmp);
  204. this->outputNames->push_back(tmpstr);
  205. }
  206. }
  207. /** Read the number of parameters for all the tests in a suite
  208. Used for benchmarking. Same functions executed with
  209. different initializations controlled by the parameters.
  210. It is not the number of parameters in a file
  211. but the number of arguments (parameters) to control a function.
  212. */
  213. Testing::nbParameters_t Semihosting::ReadNbParameters()
  214. {
  215. unsigned long nb;
  216. fscanf(this->infile,"%ld\n",&nb);
  217. return(nb);
  218. }
  219. void Semihosting::recomputeTestDir()
  220. {
  221. this->testDir = ".";
  222. int start = 1;
  223. std::vector<std::string>::const_iterator iter;
  224. for (iter = this->path->begin(); iter != this->path->end(); ++iter)
  225. {
  226. if (start)
  227. {
  228. this->testDir = *iter;
  229. start =0;
  230. }
  231. else
  232. {
  233. if (!(*iter).empty())
  234. {
  235. this->testDir += "/" + *iter;
  236. }
  237. }
  238. }
  239. }
  240. void Semihosting::ReadTestIdentification()
  241. {
  242. char tmp[255];
  243. int kind;
  244. Testing::testID_t theId;
  245. char hasPath;
  246. char hasParamID;
  247. Testing::PatternID_t paramID;
  248. fscanf(this->infile,"%d %ld\n",&kind,&theId);
  249. fscanf(this->infile,"%c\n",&hasParamID);
  250. this->m_hasParam=false;
  251. if (hasParamID == 'y')
  252. {
  253. this->m_hasParam=true;
  254. fscanf(this->infile,"%ld\n",&paramID);
  255. this->currentParam=paramID;
  256. }
  257. fscanf(this->infile,"%c\n",&hasPath);
  258. if (hasPath == 'y')
  259. {
  260. fgets(tmp,256,this->infile);
  261. // Remove end of line
  262. if (tmp[strlen(tmp)-1] == '\n')
  263. {
  264. tmp[strlen(tmp)-1]=0;
  265. }
  266. currentPath.assign(tmp);
  267. }
  268. this->currentKind=kind;
  269. this->currentId=theId;
  270. switch(kind)
  271. {
  272. case 1:
  273. printf("t \n");
  274. break;
  275. case 2:
  276. printf("s %ld\n",this->currentId);
  277. break;
  278. case 3:
  279. printf("g %ld\n",this->currentId);
  280. break;
  281. default:
  282. printf("u\n");
  283. }
  284. }
  285. Testing::testID_t Semihosting::CurrentTestID()
  286. {
  287. return(this->currentId);
  288. }
  289. /**
  290. Read identification of a group or suite.
  291. The difference with a test node is that the current folder
  292. can be changed by a group or suite.
  293. */
  294. void Semihosting::ReadIdentification()
  295. {
  296. this->ReadTestIdentification();
  297. this->path->push_back(currentPath);
  298. this->recomputeTestDir();
  299. }
  300. /**
  301. Dump the test status into the output (stdout)
  302. */
  303. void Semihosting::DispStatus(Testing::TestStatus status
  304. ,Testing::errorID_t error
  305. ,unsigned long lineNb
  306. ,Testing::cycles_t cycles)
  307. {
  308. if (status == Testing::kTestFailed)
  309. {
  310. printf("%ld %ld %ld 0 N\n",this->currentId,error,lineNb);
  311. }
  312. else
  313. {
  314. #ifdef EXTBENCH
  315. printf("%ld 0 0 t Y\n",this->currentId);
  316. #else
  317. printf("%ld 0 0 %u Y\n",this->currentId,cycles);
  318. #endif
  319. }
  320. }
  321. /**
  322. Signal end of group
  323. (Used by scripts parsing the output to display the results)
  324. */
  325. void Semihosting::EndGroup()
  326. {
  327. printf("p\n");
  328. this->path->pop_back();
  329. }
  330. /**
  331. Get pattern path.
  332. */
  333. std::string Semihosting::getPatternPath(Testing::PatternID_t id)
  334. {
  335. std::string tmp;
  336. tmp += this->patternRootPath;
  337. tmp += this->testDir;
  338. tmp += "/";
  339. tmp += (*this->patternFilenames)[id];
  340. return(tmp);
  341. }
  342. /**
  343. Get parameter path.
  344. */
  345. struct pathOrGen Semihosting::getParameterDesc(Testing::PatternID_t id)
  346. {
  347. return((*this->parameterNames)[id]);
  348. }
  349. /**
  350. Get output path.
  351. The test ID (currentId) is used in the name
  352. */
  353. std::string Semihosting::getOutputPath(Testing::outputID_t id)
  354. {
  355. char fmt[256];
  356. std::string tmp;
  357. tmp += this->outputRootPath;
  358. tmp += this->testDir;
  359. sprintf(fmt,"/%s_%ld.txt",(*this->outputNames)[id].c_str(),this->currentId);
  360. tmp += std::string(fmt);
  361. //printf("%s\n",tmp.c_str());
  362. return(tmp);
  363. }
  364. Testing::nbSamples_t Semihosting::GetPatternSize(Testing::PatternID_t id)
  365. {
  366. char tmp[256];
  367. Testing::nbSamples_t len;
  368. std::string fileName = this->getPatternPath(id);
  369. FILE *pattern=fopen(fileName.c_str(), "r");
  370. if (pattern==NULL)
  371. {
  372. return(0);
  373. }
  374. // Ignore word size format
  375. fgets(tmp,256,pattern);
  376. // Get nb of samples
  377. fgets(tmp,256,pattern);
  378. fclose(pattern);
  379. len=atoi(tmp);
  380. return(len);
  381. }
  382. Testing::nbSamples_t Semihosting::GetFileSize(std::string &filepath)
  383. {
  384. char tmp[256];
  385. Testing::nbSamples_t len;
  386. FILE *params=fopen(filepath.c_str(), "r");
  387. if (params==NULL)
  388. {
  389. return(0);
  390. }
  391. // Get nb of samples
  392. fgets(tmp,256,params);
  393. fclose(params);
  394. len=atoi(tmp);
  395. return(len);
  396. }
  397. void Semihosting::DumpParams(std::vector<Testing::param_t>& params)
  398. {
  399. bool begin=true;
  400. printf("b ");
  401. for(std::vector<Testing::param_t>::iterator it = params.begin(); it != params.end(); ++it)
  402. {
  403. if (!begin)
  404. {
  405. printf(",");
  406. }
  407. printf("%d",*it);
  408. begin=false;
  409. }
  410. printf("\n");
  411. }
  412. Testing::param_t* Semihosting::ImportParams(Testing::PatternID_t id,Testing::nbParameterEntries_t &nbEntries,Testing::ParameterKind &paramKind)
  413. {
  414. nbEntries = 0;
  415. char tmp[256];
  416. Testing::param_t *p;
  417. uint32_t val;
  418. Testing::nbSamples_t len;
  419. struct pathOrGen gen = this->getParameterDesc(id);
  420. if (gen.kind == 0)
  421. {
  422. char *result=NULL;
  423. paramKind=Testing::kDynamicBuffer;
  424. FILE *params=fopen(gen.path.c_str(), "r");
  425. if (params==NULL)
  426. {
  427. return(NULL);
  428. }
  429. // Get nb of samples
  430. fgets(tmp,256,params);
  431. len=gen.nbInputSamples;
  432. result=(char*)malloc(len*sizeof(Testing::param_t));
  433. p = (Testing::param_t*)result;
  434. nbEntries = len / gen.dimensions;
  435. for(uint32_t i=0; i < len; i++)
  436. {
  437. fscanf(params,"%d\n",&val);
  438. *p++ = val;
  439. }
  440. fclose(params);
  441. return((Testing::param_t*)result);
  442. }
  443. else
  444. {
  445. Testing::param_t* result;
  446. paramKind=Testing::kDynamicBuffer;
  447. // Output samples is number of parameter line
  448. len=gen.nbOutputSamples * gen.dimensions;
  449. result=(Testing::param_t*)malloc(len*sizeof(Testing::param_t));
  450. switch(gen.dimensions)
  451. {
  452. case 1:
  453. generate1(result,gen.data,nbEntries);
  454. break;
  455. case 2:
  456. generate2(result,gen.data,nbEntries);
  457. break;
  458. case 3:
  459. generate3(result,gen.data,nbEntries);
  460. break;
  461. case 4:
  462. generate4(result,gen.data,nbEntries);
  463. break;
  464. default:
  465. generate1(result,gen.data,nbEntries);
  466. break;
  467. }
  468. return(result);
  469. }
  470. }
  471. bool Semihosting::hasParam()
  472. {
  473. return(this->m_hasParam);
  474. }
  475. Testing::PatternID_t Semihosting::getParamID()
  476. {
  477. return(this->currentParam);
  478. }
  479. void Semihosting::ImportPattern_f64(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  480. {
  481. char tmp[256];
  482. Testing::nbSamples_t len;
  483. Testing::nbSamples_t i=0;
  484. uint64_t val;
  485. float64_t *ptr=(float64_t*)p;
  486. std::string fileName = this->getPatternPath(id);
  487. FILE *pattern=fopen(fileName.c_str(), "r");
  488. // Ignore word size format
  489. // word size format is used when generating include files with python scripts
  490. fgets(tmp,256,pattern);
  491. // Get nb of samples
  492. fgets(tmp,256,pattern);
  493. len=atoi(tmp);
  494. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  495. {
  496. len = nb;
  497. }
  498. for(i=0;i<len;i++)
  499. {
  500. // Ignore comment
  501. fgets(tmp,256,pattern);
  502. fscanf(pattern,"0x%16llx\n",&val);
  503. *ptr = TOTYP(float64_t,val);
  504. ptr++;
  505. }
  506. fclose(pattern);
  507. }
  508. void Semihosting::ImportPattern_f32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  509. {
  510. char tmp[256];
  511. Testing::nbSamples_t len;
  512. Testing::nbSamples_t i=0;
  513. uint32_t val;
  514. float32_t *ptr=(float32_t*)p;
  515. std::string fileName = this->getPatternPath(id);
  516. FILE *pattern=fopen(fileName.c_str(), "r");
  517. // Ignore word size format
  518. fgets(tmp,256,pattern);
  519. // Get nb of samples
  520. fgets(tmp,256,pattern);
  521. len=atoi(tmp);
  522. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  523. {
  524. len = nb;
  525. }
  526. //printf(":::: %s\n",fileName.c_str());
  527. for(i=0;i<len;i++)
  528. {
  529. // Ignore comment
  530. fgets(tmp,256,pattern);
  531. fscanf(pattern,"0x%08X\n",&val);
  532. //printf(":::: %08X %f\n",val, TOTYP(float32_t,val));
  533. *ptr = TOTYP(float32_t,val);
  534. ptr++;
  535. }
  536. fclose(pattern);
  537. }
  538. void Semihosting::ImportPattern_q31(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  539. {
  540. char tmp[256];
  541. Testing::nbSamples_t len;
  542. Testing::nbSamples_t i=0;
  543. uint32_t val;
  544. q31_t *ptr=(q31_t*)p;
  545. std::string fileName = this->getPatternPath(id);
  546. FILE *pattern=fopen(fileName.c_str(), "r");
  547. // Ignore word size format
  548. fgets(tmp,256,pattern);
  549. // Get nb of samples
  550. fgets(tmp,256,pattern);
  551. len=atoi(tmp);
  552. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  553. {
  554. len = nb;
  555. }
  556. for(i=0;i<len;i++)
  557. {
  558. // Ignore comment
  559. fgets(tmp,256,pattern);
  560. fscanf(pattern,"0x%08X\n",&val);
  561. *ptr = TOTYP(q31_t,val);
  562. ptr++;
  563. }
  564. fclose(pattern);
  565. }
  566. void Semihosting::ImportPattern_q15(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  567. {
  568. char tmp[256];
  569. Testing::nbSamples_t len;
  570. Testing::nbSamples_t i=0;
  571. uint32_t val;
  572. q15_t *ptr=(q15_t*)p;
  573. std::string fileName = this->getPatternPath(id);
  574. FILE *pattern=fopen(fileName.c_str(), "r");
  575. // Ignore word size format
  576. fgets(tmp,256,pattern);
  577. // Get nb of samples
  578. fgets(tmp,256,pattern);
  579. len=atoi(tmp);
  580. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  581. {
  582. len = nb;
  583. }
  584. for(i=0;i<len;i++)
  585. {
  586. // Ignore comment
  587. fgets(tmp,256,pattern);
  588. fscanf(pattern,"0x%08X\n",&val);
  589. *ptr = TOTYP(q15_t,val);
  590. ptr++;
  591. }
  592. fclose(pattern);
  593. }
  594. void Semihosting::ImportPattern_q7(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  595. {
  596. char tmp[256];
  597. Testing::nbSamples_t len;
  598. Testing::nbSamples_t i=0;
  599. uint32_t val;
  600. q7_t *ptr=(q7_t*)p;
  601. std::string fileName = this->getPatternPath(id);
  602. FILE *pattern=fopen(fileName.c_str(), "r");
  603. // Ignore word size format
  604. fgets(tmp,256,pattern);
  605. // Get nb of samples
  606. fgets(tmp,256,pattern);
  607. len=atoi(tmp);
  608. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  609. {
  610. len = nb;
  611. }
  612. for(i=0;i<len;i++)
  613. {
  614. // Ignore comment
  615. fgets(tmp,256,pattern);
  616. fscanf(pattern,"0x%08X\n",&val);
  617. *ptr = TOTYP(q7_t,val);
  618. ptr++;
  619. }
  620. fclose(pattern);
  621. }
  622. void Semihosting::ImportPattern_u32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  623. {
  624. char tmp[256];
  625. Testing::nbSamples_t len;
  626. Testing::nbSamples_t i=0;
  627. uint32_t val;
  628. uint32_t *ptr=(uint32_t*)p;
  629. std::string fileName = this->getPatternPath(id);
  630. FILE *pattern=fopen(fileName.c_str(), "r");
  631. // Ignore word size format
  632. fgets(tmp,256,pattern);
  633. // Get nb of samples
  634. fgets(tmp,256,pattern);
  635. len=atoi(tmp);
  636. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  637. {
  638. len = nb;
  639. }
  640. for(i=0;i<len;i++)
  641. {
  642. // Ignore comment
  643. fgets(tmp,256,pattern);
  644. fscanf(pattern,"0x%08X\n",&val);
  645. *ptr = val;
  646. ptr++;
  647. }
  648. fclose(pattern);
  649. }
  650. void Semihosting::ImportPattern_u16(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  651. {
  652. char tmp[256];
  653. Testing::nbSamples_t len;
  654. Testing::nbSamples_t i=0;
  655. uint32_t val;
  656. uint16_t *ptr=(uint16_t*)p;
  657. std::string fileName = this->getPatternPath(id);
  658. FILE *pattern=fopen(fileName.c_str(), "r");
  659. // Ignore word size format
  660. fgets(tmp,256,pattern);
  661. // Get nb of samples
  662. fgets(tmp,256,pattern);
  663. len=atoi(tmp);
  664. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  665. {
  666. len = nb;
  667. }
  668. for(i=0;i<len;i++)
  669. {
  670. // Ignore comment
  671. fgets(tmp,256,pattern);
  672. fscanf(pattern,"0x%08X\n",&val);
  673. *ptr = (uint16_t)val;
  674. ptr++;
  675. }
  676. fclose(pattern);
  677. }
  678. void Semihosting::ImportPattern_u8(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  679. {
  680. char tmp[256];
  681. Testing::nbSamples_t len;
  682. Testing::nbSamples_t i=0;
  683. uint32_t val;
  684. uint8_t *ptr=(uint8_t*)p;
  685. std::string fileName = this->getPatternPath(id);
  686. FILE *pattern=fopen(fileName.c_str(), "r");
  687. // Ignore word size format
  688. fgets(tmp,256,pattern);
  689. // Get nb of samples
  690. fgets(tmp,256,pattern);
  691. len=atoi(tmp);
  692. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  693. {
  694. len = nb;
  695. }
  696. for(i=0;i<len;i++)
  697. {
  698. // Ignore comment
  699. fgets(tmp,256,pattern);
  700. fscanf(pattern,"0x%08X\n",&val);
  701. *ptr = (uint8_t)val;
  702. ptr++;
  703. }
  704. fclose(pattern);
  705. }
  706. void Semihosting::DumpPattern_f64(Testing::outputID_t id,Testing::nbSamples_t nb, float64_t* data)
  707. {
  708. std::string fileName = this->getOutputPath(id);
  709. FILE *f = fopen(fileName.c_str(),"w");
  710. Testing::nbSamples_t i=0;
  711. uint64_t t;
  712. float64_t v;
  713. for(i=0; i < nb; i++)
  714. {
  715. v = data[i];
  716. t = TOINT64(v);
  717. fprintf(f,"0x%016llx\n",t);
  718. }
  719. fclose(f);
  720. }
  721. void Semihosting::DumpPattern_f32(Testing::outputID_t id,Testing::nbSamples_t nb, float32_t* data)
  722. {
  723. std::string fileName = this->getOutputPath(id);
  724. FILE *f = fopen(fileName.c_str(),"w");
  725. Testing::nbSamples_t i=0;
  726. uint32_t t;
  727. float32_t v;
  728. for(i=0; i < nb; i++)
  729. {
  730. v = data[i];
  731. t = TOINT32(v);
  732. fprintf(f,"0x%08x\n",t);
  733. }
  734. fclose(f);
  735. }
  736. void Semihosting::DumpPattern_q31(Testing::outputID_t id,Testing::nbSamples_t nb, q31_t* data)
  737. {
  738. std::string fileName = this->getOutputPath(id);
  739. FILE *f = fopen(fileName.c_str(),"w");
  740. Testing::nbSamples_t i=0;
  741. uint32_t t;
  742. for(i=0; i < nb; i++)
  743. {
  744. t = (uint32_t)data[i];
  745. fprintf(f,"0x%08x\n",t);
  746. }
  747. fclose(f);
  748. }
  749. void Semihosting::DumpPattern_q15(Testing::outputID_t id,Testing::nbSamples_t nb, q15_t* data)
  750. {
  751. std::string fileName = this->getOutputPath(id);
  752. FILE *f = fopen(fileName.c_str(),"w");
  753. Testing::nbSamples_t i=0;
  754. uint32_t t;
  755. for(i=0; i < nb; i++)
  756. {
  757. t = (uint32_t)data[i];
  758. fprintf(f,"0x%08x\n",t);
  759. }
  760. fclose(f);
  761. }
  762. void Semihosting::DumpPattern_q7(Testing::outputID_t id,Testing::nbSamples_t nb, q7_t* data)
  763. {
  764. std::string fileName = this->getOutputPath(id);
  765. FILE *f = fopen(fileName.c_str(),"w");
  766. Testing::nbSamples_t i=0;
  767. uint32_t t;
  768. for(i=0; i < nb; i++)
  769. {
  770. t = (uint32_t)data[i];
  771. fprintf(f,"0x%08x\n",t);
  772. }
  773. fclose(f);
  774. }
  775. void Semihosting::DumpPattern_u32(Testing::outputID_t id,Testing::nbSamples_t nb, uint32_t* data)
  776. {
  777. std::string fileName = this->getOutputPath(id);
  778. FILE *f = fopen(fileName.c_str(),"w");
  779. Testing::nbSamples_t i=0;
  780. uint32_t t;
  781. for(i=0; i < nb; i++)
  782. {
  783. t = (uint32_t)data[i];
  784. fprintf(f,"0x%08x\n",t);
  785. }
  786. fclose(f);
  787. }
  788. void Semihosting::DumpPattern_u16(Testing::outputID_t id,Testing::nbSamples_t nb, uint16_t* data)
  789. {
  790. std::string fileName = this->getOutputPath(id);
  791. FILE *f = fopen(fileName.c_str(),"w");
  792. Testing::nbSamples_t i=0;
  793. uint32_t t;
  794. for(i=0; i < nb; i++)
  795. {
  796. t = (uint32_t)data[i];
  797. fprintf(f,"0x%08x\n",t);
  798. }
  799. fclose(f);
  800. }
  801. void Semihosting::DumpPattern_u8(Testing::outputID_t id,Testing::nbSamples_t nb, uint8_t* data)
  802. {
  803. std::string fileName = this->getOutputPath(id);
  804. FILE *f = fopen(fileName.c_str(),"w");
  805. Testing::nbSamples_t i=0;
  806. uint32_t t;
  807. for(i=0; i < nb; i++)
  808. {
  809. t = (uint32_t)data[i];
  810. fprintf(f,"0x%08x\n",t);
  811. }
  812. fclose(f);
  813. }
  814. }