LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 08-23-2006, 02:02 AM   #1
kunal_patna23
LQ Newbie
 
Registered: May 2006
Posts: 1

Rep: Reputation: 0
Driver to blink LEDs not working


Hi everybody,
I have ported uClinux-2.4 successfully to MMU less MicroBlaze(soft core) processor from xilinx. It boots and bootlog appears on TERA TERM (Terminal for serial communication). The board which has spartan 3 400 FPGA chip (that is configured as MicroBlaze using xilinx EDK 7.1) is from Nu-Horizons having 8 LEDs along with other hardware.

I have written a device driver(MY_Driver.c) and a corresponding application program (myapp.c) to blink LEDs by passing some data to it. But the problem is that everything goes well till the last moment showing "WRITE SUCCESSFUL". And it fails to write. LED address is verified using a xilinx utility program. I believe "outb()" is not able to write. My driver is registered successfully during boot up.I get the following output after I run "myapp" on the target board via TERA TERM. All the print() statements trigger correctly. Both the programs are given below.

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

I have also tried
"#define OUTMEM *((const volatile unsigned char*)(0x40020000))
OUTMEM = data;"
other than outb() and writeb().But it fails to write. Can anyone suggest the reason for this. Programs are given below:

MY_Driver.c :
**************************************************************************************************** ******
**************************************************************************************************** ******
#include <linux/slab.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 OUTMEM *((const volatile unsigned byte *)(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, (u8 *)buf, 1))
return -EFAULT;
printk("WRITE Data froom user %x hex\n", data);
outb(data, OUTPORT);
//OUTMEM = data;
//writeb(data, OUTPORT);
return 1;
}

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

data = inb(INPORT);

printk("data = %x 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;

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

myapp.c:

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

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

int handle;

int main()
{
unsigned char 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);
}


data=0x0f;

//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;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sipix Blink (1) USB-Camera resaguk Linux - Hardware 2 04-25-2005 11:52 AM
a newbie, how do I make my cursor blink? honet *BSD 3 06-25-2004 07:59 PM
Post-install: machine won't boot w/ Vector ...blink blink blink goes the cursor nethbar VectorLinux 3 03-17-2004 02:32 PM
hehehe.. giggle... blink.. zoom.... itsjustme General 0 01-08-2004 08:58 PM
Is a symlink suppose to blink? angmaya Linux - Newbie 5 10-18-2003 12:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 12:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration