Esempio n. 1
0
void efireExit(void){
	int ctrl = 0;
	if (prussdrv_pru_disable(PRU_0) != 0){
		ctrl = 1;
		printf("ERROR: PRU_0 did not disable.");
	}
	if (prussdrv_pru_disable(PRU_1) != 0){
		ctrl = 1;
		printf("ERROR: PRU_1 did not disable.");
	}
	prussdrv_exit (); // Always returns 0
	
	tcflush(file, TCIOFLUSH);
	if (close(file) != 0){
		ctrl = 1;
		printf("ERROR: UART did not close.");
	}

	if(ctrl == 1){
		printf("ERROR EXITING: Something went really wrong.");
		exit(EXIT_FAILURE);
	}
	
	printf("Exited Succesfully.\n");
	exit(EXIT_SUCCESS);
}
Esempio n. 2
0
void PruTimer::stopThread(bool join) {
	LOG( "Stopping PruTimer..." << std::endl);
	stop=true;
	
	/* Disable PRU and close memory mapping*/
    prussdrv_pru_disable (PRU_NUM0);
    prussdrv_pru_disable (PRU_NUM1);
    prussdrv_exit ();
	
	if(ddr_mem) {
#ifdef DEMO_PRU
		free(ddr_mem);
		ddr_mem = NULL;
#else
		munmap(ddr_mem, ddr_size);
		close(mem_fd);
		ddr_mem = NULL;
		mem_fd=-1;
#endif
	}
    
	LOG( "PRU disabled, DDR released, FD closed." << std::endl);
	
	
	blockAvailable.notify_all();
	if(join && runningThread.joinable()) {
		runningThread.join();
	}
	
	LOG( "PruTimer stopped." << std::endl);
}
Esempio n. 3
0
void PruTimer::reset() {
	std::unique_lock<std::mutex> lk(mutex_memory);
	
	prussdrv_pru_disable(0);
	prussdrv_pru_disable(1);
	
	initalizePRURegisters();
	
	/* Execute firmwares on PRU */
    LOG( ("\tINFO: Starting stepper firmware on PRU0\r\n"));
	unsigned int ret = prussdrv_exec_program (PRU_NUM0, firmwareStepper.c_str());
	if(ret!=0) {
		LOG( "[WARNING] Unable to execute firmware on PRU0" << std::endl);
	}
	
    LOG( ("\tINFO: Starting endstop firmware on PRU1\r\n"));
    ret=prussdrv_exec_program (PRU_NUM1, firmwareEndstop.c_str());
	if(ret!=0) {
		LOG( "[WARNING] Unable to execute firmware on PRU1" << std::endl);
	}
	
	totalQueuedMovesTime = 0;
	ddr_mem_used = 0;
	currentNbEvents = 0;
	
	blocksID = std::queue<BlockDef>();
}
Esempio n. 4
0
int main(int argc, char** argv) {
   if(getuid()!=0){
      printf("You must run this program as root. Exiting.\n");
      exit(EXIT_FAILURE);
   } 
   
   
   // Initialize structure used by prussdrv_pruintc_intc
   // PRUSS_INTC_INITDATA is found in pruss_intc_mapping.h
   tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
   
   // Allocate and initialize memory
   prussdrv_init ();
   
   //Initilize Interrupts
   prussdrv_open (PRU_EVTOUT_0);
   
   // Map PRU's interrupts
   prussdrv_pruintc_init(&pruss_intc_initdata);
   
   // Map PRU memory to a pointer
   prussdrv_map_prumem(PRUSS0_PRU0_DATARAM, &pru0DataMemory);
   pru0DataMemory_int = (unsigned int *) pru0DataMemory;
   // Map ddr memory
   prussdrv_map_extmem((void **) &ddr_memory);
   ddr_memory_int = (unsigned int *) ddr_memory;
   unsigned int shared_ddr_len = prussdrv_extmem_size();
   unsigned int physical_address = prussdrv_get_phys_addr((void *) ddr_memory);
   
   // Use first 8 bytes of PRU memory to tell where the share memory is
   pru0DataMemory_int[0] = physical_address;
   pru0DataMemory_int[1] = shared_ddr_len;
   
   printf("%u bytes of shared DDR available.\n Physical (PRU-side) address:%x\n",  shared_ddr_len, physical_address);  
   printf("Virtual (linux-side) address: %p\n\n", ddr_memory);  
   
   
   // Load and execute the PRU program on the PRU
   prussdrv_exec_program (PRU_NUM, "./memory.bin");
   
   // Wait for event completion from PRU, returns the PRU_EVTOUT_0 number
   int n = prussdrv_pru_wait_event (PRU_EVTOUT_0);
   printf("EBB PRU program completed, event number %d.\n", n);
   printf("The number read from PRU0 memory is: %d\n", *pru0DataMemory_int);
   
   

   printf("%d\n", ddr_memory_int[199999]);
 
   
   // Disable PRU and close memory mappings
   prussdrv_pru_disable(PRU_NUM);
   prussdrv_pru_disable(1);

   prussdrv_exit ();
   return EXIT_SUCCESS;

}
/* This method frees the shared memory and disables the PRU's again. 
 * Take not that the Device Tree Overlay will NOT be unloaded, as doing this may result in an unstable system.
 */
