导航菜单
首页 >  嵌入式期末考试程序设计  > 嵌入式期末复习

嵌入式期末复习

6、设计一个程序,在用户空间的用户应用程序中输入一个10以内的整数n,通过内核空间的设备驱动程序计算从1加到n的和。 解答: (1)内核空间的驱动程序代码,将程序保存为sum_drv.c /***************************** * 驱动程序sum_drv.c ****************************/

#include #include #include #include //模块驱动程序的头文件

#define sum_drv_MAJOR 114 //设备号 创建设备入口点时要与此值一致 #define DEVICE_NAME “sum_drv_module”

void showversion(void) { printk(“kernel: ***********************************\n”); printk(“kernel: \t %s \t\n”, DEVICE_NAME); printk(“kernel: ************************************\n\n”); }

// --------设备对应的打开函数---------------- static int sum_open(struct inode *inode, struct file *file){ printk(“kernel: hello open.\n”); return 0; }

// ---------设备对应的写操作函数------------- static int sum_write(struct file *file, const char __user * buf, size_t count, loff_t *ppos){ printk(“kernel: hello write. n=%d \n”, count); int i=1; int s=0; for(i=1;i

相关推荐: