驅動:
#include
#include
#include
#include
#include
#include
#include
static int led_major = -1;
static struct class * led_mark_class = null;
static struct device * led_mark_device = null;
static struct resource * res_mark = null;
#define gpj0con (0xe0200240)
#define gpj0dat (0xe0200244)
typedef struct p_data_mark
p_data_mark;
unsigned int * p_data_test = null;
unsigned int * p_data_data = null;
static p_data_mark * p_data_mark = null;
static char buf[4] = ;
static int led_mark_open (struct inode * inode, struct file * file)
static int led_mark_close (struct inode * inode, struct file * file)
static ssize_t led_mark_write(struct file * file, const char __user * in,
size_t size, loff_t * off)
// printk(kern_err 「buf = %s\n」, buf);
if (『0』 == buf[0])
else
return 0;
}static struct file_operations led_operations_mark =
;static int __init s5pv210_led_init(void)
led_mark_class = class_create(this_module, 「led_mark」);
if (!led_mark_class)
led_mark_device = device_create(led_mark_class,
null, mkdev(led_major, 0), null, 「led-mark」);
if (!led_mark_device)
err_ioremap:res_mark = request_mem_region(gpj0con, sizeof(p_data_mark), "p_data");
if (!res_mark)
p_data_mark = ioremap(gpj0con, sizeof(p_data_mark));
if (!p_data_mark)
printk(kern_err "%p \n", p_data_mark);
p_data_mark->con |= ((1<<12) | (1<<16) | (1<<20));
p_data_mark->dat &= ~((1<<3) | (1<<4) | (1<<5));
return 0;
release_mem_region(gpj0con, sizeof(p_data_mark));
err_request_mem_region:
device_destroy(led_mark_class, mkdev(led_major, 0));
err_device_create:
class_destroy(led_mark_class);
err_class_create:
unregister_chrdev(led_major, 「led_driver」);
err_register_chrdev:
return -1;
}static void __exit s5pv210_led_exit(void)
module_init(s5pv210_led_init);
module_exit(s5pv210_led_exit);
// module_***這種巨集作用是用來新增模組描述資訊
module_license(「gpl」); // 描述模組的許可證
module_author(「mark 867439374@qq.com」); // 描述模組的作者
module_description(「s5pv210 led driver」); // 描述模組的介紹資訊
module_alias(「s5pv210_led」); // 描述模組的別名資訊
應用程式:
#include
#include
#include
#include
#include
#define pathname 「/dev/led-mark」
int main(void)
write(fd, 「1」, 1);
sleep(1);
write(fd, 「0」, 1);
sleep(1);
write(fd, 「1」, 1);
sleep(1);
write(fd, 「0」, 1);
sleep(1);
close(fd);
return 0;
}
驅動篇 乙個簡單的led驅動
1.構造裝置結構體 struct light dev cdev結構體 struct cdev 2.設定裝置資訊 struct light dev light devp 設定裝置結構體變數 int light major light major 設定主裝置號3.設定並填充file operations...
基於arm的乙個簡單的led驅動
在學寫驅動的時候一定不要盲目的跟從,要有自己的方法。要記住一點,學習驅動要學習驅動的模板,每個驅動程式其結構基本上都是一樣的。只要大家掌握了驅動的結構以後在寫驅動的時候就相對來說要簡單一些。只要大家學會寫驅動過後後頭來看其實驅動都是大同小異的。在這裡我給大家介紹乙個簡單的led驅動的寫法,defin...
乙個LED驅動的編寫
include include include include include include include include include include include define gpm4con 0x110002e0 volatile unsigned long baseaddr 0 位址...