cycloneV gpio的操作

操作流程:

1、open:用来打开内存映射设备驱动

2、mmap:映射物理地址到用户空间

3、alt_read_word:从指定寄存器读取一个值

4、alt_write_word:写入一个值到指定寄存器

5、munmap:清除内存映射

6、close:关闭设备驱动

----------------------------------

附加:

alt_setbits_word:设定指定寄存器的指定位为1

alt_setbits_word:设定指定寄存器的指定位为0

---------------------------------

例子代码:

	if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) {
		printf( "ERROR: could not open \"/dev/mem\"...\n" );
		return( 1 );
	}

	virtual_base = mmap( NULL, HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, HW_REGS_BASE );

	if( virtual_base == MAP_FAILED ) {
		printf( "ERROR: mmap() failed...\n" );
		close( fd );
		return( 1 );
	}
	printf("mmap() success\n");
	// initialize the pio controller
	
	// led: set the direction of the HPS GPIO1 bits attached to LEDs to output
	printf("%x \n",ALT_GPIO1_SWPORTA_DDR_ADDR);
	
	alt_setbits_word( ( virtual_base + ( ( uint32_t )( ALT_GPIO1_SWPORTA_DDR_ADDR ) & ( uint32_t )( HW_REGS_MASK ) ) ), BIT_LED_ALL );
	
	// key: the pio is input only controller, so we don't need to configure its direction

	//alt_setbits_word( ( virtual_base + ( ( uint32_t )( ALT_GPIO1_SWPORTA_DR_ADDR ) & ( uint32_t )( HW_REGS_MASK ) ) ), BIT_LED_ALL );
	//return 0;

	printf("pio demo\n");

 

你可能感兴趣的:(Altera,CycloneV)