zoukankan      html  css  js  c++  java
  • PX4 FMU启动流程 2. 一、 nsh_newconsole

    PX4 FMU启动流程 2. 一、 nsh_newconsole

    PX4 FMU启动流程 2. 一、 nsh_newconsole


                                                                                 -------- 转载请注明出处

                                                                                 -------- 2014-11-27.冷月追风

                                                                                 -------- email:merafour@163.com 


        这是一个 new函数。用来创建 stdio接口。

    FAR struct console_stdio_s *nsh_newconsole(void)
    {
      struct console_stdio_s *pstate = (struct console_stdio_s *)zalloc(sizeof(struct console_stdio_s));
      if (pstate)
        {
          /* Initialize the call table */

    #ifndef CONFIG_NSH_DISABLEBG
          pstate->cn_vtbl.clone      = nsh_consoleclone;
          pstate->cn_vtbl.release    = nsh_consolerelease;
    #endif
          pstate->cn_vtbl.write      = nsh_consolewrite;
          pstate->cn_vtbl.output     = nsh_consoleoutput;
          pstate->cn_vtbl.linebuffer = nsh_consolelinebuffer;
          pstate->cn_vtbl.redirect   = nsh_consoleredirect;
          pstate->cn_vtbl.undirect   = nsh_consoleundirect;
          pstate->cn_vtbl.exit       = nsh_consoleexit;

          /* (Re-) open the console input device */

    #ifdef CONFIG_NSH_CONDEV
          pstate->cn_confd           = open(CONFIG_NSH_CONDEV, O_RDWR);
          if (pstate->cn_confd < 0)
            {
              free(pstate);
              return NULL;
            }

          /* Create a standard C stream on the console device */

          pstate->cn_constream = fdopen(pstate->cn_confd, "r+");
          if (!pstate->cn_constream)
            {
              close(pstate->cn_confd);
              free(pstate);
              return NULL;
            }
    #endif

          /* Initialize the output stream */

          pstate->cn_outfd           = OUTFD(pstate);
          pstate->cn_outstream       = OUTSTREAM(pstate);
        }
      return pstate;
    }


    其实也就是填充了结构 “struct console_stdio_s”。这些接口基本上都可以通过函数名大致了解其作用。除了函数指针外还有两个比较特殊的指针:输出流。

  • 相关阅读:
    android模拟器加速
    QtEmbedded鼠标驱动流程分析(上)
    QML Tutorial 1 Basic Types
    android 版本
    【转】右键菜单大揭密
    【转】设置右键显示/隐藏系统文件
    【转】自己做的登录界面五款正常尺寸+一款宽屏【手把手教You如何制作登录界面】
    【转】如何添加鼠标右键菜单里的快捷图标
    【转】鼠标右键菜单设置大全
    【技术贴】我的文档不见了,我的文档消失了,我的电脑没有我的文档的解决办法。
  • 原文地址:https://www.cnblogs.com/eastgeneral/p/10879671.html
Copyright © 2011-2022 走看看