LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help with GPIO module error (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-with-gpio-module-error-4175464629/)

TeaYoung 06-04-2013 12:36 AM

Need help with GPIO module error
 
I do not speak English well.

I live in South Korea.

I am GPIO through the the device driver you try to create a and is.

EXYNOS4_GPA1 (GPIO-10) by connecting the LED flashing every second that the driver is making.

If you make an error coming up I do not know how to solve.


gpio.c
Code:

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/sysfs.h>
#include <linux/input.h>
#include <linux/gpio.h>
#include <mach/gpio.h>
#include <mach/regs-gpio.h>
#include <plat/gpio-cfg.h>
#include <mach/gpio-exynos4.h>
#include<linux/cdev.h>

#include <linux/init.h>
#include <linux/clk.h>
#include <linux/hrtimer.h>
#include <linux/slab.h>
#include <asm/io.h>
#include <mach/regs-pmu.h>

#define USER_SW EXYNOS4_GPA(1)

static int __init gpio_init(void)
{
 int i;

 printk(KERN_INFO "GPIO: Initializing!rnnnnn");
 
 s3c_gpio_cfgpin(USER_SW, S3C_GPIO_INPUT);  //GPA1[1] -> Input setting
 s3c_gpio_setpull(USER_SW, S3C_GPIO_PULL_UP);  //GPA[1] -> Pull up setting
 gpio_set_value(USER_SW, 0); // init GPA1[1] -> 0 (OFF)

while(1){
 gpio_set_value(USER_SW, 1);
 sleep 1;
 gpio_set_value(USER_SW, 0);
 sleep 1;
}
return 0;
}

static void __exit gpio_exit(void)
{
  printk(KERN_INFO "GPIO: exit");
}

module_init(gpio_init);
module_exit(gpio_exit);

MODULE_DESCRIPTION("Simple gpio module");
MODULE_AUTHOR("Anders Knive Lassen & Marius Lind Volstad");
MODULE_LICENSE("GPL");


Makefile
Code:

obj-m := gpio.o

KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

default:
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

test:
    echo $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

clean:
    rm -rf *.mod.c *.ko *.o *.symvers *.order
}

static void __exit gpio_exit(void)
{
  printk(KERN_INFO "GPIO: exit");
}

module_init(gpio_init);
module_exit(gpio_exit);

MODULE_DESCRIPTION("Simple gpio module");
MODULE_AUTHOR("Anders Knive Lassen & Marius Lind Volstad");
MODULE_LICENSE("GPL");


ERROR
Code:

root@linaro-ubuntu-desktop:/study/led1# make
make -C /lib/modules/3.0.75/build SUBDIRS=/study/led1 modules
make[1]: Entering directory `/usr/src/linux-odroid-3.0.y'
  CC [M]  /study/led1/gpio.o
/study/led1/gpio.c: In function ‘gpio_init’:
/study/led1/gpio.c:64:2: error: implicit declaration of function ‘EXYNOS4_GPA’ [-Werror=implicit-function-declaration]
/study/led1/gpio.c:93:2: error: ‘sleep’ undeclared (first use in this function)
/study/led1/gpio.c:93:2: note: each undeclared identifier is reported only once for each function it appears in
/study/led1/gpio.c:93:8: error: expected ‘;’ before numeric constant
/study/led1/gpio.c:95:8: error: expected ‘;’ before numeric constant
cc1: some warnings being treated as errors
make[2]: *** [/study/led1/gpio.o] Error 1
make[1]: *** [_module_/study/led1] Error 2
make[1]: Leaving directory `/usr/src/linux-odroid-3.0.y'
make: *** [default] Error 2


smallpond 06-04-2013 02:47 PM

The kernel is a different environment from user space. It doesn't make sense to sleep in the kernel because it would block other processes, so it is not allowed. Your module will never load because the init routine never completes.

gdejonge 06-04-2013 10:25 PM

Also setting an infinite loop in your module initialisation routine is a BAD idea.

Cheers.


All times are GMT -5. The time now is 10:44 PM.