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. On Sunday, July 27, 2014 4:09:56 AM UTC-7, kthab...@gmail.com wrote: > > /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 > *================== > *********************************************/ > > #define out 1 > #define in 0 > > #define export_PATH "/sys/class/gpio/export" > #define value_PATH "/sys/class/gpio/gpio%d/value" > #define direction_PATH "/sys/class/gpio/gpio%d/direction" > #define unexport_PATH "/sys/class/gpio/unexport" > > //*********************P9*********************** > #define p9_11 30 > #define p9_12 60 > #define p9_13 31 > #define p9_14 50 > #define p9_15 48 > #define p9_16 51 > #define p9_17 5 > #define p9_18 4 > //#define p9_19 13 > //#define p9_20 12 > #define p9_21 3 > #define P9_22 2 > #define p9_23 49 > #define p9_24 15 > #define p9_25 117 > #define p9_26 14 > #define p9_27 115 > //#define p9_28 113 > //#define p9_29 111 > #define p9_30 112 > //#define p9_31 110 > #define p9_41 20 > //#define p9_41 116 > //#define p9_42 114 > #define p9_42 7 > //********************************************* > > > //*********************P8*********************** > //********************************************* > > > > //******************function********************* > int gpio_export(int); > int gpio_unexport(int); > int gpio_direction(int, int); > int pin_write(int, int); > int pin_read(int); > //*********************************************** > > > #endif /*BB_GPIO_*/ > > int gpio_export(int gpio_number) > { > FILE* fp=0; > > if((fp = fopen(export_PATH,"w"))==NULL){ > printf("Cannot open export file(>>%s).\n", export_PATH); > return -1; > } > fprintf(fp,"%d",gpio_number); > fclose(fp); > } > > int gpio_unexport(int gpio_number) > { > FILE* fp; > > if((fp = fopen(unexport_PATH,"w"))==NULL){ > printf("Cannot open unexport file(>>%s).\n", unexport_PATH); > return -1; > } > fprintf(fp,"%d",gpio_number); > fclose(fp); > } > > int gpio_direction(int gpio_number,int direction) > { > FILE* fp; > char set_value[4]={0}; > char dir_path[50]={0}; > sprintf(dir_path, direction_PATH, gpio_number); > if((fp = fopen(dir_path,"w"))==NULL){ > printf("Cannot open direction file(>>%s).\n",dir_path); > return -1; > } > rewind(fp); > if(direction == out){ > strcpy(set_value,"out"); > fwrite(&set_value,sizeof(char),3,fp); > fclose(fp); > } else if(direction == in){ > strcpy(set_value,"in"); > fwrite(&set_value,sizeof(char),2,fp); > fclose(fp); > } else{ > printf("invalue pin mode(%d)\n",direction); > return -1; > } > fclose(fp); > return 1; > } > > int pin_write(int gpio_number,int value) > { > FILE* fp; > char val_path[50]={0}; > char set_value[2]={0}; > > sprintf(val_path, value_PATH, gpio_number); > if((fp = fopen(val_path,"w"))==NULL){ > printf("Cannot open value file(>>%s).\n",val_path); > return -1; > } > > rewind(fp); > if(value == 1){ > strcpy(set_value,"1"); > } > else if(value == 0){ > strcpy(set_value,"0"); > } > else { > printf("invalid value pin(%d)(%d)\n", gpio_number, value); > return -1; > } > > fwrite(&set_value, sizeof(char), 1, fp); > fclose(fp); > return 0; > } > > int pin_read(int gpio_number) > { > FILE* fp; > int value=0; > char val_path[50]={0}; > > sprintf(val_path, value_PATH, gpio_number); > if((fp = fopen(val_path,"r"))==NULL){ > printf("Cannot open value file(>>%s).\n",val_path); > return -1; > } > > rewind(fp); > value = fgetc(fp) - '0'; > fclose(fp); > return value; > } > > > > > but compile error... > > root@beaglebone:/home/debian/workspace/sources/gpio_control# \ > > gcc -o led_blink led_blink.c > /tmp/ccfrwmlk.o: In function `main': > led_blink.c:(.text+0x5c8): undefined reference to `pin_wirte' > led_blink.c:(.text+0x5e0): undefined reference to `pin_wirte' > led_blink.c:(.text+0x5f8): undefined reference to `pin_wirte' > led_blink.c:(.text+0x610): undefined reference to `pin_wirte' > collect2: ld returned 1 exit status > root@beaglebone:/home/debian/workspace/sources/gpio_control# > > i don't know why .. help please > -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.