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

[microblaze-uclinux] printk() is not triggered with the data passed in the application program



Hello everybody,
Ive written a driver (MY_Driver.c) and the corresponding application program (myapp.c) to blink the 8 LEDs.  These LEDs blink successfully through "mwr 0x40020000 0x0f" command on xmd . But when I try to write the same data using an application program I get the following on TERA TERM with nothing happening on LEDs.:

# myapp
MY_Driver open: Usage = 1
MY_Driver opened 3
WRITE Data from user 0 hex
MY_Driver release: Usage = 1
WRITE SUCCESSFUL
NOTHING HAPPENING

Clearly the "data from user is 0" on the terminal  but i am hardcoding it as 0x0f in the application program itself. Using scanf() to input data also doesnt work.  So Can anybody tell me why is this mismatch ? Is it because the local buffer not working due to the filesystem (romfs) being read only ?  Can there be some other issues involved like setting I/O direction or using interrupts ? Driver is registered successfully during boot up. Or should I write the application program for the gpio driver which is there as part of the uClinux-dist and discard my driver. Please guide me as i am not able to figure out whats wrong with my driver as well as application program

I am giving both the driver program as well as application program below. Kindly go through it and try to help me out. Thank u in advance.

Driver program (MY_Driver.c)

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

#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("WRITE 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);    // for debugging only
         
    // 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;

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

Application program (myapp.c)

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

#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);
    }

/*if(read(handle, &data, 1, 0) < 0)
    printf("Error reading MY_Driver\n");

printf(" Status from the Driver = %x hex\n",data & 255);*/

data="">
//printf("Enter Data :\n");
//scanf("%x",&data);

if(write(handle, &data, 1, 0) < 0)
    printf("Error writing MY_Driver\n");
else
    printf("WRITE SUCCESSFUL\n");

printf("NOTHING HAPPENING\n");

return 0;
}