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”。这些接口基本上都可以通过函数名大致了解其作用。除了函数指针外还有两个比较特殊的指针:输出流。

  • 相关阅读:
    spring学习(一)IOC&AOP
    MongoDB 写入数据的安全性
    MongoDB MapReduce
    MongoDB 原子操作
    MongoDB 文档间的关系
    MongoDB Java
    MongoDB 持久化
    MongoDB 聚合函数 aggregate
    MongoDB 索引
    MongoDB 文档操作
  • 原文地址:https://www.cnblogs.com/eastgeneral/p/10879671.html
Copyright © 2011-2022 走看看