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

U-Boot串口初始化详解

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

六、打印信息

在最后会打印出如下信息:

In:    serial
Out:   serial
Err:   serial

这说明串口初始化完成。

七、为什么要使用devlist,std_device[]?

为了更灵活地实现标准IO重定向,任何可以作为标准IO的设备,如USB键盘,LCD屏,串口等都可以对应一个device_t的结构体变量,只需要实现getc和putc等函数,就能加入到devlist列表中去,也就可以被assign为标准IO设备stdo_device中去。如函数 int console_assign (int file, char *devname); /* Assign the console 重定向标准输入输出*/这个函数功能就是把名为devname的设备重定向为标准IO文件file(stdin,stdout,stderr)。其执行过程是在devlist中查找devname的设备,返回这个设备的device_t指针,并把指针值赋给stdo_device[file]。
  1. int console_assign (int file, char *devname)  
  2. {  
  3.     int flag, i;  
  4.   
  5.     /* Check for valid file */  
  6.     switch (file) {  
  7.     case stdin:  
  8.         flag = DEV_FLAGS_INPUT;  
  9.         break;  
  10.     case stdout:  
  11.     case stderr:  
  12.         flag = DEV_FLAGS_OUTPUT;  
  13.         break;  
  14.     default:  
  15.         return -1;  
  16.     }  
  17.   
  18.     /* Check for valid device name */  
  19.   
  20.     for (i = 1; i <= ListNumItems (devlist); i++) {  
  21.         device_t *dev = ListGetPtrToItem (devlist, i);  
  22.   
  23.         if (strcmp (devname, dev->name) == 0) {  
  24.             if (dev->flags & flag)  
  25.                 return console_setfile (file, dev);  
  26.   
  27.             return -1;  
  28.         }  
  29.     }  
  30.   
  31.     return -1;  
  32. }  
该函数是调用console_setfile设置stdo_device[]完成重定向输入输出。
  1. static int console_setfile (int file, device_t * dev)  
  2. {  
  3.     int error = 0;  
  4.   
  5.     if (dev == NULL)  
  6.         return -1;  
  7.   
  8.     switch (file) {  
  9.     case stdin:  
  10.     case stdout:  
  11.     case stderr:  
  12.         /* Start new device */  
  13.         if (dev->start) {  
  14.             error = dev->start ();  
  15.             /* If it's not started dont use it */  
  16.             if (error < 0)  
  17.                 break;  
  18.         }  
  19.   
  20.         /* Assign the new device (leaving the existing one started) */  
  21.         stdio_devices[file] = dev;//这里是关键  
  22.   
  23.         /*  
  24.          * Update monitor functions  
  25.          * (to use the console stuff by other applications)  
  26.          */  
  27.         switch (file) {  
  28.         case stdin:  
  29.             gd->jt[XF_getc] = dev->getc;  
  30.             gd->jt[XF_tstc] = dev->tstc;  
  31.             break;  
  32.         case stdout:  
  33.             gd->jt[XF_putc] = dev->putc;  
  34.             gd->jt[XF_puts] = dev->puts;  
  35.             gd->jt[XF_printf] = printf;  
  36.             break;  
  37.         }  
  38.         break;  
  39.   
  40.     default:        /* Invalid file ID */  
  41.         error = -1;  
  42.     }  
  43.     return error;  
  44. }  
linux
相关资讯       U-boot 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

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