手机版
你好,游客 登录 注册
背景:
阅读新闻

再谈U-Boot的设备管理框架

[日期:2012-03-19] 来源:Linux社区  作者:ce123 [字体:大 中 小]

二、串口设备实例简析

drv_system_init 函数初始化串口设备,请看下面的源码:
  1. static void drv_system_init (void)  
  2. {  
  3.     device_t dev;//定义一个结构体  
  4.   
  5.     memset (&dev, 0, sizeof (dev));//为刚刚定义的结构体分配内存  
  6.   
  7.     strcpy (dev.name, "serial");//名称  
  8.     dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;   
  9.   
  10. #ifdef CONFIG_SERIAL_SOFTWARE_FIFO  
  11.     dev.putc = serial_buffered_putc;  
  12.     dev.puts = serial_buffered_puts;  
  13.     dev.getc = serial_buffered_getc;  
  14.     dev.tstc = serial_buffered_tstc;  
  15. #else  
  16.     dev.putc = serial_putc;//使用的是部分代码,下面这四个函数都是和具体平台的UART控制器相关的代码,下面我们会具体分析一个函数  
  17.     dev.puts = serial_puts;  
  18.     dev.getc = serial_getc;  
  19.     dev.tstc = serial_tstc;  
  20. #endif  
  21.   
  22.     device_register (&dev);//注册函数  
  23.   
  24. #ifdef CFG_DEVICE_NULLDEV  
  25.     memset (&dev, 0, sizeof (dev));  
  26.   
  27.     strcpy (dev.name, "nulldev");  
  28.     dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;  
  29.     dev.putc = nulldev_putc;  
  30.     dev.puts = nulldev_puts;  
  31.     dev.getc = nulldev_input;  
  32.     dev.tstc = nulldev_input;  
  33.   
  34.     device_register (&dev);  
  35. #endif  
  36. }  
下面我们分析serial_getc函数,其他的函数是类似的。该函数定义在cpu/arm920t/s3c24x0/serial.c文件,从这个路径我们就可以看出这是一个和处理器/平台相关的函数
  1. /*  
  2.  * Read a single byte from the serial port. Returns 1 on success, 0  
  3.  * otherwise. When the function is succesfull, the character read is  
  4.  * written into its argument c.  
  5.  */  
  6. int serial_getc (void)//接收字符  
  7. {  
  8.     S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR);//获得UART的寄存器结构体  
  9.   
  10.     /* wait for character to arrive */  
  11.     while (!(uart->UTRSTAT & 0x1));//判断状态寄存器的第0位是否为1  
  12.   
  13.     return uart->URXH & 0xff;  
  14. }  

三、小结

U-Boot的设备管理框架比较的简单,但我们可以从中学习到一些框架和分层的思想。
linux
相关资讯       U-boot 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款