unsigned int mdau_destroy(){
	// Disable PRU and close memory mappings 
	prussdrv_pru_disable(ADC_PRU_NUM);
	prussdrv_pru_disable(CLK_PRU_NUM);

	prussdrv_exit ();

	if(system("rmmod uio_pruss")==1){
		return EXIT_FAILURE;
	}	
	return EXIT_SUCCESS;
}
Esempio n. 6
0
int main (void)
{


    int ret = init_PRUSS();
	uint16_t chan[NUM_CHANNELS][SAMPLES_PR_PACKAGE];
	int offset = 0;



	while(1){
		/* Wait until PRU0 has finished execution */
		prussdrv_pru_wait_event(PRU_EVTOUT_0); // there's a bug that makes the pruss driver execute interrupts twice, se: https://github.com/beagleboard/am335x_pru_package/issues/3
		prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);
		prussdrv_pru_wait_event(PRU_EVTOUT_0); // there's a bug that makes the pruss driver execute interrupts twice, se: https://github.com/beagleboard/am335x_pru_package/issues/3
		prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);
		
		uint32_t flag = sharedMem_int[0];
		if(flag){
			offset = 2;
		} else {
			offset = 2050;
		}
		//printf("flag: %08x , data: ", flag);
		
		for(int k = 0; k < SAMPLES_PR_PACKAGE ; k +=8){	
			
			for(int i = 0 ; i< NUM_CHANNELS ; ++i){
				chan[i][k] = sharedMem_chan[k+offset+i];
			}
			
			printf("chan 0 : %04.2f \n", chan[0][k]*3.2227);
		
		}
		//printf("\n");
		

		prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);

	}
    

    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable(0);
    prussdrv_pru_disable(1);

    prussdrv_exit ();

    return(ret);
}
Esempio n. 7
0
int main (void)
{
    unsigned int ret;
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
    
    printf("\nINFO: Starting %s example.\r\n", "PRU_memAccessPRUDataRam");
    /* Initialize the PRU */
    prussdrv_init ();		
    
    /* Open PRU Interrupt */
    ret = prussdrv_open(PRU_EVTOUT_0);
    if (ret)
    {
        printf("prussdrv_open open failed\n");
        return (ret);
    }
    
    /* Get the interrupt initialized */

    /* Initialize example */
    
    /* Execute example on PRU */
    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable (PRU_NUM);
    prussdrv_exit ();

    return(0);

}
Esempio n. 8
0
int main(int argc, const char *argv[]){
   printf("\n\n");

   // Listen to SIGINT signals (program termination)
   signal(SIGINT, signal_handler);

   // Tell linux not to use the user leds in the board.
   take_over_leds();

   // Load device tree overlay to enable PRU hardware.
   load_device_tree_overlay();

   // Load and run binary into pru0
   init_pru_program();

   open_sound_file();
   start_thread();

   /* while(!finish){ */
   sleep(5);
   /* } */
   prussdrv_pru_disable(PRU_NUM);
   prussdrv_exit ();
   stop_thread();

   close_sound_file();

   return 0;
}
Esempio n. 9
0
   void main (void)
   {
       int n;
       /* Initialize structure used by prussdrv_pruintc_intc   */
       /* PRUSS_INTC_INITDATA is found in pruss_intc_mapping.h */
       tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

       /* Allocate and initialize memory */
       prussdrv_init ();
       prussdrv_open (PRU_EVTOUT_0);

       /* Map PRU's INTC */
       prussdrv_pruintc_init(&pruss_intc_initdata);

       /* Copy data to PRU memory */
       unsigned int x = 7;
       prussdrv_pru_write_memory(PRUSS0_PRU0_DATARAM, 0, &x, 4);

       /* Load and execute binary on PRU */
       prussdrv_exec_program (PRU_NUM, "./buttonTest.bin");

       /* Wait for event completion from PRU */
       n = prussdrv_pru_wait_event (PRU_EVTOUT_0);  // This assumes the PRU generates an interrupt
                                                    // connected to event out 0 immediately before halting
       printf("PRU program completed, event number %d.\n", n);

       /* Disable PRU and close memory mappings */
       prussdrv_pru_disable(PRU_NUM);
       prussdrv_exit ();
    }
