示例#1
0
文件: pruss_add.c 项目: DTJF/libpruio
//! 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;
}
示例#2
0
文件: int.c 项目: 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);
}
示例#3
0
int init_pru_motion_queue(struct MotionQueue *queue) {
  if (!map_gpio()) {
    fprintf(stderr, "Couldn't mmap() GPIO ranges.\n");
    return 1;
  }

  // Prepare all the pins we need for output. All the other bits are inputs,
  // so the STOP switch bits are automatically prepared for input.
  gpio_0[GPIO_OE/4] = ~(MOTOR_OUT_BITS | (1 << AUX_1_BIT) | (1 << AUX_2_BIT));
  gpio_1[GPIO_OE/4] = ~(DIRECTION_OUT_BITS | (1 << MOTOR_ENABLE_GPIO1_BIT));

  pru_motor_enable_nowait(0);  // motors off initially.

  tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
  prussdrv_init();

  /* Get the interrupt initialized */
  int ret = prussdrv_open(PRU_EVTOUT_0);  // allow access.
  if (ret) {
    fprintf(stderr, "prussdrv_open() failed (%d)\n", ret);
    return ret;
  }
  prussdrv_pruintc_init(&pruss_intc_initdata);
  if (map_pru_communication() == NULL) {
    fprintf(stderr, "Couldn't map PRU memory for queue.\n");
    return 1;
  }

  prussdrv_pru_write_memory(PRUSS0_PRU0_IRAM, 0, PRUcode, sizeof(PRUcode));
  prussdrv_pru_enable(0);

  // Initialize operations.
  queue->enqueue = &pru_enqueue_segment;
  queue->wait_queue_empty = &pru_wait_queue_empty;
  queue->motor_enable = &pru_motor_enable_nowait;
  queue->shutdown = &pru_shutdown;
 
  return 0;
}
示例#4
0
static bool initPru(void) {
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

    printf("Initializing PRU\n");
    prussdrv_init();

    // Open PRU driver and prepare for using the interrupt on event output 1
    if (prussdrv_open(PRU_EVTOUT_1)) {
        fprintf(stderr, "prussdrv_open failed!\n");
        return false;
    }

    // Initialize the PRUSS interrupt controller
    if (prussdrv_pruintc_init(&pruss_intc_initdata)) {
        fprintf(stderr, "prussdrv_pruintc_init failed!\n");
        return false;
    }

    // Get pointer to the shared PRUSS memory. On the AM355x this block is 12KB
    // in size and located locally at 0x0001_0000 within the PRU cores and
    // globally at 0x4A31_0000 in the MPU's memory map. The entire memory is
    // used as our printer queue so we map the global variable to that address.
    prussdrv_map_prumem(PRUSS0_SHARED_DATARAM, (void *)&queue);

    // Initialize the PRU from an array in memory rather than from a file on
    // disk. Make sure PRU sub system is first disabled/reset. Then, transfer
    // the program into the PRU. Note that the write memory functions expect
    // the offsets to be provided in words so we our byte-addresses by four.
    printf("Loading PRU firmware and enabling PRU\n");
    prussdrv_pru_disable(1);
    prussdrv_pru_write_memory(PRUSS0_PRU1_IRAM, pruprinter_fw_iram_start / 4,
            (unsigned int *)&pruprinter_fw_iram, pruprinter_fw_iram_length);
    prussdrv_pru_write_memory(PRUSS0_PRU1_DATARAM, pruprinter_fw_dram_start / 4,
            (unsigned int *)&pruprinter_fw_dram, pruprinter_fw_dram_length);
    prussdrv_pru_enable(1);

    return true;
}