sama5 kio接口控制

//example 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#define TX1_LED     160 //

#define RX1_LED     161//

 

int main(int argc, char * argv)
{
        int i, n, fd;
        char num,val;
        int ret;
        fd = open("/dev/kio", O_RDWR);                //打开设备
        if (fd < 0)
        {
            printf("can't open /dev/kio!\n");
            exit(1);
        }
        sleep(1);
        ioctl(fd, 1, TX1_LED);                //设置GPIO160输出 TX1_LED

    ioctl(fd, 1, RX1_LED);                //设置GPIO161输出 RX1_LED
       
        while (1) 
        {
                num = 1;
                ret = write(fd,"1",TX1_LED); //置高
                if(ret < 0)
                {
                        perror("write");
                        return -1;
                }
                sleep(1);
                ret = write(fd,"0",TX1_LED);//置低
                if(ret < 0)
                {
                    perror("write");
                    return -1;
     }

 

     ret = write(fd,"1",RX1_LED); //置高
                if(ret < 0)
                {
                        perror("write");
                        return -1;
                }
                sleep(1);
                ret = write(fd,"0",RX1_LED);//置低
                if(ret < 0)
                {
                    perror("write");
                    return -1;
     }

     

  }

}

你可能感兴趣的:(sama5 kio接口控制)