Example #1
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;

}
Example #2
0
int PRUloader::setup_pruss(void) {
	/* Allocate and initialize memory */
	if (prussdrv_init()){
		perror("prussdrv_init failed");
		return -1;
	}
	if (prussdrv_open(PRU_EVTOUT_0)){
		perror("prussdrv_open evt0 failed");
		return -1;
	}
    if (prussdrv_open(PRU_EVTOUT_1)){
        printf("prussdrv_open evt1 failed\n");
        return -1;
    }
	if (prussdrv_pruintc_init(&pruss_intc_initdata)){
		perror("prussdrv_pruintc_init failed");
		return -1;
	}

    /* Start IRQ thread for event handling */
    pthread_attr_t pthread_attr;
    struct sched_param sched_param;
    pthread_attr_init(&pthread_attr);
    int evt_priority = sched_get_priority_max(SCHED_FIFO) - 2;
    pthread_attr_setinheritsched(&pthread_attr, PTHREAD_EXPLICIT_SCHED);
    pthread_attr_setschedpolicy(&pthread_attr, SCHED_FIFO);
    sched_param.sched_priority = evt_priority;
    pthread_attr_setschedparam(&pthread_attr, &sched_param);
    quit_rx_thread = false;
    if(pthread_create(&irq_thread_evt0, &pthread_attr, &pruevtout0_thread, this) != 0){
    	printf("ERR >> Event thread not created\r\n");
    	return -1;
    }
    pthread_attr_destroy(&pthread_attr);

	// map pruss memory
	prussdrv_map_extmem(&ddrMemOrigin);
	// get max size
	ddr_mem_size = prussdrv_extmem_size();
	printf("PRU_DEBUG >> DDR size is 0x%0x bytes\r\nPRU_DEBUG >> DDR virtual address is 0x%0x\r\n", (uint32_t)ddr_mem_size, (uint32_t)ddrMemOrigin);
	// Get physical address
	phy_add = prussdrv_get_phys_addr(ddrMemOrigin);
	printf("PRU_DEBUG >> Start of physical address allocated is 0x%X\r\n",	phy_add);

	memset((char *)ddrMemOrigin, 0, ddr_mem_size);

	return 1;
}