In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to control LED without relying on linux kernel programs. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
1. Driver my_led_module.c
# include # define DEVICE_NAME "mini2440_leds" / / device name # define LED_MAJOR 260#define LED_ON 1 / / LED on status # define LED_OFF 0 / / LED off status volatile unsigned long virt, phys;// is used to store virtual address and physical address volatile unsigned long * GPBCON, * GPBDAT, * GPBUP / / use and store the address of the three registers static int leds_open (struct inode * inode, struct file * file) {return 0;} static int leds_ioctl (struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg) {/ / check the number of LED, since there are only 4 on the development board, the index starts at 0 if (arg)
< 0 || arg >3) {return-EINVAL;} / / determine which state LED should execute switch (cmd) {case LED_ON: {if (arg = = 0) {* GPBDAT & = 0x1C0;} else if (arg = = 1) {* GPBDAT & = 0x1A0 } else if (arg = = 2) {* GPBDAT & = 0x160;} else if (arg = = 3) {* GPBDAT & = 0x0E0;} break } case LED_OFF: {if (arg = = 0) {* GPBDAT | = 0x020;} else if (arg = = 1) {* GPBDAT | = 0x040;} else if (arg = = 2) {* GPBDAT | = 0x080 } else if (arg = = 3) {* GPBDAT | = 0x100;} break;} default: {return-EINVAL;}} return 0 } static struct file_operations leds_fops = {.owner = THIS_MODULE, .open = leds_open, .ioctl = leds_ioctl,}; void led_device_init (void) {/ / 0x56000010 + 0x10 covers all IO pin register addresses phys = 0x56000010 / / 0x56000010=GPBCON / / apply for a contiguous space of length 0x10 in the virtual address space / / so that the physical address phys to phys+0x10 corresponds to the virtual address virt to virt+0x10 virt = (unsigned long) ioremap (phys, 0x10); GPBCON = (unsigned long *) (virt+ 0x00); / / specify the address of the three registers to be operated GPBDAT = (unsigned long *) (virt+ 0x04) GPBUP = (unsigned long *) (virt + 0x08); / / GPBCON * GPBCON = 0x154FDD; / / GPBDAT * GPBDAT = 0x1E0; / / GPBUP * GPBUP = 0x7FF;} static int _ init led_init (void) {int ret; led_device_init (); / / device registration ret = register_chrdev (LED_MAJOR, DEVICE_NAME, & leds_fops) If (ret < 0) {printk (DEVICE_NAME "register falid!\ n");} else {printk (DEVICE_NAME "initialized!\ n");} return ret;} static void _ exit led_exit (void) {/ / logout device unregister_chrdev (LED_MAJOR, DEVICE_NAME);} module_init (led_init); module_exit (led_exit); MODULE_LICENSE ("GPL"); MODULE_AUTHOR ("Benjamin") MODULE_DESCRIPTION ("Mini2440 led driver"); this is how to control LED without relying on linux kernel programs. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.