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");

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

smile_5me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值