Beispiel #1
0
void initialize_pru(){
    unsigned int ret;
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

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

    //Initialize pointer to PRU data memory
    if (PRU_NUM == 0)
    {
      prussdrv_map_prumem (PRUSS0_PRU0_DATARAM, &pruDataMem);
    }
    else if (PRU_NUM == 1)
    {
      prussdrv_map_prumem (PRUSS0_PRU1_DATARAM, &pruDataMem);
    }  
    pruDataMem_int = (volatile signed int*) pruDataMem;
}
Beispiel #2
0
int pru_setup()
{
  /* Initialize the PRU and prussdrv module (always returns 0) */
  prussdrv_init();

  /* Open interrupt(s): you should open at least PRU_EVTOUT_0 */
  if (prussdrv_open(PRU_EVTOUT_0) != 0) {
    fprintf(stderr, "There was an error while opening PRU_EVTOUT_0.\n");
    fprintf(stderr, "Did you load the PRU DTO?\n");
    return(-1);
  }

  if (prussdrv_open(PRU_EVTOUT_1) != 0) {
    fprintf(stderr, "There was an error while opening PRU_EVTOUT_1.\n");
    fprintf(stderr, "Did you load the PRU DTO?\n");
    return(-1);
  }

  /* Initialize struct with INTC interrupt map (see PRU ref. guide, Fig. 97) */
  tpruss_intc_initdata pru_intc_data = PRUSS_INTC_INITDATA;

  /* Initialize INTC */
  if (prussdrv_pruintc_init(&pru_intc_data) != 0) {
    return(-1);
    fprintf(stderr, "An error occurred while initializing INTC.");
  }

  return(0);
}
Beispiel #3
0
PRU::PRU(int number) {
    // Store the PRU number (0 or 1)
    if (number < 2) {
        this->pruNumber = number;
    } else {
        this->pruNumber = 0;
    }

    // Initialise driver
    prussdrv_init ();
    
    // Open interrupt
    unsigned int ret = prussdrv_open(PRU_EVTOUT_0);
    if (ret) {
        printf("prussdrv_open open failed\n");
        return;
    }
    
    //Initialise interrupt
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;    
    prussdrv_pruintc_init(&pruss_intc_initdata);
    
    // Allocate shared PRU memory
    if (!this->memoryPtr) {
        static void *sharedMem;
        prussdrv_map_prumem(PRUSS0_SHARED_DATARAM, &sharedMem);
        this->memoryPtr = (unsigned int*) sharedMem;
    }
}
Beispiel #4
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 ();
    }
Beispiel #5
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(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;  
 }  
