You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

828 lines
25 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include <stdio.h>
  2. #include "../../source/lib/components/base/basicLogCollection.h"
  3. #include "../../source/lib/components/object/objectCliLoggingServices.h"
  4. #include "../../source/lib/components/object/objectFileLoggingService.h"
  5. #include "../../source/lib/hardware/soc/classSOC.h"
  6. #include "../../source/lib/hardware/can/canbus.h"
  7. #include "../../source/lib/data/protocol/protocolTGZ.h"
  8. #include "mainWindow.h"
  9. #include "tgzWindow.h"
  10. #include "tgz2Window.h"
  11. #include "pwmInfoWindow.h"
  12. #include "pruCoresWindow.h"
  13. #include "tupus1_0Window.h"
  14. #include "tupus1_1Window.h"
  15. #include "tupus0_1Window.h"
  16. #include "tupus0_0Window.h"
  17. #include "pru0Window.h"
  18. #include "pru1Window.h"
  19. #include "adc1Window.h"
  20. #include "motorWindow.h"
  21. #include "gpioWindow.h"
  22. #define LOG( X ) LogEng->Log( "main", 0, X )
  23. #define LOG_ERROR( X ) LogEng->Log( "main", 0, _LOG_ERROR, X )
  24. #ifdef NEWT_CLI
  25. #include <signal.h>
  26. struct callbackInfo {
  27. newtComponent en;
  28. char * state;
  29. };
  30. void disableCallback(newtComponent co, void * data) {
  31. struct callbackInfo * cbi = ( struct callbackInfo *) data;
  32. if (*cbi->state == ' ') {
  33. newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
  34. } else {
  35. newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
  36. }
  37. newtRefresh();
  38. };
  39. void suspend(void * d) {
  40. newtSuspend();
  41. raise( SIGTSTP );
  42. newtResume();
  43. };
  44. #endif
  45. int main (int argc, char *argv[]){
  46. #ifdef TURBOVISION
  47. WindowCLI *a;
  48. a = new WindowCLI();
  49. a->run();
  50. #else
  51. #ifdef NEWT_CLI
  52. newtComponent mainMenuForm, checkbox, rb[3], button;
  53. char cbValue;
  54. int i;
  55. newtInit();
  56. newtCls();
  57. newtSetSuspendCallback( suspend, NULL );
  58. newtDrawRootText( 0, 0, "Direct Memory Tool" );
  59. newtDrawRootText( -29, -2, "� Dr. Frucht Systems Ltd." );
  60. canBus *mCanBus_OLD;
  61. canBus *mCanBus_NEW;
  62. protocolTGZ *mTGZdevice_OLD;
  63. protocolTGZ *mTGZdevice_NEW;
  64. mainWindow *my_win;
  65. tgz1Window *tgz_oldWindow = NULL;
  66. tgz2Window *tgz_newWindow = NULL;
  67. pwmInfoWindow *pwmWindow0;
  68. pruCoresWindow *coreWindow;
  69. tupus0_0Window *t00W;
  70. tupus0_1Window *t01W;
  71. tupus1_0Window *t10W;
  72. tupus1_1Window *t11W;
  73. pru0Window *pPW0;
  74. pru1Window *pPW1;
  75. adc1Window *pADC;
  76. motorWindow *mW;
  77. basicLogCollection *LogEng;
  78. classSOC *mSOC;
  79. objectCliLoggingService *LogWND;
  80. objectFileLoggingService *LogFile;
  81. gpioWindow *gpioWND;
  82. int ch;
  83. my_win = new mainWindow();
  84. LogEng = basicLogCollection::getInstance();
  85. LogWND = new objectCliLoggingService();
  86. LogFile = new objectFileLoggingService("my.log");
  87. LogEng->addHandler( LogFile );
  88. LogEng->addHandler( LogWND );
  89. mSOC = classSOC::getInstance();
  90. init_PRMCM();
  91. //printf( "PRMCM Init Done\n" );
  92. enable_ADC1_CLK();
  93. //printf( "ADC1 CLK Enable Done\n" );
  94. init_ADC_0();
  95. init_ADC_1();
  96. //prepareFSM1();
  97. if(!init_GPIO_0())LOG("GPIO0 Init Error!");
  98. if(!init_GPIO_1())LOG("GPIO1 Init Error!");
  99. if(!init_GPIO_2())LOG("GPIO2 Init Error!");
  100. if(!init_GPIO_3())LOG("GPIO3 Init Error!");
  101. if(!init_GPIO_4())LOG("GPIO4 Init Error!");
  102. if(!init_GPIO_5())LOG("GPIO5 Init Error!");
  103. //mSOC->pru_load( 0, 0, "CORE0_0.bin" );
  104. //mSOC->pru_load( 0, 1, "CORE0_1.bin" );
  105. //mSOC->pru_load( 1, 0, "CORE1_0.bin" );
  106. //mSOC->pru_load( 1, 1, "CORE1_1.bin" );
  107. //mSOC->pru_run( 1, 1 );
  108. //mSOC->pru_run( 1, 0 );
  109. //mSOC->pru_run( 0, 1 );
  110. //mSOC->pru_run( 0, 0 );
  111. pwmWindow0 = new pwmInfoWindow();
  112. coreWindow = new pruCoresWindow();
  113. t11W = new tupus1_1Window();
  114. t10W = new tupus1_0Window();
  115. t01W = new tupus0_1Window();
  116. t00W = new tupus0_0Window();
  117. //pPW0 = new pru0Window();
  118. //pPW1 = new pru1Window();
  119. pADC = new adc1Window();
  120. mW = new motorWindow();
  121. mCanBus_OLD = new canBus( "can1", 0x200, 0x201 );
  122. if( mCanBus_OLD != NULL ) {
  123. LOG("CAN Bus creation success");
  124. mTGZdevice_OLD = new protocolTGZ( mCanBus_OLD );
  125. if( mTGZdevice_OLD == NULL ) {
  126. LOG_ERROR("TGZ OLD protocol creation failure");
  127. }else{
  128. tgz_oldWindow = new tgz1Window( mTGZdevice_OLD );
  129. LOG("TGZ OLD protocol creation success");
  130. };
  131. } else {
  132. LOG_ERROR("CAN Bus creation failure");
  133. };
  134. mCanBus_NEW = new canBus( "can1", 0x300, 0x301 );
  135. if( mCanBus_NEW != NULL ) {
  136. LOG("CAN Bus creation success");
  137. mTGZdevice_NEW = new protocolTGZ( mCanBus_NEW );
  138. if( mTGZdevice_NEW == NULL ) {
  139. LOG_ERROR("TGZ NEW protocol creation failure");
  140. }else{
  141. mTGZdevice_NEW->setSpeeds( 0, 0 );
  142. tgz_newWindow = new tgz2Window( mTGZdevice_NEW );
  143. LOG("TGZ NEW protocol creation success");
  144. };
  145. } else {
  146. LOG_ERROR("CAN Bus creation failure");
  147. };
  148. gpioWND = new gpioWindow();
  149. newtRefresh();
  150. newtComponent answer;
  151. int momo = 0;
  152. do {
  153. my_win->show();
  154. answer = my_win->run();
  155. my_win->hide();
  156. momo = my_win->decodeEvent( answer );
  157. if( momo ){
  158. switch( momo ) {
  159. case 1:{//ADC
  160. pADC->show();
  161. pADC->run();
  162. pADC->hide();
  163. break;
  164. };
  165. case 2:{//PWM
  166. pwmWindow0->show();
  167. pwmWindow0->run();
  168. pwmWindow0->hide();
  169. break;
  170. };
  171. case 3:{//Motors
  172. mW->show();
  173. mW->run();
  174. mW->hide();
  175. break;
  176. };
  177. case 4:{//PRUSS
  178. pwmWindow0->show();
  179. pwmWindow0->run();
  180. pwmWindow0->hide();
  181. break;
  182. };
  183. case 5:{//PRU
  184. coreWindow->show();
  185. coreWindow->run();
  186. coreWindow->hide();
  187. break;
  188. };
  189. case 6:{
  190. mSOC->pru_sreset( 1, 1 );
  191. mSOC->pru_sreset( 1, 0 );
  192. mSOC->pru_sreset( 0, 1 );
  193. mSOC->pru_sreset( 0, 0 );
  194. LogWND->show();
  195. LogWND->run();
  196. LogWND->hide();
  197. break;
  198. };
  199. case 7:{
  200. mSOC->pru_stop( 0, 0 );
  201. mSOC->pru_stop( 0, 1 );
  202. mSOC->pru_stop( 1, 0 );
  203. mSOC->pru_stop( 1, 1 );
  204. LogWND->show();
  205. LogWND->run();
  206. LogWND->hide();
  207. break;
  208. };
  209. case 8:{
  210. mSOC->pru_run( 1, 1 );
  211. mSOC->pru_run( 1, 0 );
  212. mSOC->pru_run( 0, 1 );
  213. mSOC->pru_run( 0, 0 );
  214. LogWND->show();
  215. LogWND->run();
  216. LogWND->hide();
  217. break;
  218. };
  219. case 9:{
  220. mSOC->pru_save( 1, 0, "toto0.bin", true );
  221. mSOC->pru_save( 1, 1, "toto1.bin", true );
  222. LogWND->show();
  223. LogWND->run();
  224. LogWND->hide();
  225. break;
  226. };
  227. case 10:{
  228. mSOC->pru_save( 1, 0, "toto0.bin", false );
  229. mSOC->pru_save( 1, 1, "toto1.bin", false );
  230. LogWND->show();
  231. LogWND->run();
  232. LogWND->hide();
  233. break;
  234. };
  235. case 11:{
  236. mSOC->pru_load( 0, 0, "PRU_0_0.bin" );
  237. mSOC->pru_load( 0, 1, "PRU_0_1.bin" );
  238. mSOC->pru_load( 1, 0, "PRU_1_0.bin", false );
  239. mSOC->pru_load( 1, 1, "PRU_1_1.bin", false );
  240. mSOC->pru_run( 0, 0 );
  241. mSOC->pru_run( 0, 1 );
  242. mSOC->pru_run( 1, 0 );
  243. mSOC->pru_run( 1, 1 );
  244. LogWND->show();
  245. LogWND->run();
  246. LogWND->hide();
  247. break;
  248. };
  249. case 12:{ // Old TGZ
  250. if( tgz_oldWindow!= NULL ) {
  251. newtComponent l_answer;
  252. int l_momo = 0;
  253. do{
  254. tgz_oldWindow->show();
  255. l_answer = tgz_oldWindow->run();
  256. tgz_oldWindow->hide();
  257. l_momo = tgz_oldWindow->decodeEvent( l_answer );
  258. if( l_momo ){
  259. switch( l_momo ) {
  260. case 1: mTGZdevice_OLD->toggleRun(); break;
  261. case 2: mTGZdevice_OLD->toggleErrorReset(); break;
  262. case 3: mTGZdevice_OLD->togglePRF(); break;
  263. case 4: mTGZdevice_OLD->toggleDivider(); break;
  264. case 5: mTGZdevice_OLD->togleRatio(); break;
  265. case 6: mTGZdevice_OLD->startDeviceStateInquiry(); break;
  266. case 255: l_momo = 0; break;
  267. };
  268. newtRefresh();
  269. };
  270. } while( l_momo );
  271. };
  272. break;
  273. };
  274. case 13:{ // New TGZ
  275. if( tgz_newWindow!= NULL ) {
  276. newtComponent l_answer;
  277. int l_momo = 0;
  278. do{
  279. tgz_newWindow->show();
  280. l_answer = tgz_newWindow->run();
  281. tgz_newWindow->hide();
  282. l_momo = tgz_newWindow->decodeEvent( l_answer );
  283. if( l_momo ){
  284. switch( l_momo ) {
  285. case 1: mTGZdevice_NEW->toggleRun(); break;
  286. case 2: mTGZdevice_NEW->toggleErrorReset(); break;
  287. case 3: mTGZdevice_NEW->toggleQSpeed(); break;
  288. case 4: mTGZdevice_NEW->toggleBSpeed(); break;
  289. case 5: mTGZdevice_NEW->startDeviceStateInquiry(); break;
  290. case 255: l_momo = 0; break;
  291. };
  292. newtRefresh();
  293. };
  294. } while( l_momo );
  295. };
  296. break;
  297. };
  298. case 14:{//View LOG
  299. LogWND->show();
  300. LogWND->run();
  301. LogWND->hide();
  302. break;
  303. };
  304. case 15:{// View GPIO
  305. gpioWND->show();
  306. break;
  307. };
  308. case 255: momo = 0; break;
  309. default:{
  310. //momo = 0;
  311. };
  312. };
  313. newtRefresh();
  314. };
  315. } while( momo );
  316. delete( my_win );
  317. newtFinished();
  318. printf( "Momo: %d Ans: %p\n\n", momo, answer );
  319. #else
  320. canBus *mCanBus;
  321. protocolTGZ *mTGZdevice;
  322. basicNCursesEngine *MyCurses;
  323. mainWindow *my_win;
  324. //tgzWindow *pWindow;
  325. pwmInfoWindow *pwmWindow0;
  326. tupus0_0Window *t00W;
  327. tupus0_1Window *t01W;
  328. tupus1_0Window *t10W;
  329. tupus1_1Window *t11W;
  330. pru0Window *pPW0;
  331. pru1Window *pPW1;
  332. adc1Window *pADC;
  333. motorWindow *mW;
  334. basicLogCollection *LogEng;
  335. objectCURSESLoggingService *LogWND;
  336. classSOC *mSOC;
  337. objectFileLoggingService *LogFile;
  338. int ch;
  339. MyCurses = basicNCursesEngine::getInstance();
  340. LogEng = basicLogCollection::getInstance();
  341. LogWND = new objectCURSESLoggingService();
  342. LogFile = new objectFileLoggingService("my.log");
  343. LogEng->addHandler( LogFile );
  344. LogEng->addHandler( LogWND );
  345. refresh();
  346. mSOC = classSOC::getInstance();
  347. init_PRMCM();
  348. printf( "PRMCM Init Done\n" );
  349. enable_ADC1_CLK();
  350. printf( "ADC1 CLK Enable Done\n" );
  351. init_ADC_0();
  352. init_ADC_1();
  353. printf( "ADC Init Done\n" );
  354. printf( "Revision 0: 0x%08X\n", getRevisionADC0() );
  355. printf( "Revision 1: 0x%08X\n", getRevisionADC1() );
  356. //prepareFSM1();
  357. //mSOC->pru_load( 0, 0, "CORE0_0.bin" );
  358. //mSOC->pru_load( 0, 1, "CORE0_1.bin" );
  359. //mSOC->pru_load( 1, 0, "CORE1_0.bin" );
  360. //mSOC->pru_load( 1, 1, "CORE1_1.bin" );
  361. //mSOC->pru_run( 1, 1 );
  362. //mSOC->pru_run( 1, 0 );
  363. //mSOC->pru_run( 0, 1 );
  364. //mSOC->pru_run( 0, 0 );
  365. my_win = new mainWindow();
  366. pwmWindow0 = new pwmInfoWindow();
  367. t11W = new tupus1_1Window();
  368. t10W = new tupus1_0Window();
  369. t01W = new tupus0_1Window();
  370. t00W = new tupus0_0Window();
  371. //pPW0 = new pru0Window();
  372. //pPW1 = new pru1Window();
  373. pADC = new adc1Window();
  374. mW = new motorWindow();
  375. mCanBus = new canBus( "can1", 0x200, 0x201 );
  376. if( mCanBus != NULL ) {
  377. LOG("CAN Bus creation success");
  378. mTGZdevice = new protocolTGZ( mCanBus, 0x200, 0x201 );
  379. if( mTGZdevice == NULL ) {
  380. LOG_ERROR("TGZ protocol creation failure");
  381. }else{
  382. LOG("TGZ protocol creation success");
  383. };
  384. } else {
  385. LOG_ERROR("CAN Bus creation failure");
  386. };
  387. //pWindow = new tgzWindow( mTGZdevice );
  388. while((ch = getch()) != KEY_F(1) ) {
  389. switch(ch){
  390. case KEY_LEFT:
  391. //MyCurses->destroy_win(my_win);
  392. //my_win = MyCurses->create_win(height, width, starty,--startx);
  393. break;
  394. case KEY_RIGHT:
  395. //MyCurses->destroy_win(my_win);
  396. //my_win = MyCurses->create_win(height, width, starty,++startx);
  397. break;
  398. case KEY_UP:
  399. break;
  400. case KEY_DOWN:
  401. //MyCurses->destroy_win(my_win);
  402. //my_win = MyCurses->create_win(height, width, ++starty,startx);
  403. break;
  404. };
  405. switch( ch ) {
  406. case '1':
  407. mTGZdevice->toggleErrorReset();
  408. //pWindow->paint();
  409. break;
  410. case '2':
  411. mTGZdevice->toggleRun();
  412. //pWindow->paint();
  413. break;
  414. case '3':
  415. mTGZdevice->togglePRF();
  416. //pWindow->paint();
  417. break;
  418. case '4':
  419. mTGZdevice->togleRatio();
  420. //pWindow->paint();
  421. break;
  422. case '5':
  423. mTGZdevice->toggleDivider();
  424. //pWindow->paint();
  425. break;
  426. case '6':
  427. mTGZdevice->stopPRF();
  428. //pWindow->paint();
  429. break;
  430. case '7':
  431. mTGZdevice->stopAzimuth();
  432. //pWindow->paint();
  433. break;
  434. //case '0':{
  435. // char *pName;
  436. // pName = mTGZdevice->generateFileNameForStat();
  437. // //mW->saveStatToFile( pName );
  438. // free( pName );
  439. // break;
  440. // };
  441. case 'q':
  442. case 'Q': return 0;
  443. case '9':
  444. case 'r':
  445. case 'R':
  446. // mW->resetStat();
  447. mSOC->pru_sreset( 1, 1 );
  448. mSOC->pru_sreset( 1, 0 );
  449. mSOC->pru_sreset( 0, 1 );
  450. mSOC->pru_sreset( 0, 0 );
  451. break;
  452. case ' ':
  453. my_win->paint();
  454. pwmWindow0->paint();
  455. //pWindow->paint();
  456. //mW->paint();
  457. t00W->paint();
  458. t01W->paint();
  459. t10W->paint();
  460. t11W->paint();
  461. //pPW0->paint();
  462. //pPW1->paint();
  463. pADC->paint();
  464. LogWND->paint();
  465. continue;
  466. break;
  467. case 's':
  468. case 'S':
  469. mSOC->pru_save( 1, 0, "toto0.bin" );
  470. mSOC->pru_save( 1, 1, "toto1.bin" );
  471. break;
  472. case 'l':
  473. case 'L':
  474. mSOC->pru_load( 0, 0, "PRU_0_0.bin" );
  475. mSOC->pru_load( 0, 1, "PRU_0_1.bin" );
  476. mSOC->pru_load( 1, 0, "PRU_1_0.bin" );
  477. mSOC->pru_load( 1, 1, "PRU_1_1.bin" );
  478. mSOC->pru_run( 0, 0 );
  479. mSOC->pru_run( 0, 1 );
  480. mSOC->pru_run( 1, 0 );
  481. mSOC->pru_run( 1, 1 );
  482. break;
  483. case '8':
  484. case 'g':
  485. case 'G':
  486. mTGZdevice->startDeviceStateInquiry();
  487. sleep(1);
  488. break;
  489. case 'c':
  490. case 'C':
  491. mSOC->cleanTUPUS( 0, 0 );
  492. mSOC->cleanTUPUS( 1, 0 );
  493. t00W->paint();
  494. t01W->paint();
  495. t10W->paint();
  496. t11W->paint();
  497. break;
  498. case 'i':
  499. case 'I':
  500. //pWindow->paint();
  501. break;
  502. case 'o':
  503. case 'O':
  504. mSOC->setCoreOnLine( 0 );
  505. t01W->paint();
  506. t00W->paint();
  507. t11W->paint();
  508. t10W->paint();
  509. break;
  510. case 'p':
  511. case 'P':
  512. t00W->paint();
  513. t01W->paint();
  514. t11W->paint();
  515. t10W->paint();
  516. //pPW0->paint();
  517. //pPW1->paint();
  518. pADC->paint();
  519. break;
  520. case 'w':
  521. case 'W':
  522. mSOC->pru_run( 1, 1 );
  523. mSOC->pru_run( 1, 0 );
  524. mSOC->pru_run( 0, 1 );
  525. mSOC->pru_run( 0, 0 );
  526. break;
  527. case 't':
  528. case 'T':
  529. mSOC->pru_stop( 0, 0 );
  530. mSOC->pru_stop( 0, 1 );
  531. mSOC->pru_stop( 1, 0 );
  532. mSOC->pru_stop( 1, 1 );
  533. break;
  534. case 'z':
  535. case 'Z':
  536. pwmWindow0->paint();
  537. break;
  538. default:
  539. break;
  540. };
  541. //pWindow->paint();
  542. mW->paint();
  543. usleep(50000);
  544. };
  545. #endif
  546. #endif
  547. // MyCurses->destroy_win( my_win );
  548. /* return 0;
  549. init_GPIO_0();
  550. init_GPIO_1();
  551. init_GPIO_2();
  552. init_GPIO_3();
  553. init_GPIO_4();
  554. init_GPIO_5();
  555. printf( " GPIO INIT DONE \n");
  556. printf(" GPIO1 OE: 0x%08X\n", getOutputMode(1) );
  557. //printf(" GPIO3 OE: 0x%08X\n", getOutputMode(3) );
  558. setOutputMode( 1, 0x0 );
  559. //setOutputMode( 3, 0x0 );
  560. uint32_t index = 0;
  561. uint32_t c_out = 0;
  562. uint32_t b_out = 0;
  563. uint32_t k = 0;
  564. uint32_t Data = 0;
  565. init_PRMCM();
  566. printf( "PRMCM Init Done\n" );
  567. enable_ADC1_CLK();
  568. printf( "ADC1 CLK Enable Done\n" );
  569. enable_EPWM_CLK();
  570. printf( "EPWM CLK Enable Done\n" );
  571. init_ADC_0();
  572. init_ADC_1();
  573. printf( "ADC Init Done\n" );
  574. printf( "Revision 0: 0x%08X\n", getRevisionADC0() );
  575. printf( "Revision 1: 0x%08X\n", getRevisionADC1() );
  576. prepareFSM1();
  577. //printf( "ADC FSM Ready\nStrike Enter\n" );
  578. //char kaka;
  579. //kaka = getchar();
  580. //printf( "Starting Loop\n" );
  581. uint16_t AD0_Data = 0;
  582. uint8_t AD0_Channel = 0;
  583. uint16_t AD1_Data = 0;
  584. uint8_t AD1_Channel = 0;
  585. while(0){
  586. index++;
  587. if( index > 15 ) index = 1;
  588. c_out = 0x0F000000 & (~( index << 24 ));
  589. b_out = 0x00000060 & (~( index << 5 ));
  590. setOutputDirect( 1, c_out );
  591. //setOutputDirect( 3, b_out );
  592. usleep(10000);
  593. //ADC
  594. startADC1();
  595. printf("ADC Cycle Started\n\n");
  596. for( k = 0; k < 8; k++ ) {
  597. Data = getDataADC1_FIFO0( 100 );
  598. if( Data != ADC_VALUE_TIMEOUT ) {
  599. #ifdef ADC_WORK_SIMULTANEOUS_MODE
  600. AD0_Channel = ( Data >> 28 ) & 0xF;
  601. AD0_Data = ( Data >> 16 ) & 0xFFF;
  602. AD1_Channel = ( Data >> 12 ) & 0xF;
  603. AD1_Data = Data & 0xFFF;
  604. #else
  605. AD0_Channel = 0;
  606. AD0_Data = 0;//( Data >> 16 ) & 0xFFF;
  607. AD1_Channel = ( Data >> 16 ) & 0xF;
  608. AD1_Data = ( Data >> 0 ) & 0xFFF;
  609. #endif
  610. printf( " Data: 0x%08X ADC0[%d]: 0x%03X ADC1[%d]: 0x%03X\n", Data, AD0_Channel, AD0_Data, AD1_Channel, AD1_Data );
  611. } else {
  612. printf( " ADC FIFO 0 [%d]: TIMEOUT\n", k );
  613. };
  614. // Data = getDataADC1_FIFO1( 100 );
  615. //if( Data != ADC_VALUE_TIMEOUT ) {
  616. //printf( " ADC FIFO 1 [%d]: 0x%08X\n", k, Data );
  617. //} else {
  618. //printf( " ADC FIFO 1 [%d]: TIMEOUT\n", k );
  619. //};
  620. };
  621. };
  622. //pwm_run( 0, 2000 );
  623. //pwm_run( 1, 2000 );
  624. //pwm_run( 2, 2000 );
  625. //print_PWM_info(0);
  626. //printf( "PWM Running\nStrike Enter\n" );
  627. //kaka = getchar();
  628. //pwm_stop( 0 );
  629. //pwm_stop( 1 );
  630. //pwm_stop( 2 );
  631. // */
  632. return(0);
  633. };
  634. /*
  635. * devmem2.c: Simple program to read/write from/to any location in memory.
  636. *
  637. * Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
  638. *
  639. *
  640. * This software has been developed for the LART computing board
  641. * (http://www.lart.tudelft.nl/). The development has been sponsored by
  642. * the Mobile MultiMedia Communications (http://www.mmc.tudelft.nl/)
  643. * and Ubiquitous Communications (http://www.ubicom.tudelft.nl/)
  644. * projects.
  645. *
  646. * The author can be reached at:
  647. *
  648. * Jan-Derk Bakker
  649. * Information and Communication Theory Group
  650. * Faculty of Information Technology and Systems
  651. * Delft University of Technology
  652. * P.O. Box 5031
  653. * 2600 GA Delft
  654. * The Netherlands
  655. *
  656. *
  657. * This program is free software; you can redistribute it and/or modify
  658. * it under the terms of the GNU General Public License as published by
  659. * the Free Software Foundation; either version 2 of the License, or
  660. * (at your option) any later version.
  661. *
  662. * This program is distributed in the hope that it will be useful,
  663. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  664. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  665. * GNU General Public License for more details.
  666. *
  667. * You should have received a copy of the GNU General Public License
  668. * along with this program; if not, write to the Free Software
  669. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  670. *
  671. */
  672. /*
  673. #include <stdio.h>
  674. #include <stdlib.h>
  675. #include <unistd.h>
  676. //#include <string.h>
  677. #include <errno.h>
  678. #include <signal.h>
  679. #include <fcntl.h>
  680. #include <ctype.h>
  681. #include <termios.h>
  682. #include <sys/types.h>
  683. #include <sys/mman.h>
  684. #define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \
  685. __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
  686. #define MAP_SIZE 4096UL
  687. #define MAP_MASK (MAP_SIZE - 1)
  688. int mainz(int argc, char **argv) {
  689. int fd;
  690. void *map_base, *virt_addr;
  691. unsigned long read_result, writeval;
  692. off_t target;
  693. int access_type = 'w';
  694. if(argc < 2) {
  695. fprintf(stderr, "\nUsage:\t%s { address } [ type [ data ] ]\n"
  696. "\taddress : memory address to act upon\n"
  697. "\ttype : access operation type : [b]yte, [h]alfword, [w]ord\n"
  698. "\tdata : data to be written\n\n",
  699. argv[0]);
  700. exit(1);
  701. }
  702. target = strtoul(argv[1], 0, 0);
  703. if(argc > 2)
  704. access_type = tolower(argv[2][0]);
  705. if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;
  706. printf("/dev/mem opened.\n");
  707. fflush(stdout);
  708. // Map one page
  709. map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
  710. if(map_base == (void *) -1) FATAL;
  711. printf("Memory mapped at address %p.\n", map_base);
  712. fflush(stdout);
  713. virt_addr = map_base + (target & MAP_MASK);
  714. switch(access_type) {
  715. case 'b':
  716. read_result = *((unsigned char *) virt_addr);
  717. break;
  718. case 'h':
  719. read_result = *((unsigned short *) virt_addr);
  720. break;
  721. case 'w':
  722. read_result = *((unsigned long *) virt_addr);
  723. break;
  724. default:
  725. fprintf(stderr, "Illegal data type '%c'.\n", access_type);
  726. exit(2);
  727. }
  728. printf("Value at address 0x08%X (%p): 0x%08X\n", target, virt_addr, read_result);
  729. fflush(stdout);
  730. if(argc > 3) {
  731. writeval = strtoul(argv[3], 0, 0);
  732. switch(access_type) {
  733. case 'b':
  734. *((unsigned char *) virt_addr) = writeval;
  735. read_result = *((unsigned char *) virt_addr);
  736. break;
  737. case 'h':
  738. *((unsigned short *) virt_addr) = writeval;
  739. read_result = *((unsigned short *) virt_addr);
  740. break;
  741. case 'w':
  742. *((unsigned long *) virt_addr) = writeval;
  743. read_result = *((unsigned long *) virt_addr);
  744. break;
  745. }
  746. printf("Written 0x%X; readback 0x%X\n", writeval, read_result);
  747. fflush(stdout);
  748. }
  749. if(munmap(map_base, MAP_SIZE) == -1) FATAL;
  750. close(fd);
  751. return 0;
  752. }
  753. */
  754. #undef LOG
  755. #undef LOG_ERROR