コード例 #1
0
ファイル: test.c プロジェクト: shotgunlew/scratch
int main() {
	//set pin to output
	p.p_addr = GPIO_BASE_ADDR;
	map_gpio(&p);
	set_as_input(&p, 4);
	//set_as_output(&p, 4);
	set_output(&p, 4, 0);
	clear_output(&p, 4);
	read_pin(&p, 4);	
	return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: rockybulwinkle/beaglebone
int main(){
	int fd = open("/dev/mem", O_RDWR);
	gpio_control * gpio_0 = map_gpio(fd, GPIO0_BASE);
	gpio_control * gpio_1 = map_gpio(fd, GPIO1_BASE);

	*(gpio_1->oe) &= ~P9_12;
	*(gpio_0->oe) &= ~P9_11;
	*(gpio_0->oe) |= P9_21;
	*(gpio_0->oe) |= P9_22;
	while(1){
		if ((*(gpio_0->in)) & P9_22){
			*(gpio_1->out) |= P9_12;
		} else{
			*(gpio_1->out) &= ~P9_12;
		}
		if ((*(gpio_0->in)) & P9_21){
			*(gpio_0->out) |= P9_11;
		} else{
			*(gpio_0->out) &= ~P9_11;
		}
	}
	return 0;
}
コード例 #3
0
ファイル: pru-motion-queue.c プロジェクト: miloh/beagleg
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;
}