• GM8180_gpio内核模块调试 分类: arm-linux-Ubuntu 2013-07-22 16:30 311人阅读 评论(0) 收藏


    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <sys/ioctl.h>
    #include <stdlib.h>
    #include "gpio.h"

    struct gpio_params gmm;
    int gpid =-1;
    void main(int argc,char *argv[])
    {
     char filename[20];
            int i,k;

     gpid = open("/dev/gpio", O_RDWR);
     if (!gpid)
     {
         printf("GPIO initial fail ");
      
     }

     gmm.ctrl_pin = 0xc0; // choose GPIO7 pin  
     gmm.data_direct = 0xc0; //set as output pin 
     if(ioctl(gpid, GPIO_SET_DATA_DIRECT,&gmm))    
      printf("GPIO_SET_DATA_DIRECT failed ");

            for(i=0;i<10;i++)
            {
        gmm.data_out = i%2==0?0x80:0x40; 
        if(ioctl(gpid, GPIO_SET_DATA_OUTPUT,&gmm))    
       printf("GPIO_SET_DATA_OUTPUT failed ");
             printf("%d ",i);
      usleep(500000);

             }

     close(gpid);
     return ;

    }

    //gpio.h

    #define _GM8180_Platform
    struct gpio_params {
     u_int group;
     u_int  ctrl_pin; 
     u_int  data_out; 
     u_int  data_in; 

     u_int  int_clear;  
     u_int  data_direct;   
     u_int  int_enable;   
     u_int  int_trigger;

     u_int  int_both;   
     u_int  int_riseneg;   
    } gpio_params;
    //Modify By Ken.Hsieh
    #ifdef _GM8120_Platform
    #define GPIO_SET_DATA_OUTPUT  3
    #define GPIO_READ_DATA_INPUT  4 
    #define GPIO_SET_DATA_DIRECT 5
    #define GPIO_SET_INT            6
    #define GPIO_SET_INT_FUNC       7
    #define GPIO_CLEAR_INT          8
    #endif

    #ifdef _GM8180_Platform
    #define IOC_MAGIC  'g'

    #define GPIO_SET_DATA_OUTPUT    _IOWR(IOC_MAGIC, 8, gpio_params)
    #define GPIO_READ_DATA_INPUT    _IOWR(IOC_MAGIC, 9, gpio_params)
    #define GPIO_SET_DATA_DIRECT    _IOWR(IOC_MAGIC, 10, gpio_params)
    #define GPIO_SET_INT_FUNC       _IOWR(IOC_MAGIC, 11, gpio_params)
    #define GPIO_SET_INT            _IOWR(IOC_MAGIC, 12, gpio_params)
    #define GPIO_CLEAR_INT          _IOWR(IOC_MAGIC, 13, gpio_params)
    #endif

    //makefile

    LINUX_SRC := /usr/src/arm-linux-2.6/linux-2.6.14-fa
    CC = arm-linux-gcc
    STRIP =arm-linux-strip
    INCLUDE = -I$(LINUX_SRC)/include/
    INCLUDE += -I/usr/src/arm-linux-2.6/module/GPIO

    TARGET1=gpio
    all:
     $(CC) $(INCLUDE) gpio.c -o $(TARGET1)
     $(STRIP) $(TARGET1) 
    clean:
     rm -f gpio 

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    AtCoder Beginner Contest 184 ABCDE 题解
    Codeforces Round #685 (Div. 2) C. String Equality 思维
    Codeforces Round #682 (Div. 2) ABC 题解
    Gym 102215 & 队内训练#5
    【题解】 CF436E Cardboard Box 带悔贪心
    【题解】 「NOI2019」序列 模拟费用流 LOJ3158
    【笔记】 exlucas
    【题解】 「HNOI2018」毒瘤 树形dp+动态dp+容斥+格雷码 LOJ2496
    【笔记】 异或高斯消元方案数
    【笔记】 用生成函数推二项式反演
  • 原文地址:https://www.cnblogs.com/mao0504/p/4706906.html
Copyright © 2020-2023  润新知