Beispiel #7
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  pru_init
//  Initializes the PRU system
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void pru_init() {

  // Initialise driver
  prussdrv_init();
  
  // Open interrupt
  unsigned int ret = prussdrv_open(PRU_EVTOUT_0);
  if (ret) {  printf("prussdrv_open open failed\n");  }
  
  //Initialise interrupt
  tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
  prussdrv_pruintc_init(&pruss_intc_initdata);
  
  // Point to PRU shared memory
  static void* sharedMem;
  prussdrv_map_prumem( PRUSS0_SHARED_DATARAM, &sharedMem );
  memoryPtr = (unsigned int*) sharedMem;
  memset( memoryPtr, 0, 4* SERVO_CH );

  // Load assembly code
  prussdrv_exec_program ( 1, "PRU1.bin" );

  // Loops per PWM period
  memoryPtr[2048] = 150000;

}
Beispiel #8
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);

}
Beispiel #9
0
/*** pru_setup() -- initialize PRU and interrupt handler

Initializes the PRU specified by PRU_NUM and sets up PRU_EVTOUT_0 handler.

The argument is a pointer to a nul-terminated string containing the path
to the file containing the PRU program binary.

Returns 0 on success, non-0 on error.
***/
static int pru_setup(const char * const path) {
   int rtn;
   tpruss_intc_initdata intc = PRUSS_INTC_INITDATA;

   if(!path) {
      fprintf(stderr, "pru_setup(): path is NULL\n");
      return -1;
   }

   /* initialize PRU */
   if((rtn = prussdrv_init()) != 0) {
      fprintf(stderr, "prussdrv_init() failed\n");
      return rtn;
   }

   /* open the interrupt */
   if((rtn = prussdrv_open(PRU_EVTOUT_0)) != 0) {
      fprintf(stderr, "prussdrv_open() failed\n");
      return rtn;
   }

   /* initialize interrupt */
   if((rtn = prussdrv_pruintc_init(&intc)) != 0) {
      fprintf(stderr, "prussdrv_pruintc_init() failed\n");
      return rtn;
   }

   /* load and run the PRU program */
   if((rtn = prussdrv_exec_program(PRU_NUM, path)) < 0) {
      fprintf(stderr, "prussdrv_exec_program() failed\n");
      return rtn;
   }

   return rtn;
}
Beispiel #10
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;
}
void initialize_pru(){
	unsigned int ret;
	tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

	prussdrv_init ();
	/* Open PRU Interrupt */
	if (PRU_NUM == 0){
		ret = prussdrv_open(PRU_EVTOUT_0);
	}
	if (PRU_NUM == 1){
		ret = prussdrv_open(PRU_EVTOUT_1);
	}
	if (ret)
	{
		printf("prussdrv_open open failed\n");
		exit(ret);
	}

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

	//Initialize pointer to PRU data memory
	if (PRU_NUM == 0)
	{
		prussdrv_map_prumem (PRUSS0_PRU0_DATARAM, &pruDataMem);
	}
	else if (PRU_NUM == 1)
	{
		prussdrv_map_prumem (PRUSS0_PRU1_DATARAM, &pruDataMem);
	}
	pruDataMem_int = (volatile signed int*) pruDataMem;

	//initialize external ram:
	//
	int mem_fd = open("/dev/mem", O_RDWR);
	if (mem_fd < 0){
		printf("couldn't open /dev/mem\n");
		exit(-1);
	}

	pru1_ddr= (uint8_t*)mmap(0, PRU_DDR_SIZE, PROT_WRITE | PROT_READ, MAP_SHARED, mem_fd, PRU1_DDR);
	if (pru1_ddr == NULL){
		printf("couldn't map pru1 ddr\n");
		exit(-1);
	}



	pruDataMem_int[0] = 1;
	pruDataMem_int[1] = 0;
	pruDataMem_int[2] = PRU1_DDR;
	pruDataMem_int[3] = PRU1_DDR+320*240*2;
	pruDataMem_int[4] = PRU1_DDR+320*240*4;
	pruDataMem_int[5] = PRU1_DDR+320*240*6;
	pruDataMem_int[6] = PRU1_DDR+320*240*8;
	printf("WE DIDN'T ALL DIE!\n");
	fflush(stdout);

}
Beispiel #12
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;

}
Beispiel #13
0
// Initialize the pruss
int pruInit(unsigned short pruNum) {
    int         i,  n;

    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

    prussdrv_init();

    // Open PRU Interrupt 
    int pru_int = (pru_num == 0) ? PRU_EVTOUT_0 : PRU_EVTOUT_1;
    if (prussdrv_open(pru_int) != 0) {
        fprintf(stderr, "prussdrv_open open failed\n");
        return EXIT_FAILURE;
    }

    // initialize the interrupt
    prussdrv_pruintc_init(&pruss_intc_initdata);

    // Set up shared memory area for arm--pru communication
    prussdrv_map_prumem(PRUSS0_SHARED_DATARAM, &pruSharedMem); 

    pruSharedMem_int = (uint32_t *)pruSharedMem;

    pruSharedMem_int[TOPRU] = 0x00;
    pruSharedMem_int[TOPRU_F] = 0x00;
    pruSharedMem_int[FROMPRU] = 0x00;
    pruSharedMem_int[FROMPRU_F] = 0x00;

    // Initialize pointer to PRU data memory
    if (pruNum == 0) {
      prussdrv_map_prumem (PRUSS0_PRU0_DATARAM, &pruDataMem);
    }
    else if (pruNum == 1) {
      prussdrv_map_prumem (PRUSS0_PRU1_DATARAM, &pruDataMem);
    }  
    pruDataMem_int = (uint16_t *)pruDataMem;

    strcpy(&filename[namelen], ".dat");

    // Load dictionary into data memory
    FILE *file = fopen(filename, "r");
    if (file == NULL) {
        fprintf(stderr, "Unable to open dictionary file, %s\n", filename);
        return EXIT_FAILURE;
    }

    i = 0;
    while (fscanf(file, "%x", &n) == 1) {
        pruDataMem_int[i++] = (uint16_t)n; 
    }
    fclose(file);

    strcpy(&filename[namelen], ".bin");

    // start pru program
    prussdrv_exec_program (pru_num, filename);

    return EXIT_SUCCESS;
}
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);

}
Beispiel #15
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);

}
Beispiel #16
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;
}
/* This method programs the PRU's and makes them execute their program. ./PRUADC.bin and ./PRUClock.bin should be present.
 * The PRU's fill the shared memory with 10-bit samples stored as uint_16. This method allocates memory to copy these values as an array
 * of doubles and returns a pointer to this array. Returns NULL if VREF are not set. To set these, call mdau_create.
 */
