嵌入式实训-LED显示+文件系统定制实验报告

嵌入式实训-LED显示+文件系统定制实验报告

2023年7月14日发(作者:)

word格式-可编辑-感谢下载支持

LED显示控制+文件系统定制

系 名:

专 业:

指导教师:

姓 名:

学 号:

班 级:

组 员:

科 目:

二○一 年 月

word格式-可编辑-感谢下载支持

目 录

一、设计任务和技术要求: .................................................................................................................... .

二、器件介绍……………………………………………………………………………………………

三、设计代码:………………………………………………………………………………………….

四、设计结果: ..................................................................................................................................... ..

五、系统评价: ...................................................................................................................................... .

六、心得体会: ...................................................................................................................................... .

一、设计任务和技术要求:

➢ 编写LED驱动程序,驱动程序采用手动定义设备名称(自己姓名拼音word格式-可编辑-感谢下载支持

_led)和主设备号,设备号必须是系统尚未使用的设备号

➢ 编写对应驱动的makefile文件

➢ 将驱动程序编译成模块,并实现模块的加载及卸载

➢ 编写驱动测试程序,要求运行该测试程序后,能够对led设备打开成功与否做出判断;能够显示led控制菜单选项(至少2个控制选项),例如,选择“1”,led等循环点亮;选择“2”,指定led1灯点亮

➢ 编写对应测试程序的makefile 文件

文件系统定制

要求:

➢ 制作文件系统类型为yaffs的文件系统;

➢ 文件系统启动时显示小组成员信息;

➢ 文件系统启动时需要按提示输入用户名信息;

➢ 文件系统成功挂载后,通过串口传送刚刚编写的led控制程序,并运行该led控制程序,要求能够按照规定的控制方式实现led灯的控制

二、设计代码

程序清单:

应用程序测试leds_test.c如下:

#include

#include word格式-可编辑-感谢下载支持

#include

#include

#define IOCTL_LED_ON 1

#define IOCTL_LED_OFF 5

#define IOCTL_LED_RUN 3

void usage(char *exename)

{

printf("Usage:n");

printf(" %s n", exename);

printf(" led_no = 1, 2, 3 or 4n");

}

int main(int argc, char **argv)

