|
发表于 2017-11-7 15:12:42
只看该作者
板凳
本帖最后由 iamFirefly 于 2017-11-7 15:20 编辑
- </blockquote><div class="blockcode"><blockquote><blockquote>#include <sys/mman.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #define MMAP_PATH "/dev/mem"
- #define RK3399_GPIO_DATA 0x0000
- #define RK3399_GPIO_DIRC 0x0004
- #define DIRC_OUTPUT 1
- #define DIRC_INPUT 0
- #define DATA_LOW 0
- #define DATA_HIGH 1
- static uint8_t* gpio3_clocken_base_reg = NULL;
- static uint8_t* gpio3_iomux_base_reg = NULL;
- static uint8_t* gpio3_mmap_base_reg = NULL;
- int gpio_mmap_fd = 0;
- int gpio_mmap(void)
- {
- if ((gpio_mmap_fd = open(MMAP_PATH, O_RDWR|O_SYNC)) < 0) {
- fprintf(stderr, "unable to open mmap file");
- return -1;
- }
- return 0;
- }
- //=============GPIO 3
- int getGpio3State()
- {
- uint32_t con,iom,data,dirc;
- printf("\n================\n GPIO3 Info \n");
- /* clock en */
- gpio3_clocken_base_reg = (uint8_t*) mmap(NULL, 4096, PROT_READ | PROT_WRITE,
- MAP_SHARED, gpio_mmap_fd,0xff760000);
-
- con = *(volatile uint32_t *)(gpio3_clocken_base_reg+0x037c);
- printf(" the clock config reg is %0x \n",con);
- /* iomux */
- gpio3_iomux_base_reg = (uint8_t*) mmap(NULL, 4096*4, PROT_READ | PROT_WRITE,
- MAP_SHARED, gpio_mmap_fd,0xff770000);
- iom = *(volatile uint32_t *)(gpio3_iomux_base_reg+0xe01c);
- printf(" the iomux reg is %0x \n",iom);
- /* input or output */
- gpio3_mmap_base_reg = (uint8_t*) mmap(NULL, 4096, PROT_READ | PROT_WRITE,MAP_SHARED, gpio_mmap_fd,0xFF788000);
-
- dirc = *(volatile uint32_t *)(gpio3_mmap_base_reg+RK3399_GPIO_DIRC);
- printf(" the direct reg is %0x \n",dirc);
- data = *(volatile uint32_t *)(gpio3_mmap_base_reg+RK3399_GPIO_DATA);
- printf("before set the data reg is %0x \n",data);
- }
- void setGpio3State()
- {
- uint32_t con,iom,data,dirc;
复制代码
|
|