misc_led.c
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static volatile unsigned long * gpfcon; // = (volatile unsigned long *)0x56000050;
static volatile unsigned long * gpfdat; // = (volatile unsigned long *)0x56000054;
int led_open(struct inode *inode, struct file *file)
ssize_t led_write(struct file *file, const char __user *buf, size_t size, loff_t *offset)
copy_from_user(ker_buf, buf, 2);
if (ker_buf[0] < 0 || ker_buf[0] > 3)
return -einval;
if ((ker_buf[1] != 0) && (ker_buf[1] != 1))
return -einval;
if (ker_buf[1])
else
return 2;
}/* buf[0] - led1,0亮, 1滅 */
/* buf[1] - led2,0亮, 1滅 */
/* buf[2] - led3,0亮, 1滅 */
/* buf[3] - led4,0亮, 1滅 */
ssize_t led_read(struct file *file, char __user *buf, size_t size, loff_t *offset)
static const struct file_operations led_fops = ;
staticstruct miscdeviceled_misc = ;
int led_init(void)
void led_exit(void)
module_init(led_init);
module_exit(led_exit);
module_license("gpl");
test.c
#include
#include
#include
#include
#include
/* led_test
* led_test r
*/void print_usage(char *str)
int main(int argc, char **argv)
fd = open("/dev/led", o_rdwr);
if (fd < 0)
if (argc == 3)
else
ret = write(fd, buf, 2);
if (ret != 2)
}else}}
return 0;
}
混雜裝置驅動
混雜裝置驅動程式是那些簡單的字元驅動程式,它們擁有一些相同的特性。核心將這些共同行抽象至乙個api中 具體實現 見 drivers char misc 這些簡化了驅動程式的初始化的方式。所有的混雜裝置都被分配乙個主裝置號10,但每個裝置可選擇乙個單獨的次裝置號。普通的字元驅動程式完成初始化的順序如下...
LED字元裝置驅動
一 實驗環境 開發機環境 作業系統 ubuntu 10.10 交叉編譯環境 arm linux gcc 4.4.1,安裝位置 usr local arm 4.4.1 6410板子核心原始碼路徑 work linux 2.6.36.2 v1.05 目標板環境 ok6410 a linux2.6.36 ...
字元裝置驅動 Led
驅動檔案 使用linux3.2.81核心 include include include include include include include include include include include static struct class ledsdrv class 類結構體 st...