[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[microblaze-uclinux] Application Program to blink LEDs not working



HI all,
I am a newbie to drivers and struggling.
I've written and installed the driver to blink LEDs with its corresponding application program on the board . Both appear in the file system of uclinux after it has been ported. Driver is registered successfully during boot up.  But it's not working. I am still trying to figure out where I've gone wrong. Application Program opens the driver file successfully and everything goes well but finally it doesnt write to LEDs. I am giving both the programs below. Please help me out.

Here is MY_Driver.c program

**************************************************************************************************************************************************************************************************
#include <linux/malloc.h>
#include <linux/module.h>
#include <asm/io.h>
#include <linux/poll.h> 
#include <linux/init.h>

#define    MY_Driver_MAJOR    240

#define OUTPORT 0x40020000
#define INPORT 0x40000000


static ssize_t MY_Driver_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
{
    u8 data;

    if (copy_from_user(&data, buf, sizeof(data)))
           return -EFAULT;
    printk("Data from user %x hex\n", data);
    outb(data, OUTPORT);
    return 0;
}

static ssize_t MY_Driver_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
{
    u8 data;

    data = ""        

    printk("data = "" hex\n", data);   
         
    // transfer data from kernel address space to user address space

    if(copy_to_user( buffer, &data, sizeof(u8)))
        return -EFAULT;   

    return 0;
}

static int MY_Driver_open(struct inode * inode, struct file * file)
{
    printk("MY_Driver open: Usage = %d\n", MOD_IN_USE);
    MOD_INC_USE_COUNT;
    return 0;
}

static int MY_Driver_release(struct inode * inode, struct file * file)
{
    MOD_DEC_USE_COUNT;
    printk("MY_Driver release: Usage = %d\n", MOD_IN_USE);
    return 0;
}

struct file_operations MY_Driver_fops = {
    owner: THIS_MODULE,
    open:    MY_Driver_open,
    release: MY_Driver_release,
    write:  MY_Driver_write,
    read:   MY_Driver_read
      };
     
     

int __init MY_Driver_init (void)
{
    if (register_chrdev(MY_Driver_MAJOR,"MY_Driver",&MY_Driver_fops)) {
        printk("MY_Driver: Failed to get major %d\n", MY_Driver_MAJOR);
        return -EIO;
    }
    printk("Registered device MY_Driver: major %d\n",MY_Driver_MAJOR);
    return 0;
}

static void __exit MY_Driver_cleanup (void)
{
    printk("Freed resources: MOD_IN_USE = %d\n", MOD_IN_USE);
    unregister_chrdev(MY_Driver_MAJOR,"MY_Driver");
    printk("Unregistered device MY_Driver: major %d\n",MY_Driver_MAJOR);
}


//module_init(MY_Driver_init);
//module_exit(MY_Driver_cleanup);

MODULE_LICENSE("GPL");

EXPORT_NO_SYMBOLS;

******************************************************************************************************************************************************************************************

And Here is the application program to write the data 0x0F to 8 LEDs:

******************************************************************************************************************************************************************************************

#include <stdio.h>
//#include <sys/ioctl.h>
#include <fcntl.h>


int    handle;

int main()
{
int data;

handle = open("/dev/MY_Driver", O_RDWR);
if(handle > 0)
    printf("MY_Driver opened %d\n", handle);
else
    {
    printf("Error opening MY_Driver\n");
    exit(1);
    }

printf("Data to Write : 0x0F ");
//scanf("%x",&data);
data = ""> if(write(handle, &data, 1, 0) < 0)
   printf("Error writing MY_Driver\n");;

return 0;
}