微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机和嵌入式系统linux的区别

单片机和嵌入式系统linux的区别

时间:11-26 来源:互联网 点击:

据结构:

static const struct hc_driver ohci_at91_hc_driver = {
.deion = hcd_name,
.product_desc = "AT91 OHCI",
.hcd_priv_size = sizeof(struct ohci_hcd),


.irq = ohci_irq,
.flags = HCD_USB11 | HCD_MEMORY,


.start = ohci_at91_start,
.stop = ohci_stop,
.shutdown = ohci_shutdown,


.urb_enqueue = ohci_urb_enqueue,
.urb_dequeue = ohci_urb_dequeue,
.endpoint_disable = ohci_endpoint_disable,


.get__number = ohci_get_,


.hub_status_data = ohci_hub_status_data,
.hub_control = ohci_hub_control,
.hub_irq_enable = ohci_rhsc_enable,
#ifdef CONFIG_PM
.bus_suspend = ohci_bus_suspend,
.bus_resume = ohci_bus_resume,
#endif
.start_port_reset = ohci_start_port_reset,
};

基于通用性,即使是你自己写的Linux驱动,简单到只是点亮一个LED,基于“通用性”,这个驱动也要向上提供统一的接口。下面是单片机LED驱动程序和Linux下的LED驱动程序的部分代码。

单片机LED驱动程序:

void led_init(void)
{
GPBCON = GPB5_out; // 将LED对应的GPB5引脚设为输出
}

void led_on(void)
{
GPBDAT &= ~(1<5);
}

void led_off(void)
{
GPBDAT |= (1<5);
}

Linux的LED驱动程序:
#define DEVICE_NAME "leds"
#define LED_MAJOR 231

#define IOCTL_LED_ON 0
#define IOCTL_LED_OFF 1

static unsigned long led_table [] = {
S3C2410_GPB5,
S3C2410_GPB6,
S3C2410_GPB7,
S3C2410_GPB8,
};

static unsigned int led_cfg_table [] = {
S3C2410_GPB5_OUTP,
S3C2410_GPB6_OUTP,
S3C2410_GPB7_OUTP,
S3C2410_GPB8_OUTP,
};

static int s3c24xx_leds_open(struct inode *inode, struct file *file)
{
int i;

for (i = 0; i < 4; i++) {
// 设置GPIO引脚的功能:本驱动中LED所涉及的GPIO引脚设为输出功能
s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]);
}
return 0;
}

static int s3c24xx_leds_ioctl(
struct inode *inode,
struct file *file,
unsigned int cmd,
unsigned long arg)
{
if (arg > 4) {
return -EINVAL;
}

switch(cmd) {
case IOCTL_LED_ON:
// 设置指定引脚的输出电平为0
s3c2410_gpio_setpin(led_table[arg], 0);
return 0;

case IOCTL_LED_OFF:
// 设置指定引脚的输出电平为1
s3c2410_gpio_setpin(led_table[arg], 1);
return 0;

default:
return -EINVAL;
}
}

static struct file_operations s3c24xx_leds_fops = {
.owner = THIS_MODULE,
.open = s3c24xx_leds_open,
.ioctl = s3c24xx_leds_ioctl,
};

static int __init s3c24xx_leds_init(void)
{
int ret;


ret = register_chrdev(LED_MAJOR, DEVICE_NAME, &s3c24xx_leds_fops);
if (ret < 0) {
printk(DEVICE_NAME " cant register major number");
return ret;
}

printk(DEVICE_NAME " initialized");
return 0;
}

static void __exit s3c24xx_leds_exit(void)
{

unregister_chrdev(LED_MAJOR, DEVICE_NAME);
}

module_init(s3c24xx_leds_init);
module_exit(s3c24xx_leds_exit);

2.2. 应用程序开发的区别

2.2.1 对于不带操作系统的应用编程,应用程序和驱动程序之间的间隔并不明显。

举个例子,要在LCD上显示字母“a”,在单片机上的做法是:
① 事先在Flash上保存“a”的点阵数据,假设它的象素大小是8x8,那么这个点阵大小就是8x8=64 bits,即8字节
② 应用程序读取这64bit数据,逐个象素地在LCD上描点

相对的,基于操作系统的应用编程,就不需要懂得硬件知识,执行一个简单的“echo a > /dev/tty1”就可以在LCD上显示“a”了。

2.2.2 不带操作系统的应用程序,可借用的软件资源很少;

带操作系统的应用程序,网上各种开源的软件很多。

比如要做一个播放器,在不带操作系统上实现会非常困难;如果是在Linux下,有现成的。

2.2.3 不带操作系统的应用程序,各个任务是串行执行的;

带操作系统的应用程序,各个任务是并行执行的。

2.2.4 不带操作系统的应用程序,一旦发生程序错误,整个系统将崩溃

带操作系统的应用程序,即使发生了程序错误,操作系统本身并不会崩溃

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top