« Return to Thread: GPIO programming and Interrupts

GPIO programming and Interrupts

by Challenger :: Rate this Message:

Reply to Author | View in Thread

Hello ,

I have written a device driver to make use of the gpio to trigger interrupts. I have attached a part of the whole code. You can try using it.
I have attached the makefile as well. Edit the path to kernel source in the makefile.

shashi.




 
Date: Tue, 30 Jun 2009 01:39:42 -0700 (PDT)
From: cruizbugs <cruiz_bugs@...>
Subject: [Gumstix-users]  GPIO programming and Interrupts
To: gumstix-users@...
Message-ID: <24268234.post@...>
Content-Type: text/plain; charset=us-ascii


Hi, I have a few questions.

I have a task to make my gumstix to control a switch.

So, I am using a GPIO 28 to control the external device.
I understand that I can use
# echo "GPIO out set" > /proc/gpio/GPIO28
# echo "GPIO out clear" > /proc/gpio/GPIO28
to control the pin output manually, but what I have to do is to make an
automatic on-off.
meaning,
I will have to read from a .txt file that contains all the day and time to
on/off.
this text file will turn on-off the switch every few minutes, i.e.
Monday 01:00 am ON
Monday 01:02 am OFF
Monday 01:05 am ON
Monday 01:59 am OFF
etc..

So, regarding this task and since i'm still new to linux,
1. i was thinking what programming language I should use? C or C++ ? which
one easier?

2. i found this http://docwiki.gumstix.org/index.php/Sample_code/C/gpregs
how to run this file ? does this work for verdex pro XL6P ? i'm using GPIO
on consoleLCD16

3. Is there any idea on how to do this effectively?
I was being told to try to use interrupt, for example, for every minute i
will receive an interrupt, then i will read the list of the timing and check
out if I have to on or off the switch.
but the problem is, how to set this kind of interrupt? i heard about kernel
programming, but i'm still quite lost here.
or is there any other better way to do this task?
I saw http://docwiki.gumstix.org/GPIO_event , but i dont think this is
related to what I have to do, right ??

sorry I ask alot.
Thanks you in advance :-)






[gpio_interrupt.c]

#include<linux/init.h>
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/slab.h>
#include<linux/errno.h>
#include<linux/types.h>
#include<linux/fs.h>
#include<linux/proc_fs.h>
#include<linux/fcntl.h>
#include<linux/fb.h>
#include<linux/interrupt.h>
#include<linux/ioctl.h>
#include<linux/types.h>
#include<linux/fcntl.h>
#include<linux/errno.h>
#include<linux/gpio.h>
#include<linux/mman.h>
#include<linux/mm.h>
#include<linux/vmalloc.h>
#include<linux/slab.h>
#define OVERO_SPI_PENDOWN 144
#define OVERO_GPIO1_PENDOWN 145
#define gpio145_pad 0x48002174
#define gpiobank5 0x49056034
MODULE_LICENSE("Dual BSD/GPL");
void gpioint_exit(void);
int  gpioint_init(void);
static int result,temp=0;
static irqreturn_t gpio_ISR(int irq,void *dev_id);
static irqreturn_t gpio_ISR1(int irq,void *dev_id);
static void volatile *gpio5_base1, *gpio5_base2;
module_init(gpioint_init);
module_exit(gpioint_exit);
int fgen_open(struct inode *inode, struct file *filp);
int fgen_release(struct inode *inode, struct file *filp);
struct file_operations fgen_fops = {
 
  open: fgen_open,
 
  release: fgen_release
};
int gpioint_init()
{
//int i,j,k;
 
 result = register_chrdev(0, "gpio_test",&fgen_fops);
 printk("gpio:major number %d \n",result);
 
if ((gpio_request(OVERO_SPI_PENDOWN,"gpio_test")) == 0 && (gpio_direction_input(OVERO_SPI_PENDOWN))==0)
                {
                        gpio_export(OVERO_SPI_PENDOWN,0);

        } else
                {
                printk(KERN_ERR "could not obtain gpio for gpio144 IRQ\n");
                return(0);
        }
if ((gpio_request(OVERO_GPIO1_PENDOWN,"gpio_test")) == 0 && (gpio_direction_input(OVERO_GPIO1_PENDOWN))==0)
                {
                        gpio_export(OVERO_GPIO1_PENDOWN,0);

        } else
                {
                printk(KERN_ERR "could not obtain gpio for gpio145 IRQ\n");
                return(0);
        }

if(request_irq(OMAP_GPIO_IRQ(OVERO_SPI_PENDOWN),gpio_ISR, IRQF_TRIGGER_LOW, "gpio_test",NULL))
        {
                printk(" can't load interrupt\n");
        }
printk("\n IRQ value=%d  \n",OMAP_GPIO_IRQ(OVERO_SPI_PENDOWN));


if(request_irq(OMAP_GPIO_IRQ(OVERO_GPIO1_PENDOWN),gpio_ISR1, IRQF_TRIGGER_HIGH, "gpio_test",NULL))
        {
                printk(" can't load interrupt\n");
        }
printk("\n IRQ value=%d  \n",OMAP_GPIO_IRQ(OVERO_GPIO1_PENDOWN));

 }

void gpioint_exit(void)
{
  /* Freeing the major number */
  unregister_chrdev(result, "gpio_test");
  /* Freeing interrupt */
 
        free_irq(OMAP_GPIO_IRQ(OVERO_SPI_PENDOWN),NULL);
        free_irq(OMAP_GPIO_IRQ(OVERO_GPIO1_PENDOWN),NULL);
 printk("<1>Removing fgen module\n");
}


static irqreturn_t gpio_ISR(int irq,void *dev_id)
{

        printk("interrupt acknowledged 144\n");

        return IRQ_HANDLED;
}
static irqreturn_t gpio_ISR1(int irq,void *dev_id)
{

        printk("interrupt acknowledged 145\n");
        return IRQ_HANDLED;
}

int fgen_open(struct inode *inode, struct file *filp)
{
  /* Success */
  return 0;
}
int fgen_release(struct inode *inode, struct file *filp)
{
  /* Success */
  return 0;
}




------------------------------------------------------------------------------

_______________________________________________
gumstix-users mailing list
gumstix-users@...
https://lists.sourceforge.net/lists/listinfo/gumstix-users

Makefile (320 bytes) Download Attachment

 « Return to Thread: GPIO programming and Interrupts