{

unsigned int led_no;

int fd = -1;

unsigned int count=10;

if (argc > 3 || argc == 1)

goto err;

fd = open("/dev/cylled", 0); // 打开设备

if (fd < 0) {

printf("Can't open /dev/fdwled,n");

return -1;

}

if (argc == 2) {

if (!strcmp(argv[1], "run"))

{

ioctl(fd, IOCTL_LED_RUN, count); //运行跑马灯

} else {

goto err;

}

}

if (argc == 3) {

led_no = strtoul(argv[1], NULL, 0) - 1; // 操作哪个LED?

if (led_no > 3)

goto err;

if (!strcmp(argv[2], "on")) {

ioctl(fd, IOCTL_LED_ON, led_no); // 点亮

} else if (!strcmp(argv[2], "off")) {

ioctl(fd, IOCTL_LED_OFF, led_no); // 熄灭

} else { word格式-可编辑-感谢下载支持

goto err;

}

}

close(fd);

return 0;

err:

按键驱动:

/*

* linux/drivers/char/mini210_buttons.c

*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License version 2 as

* published by the Free Software Foundation.

*/

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include word格式-可编辑-感谢下载支持

#include

#include

#include

#define DEVICE_NAME "buttons"

struct button_desc {

int gpio;

int number;

char *name;

struct timer_list timer;

};

static struct button_desc buttons[] = {

{ S5PV210_GPH2(0), 0, "KEY0" },

{ S5PV210_GPH2(1), 1, "KEY1" },

{ S5PV210_GPH2(2), 2, "KEY2" },

{ S5PV210_GPH2(3), 3, "KEY3" },

{ S5PV210_GPH3(0), 4, "KEY4" },

{ S5PV210_GPH3(1), 5, "KEY5" },

{ S5PV210_GPH3(2), 6, "KEY6" },

{ S5PV210_GPH3(3), 7, "KEY7" },

};

static volatile char key_values[] = {

'0', '0', '0', '0', '0', '0', '0', '0'

};

static DECLARE_WAIT_QUEUE_HEAD(button_waitq);

static volatile int ev_press = 0;

static void mini210_buttons_timer(unsigned long _data)

{

struct button_desc *bdata = (struct button_desc *)_data;

int down;

int number; word格式-可编辑-感谢下载支持

unsigned tmp;

tmp = gpio_get_value(bdata->gpio);

/* active low */

down = !tmp;

printk("KEY %d: %08xn", bdata->number, down);

number = bdata->number;

if (down != (key_values[number] & 1)) {

key_values[number] = '0' + down;

ev_press = 1;

wake_up_interruptible(&button_waitq);

}

}

static irqreturn_t button_interrupt(int irq, void *dev_id)

{

struct button_desc *bdata = (struct button_desc *)dev_id;

mod_timer(&bdata->timer, jiffies + msecs_to_jiffies(40));

return IRQ_HANDLED;

}

static int mini210_buttons_open(struct inode *inode, struct file *file)

{

int irq;

int i;

int err = 0;

for (i = 0; i < ARRAY_SIZE(buttons); i++) {

if (!buttons[i].gpio)

continue;

setup_timer(&buttons[i].timer, mini210_buttons_timer, word格式-可编辑-感谢下载支持

(unsigned long)&buttons[i]);

irq = gpio_to_irq(buttons[i].gpio);

err = request_irq(irq, button_interrupt, IRQ_TYPE_EDGE_BOTH,

buttons[i].name, (void *)&buttons[i]);

if (err)

break;

}

if (err) {

i--;

for (; i >= 0; i--) {

if (!buttons[i].gpio)

continue;

irq = gpio_to_irq(buttons[i].gpio);

disable_irq(irq);

free_irq(irq, (void *)&buttons[i]);

del_timer_sync(&buttons[i].timer);

}

return -EBUSY;

}

ev_press = 1;

return 0;

}

static int mini210_buttons_close(struct inode *inode, struct file *file)

{

int irq, i;

for (i = 0; i < ARRAY_SIZE(buttons); i++) {

if (!buttons[i].gpio)

continue;

word格式-可编辑-感谢下载支持

irq = gpio_to_irq(buttons[i].gpio);

free_irq(irq, (void *)&buttons[i]);

del_timer_sync(&buttons[i].timer);

}

return 0;

}

static int mini210_buttons_read(struct file *filp, char __user *buff,

size_t count, loff_t *offp)

{

unsigned long err;

if (!ev_press) {

if (filp->f_flags & O_NONBLOCK)

return -EAGAIN;

else

wait_event_interruptible(button_waitq, ev_press);

}

ev_press = 0;

err = copy_to_user((void *)buff, (const void *)(&key_values),

min(sizeof(key_values), count));

return err ? -EFAULT : min(sizeof(key_values), count);

}

static unsigned int mini210_buttons_poll( struct file *file,

struct poll_table_struct *wait)

{

unsigned int mask = 0;

poll_wait(file, &button_waitq, wait);

if (ev_press)

mask |= POLLIN | POLLRDNORM; word格式-可编辑-感谢下载支持

return mask;

}

static struct file_operations dev_fops = {

.owner = THIS_MODULE,

.open = mini210_buttons_open,

.release = mini210_buttons_close,

.read = mini210_buttons_read,

.poll = mini210_buttons_poll,

};

static struct miscdevice misc = {

.minor = MISC_DYNAMIC_MINOR,

.name = DEVICE_NAME,

.fops = &dev_fops,

};

static int __init button_dev_init(void)

{

int ret;

ret = misc_register(&misc);

printk(DEVICE_NAME"tinitializedn");

return ret;

}

static void __exit button_dev_exit(void)

{

misc_deregister(&misc);

}

module_init(button_dev_init);

module_exit(button_dev_exit);

word格式-可编辑-感谢下载支持

MODULE_LICENSE("GPL");

MODULE_AUTHOR("FriendlyARM Inc.");

word格式-可编辑-感谢下载支持

程序cylled.c如下(基于实验11的代码进行更改):

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define DEVICE_NAME "cylled"

#define LED_MAJOR 222 word格式-可编辑-感谢下载支持

#define IOCTL_LED_ON 1

#define IOCTL_LED_OFF 5

#define IOCTL_LED_RUN 3 %定义三个宏

#define LED_NUM ARRAY_SIZE(led_gpios)

static int led_gpios[]={

S5PV210_GPJ2(0),

S5PV210_GPJ2(1),

S5PV210_GPJ2(2),

S5PV210_GPJ2(3),

};

static long mini210_leds_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)

