About the driver (a simple application about LEDs on the 2410 + LINUX Platform)

Source: Internet
Author: User

// 4led. c

 

# Include <Linux/config. h>
# Include <Linux/module. h>
# Include <Linux/kernel. h>
# Include <Linux/init. h>

# Include <Linux/miscdevice. h>
# Include <Linux/sched. h>
# Include <Linux/delay. h>
# Include <Linux/poll. h>
# Include <Linux/spinlock. h>
# Include <Linux/IRQ. h>
# Include <Linux/delay. h>

# Include <ASM/hardware. h>

# Define device_name "ledwen"
# Define led_major 240

 

Module_license ("GPL"); // used to remove copyright notice

 

Static unsigned long led_table [] = {
Gpio_b7,
Gpio_b8,
Gpio_b9,
Gpio_b10,
};

/*************************************** **********************************/
Static int matrix4_leds_ioctl (struct inode * inode, struct file * file, unsigned int cmd, unsigned long Arg)
{
Switch (CMD)

{
Case 0:
Case 1:
If (Arg> 4)
Return-einval;
Write_gpio_bit (led_table [Arg],! CMD );
Printk ("led: % d", ARG, CMD/N );
Default:
Return-einval;
}
}

/*************************************** **********************************/
Static struct file_operations matrix4_leds_fops = {
Owner: this_module,
IOCTL: matrix4_leds_ioctl,
};

Static devfs_handle_t devfs_handle;

Static int _ init matrix4_leds_init (void)
{
Int ret;
Int I;

Ret = register_chrdev (led_major, device_name, & matrix4_leds_fops );
If (Ret <0 ){
Printk (device_name "can't register major number/N ");
Return ret;
}
Devfs_handle = devfs_register (null, device_name, devfs_fl_default,
Led_major, 0, s_ifchr | s_irusr | s_iwusr, & matrix4_leds_fops, null );
For (I = 0; I <8; I ++ ){
Set_gpio_ctrl (led_table [I] | gpio_pullup_en | gpio_mode_out );
Write_gpio_bit (led_table [I], 1 );
}

Printk (device_name "initialized/N ");
Return 0;
}

Static void _ exit matrix4_leds_exit (void)
{
Devfs_unregister (devfs_handle );
Unregister_chrdev (led_major, device_name );
}

Module_init (matrix4_leds_init );
Module_exit (matrix4_leds_exit );

 

The above Code uses commands in the VM:

# Arm-Linux-gcc-dw.kernel _-I/friendly-arm/kernel/include-dkbuild_basename = matrix4-leds-dmodule-c-o 4led. O 4led. c

Compile it.

In the above compilation command-dkbuild_basename = matrix4-leds segment do not know why the meaning, the practice operation found that this section can also be compiled through, and can run.

 

After compilation is passed, it is uploaded to the target board and loaded with the command: insmod 4led. O. (Note that the file name is not led, but ledwen)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.