Esempio n. 10
0
 int main(int argc, char **argv) {  
  if (argc != 2) {  
   printf("Usage: %s pru_code.bin\n", argv[0]);  
   return 1;  
  }  
   
  // If this segfaults, make sure you're executing as root.  
  prussdrv_init();  
  if (prussdrv_open(PRU_EVTOUT_0) == -1) {  
   printf("prussdrv_open() failed\n");  
   return 1;  
  }  
    
  tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;  
  prussdrv_pruintc_init(&pruss_intc_initdata);  
   
  // Change to 1 to use PRU1  
  int which_pru = 0;  
  printf("Executing program and waiting for termination\n");  
  prussdrv_exec_program(which_pru, argv[1]);  
   
  // Wait for the PRU to let us know it's done  
  prussdrv_pru_wait_event(PRU_EVTOUT_0);  
  printf("All done\n");  
   
  prussdrv_pru_disable(which_pru);  
  prussdrv_exit();  
   
  return 0;  
 }  
Esempio n. 11
0
int main (void)
{
    // Initialize the PRU
    printf("Initializing PRU\n");
    prussdrv_init ();
    
    // Open an event
    if (prussdrv_open(PRU_EVTOUT_0))
    {
        printf("prussdrv_open open failed\n");
        return -1;
    }
    
    // Execute code on PRU
    printf("Executing follow pru code\n");
    prussdrv_exec_program (0, "follow.bin");

    // Wait for Ctrl-C
    signal(SIGINT, on_sigint);
    while (is_sigint == 0)
    {
    }
    
    // Disable PRU and close memory mapping
    prussdrv_pru_disable (0);
    prussdrv_exit ();
    
    return(0);
}
Esempio n. 12
0
int main(int argc, char** argv) {
    printf("\nStarting %s example.\r\n", argv[0]);
    /* Initialize the PRU */
    prussdrv_init();

    /* Open PRU Interrupt */
    int open_result = prussdrv_open(PRU_EVTOUT_0);
    if (open_result) {
        printf("prussdrv_open open failed\n");
        return open_result;
    }

    /* Get the interrupt initialized */
    prussdrv_pruintc_init(&pruss_intc_initdata);

    uint16_t* pruMemory;
    prussdrv_map_prumem(PRUSS0_PRU0_DATARAM, (void**) &pruMemory);
    memcpy(pruMemory, digits, sizeof(digits));

    printf("\tExecuting.\r\n");
    prussdrv_exec_code(PRU0, counter, sizeof(counter));

    printf("\tWaiting for HALT command.\r\n");
    prussdrv_pru_wait_event(PRU_EVTOUT_0);
    prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);

    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable(PRU0);
    prussdrv_exit();

    return(0);

}
Esempio n. 13
0
File: int.c Progetto: bkovitz/pru
int main(void) {

  prussdrv_init();
  prussdrv_open(PRU_EVTOUT_0);
  prussdrv_pru_reset(PRU0);

  enable_pru_interrupts();
  
  prussdrv_map_prumem(PRUSS0_PRU0_DATARAM, (void**)&pru0_data_ram);
  *pru0_data_ram = 99;
  prussdrv_pru_write_memory(
    PRUSS0_PRU0_IRAM, 0, (unsigned int*)intp_bin, intp_bin_len
  );

// Contra the ARM PRU Linux API documentation, this function does not exist!
//  prussdrv_start_irqthread(
//    PRU_EVTOUT_0, sched_get_priority_max(SCHED_FIFO) - 2, pruevtout0_thread
//  );

  pthread_t irqthread;
  int iret = pthread_create(&irqthread, NULL, pruevtout0_thread, NULL);
  printf("iret = %d\n", iret);
  sleep(1);

  printf("starting PRU...\n");
  prussdrv_pru_enable(PRU0);

  sleep(3);
  printf("after sleep\n");
  printf("count = %d\n", *pru0_data_ram);
  prussdrv_pru_disable(PRU0);
  printf("PRU disabled\n");
  printf("count = %d\n", *pru0_data_ram);
}
Esempio n. 14
0
int main()
{
	void *pru0_memory;
	unsigned int *pru0_memory_uint;
	int distance_samples;
	int n;

	tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

	prussdrv_init();
	prussdrv_open(PRU_EVTOUT_0);

	prussdrv_pruintc_init(&pruss_intc_initdata);
	prussdrv_map_prumem(PRUSS0_PRU0_DATARAM, &pru0_memory);
	pru0_memory_uint = (unsigned int*)pru0_memory;

	prussdrv_exec_program(0, "./hcsr04.bin");

	n = prussdrv_pru_wait_event(PRU_EVTOUT_0);
	distance_samples = *pru0_memory_uint;

	printf("Measured distance: %f cm\n", (float)distance_samples / (USECS_DIV * HCSR04_DIV));

	prussdrv_pru_disable(0);
	prussdrv_exit();
	return 0;
}
Esempio n. 15
0
//! The main function.
int main(int argc, char **argv)
{
  pruIo *io = pruio_new(PRUIO_ACT_PRU1, 0, 0, 0); //! create new driver structure
  do {
    uint32 pru_num, pru_iram, pru_dram, pru_intr;
//
// Check init success
//
    if(io->Errr) {
               printf("initialisation failed (%s)\n", io->Errr); break;}

    if(io->PruNo) { //                              we use the other PRU
      pru_num = 0;
      pru_iram = PRUSS0_PRU0_IRAM;
      pru_dram = PRUSS0_PRU0_DRAM;
      pru_intr = PRU0_ARM_INTERRUPT; }
    else {
      pru_num = 1;
      pru_iram = PRUSS0_PRU1_IRAM;
      pru_dram = PRUSS0_PRU1_DRAM;
      pru_intr = PRU1_ARM_INTERRUPT; }
//
// Now prepare the other PRU
//
    if(prussdrv_open(PRU_EVTOUT_0)) { // note: libpruio uses PRU_EVTOUT_5
                               printf("prussdrv_open failed\n"); break;}
    //Note: no prussdrv_pruintc_init(), libpruio did it already

    load_firmware(pru_iram);
//
// Pass parameters to PRU
//
    uint32 *dram;
    prussdrv_map_prumem(pru_dram, (void *) &dram); // get dram pointer
    dram[1] = 23; // start value
    dram[2] = 7;  // value to add
    dram[3] = 67; // loop count (max 16 bit = 65536)
    dram[4] = pru_intr + 16; // the interrupt we're waiting for
//
// Execute
//
    printf("instructions loaded, starting PRU-%d\n", pru_num);
    prussdrv_pru_enable(pru_num); // start
    prussdrv_pru_wait_event(PRU_EVTOUT_0); // wait until finished
    prussdrv_pru_clear_event(PRU_EVTOUT_0, pru_intr); // clear interrupt (optional, useful when starting again)
//
// Check result
//
    if(dram[0] == (dram[1] + (dram[2] * dram[3])))
      {printf("Test OK %d == %d + (%d * %d)\n", dram[0], dram[1], dram[2], dram[3]);}
    else
      {printf("Test failed: %d != %d + (%d * %d)\n", dram[0], dram[1], dram[2], dram[3]);}

    prussdrv_pru_disable(pru_num); // disable PRU
    // note: no prussdrv_exit(), libpruio does it in the destructor
  } while (0);

  pruio_destroy(io);        /* destroy driver structure */
	return 0;
}
Esempio n. 16
0
int main(int ac, char** av)
{
  tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
  uint32_t x[2];

  prussdrv_init();

  if (prussdrv_open(PRU_EVTOUT_0))
  {
    printf("prussdrv_open open failed\n");
    return -1;
  }

  prussdrv_pruintc_init(&pruss_intc_initdata);

  /* execute code on pru0 */
#define PRU_NUM 0
  prussdrv_exec_program(PRU_NUM, "./iep.bin");

  signal(SIGINT, on_sigint);
  while (is_sigint == 0)
  {
    usleep(500000);
    read_words(x);
    printf("0x%08x, 0x%08x\n", x[0], x[1]);
  }

  /* disable pru and close memory mapping */
  prussdrv_pru_disable(PRU_NUM);
  prussdrv_exit();

  return 0;
}
int main (void)
{
    unsigned int ret;
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

    printf("\nINFO: Starting %s example.\r\n", "PRU_memAccessPRUDataRam");
    /* Initialize the PRU */
    prussdrv_init ();

    /* Open PRU Interrupt */
    ret = prussdrv_open(PRU_EVTOUT_0);
    if (ret)
    {
        printf("prussdrv_open open failed\n");
        return (ret);
    }

    /* Get the interrupt initialized */
    prussdrv_pruintc_init(&pruss_intc_initdata);

    /* Initialize example */
    printf("\tINFO: Initializing example.\r\n");
    LOCAL_exampleInit(PRU_NUM);

    /* Execute example on PRU */
    printf("\tINFO: Executing example.\r\n");
    char path[] = "./PRU_memAccessPRUDataRam.bin";
    if(prussdrv_exec_program (PRU_NUM, path))
    {
        fprintf(stderr, "ERROR: Could not open %s\n", path);
        return 1;
    }

    /* Wait until PRU0 has finished execution */
    printf("\tINFO: Waiting for HALT command.\r\n");
    prussdrv_pru_wait_event (PRU_EVTOUT_0);
    printf("\tINFO: PRU completed transfer.\r\n");
    prussdrv_pru_clear_event (PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);

    /* Check if example passed */
    if ( LOCAL_examplePassed(PRU_NUM) )
    {
        printf("INFO: Example executed succesfully.\r\n");
    }
    else
    {
        printf("INFO: Example failed.\r\n");
    }

    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable (PRU_NUM);
    prussdrv_exit ();

    return(0);

}
Esempio n. 18
0
int pru_stop(int pru_number)
{
  /* Halt and disable the PRU (returns -1 if argument is not 0 or 1) */
  if (prussdrv_pru_disable(pru_number) != 0) {
    fprintf(stderr, "The argument passed to prussdrv_pru_disable() must be 0 or 1.\n");
    return(-1);
  }

  return(0);
}
Esempio n. 19
0
void PRUloader::stopPRU(void){
	pruDataMem_byte[0] = 0;
	printf("\r\nWaiting for PRU to HALT\r\n");
	/* Wait for event completion from PRU */
	prussdrv_pru_wait_event(PRU_EVTOUT_1); // This assumes the PRU generates an interrupt connected to event out 0 immediately before halting
	prussdrv_pru_clear_event(PRU_EVTOUT_1, PRU1_ARM_INTERRUPT);
	/* Disable PRU and close memory mappings */
	prussdrv_pru_disable(PRU_NUM);
	prussdrv_exit();
}
Esempio n. 20
0
int main (void)
{
    unsigned int ret, i, j, k;
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
    
    printf("\nINFO: Starting %s example.\r\n", "pru_gpio");
    /* Initialize the PRU */
    prussdrv_init ();		

    //NOTE : The PRU code does not export the PIN so this must be
    //done for any pin that used.
    LOCAL_export_pin(32 + 16,"out"); //GPIO1_16
    LOCAL_export_pin(32 + 13,"in");  //GPIO1_13

    /* Open PRU Interrupt */
    ret = prussdrv_open(PRU_EVTOUT_0);
    if (ret)
    {
        printf("prussdrv_open open failed\n");
        return (ret);
    }
    
    /* Get the interrupt initialized */
    prussdrv_pruintc_init(&pruss_intc_initdata);

    /* Initialize example */
    printf("\tINFO: Initializing example.\r\n");
    LOCAL_exampleInit();

    //Start th emain loop
    pruDataMem_byte[CMD_VALUE] = CMD_NO_OP;
    
    /* Execute example on PRU */
    printf("\tINFO: Executing example.\r\n");
    prussdrv_exec_program (PRU_NUM, "./pru_gpio.bin");

    //The PRU is just configured to use GPIO1 for now.  This can be changed easily in the assembly.
    set_pin(16); //GPIO1_16
    clear_pin(16);
    int value = read_pin(13); //GPIO1_13

    printf("PIN value is %d\n",value); 

    printf("\tINFO: PRU completed transfer.\r\n");
    prussdrv_pru_clear_event (PRU0_ARM_INTERRUPT);

    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable (PRU_NUM);
    prussdrv_exit ();

    LOCAL_unexport_pin(38);

    return(0);

}
Esempio n. 21
0
int main (int argc, char* argv[])
{
int arg_length = strlen(argv[1]);
unsigned int code=0;
unsigned int code_array[15];
int i;
if (arg_length != 15){
printf("Number of bits in pattern is not equal to 15\n");
exit(EXIT_FAILURE);
}



for (i=0;i<15;i++)
{
code_array[i] = (unsigned int)(argv[1][i]-48);
printf("digit %d: %d\n",i, code_array[i]);
code = code | (code_array[i] << i) ;

}

printf("code: %x\n", code);

if(getuid()!=0){
      printf("You must run this program as root. Exiting.\n");
      exit(EXIT_FAILURE);
   }
   // Initialize structure used by prussdrv_pruintc_intc
   // PRUSS_INTC_INITDATA is found in pruss_intc_mapping.h
   tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

   // Allocate and initialize memory
   prussdrv_init ();
   prussdrv_open (PRU_EVTOUT_0);

   // Map PRU's interrupts
   prussdrv_pruintc_init(&pruss_intc_initdata);
   
   // Load the code into the PRU memory
   prussdrv_pru_write_memory(PRUSS0_PRU0_DATARAM, 0, &code, 4);


   // Load and execute the PRU program on the PRU
   prussdrv_exec_program (PRU_NUM, "/usr/scripts/PRU/send_15_bit_IR_pattern.bin");

   // Wait for event completion from PRU, returns the PRU_EVTOUT_0 number
   int n = prussdrv_pru_wait_event (PRU_EVTOUT_0);
   printf("EBB PRU program completed, event number %d.\n", n);

   // Disable PRU and close memory mappings
   prussdrv_pru_disable(PRU_NUM);
   prussdrv_exit ();
  
   return EXIT_SUCCESS;
}
int main (int argc, char ** argv)
{
	if (argc != 2){
		printf("you need to give me the number of frames to captures\n");
		exit(-1);
	}
	int num_frames = atoi(argv[1]);
	initialize_pru();
	start_pru();
	FILE * image_data = fopen("/media/usb/image.data", "w");
	if (image_data == NULL){
		fprintf(stderr, "Failed to open image output file");
		exit(-1);
	}

	const char  *version = FreeImage_GetVersion();
	printf("Freeimage version %s\n", version);

	FIBITMAP* dib = FreeImage_Allocate(320, 203, 16, 0xF800, 0x07E0,0x001F); // allocate 320x203 RGB565 bitmap

	int bytespp = FreeImage_GetLine(dib)/FreeImage_GetWidth(dib);

	FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);

	if (image_type == FIT_BITMAP){
		printf("1\n");
	}

	printf("%d %d\n", FreeImage_GetHeight(dib), FreeImage_GetWidth(dib));

	BYTE * bits = FreeImage_GetBits(dib);
	FILE * fp = fopen("image.data", "rb");
	char filename[] = "/root/1314-BeagleBone-Quadcopter/code/ControlTower/ramfs/latest_image.bmp";
	int i = 0;

	for (i = 0; i < num_frames; i++){
		while(i==pruDataMem_int[100]){usleep(100000);}
		int buffer = pruDataMem_int[1];
		printf("%d buffer=%d\n", pruDataMem_int[100], buffer);
		if (i%10==0){
			memcpy(bits, pru1_ddr+buffer*320*240*2, 320*203*2);
			FreeImage_Save(FIF_BMP, dib, filename,0);
		}
	}
	uninitialize_pru();
	fflush(image_data);
	printf("%d\n", ((volatile uint8_t *)pru1_ddr)[0]);
	fclose(image_data);

	prussdrv_pru_disable (PRU_NUM);
	prussdrv_exit ();

	return(0);
}
Esempio n. 23
0
int main (void)
{
	static FILE *fp = 0;
	unsigned int ret;
	tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

	printf("\nINFO: Starting %s example.\r\n", "blink");
	/* Initialize the PRU */
	prussdrv_init ();		

	// Set ADC CS
	if((fp=fopen("/sys/class/gpio/export", "w"))==NULL){
		printf("Cannot open GPIO file 62.\n");
		return (1);
	}
	fprintf(fp,"62");
	fclose(fp);

	if((fp=fopen("/sys/class/gpio/gpio62/direction", "w"))==NULL){
		printf("cannot open gpio direction file.\n");
		return(1);
	}
	fprintf(fp,"out");
	fclose(fp);
	mux("lcd_pclk",0x0d);

	/* Open PRU Interrupt */
	ret = prussdrv_open(PRU_EVTOUT_0);
	if (ret)
	{
		printf("prussdrv_open open failed\n");
		return (ret);
    }
    
    /* Get the interrupt initialized */
    prussdrv_pruintc_init(&pruss_intc_initdata);

    /* Execute example on PRU */
    printf("\tINFO: Executing example.\r\n");
    prussdrv_exec_program (PRU_NUM, "./blink.bin");
    
    /* Wait until PRU0 has finished execution */
    printf("\tINFO: Waiting for HALT command.\r\n");
    prussdrv_pru_wait_event (PRU_EVTOUT_0);
    printf("\tINFO: PRU completed transfer.\r\n");
    prussdrv_pru_clear_event (PRU0_ARM_INTERRUPT);

    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable (PRU_NUM);
    prussdrv_exit ();

    return(0);
}
Esempio n. 24
0
int main (void)
{
    unsigned int ret;
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
    
    printf("\nINFO: Starting %s test.\r\n", "GPIO input level");
    /* Initialize the PRU */
    prussdrv_init ();		
    
    /* Open PRU Interrupt */
    ret = prussdrv_open(PRU_EVTOUT_0);
    if (ret)
    {
        printf("prussdrv_open open failed\n");
        return (ret);
    }
    
    /* Get the interrupt initialized */
    prussdrv_pruintc_init(&pruss_intc_initdata);

    /* Initialize example */
    printf("\tINFO: Initializing test.\r\n");
    LOCAL_exampleInit(PRU_NUM);
    
    /* Execute example on PRU */
    printf("\tINFO: Executing test.\r\n");
    prussdrv_exec_program (PRU_NUM, "./levelIn.bin");

    /* Wait until PRU0 has finished execution */
    printf("\tINFO: Waiting for HALT command.\r\n");
    prussdrv_pru_wait_event (PRU_EVTOUT_0);
    printf("\tINFO: PRU completed transfer.\r\n");
    prussdrv_pru_clear_event (PRU0_ARM_INTERRUPT);

    /* Check if example passed */
    if ( LOCAL_examplePassed(PRU_NUM) )
    {
        printf("Test executed succesfully.\r\n");
    }
    else
    {
        printf("Test failed.\r\n");
    }
    
    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable(PRU_NUM); 
    prussdrv_exit ();
    munmap(ddrMem, 0x0FFFFFFF);
    close(mem_fd);

    return(0);
}
Esempio n. 25
0
static void pru_shutdown(char flush_queue) {
  if (flush_queue) {
    struct MotionSegment end_element;
    bzero(&end_element, sizeof(end_element));
    end_element.state = STATE_EXIT;
    pru_enqueue_segment(&end_element);
    pru_wait_queue_empty();
  }
  prussdrv_pru_disable(PRU_NUM);
  prussdrv_exit();
  pru_motor_enable_nowait(0);
  unmap_gpio();
}
Esempio n. 26
0
void main (void)
{
   tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
   prussdrv_init ();
   prussdrv_open (PRU_EVTOUT_0);
   prussdrv_pruintc_init(&pruss_intc_initdata);
   prussdrv_exec_program (PRU_NUM, "./buttonTest.bin");
   /* Wait for event completion from PRU */
   int n = prussdrv_pru_wait_event (PRU_EVTOUT_0);
   printf("PRU test completed, event number %d.\n", n);
   /* Disable PRU and close memory mappings */
   prussdrv_pru_disable(PRU_NUM);
   prussdrv_exit ();
}
Esempio n. 27
0
int
main (int ac, char** av)
{
  tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
  uint32_t x[MEM_SIZE];
  const size_t n = sizeof (x) / sizeof (x[0]);
  size_t i;
  size_t count = 0;

  printf ("n: %u \n", n);

  prussdrv_init ();

  if (prussdrv_open (PRU_EVTOUT_0))
    {
      printf ("prussdrv_open open failed\n");
      return -1;
    }

  prussdrv_pruintc_init (&pruss_intc_initdata);

  /* zero_words(n); */

  /* write data from data.bin */
  prussdrv_load_datafile (PRU_NUM, "./data.bin");

  /* execute code on pru0 */
  prussdrv_exec_program_at (PRU_NUM, "./text.bin", START_ADDR);
  // prussdrv_exec_program(PRU_NUM, "./text.bin");

  signal (SIGINT, on_sigint);
  while (is_sigint == 0)
    {
      printf ("reading count: %d\n", count++);
      usleep (1000000);
      read_words (x, n);
      for (i = 0; i != n; ++i)
        {
          //printf("mem 0x%08x: (%f)\n", x[i], *((float*)(x + i)));
          printf ("mem %d %08x: (%08x)\n", i, (x + i), (unsigned int) (*(x + i)));
        }
      printf ("\n");
    }

  /* disable pru and close memory mapping */
  prussdrv_pru_disable (PRU_NUM);
  prussdrv_exit ();

  return 0;
}
Esempio n. 28
0
int main (void)
{
    int ret1,i;
    int fd,len;
    char buf[64];

    unsigned int ret,value;
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

    signal(SIGINT, signal_callback_handler);
    printf("\nINFO: Starting %s example.\r\n", "pt - SR04");



    /* Initialize the PRU */
    prussdrv_init ();

    /* Open PRU Interrupt */
    ret = prussdrv_open(PRU_EVTOUT_0);
    if (ret)
    {
        printf("prussdrv_open open failed\n");
        return (ret);
    }

    /* Get the interrupt initialized */
    prussdrv_pruintc_init(&pruss_intc_initdata);

    /* Initialize example */
    printf("\tINFO: Initializing example.\r\n");
    LOCAL_exampleInit(PRU_NUM);

    /* Execute example on PRU */
    printf("\tINFO: Executing example.\r\n");
    prussdrv_exec_program (PRU_NUM, "./pu.bin");


    printf("\tINFO: Waiting for \r\n");
    while(1) {
    prussdrv_pru_wait_event (PRU_EVTOUT_0);
    prussdrv_pru_clear_event (PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);
    ret1 = LOCAL_pr(PRU_NUM); // go get & print result
    }
    usleep (500000); //Just pause so don't go too fast
    prussdrv_pru_disable (PRU_NUM);
    prussdrv_exit ();
    sleep(20);
    return(0);

}
Esempio n. 29
0
int main (void)
{
    /* Initialize the PRU */
    printf("Initializing PRU\n");
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
    prussdrv_init ();
    
    /* Open PRU Interrupt */
    if(prussdrv_open(PRU_EVTOUT_0))
    {
        // Handle failure
        fprintf(stderr, "prussdrv_open open failed\n");
        return 1;
    }
    
    /* Get the interrupt initialized */
    prussdrv_pruintc_init(&pruss_intc_initdata);
    
    /* Get pointers to PRU local memory */
    void *pruDataMem;
    prussdrv_map_prumem (PRUSS0_PRU0_DATARAM, &pruDataMem);
    unsigned int *pruData = (unsigned int *) pruDataMem;
    
    /* Execute example on PRU */
    printf("Executing sonar pru code\n");
    prussdrv_exec_program (0, "hcsr04_demo.bin");
    
    /* Get 1000 measurements */
    int i = 0;
    while(i++ < 1000)
    {
        // Wait for the PRU interrupt to occur
        prussdrv_pru_wait_event (PRU_EVTOUT_0);
        prussdrv_pru_clear_event (PRU0_ARM_INTERRUPT);
        
        // Print out the distance received from the sonar (sound takes 58.77 microseconds to travel 1 cm at sea level in dry air)
        printf("Distance = %f cm\n", (float) pruData[0] / 58.77);
    }
    
    /* Check if example passed */
    printf("Executed succesfully.\r\n");
    
    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable (0);
    prussdrv_exit ();
    
    return(0);
    
}
Esempio n. 30
0
int main (void)
{
    unsigned int ret;
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
    
    printf("\nINFO: Starting %s example.\r\n", "dmx");
    /* Initialize the PRU */
    prussdrv_init ();		

    LOCAL_export_pin(38);
    
    /* Open PRU Interrupt */
    ret = prussdrv_open(PRU_EVTOUT_0);
    if (ret)
    {
        printf("prussdrv_open open failed\n");
        return (ret);
    }
    
    /* Get the interrupt initialized */
    prussdrv_pruintc_init(&pruss_intc_initdata);

    /* Initialize example */
    printf("\tINFO: Initializing example.\r\n");
    LOCAL_exampleInit();
    
    /* Execute example on PRU */
    printf("\tINFO: Executing example.\r\n");
    prussdrv_exec_program (PRU_NUM, "./dmx.bin");
    LOCAL_udp_listen();
 
    pruDataMem_byte[DMX_HALT_ADDR] = 1;
    
    /* Wait until PRU0 has finished execution */
    printf("\tINFO: Waiting for HALT command.\r\n");
    prussdrv_pru_wait_event (PRU_EVTOUT_0);
    printf("\tINFO: PRU completed transfer.\r\n");
    prussdrv_pru_clear_event (PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);

    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable (PRU_NUM);
    prussdrv_exit ();

    LOCAL_unexport_pin(38);

    return(0);

}