comparison core/PRU.cpp @ 15:901d205d1a3c

Updated to latest PRU library; external PRU file no longer needed. Also catch SIGTERM as well as SIGINT to clean up gracefully.
author andrewm
date Sat, 07 Feb 2015 16:41:56 +0000
parents a6beeba3a648
children 670be80463a3
comparison
equal deleted inserted replaced
14:06f93bef7dd2 15:901d205d1a3c
16 #include "../include/PRU.h" 16 #include "../include/PRU.h"
17 #include "../include/prussdrv.h" 17 #include "../include/prussdrv.h"
18 #include "../include/pruss_intc_mapping.h" 18 #include "../include/pruss_intc_mapping.h"
19 #include "../include/GPIOcontrol.h" 19 #include "../include/GPIOcontrol.h"
20 #include "../include/render.h" 20 #include "../include/render.h"
21 #include "../include/pru_rtaudio_bin.h"
21 22
22 #include <iostream> 23 #include <iostream>
23 #include <stdlib.h> 24 #include <stdlib.h>
24 #include <cstdio> 25 #include <cstdio>
25 #include <cerrno> 26 #include <cerrno>
247 /* PRUSS_INTC_INITDATA is found in pruss_intc_mapping.h */ 248 /* PRUSS_INTC_INITDATA is found in pruss_intc_mapping.h */
248 tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA; 249 tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
249 250
250 /* Allocate and initialize memory */ 251 /* Allocate and initialize memory */
251 prussdrv_init(); 252 prussdrv_init();
252 if(prussdrv_open(PRU_EVTOUT_0)) { 253 if(prussdrv_open(pru_number == 0 ? PRU_EVTOUT_0 : PRU_EVTOUT_1)) {
253 rt_printf("Failed to open PRU driver\n"); 254 rt_printf("Failed to open PRU driver\n");
254 return 1; 255 return 1;
255 } 256 }
256 257
257 /* Map PRU's INTC */ 258 /* Map PRU's INTC */
329 330
330 return 0; 331 return 0;
331 } 332 }
332 333
333 // Run the code image in the specified file 334 // Run the code image in the specified file
334 int PRU::start(char * const filename) 335 int PRU::start()
335 { 336 {
336 /* Clear any old interrupt */ 337 /* Clear any old interrupt */
337 prussdrv_pru_clear_event(pru_number == 0 ? PRU0_ARM_INTERRUPT : PRU1_ARM_INTERRUPT); 338 if(pru_number == 0)
339 prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);
340 else
341 prussdrv_pru_clear_event(PRU_EVTOUT_1, PRU1_ARM_INTERRUPT);
338 342
339 /* Load and execute binary on PRU */ 343 /* Load and execute binary on PRU */
340 if(prussdrv_exec_program(pru_number, filename)) { 344 if(prussdrv_exec_code(pru_number, PRUcode, sizeof(PRUcode))) {
341 rt_printf("Failed to execute PRU code from %s\n", filename); 345 rt_printf("Failed to execute PRU code\n");
342 return 1; 346 return 1;
343 } 347 }
344 348
345 running = true; 349 running = true;
346 return 0; 350 return 0;
448 // Wait for an interrupt from the PRU indicate it is finished 452 // Wait for an interrupt from the PRU indicate it is finished
449 void PRU::waitForFinish() 453 void PRU::waitForFinish()
450 { 454 {
451 if(!running) 455 if(!running)
452 return; 456 return;
453 prussdrv_pru_wait_event (PRU_EVTOUT_0); 457 prussdrv_pru_wait_event (pru_number == 0 ? PRU_EVTOUT_0 : PRU_EVTOUT_1);
454 prussdrv_pru_clear_event(pru_number == 0 ? PRU0_ARM_INTERRUPT : PRU1_ARM_INTERRUPT); 458 if(pru_number == 0)
459 prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);
460 else
461 prussdrv_pru_clear_event(PRU_EVTOUT_1, PRU1_ARM_INTERRUPT);
455 } 462 }
456 463
457 // Turn off the PRU when done 464 // Turn off the PRU when done
458 void PRU::disable() 465 void PRU::disable()
459 { 466 {