X5笔记

来源:互联网 发布:腾讯域名个人备案 编辑:程序博客网 时间:2024/04/28 20:27

X5项目笔记

本文会持续更新,将X5飞控中的一些知识点记录下来。


一、关于启动脚本。

           1、sensor启动。在rcS中调用“ sh /etc/init.d/rc.sensors” 调用并启动脚本rc.sensors。有关传感器的启动在该脚本里。其中就有ms5611.

        2、X5_source\NuttX\NuttX\include\nuttx\config.h 是根据      X5_source\ nuttx-configs\px4fmu-v1\nsh\defconfig  来生成的。

二、关于X5 fmu的编译。

     1、 编译后生成的烧录文件:Firmware\svn505\Build\px4fmu-v1_default.build\firmware.bin

     2、extern "C" { __EXPORT int mpu6000_main(int argc, char *argv[]); }

         之所以将mpu6000_main函数用export到处,应该是在int nsh_consolemain(int argc, char *argv[])线程相关的地方调用,而int nsh_consolemain(int argc, char *argv[])函数所在的文件是C文件。

三、关于uart

       1、目前BootLoader用的uart是uart1,内核里用的是uart2;

             CONFIG_USART2_SERIAL_CONSOLE =y

四、内核的启动

      1、int
CDev::register_class_devname(const char *class_devname)
{
    if (class_devname == nullptr) {
        return -EINVAL;
    }

    int class_instance = 0;
    int ret = -ENOSPC;

    while (class_instance < 4) {
        char name[32];
        snprintf(name, sizeof(name), "%s%d", class_devname, class_instance);
        ret = register_driver(name, &fops, 0666, (void *)this);
        if (ret == OK) break;
        class_instance++;
    }

    if (class_instance == 4) {
        return ret;
    }
    return class_instance;

}


------------------------>

int register_driver(FAR const char *path, FAR const struct file_operations *fops,
                    mode_t mode, FAR void *priv)
{
  FAR struct inode *node;
  int ret;

  /* Insert a dummy node -- we need to hold the inode semaphore because we
   * will have a momentarily bad structure.
   */

  inode_semtake();
  ret = inode_reserve(path, &node);
  if (ret >= 0)
    {
      /* We have it, now populate it with driver specific information. */

      INODE_SET_DRIVER(node);

      node->u.i_ops   = fops;
#ifdef CONFIG_FILE_MODE
      node->i_mode    = mode;
#endif
      node->i_private = priv;
      ret             = OK;
    }

  inode_semgive();
  return ret;
}
---------------------------------------->



int inode_reserve(FAR const char *path, FAR struct inode **inode)
{
  const char       *name = path;
  FAR struct inode *left;
  FAR struct inode *parent;

  /* Assume failure */

  DEBUGASSERT(path && inode);
  *inode = NULL;

  /* Handle paths that are interpreted as the root directory */

  if (!*path || path[0] != '/')
    {
      return -EINVAL;
    }

  /* Find the location to insert the new subtree */

  if (inode_search(&name, &left, &parent, (FAR const char **)NULL) != NULL)
    {
      /* It is an error if the node already exists in the tree */

      return -EEXIST;
    }


  /* Now we now where to insert the subtree */

  for (;;)
    {
      FAR struct inode *node;

      /* Create a new node -- we need to know if this is the
       * the leaf node or some intermediary.  We can find this
       * by looking at the next name.
       */

      FAR const char *next_name = inode_nextname(name);
      if (*next_name)
        {
          /* Insert an operationless node */

          node = inode_alloc(name);
          if (node)
            {
              inode_insert(node, left, parent);

              /* Set up for the next time through the loop */

              name   = next_name;
              left   = NULL;
              parent = node;
              continue;
            }
        }
      else
        {
          node = inode_alloc(name);
          if (node)
            {
              inode_insert(node, left, parent);
              *inode = node;
              return OK;
            }
        }

      /* We get here on failures to allocate node memory */

      return -ENOMEM;
    }
}

同一个设备可能会注册多大4个设备,如果设备/dev/dev0存在了,再注册/dev/dev0,inode_search就会报错,最终register_class_devname会尝试注册/dev/dev1。



五、sd卡

        1、程序调用路径:

configs//px4fmu-v1/src/Makefile——>

-include $(TOPDIR)/Make.defs

configs/px4fmu-v1/nsh/Make.defs   ——>

LDSCRIPT         = ld.script

Ld.script (d:\px4\workspace\x6\svnx6\nuttx-configs\px4fmu-v1\scripts):ENTRY(__start)        /* treat __start as the anchor for dead code stripping */

void __start(void)  ——>

Stm32_start.c (d:\px4\workspace\x6\svnx6\nuttx\nuttx\arch\arm\src\stm32):  os_start();

void os_start(void) ——>

DEBUGVERIFY(os_bringup());         int os_bringup(void) ——>

         taskid = TASK_CREATE("init", SCHED_PRIORITY_DEFAULT,
                       CONFIG_USERMAIN_STACKSIZE,
                       (main_t)CONFIG_USER_ENTRYPOINT,
                       (FAR char * const *)NULL); 

CONFIG_USER_ENTRYPOINT="nsh_main"

#define CONFIG_USER_ENTRYPOINT nsh_main    

int nsh_main(int argc, char *argv[])   ------------------------------>


nsh_initialize();--------------------->

(void)nsh_archinitialize(); ------------------------>

__EXPORT int nsh_archinitialize(void)--------------------->

result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3);








0 0