{

int i;

int j; word格式-可编辑-感谢下载支持

switch(cmd)

{

case IOCTL_LED_RUN: %定义RUN,用了两个for循环。

for(i=0;i

{

for(j=0;j<4;j++)

{

gpio_set_value(led_gpios[j],0);

msleep(100);

gpio_set_value(led_gpios[j],1);

}

}

break;

case IOCTL_LED_ON:

if(arg>LED_NUM)

{

return -EINVAL; word格式-可编辑-感谢下载支持

}

gpio_set_value(led_gpios[arg],0);

break;

case IOCTL_LED_OFF:

if(arg>LED_NUM)

{

return -EINVAL;

}

gpio_set_value(led_gpios[arg],1);

break;

default:

return -EINVAL;

}

return 0;

}

static struct file_operations mini210_led_dev_fops={

.owner =THIS_MODULE, word格式-可编辑-感谢下载支持

.unlocked_ioctl =mini210_leds_ioctl,

};

static int __init mini210_led_dev_init(void)

{

int ret;

int i;

for(i=0;i

{

ret=gpio_request(led_gpios[i],"LED");

if(ret)

{

printk("%s: request GPIO %d for LED failed,

ret=%dn",DEVICE_NAME ,led_gpios[i],ret);

return ret;

}

s3c_gpio_cfgpin(led_gpios[i],S3C_GPIO_OUTPUT); word格式-可编辑-感谢下载支持

gpio_set_value(led_gpios[i],1);

}

ret=register_chrdev(LED_MAJOR,DEVICE_NAME,&mini210_led_dev_fops);

if(ret<0)

{

printk("%s can't register major numbern",DEVICE_NAME);

return ret;

}

return 0;

}

static void __exit mini210_led_dev_exit(void)

{

int i;

for(i=0;i

{

gpio_free(led_gpios[i]);

}

unregister_chrdev(LED_MAJOR,DEVICE_NAME); word格式-可编辑-感谢下载支持

}

module_init(mini210_led_dev_init);

module_exit(mini210_led_dev_exit);

MODULE_LICENSE("GPL");

MODULE_AUTHOR("cyl");

五.设计结果:

Makefile word格式-可编辑-感谢下载支持

Serial COM1 命令代码 word格式-可编辑-感谢下载支持

第一盏灯亮

第二盏灯亮

word格式-可编辑-感谢下载支持

第三盏灯亮

显示小组成员信息(文件系统)

用户名122014021登陆 word格式-可编辑-感谢下载支持

加载驱动

创建设备名

卸载驱动

运行跑马灯命令

点灯关灯

6.心得体会:

在了解了基础知识之后,我开始进行上机操作,当然,其中遇到很多的难题,很多东西都是第一次接触,又没有别人在旁边指导操作,完全凭借自己去摸索练习。其 中的困难可想而知。然而坚持就是胜利,牙一咬眼一闭坚持做下去,而通过本次实验,我感觉收获还是蛮多的。可能我对于嵌入式的知识学习的还是不太多,但是这 之外的东西收获颇丰。它让我学会了如何通过自己的努力去认知一个新事物,更重要的是端正自己的学习态度,只有真正下功夫去学习,才能有收获,正所谓“一份 耕耘,一份收获。”没有付出,何谈回报呢?再者,通过本次实验,我也学会了如何去分析问题,如何找出自己设计中的不足,继而去排除解决问题,这就是一个自 我学习的过程。当我们通过实验去学习理论知识时,自己动手得出的结论,不仅能加深我们对嵌入式的理解,更能加深我们对此的记忆。学习到一个实验的完成过程。更深刻地了解arm的工作原理及其应用,对比出之前单片机系统应用的不同。

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1689331505a231090.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信