i wanna 8bit gpio control

/sys/class/gpio/export this driver file i have used.

but this control only one bit. so, i try to 8bit control like this

#include “bb_gpio.h”
#include <stdio.h>
#include <sys/time.h>
//#include <string.h>

void main(void)
{
gpio_export(p9_11); gpio_export(p9_12);
gpio_export(p9_13); gpio_export(p9_14);
gpio_export(p9_15); gpio_export(p9_16);
gpio_export(p9_17); gpio_export(p9_18);

gpio_direction(p9_11,out); gpio_direction(p9_12,out);
gpio_direction(p9_13,out); gpio_direction(p9_14,out);
gpio_direction(p9_15,out); gpio_direction(p9_16,out);
gpio_direction(p9_17,out); gpio_direction(p9_18,out);

while(1){
pin_write(p9_11,1); pin_write(p9_12,1);
pin_write(p9_13,1); pin_write(p9_14,1);
pin_write(p9_15,1); pin_write(p9_16,1);
pin_write(p9_17,1); pin_write(p9_18,1);
sleep(1);
pin_write(p9_11,0); pin_wirte(p9_12,0);
pin_write(p9_13,0); pin_wirte(p9_14,0);
pin_write(p9_15,0); pin_wirte(p9_16,0);
pin_write(p9_17,0); pin_wirte(p9_18,0);
sleep(1);
};
}

================#include “bb_gpio.h”================

#ifndef BB_GPIO_H_
#define BB_GPIO_H_

#include <stdio.h>
#include <string.h>

/********************************************

  • BB_GPIO headerfile
  • This file only used to gpio control
  • other feature using device-tree-overlay
  • when using GPIO, the pin work to MODE7
    *=====formula======
  • GPIO N1[N2]
  • gpio_number = (32 x N1) + N2

led_blink.c (868 Bytes)

bb_gpio.h (3.42 KB)

If you look closely at the error text you’ll see you misspelt “write” as “wirte”.

That’s still one bit control. There’s going to be some unknown time between the bits that will depend on cpu usage. For true 8 bit, you need to use mmap to get a pointer to the gpio control block and modify the registers directly.
Each gpio block has 32 pins, and each gpio block has a set and clear register that’s 32 bits wide, one bit for each pin. Setting a bit in the set register will set the pin. Setting a bit in the clear register will clear the pin. So, to set 8 pins at once, you would write the 8 bits to the set, then to clear all 8, you would write those 8 bits to the clear register. This will truly be “at once”, at least to the capabilities of the hardware.

Sysfs has some pretty absurd overhead, so you’ll get a few hundred kHz at most. With the the register manipulation using mmap, you’ll end up with ~4 MHz for a toggle like that.

Hi Brandon,

I’m currently using mmap (in Python) to achieve register wide GPIO. I’m concerned though, that the kernel still thinks it owns that memory and might inadvertently write to it (for ex: if you forget to disable the heartbeat trigger). Do you know of a way to disable the sysfs interface / claim those pins as being in use so that you can safely manipulate the mmap either through software or a device tree overlay?

Thanks for your help.

I believe the only way is to remove them from the main device tree overlay since that will be loaded before anything else you can do. Decompile the dtbo, remove the usr led entries in the resulting dts, and recompile to dtbo (at least this is how it used to work).