Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

driver module nios2linux nommu

nios2linux

nommu

altera de2 2c35

de2_net.sof, de2_net.ptf

Ok i am trying to write an driver module with ioctl interface to access to leds. (For example).

Under Kernel Settings i did:

[*] Enable loadable module support --->

[*] Module unloading

Here is my driver module:

# include <linux/module.h># include <linux/init.h>                                    # include <linux/kernel.h># include <linux/fs.h>
                                   
MODULE_AUTHOR("xxx");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("xxx");
MODULE_SUPPORTED_DEVICE("none");
# define driverMAJOR    (250) 
int led_ioctl (struct inode *inode, struct file *file, unsigned int var1, unsigned long var2)
{
     //nothing here ... just testing
    return 0;
}
static struct file_operations fops = {
        .owner = THIS_MODULE,
        .ioctl = led_ioctl,
};
static int __init led_init(void)                           
{
    int retval = -1;
    retval = register_chrdev(driverMAJOR, "led", &fops);
    if (retval<0) printk("Cannot register led device!\n");
    else 
    {
        printk("Device registered!\n");
    }
    return 0;
}
static void __exit led_exit(void)                          
{
    unregister_chrdev(driverMAJOR, "led");
    return;
}
module_init( led_init );
module_exit( led_exit );

with nios2-terminal i say:

mknod /dev/led c 250 0

insmod led.ko

Everything looks ok.

Here is my userland program:

# include <stdio.h># include <sys/types.h># include <sys/stat.h># include <fcntl.h># include <stdio.h># include <unistd.h># include <sys/mman.h>
int main (void)
{
    int fd = open("/dev/led", O_RDWR); 
  //nothing here
   
    return 0;
}

As soon as i execute it, the board reboots ...

nios2-terminal gives a lot of cryptic signs and thats it.

I am stuck, any tips?
No RepliesBe the first to reply