double* mdau_read_frame(){
	if(VREF == 0){
		return NULL;
	}
	
	// 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;
	
	// Map the PRU's interrupts
	prussdrv_pruintc_init(&pruss_intc_initdata);
	
	// Load and execute the PRU program on the PRU
	prussdrv_exec_program (ADC_PRU_NUM, "./PRUADC.bin");
	prussdrv_exec_program (CLK_PRU_NUM, "./PRUClock.bin");

	// Wait for event completion from PRU, returns the PRU_EVTOUT_0 number
	prussdrv_pru_wait_event (PRU_EVTOUT_0);
	
	int fd;
    void *map_base, *virt_addr;
    unsigned long read_result;
    unsigned int addr = readFileValue(MMAP1_LOC "addr");
    unsigned int dataSize = readFileValue(MMAP1_LOC "size");
    unsigned int frame_size = dataSize / 2;
    off_t target = addr;

    if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1){
	return NULL;
    }

    map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
    if(map_base == (void *) -1) {
       return NULL;
    }
    
	double* samples = malloc(frame_size*sizeof(double));
	if(samples == NULL){
		return NULL;
	}
	
    int i=0;
    for(i=0; i<frame_size; i++){
	virt_addr = map_base + (target & MAP_MASK);
        read_result = *((uint16_t *) virt_addr);
        samples[i] = VREF * read_result / ADC_MAXIMUM ;
        target+=2;                   // 2 bytes per sample
    }

    if(munmap(map_base, MAP_SIZE) == -1) {
       return NULL;
    }
    close(fd);
    return samples;
}
Beispiel #18
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);
}
Beispiel #19
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);
}
Beispiel #20
0
void init_pru_program(){
	  tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
	  prussdrv_init();
	  dbg("\tPRUSS driver was initialized...\n");
	  prussdrv_open(PRU_EVTOUT_0);
	  prussdrv_pruintc_init(&pruss_intc_initdata);
	  dbg("\tPRUSS driver intc was initialized...\n");
	  prussdrv_load_datafile(PRU_NUM, "./data.bin");
	  dbg("\tDatafile was loaded...\n");
	  prussdrv_exec_program_at(PRU_NUM, "./text.bin", START_ADDR);
	  dbg("\tTextfile was loaded...\n");

}
Beispiel #21
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 ();
}
Beispiel #22
0
void init_pru_program(){
   tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
   prussdrv_init();
   prussdrv_open(PRU_EVTOUT_0);
   prussdrv_pruintc_init(&pruss_intc_initdata);

   // Get pointer to shared ram
   void* p;
   prussdrv_map_prumem(PRUSS0_SHARED_DATARAM, &p);
   shared_ram = (unsigned int*)p;

   prussdrv_load_datafile(PRU_NUM, "./data.bin");
   prussdrv_exec_program_at(PRU_NUM, "./text.bin", START_ADDR);
}
Beispiel #23
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;
}
Beispiel #24
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);

}
Beispiel #25
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);
    
}
Beispiel #26
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
		printf("-1");
		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 code on PRU */
	//printf(">> Executing HCSR-04 code\n");
	prussdrv_exec_program(0, "hcsr04.bin");

	/* Get measurements */
	//int i = 0;
	//while (i++ < 20) {

		// Wait for the PRU interrupt
		prussdrv_pru_wait_event (PRU_EVTOUT_0);
		prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);
		
		// Print the distance received from the sonar
		// At 20 degrees in dry air the speed of sound is 342.2 cm/sec
		// so it takes 29.12 us to make 1 cm, i.e. 58.44 us for a roundtrip of 1 cm
		printf("%.2f \n", (float) pruData[0] / 58.44);
		//sleep(1);
	//}

	/* Disable PRU and close memory mapping*/
	prussdrv_pru_disable(0);
	prussdrv_exit();
	//printf(">> PRU Disabled.\r\n");
	return (0);

}
Beispiel #27
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);

}
Beispiel #28
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;
}
Beispiel #29
0
int main (void)
{
    unsigned int ret, i;
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
    
    printf("\nINFO: Starting %s example.\r\n", "WritePPM");
    /* 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, "./WritePPM.bin");

    prussdrv_map_prumem(PRUSS0_PRU1_DATARAM, &dataMem);
    dataMem_int = (unsigned int*) dataMem;
    printf("local dataram addr: %08X\n", (unsigned int) dataMem);
    while (1) {
    //for (i = 0; i < 6; i++) {
        //printf("%08X : %08X\n", dataMem_int[0], dataMem_int[1]);
	//printf("%08X:%08X | ", dataMem_int[(4*i)+2], dataMem_int[(4*i)+3]);
    //}
    printf("%08X\n", dataMem_int[2]);
    usleep(10000);
    }
    
    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable(PRU_NUM); 
    prussdrv_exit ();
    close(mem_fd);

    return(0);
}
Beispiel #30
0
int init_PRUSS(){
   
    unsigned int ret;
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

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

	puts("pru0 evntout done");
    /* Open PRU Interrupt */
    ret = prussdrv_open(PRU_EVTOUT_1);
    if (ret)
    {
        printf("prussdrv_open open failed\n");
        return (ret);
    }
		puts("pru1 evntout");

    /* Get the interrupt initialized */
    prussdrv_pruintc_init(&pruss_intc_initdata);
	puts("pruss intc init done");

    /* Execute example on PRU */
    prussdrv_exec_program (0, "./buffer.bin");
    puts("exec pru0");

    prussdrv_exec_program (1, "./sampler.bin");
    
     puts("exec pru1");


    /* Allocate Shared PRU memory. */
    prussdrv_map_prumem(PRUSS0_SHARED_DATARAM, &sharedMem);
    sharedMem_int = (uint32_t*) sharedMem;
    sharedMem_chan = (uint16_t*) sharedMem;
    

	return 0;
}