Driving Beaglebone GPIO through /dev/mem

前端 未结 7 1659
温柔的废话
温柔的废话 2020-12-04 08:34

I\'m trying to write a C program for blinking a LED on the Beaglebone. I know I can use the sysfs way...but I\'d like to see if it is possible to get the same result mapping

相关标签:
7条回答
  • 2020-12-04 09:28

    for enable GPIO banks....

    enableClockModules () {
        // Enable disabled GPIO module clocks.
        if (mapAddress[(CM_WKUP_GPIO0_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] & IDLEST_MASK) {
          mapAddress[(CM_WKUP_GPIO0_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] |= MODULEMODE_ENABLE;
          // Wait for the enable complete.
          while (mapAddress[(CM_WKUP_GPIO0_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] & IDLEST_MASK);
        }
        if (mapAddress[(CM_PER_GPIO1_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] & IDLEST_MASK) {
          mapAddress[(CM_PER_GPIO1_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] |= MODULEMODE_ENABLE;
          // Wait for the enable complete.
          while (mapAddress[(CM_PER_GPIO1_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] & IDLEST_MASK);
        }
        if (mapAddress[(CM_PER_GPIO2_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] & IDLEST_MASK) {
          mapAddress[(CM_PER_GPIO2_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] |= MODULEMODE_ENABLE;
          // Wait for the enable complete.
          while (mapAddress[(CM_PER_GPIO2_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] & IDLEST_MASK);
        }
        if (mapAddress[(CM_PER_GPIO3_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] & IDLEST_MASK) {
          mapAddress[(CM_PER_GPIO3_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] |= MODULEMODE_ENABLE;
          // Wait for the enable complete.
          while (mapAddress[(CM_PER_GPIO3_CLKCTRL - MMAP_OFFSET) / GPIO_REGISTER_SIZE] & IDLEST_MASK);
        }
    }
    

    Where...

    MMAP_OFFSET = 0x44C00000

    MMAP_SIZE = 0x481AEFFF - MMAP_OFFSET

    GPIO_REGISTER_SIZE = 4

    MODULEMODE_ENABLE = 0x02

    IDLEST_MASK = (0x03 << 16)

    CM_WKUP = 0x44E00400

    CM_PER = 0x44E00000

    CM_WKUP_GPIO0_CLKCTRL = (CM_WKUP + 0x8)

    CM_PER_GPIO1_CLKCTRL = (CM_PER + 0xAC)

    CM_PER_GPIO2_CLKCTRL = (CM_PER + 0xB0)

    CM_PER_GPIO3_CLKCTRL = (CM_PER + 0xB4)

    I have written a small library that perhaps you might be interested. At the moment only works with digital pins.

    Regards

    0 讨论(0)
提交回复
热议问题