当前位置:网站首页>Px4 module design Xi: built in framework
Px4 module design Xi: built in framework
2022-07-22 15:56:00 【lida2003】
PX4 Module design 11 :Built-In frame
Previously, I introduced PX4 Module design ten :PX4 The boot process , In application , The most important stage is the initialization of flight control application , The process is through nsh The startup script realizes . Maybe for linux bash Familiar students will immediately say “ This is the process starting in sequence ”. Of course, this statement is good , Now the question is Nuttx There is no concept of process .
notes : Of course. px4 You really see a lot of binary in the simulation program bin file , That's because of Linux On system simulation . Then you can think that maybe he starts the task through function call , If you use this method, you must know the function entry of these applications .
I searched the Internet for information , In fact, there is not much introduction about this piece , Maybe it's too simple , Maybe the perspective of application doesn't need attention . But from the perspective of understanding and logic, we should know how the whole application starts , This is part of the framework design .
Next, let's take a look at how this startup depends on scripts .
1. Nuttx Built-In frame
NuttX It's a real-time operating system , The main emphasis is POSIX and ANSI Standard compatibility , At the same time, it takes up less resources . Suitable for 8 Bit or higher MCU Environmental Science . But the system is similar to Linux Asynchronously distinguish between inner core state and user state , The whole system is in one address space .
Let's start with Nuttx NSH Build-In Framework, This is the basis for our understanding , Although part of the content is different from the actual code , But you can see the general idea .
adopt builtin_list.c Code , It can be seen that there is builtin_list Has been added to g_builtins Array .
41 #include "builtin_proto.h"
42
43 const struct builtin_s g_builtins[] =
44 {
45 # include "builtin_list.h"
46 { NULL, 0, 0, 0 }
47 };
48
49 const int g_builtin_count = sizeof(g_builtins) / sizeof(g_builtins[0]);
Come here , We can clearly understand Nuttx The following is how to quote and NSH associative . Next, we should focus on the current PX4 How the code will PX4 Application and NSH associative .
2. PX4 Built-In frame
PX4 Built-In The framework involves two parts :
- Nuttx Built-In application
- PX4 Built-In application
notes : Use here holybro_kakutef7 As an example .
2.1 NSH Built-In Associated files
Two associated files ( Function definition and symbol table array ), Most of them are PX4 Application :
notes :NSH The application is sercon_main、serdis_main、nsh_main、sh_main.
platforms\nuttx\NuttX\apps\builtin\builtin_proto.h
int sercon_main(int argc, char *argv[]);
int atxxxx_main(int argc, char *argv[]);
int bmp280_main(int argc, char *argv[]);
int board_adc_main(int argc, char *argv[]);
int dshot_main(int argc, char *argv[]);
int frsky_telemetry_main(int argc, char *argv[]);
int icm20689_main(int argc, char *argv[]);
int mpu6000_main(int argc, char *argv[]);
int pwm_out_main(int argc, char *argv[]);
int rc_input_main(int argc, char *argv[]);
int manual_control_main(int argc, char *argv[]);
int attitude_estimator_q_main(int argc, char *argv[]);
int battery_status_main(int argc, char *argv[]);
int commander_main(int argc, char *argv[]);
int control_allocator_main(int argc, char *argv[]);
int dataman_main(int argc, char *argv[]);
int flight_mode_manager_main(int argc, char *argv[]);
int land_detector_main(int argc, char *argv[]);
int logger_main(int argc, char *argv[]);
int mavlink_main(int argc, char *argv[]);
int mc_att_control_main(int argc, char *argv[]);
int mc_pos_control_main(int argc, char *argv[]);
int mc_rate_control_main(int argc, char *argv[]);
int navigator_main(int argc, char *argv[]);
int rc_update_main(int argc, char *argv[]);
int sensors_main(int argc, char *argv[]);
int mixer_main(int argc, char *argv[]);
int param_main(int argc, char *argv[]);
int pwm_main(int argc, char *argv[]);
int nsh_main(int argc, char *argv[]);
int sh_main(int argc, char *argv[]);
int serdis_main(int argc, char *argv[]);
platforms\nuttx\NuttX\apps\builtin\builtin_list.h
{ "sh", 100, 2048, sh_main },
{ "sercon", SCHED_PRIORITY_DEFAULT, 2048, sercon_main },
{ "atxxxx", SCHED_PRIORITY_DEFAULT, 2048, atxxxx_main },
{ "bmp280", SCHED_PRIORITY_DEFAULT, 2048, bmp280_main },
{ "board_adc", SCHED_PRIORITY_DEFAULT, 2048, board_adc_main },
{ "dshot", SCHED_PRIORITY_DEFAULT, 2048, dshot_main },
{ "frsky_telemetry", SCHED_PRIORITY_DEFAULT, 2048, frsky_telemetry_main },
{ "icm20689", SCHED_PRIORITY_DEFAULT, 2048, icm20689_main },
{ "mpu6000", SCHED_PRIORITY_DEFAULT, 2048, mpu6000_main },
{ "pwm_out", SCHED_PRIORITY_DEFAULT, 2048, pwm_out_main },
{ "rc_input", SCHED_PRIORITY_DEFAULT, 2048, rc_input_main },
{ "manual_control", SCHED_PRIORITY_DEFAULT, 2048, manual_control_main },
{ "attitude_estimator_q", SCHED_PRIORITY_DEFAULT, 2048, attitude_estimator_q_main },
{ "battery_status", SCHED_PRIORITY_DEFAULT, 2048, battery_status_main },
{ "commander", SCHED_PRIORITY_DEFAULT, 2048, commander_main },
{ "control_allocator", SCHED_PRIORITY_DEFAULT, 3000, control_allocator_main },
{ "dataman", SCHED_PRIORITY_DEFAULT, 2048, dataman_main },
{ "flight_mode_manager", SCHED_PRIORITY_DEFAULT, 2048, flight_mode_manager_main },
{ "land_detector", SCHED_PRIORITY_DEFAULT, 2048, land_detector_main },
{ "logger", SCHED_PRIORITY_MAX-30, 2048, logger_main },
{ "mavlink", SCHED_PRIORITY_DEFAULT, 2048, mavlink_main },
{ "mc_att_control", SCHED_PRIORITY_DEFAULT, 2048, mc_att_control_main },
{ "mc_pos_control", SCHED_PRIORITY_DEFAULT, 2048, mc_pos_control_main },
{ "mc_rate_control", SCHED_PRIORITY_DEFAULT, 2048, mc_rate_control_main },
{ "navigator", SCHED_PRIORITY_DEFAULT, 2048, navigator_main },
{ "rc_update", SCHED_PRIORITY_DEFAULT, 2048, rc_update_main },
{ "sensors", SCHED_PRIORITY_DEFAULT, 2048, sensors_main },
{ "mixer", SCHED_PRIORITY_DEFAULT, 4096, mixer_main },
{ "param", SCHED_PRIORITY_DEFAULT, 2048, param_main },
{ "pwm", SCHED_PRIORITY_DEFAULT, 2048, pwm_main },
{ "nsh", 100, 2048, nsh_main },
{ "serdis", SCHED_PRIORITY_DEFAULT, 2048, serdis_main },
2.2 NSH Built-In Associated file generation
The associated file is through Makefile The script passes the .pdat/.bdat Generated by merging the contents in the file .
27 # Registry entry lists
28
29 PDATLIST = $(strip $(call RWILDCARD, registry, *.pdat))
30 BDATLIST = $(strip $(call RWILDCARD, registry, *.bdat))
31
32 builtin_list.c: builtin_list.h builtin_proto.h
33
34 registry$(DELIM).updated:
35 $(Q) touch registry$(DELIM).updated
36
37 builtin_list.h: registry$(DELIM).updated
38 ifeq ($(BDATLIST),)
39 $(call DELFILE, builtin_list.h)
40 $(Q) touch builtin_list.h
41 else
42 $(call CATFILE, builtin_list.h, $(BDATLIST))
43 endif
44
45 builtin_proto.h: registry$(DELIM).updated
46 ifeq ($(PDATLIST),)
47 $(call DELFILE, builtin_proto.h)
48 $(Q) touch builtin_proto.h
49 else
50 $(call CATFILE, builtin_proto.h, $(PDATLIST))
51 endif
2.3 NSH Built-In Registration file generation
Through analysis , You can see that the main sources of each file are as follows :
- platforms\nuttx\NuttX\CMakeLists.txt ==》 px4 px4_kernel
- platforms\nuttx\NuttX\apps\system\nsh ==》 nsh sh
- platforms\nuttx\NuttX\apps\system\cdcacm ==》sercon serdis
notes :px4.bdat/.pdat yes px4 Application , The others are Nuttx Application .
./platforms/nuttx/NuttX/apps/builtin/registry/
├── px4.bdat
├── px4.pdat
├── nsh.bdat
├── nsh.pdat
├── sercon.bdat
├── sercon.pdat
├── serdis.bdat
├── serdis.pdat
├── sh.bdat
└── sh.pdat
notes :Google/Baidu No information was given .PX4 I also consulted on the Forum , But there is no feedback . It is estimated that everyone's focus is on the application .How .bdat/.pdat files generated in NuttX/apps/builtin/registry/? .
2.4 NSH application .pdat/.bdat Generation pathway
NSH Applied Makefile The document will be quoted in advance
include $(APPDIR)/Make.defs
This document platforms\nuttx\NuttX\apps\Make.defs Pass the entry function of each application through Symbol rename script define.sh It's sorted out , Output to the registration file .
86 define REGISTER
87 $(Q) echo Register: $1
88 $(Q) echo { \"$1\", $2, $3, $4 }, > "$(BUILTIN_REGISTRY)$(DELIM)$1.bdat"
89 $(Q) if [ ! -z $4 ]; then \
90 echo "int $4(int argc, char *argv[]);" > "$(BUILTIN_REGISTRY)$(DELIM)$1.pdat"; \
91 fi;
92 $(Q) touch "$(BUILTIN_REGISTRY)$(DELIM).updated"
93 endef
2.5 PX4 application .pdat/.bdat Generation pathway
PX4 The applied symbol passes CMakeList Under the px4_add_module Add to global variable , And through .in File output to .bdat/.pdat Registration documents
111 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/px4_kernel.bdat.in ${CMAKE_CURRENT_BINARY_DIR}/px4_kernel.bdat)
112 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/px4_kernel.pdat.in ${CMAKE_CURRENT_BINARY_DIR}/px4_kernel.pdat)
...
117 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/px4_kernel.bdat kernel_builtin_list.h
118 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/px4_kernel.pdat kernel_builtin_proto.h
...
125 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/px4.bdat.in ${CMAKE_CURRENT_BINARY_DIR}/px4.bdat)
126 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/px4.pdat.in ${CMAKE_CURRENT_BINARY_DIR}/px4.pdat)
...
138 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/px4.bdat ${APPS_DIR}/builtin/registry/px4.bdat
139 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/px4.pdat ${APPS_DIR}/builtin/registry/px4.pdat
3. Nuttx Built-In Code implementation
The key to executing scripts Built-In The functions are the following two :
- builtin_isavail
- builtin_for_index
nsh_script
└──> nsh_parse
└──> nsh_parse_command
└──> nsh_execute
└──> nsh_builtin
└──> exec_builtin
├──> builtin_isavail
├──> builtin_for_index
└──> task_spawn(builtin->name, builtin->main, &file_actions,
&attr, (argv) ? &argv[1] : (FAR char * const *)NULL,
(FAR char * const *)NULL);
3.1 builtin_isavail
lib_builtin_isavail.c Realized builtin_isavail function , Confirm whether the command is not valid Built-In command .
56 int builtin_isavail(FAR const char *appname)
57 {
58 FAR const char *name;
59 int i;
60
61 for (i = 0; (name = builtin_getname(i)) != NULL; i++)
62 {
63 if (strcmp(name, appname) == 0)
64 {
65 return i;
66 }
67 }
68
69 return -ENOENT;
70 }
3.2 builtin_for_index
lib_builtin_forindex.c Realized builtin_for_index function , Return the relevant execution parameters of the command ( priority , Stack size , Function entry symbols, etc ).
52 FAR const struct builtin_s *builtin_for_index(int index)
53 {
54 if (index < g_builtin_count)
55 {
56 return &g_builtins[index];
57 }
58
59 return NULL;
60 }
4. summary
Nuttx Official website Built-In To introduce the REGISTER And the reality PX4 The main difference of the project is PX4 Adopted .bdat/.pdat The way of intermediate files ( See :2.4 NSH application .pdat/.bdat Generation pathway )
PX4 Used a lot of submodule, The introduction of relevant integration is relatively lacking , Especially the engineering surface .( about C Background R & D personnel may be a little unaccustomed . Usually C The background will make every line of code clear . I don't want to use a lot of components now , Don't pay much attention to the framework , Pay more attention to the fast pace of application .)
About Symbol rename script define.sh There's no unfolding here , Interested friends can study by themselves , Its main function is to main The symbol is converted to another non repeating symbol , such as :sh_main
-Dmain=shmain
5. Reference material
【1】PX4 A brief introduction to the open source software framework
【2】PX4 A concise introduction to open source engineering structure
【3】Nuttx NSH Build-In Framework
边栏推荐
- Wechat applet realizes PDF preview function - pdf.js (including source code analysis)
- LastWordLen
- 元宇宙赋能场景金融:商业银行竞争发展新赛道
- ctfshow MengXIn 下
- Two bytes, carried out by the interviewer and shared with everyone
- [js]: splice(), charCodeAt()
- Niuke 2022 summer training session I chiitoitsu solution
- DOM之style的操作
- SSTI简单总结和CISCN 2019华东南]Double Secret
- 广告无处不在,如何利用广告去推广自己的产品?
猜你喜欢
单片机是如何工作的?
C语言编写九九乘法表,实现不同三角形形状表格输出
命令行程序测试自动化
统计,在sql中求每个部门的数据比值
信息系统项目管理师必背核心考点(四十八)合同类型的选择
The first session of Niuke 2022 summer training c question grab the seat! Solution
元宇宙赋能场景金融:商业银行竞争发展新赛道
Pull daily activities, use cloud functions to send wechat applet subscription messages
常见的probe set和gallery set究竟是什么
浏览器无痕浏览还能查到记录吗,如何开启无痕模式
随机推荐
C language dynamic memory allocation
How to deal with tough interview questions
Leetcode high frequency question: zigzag (zigzag, zigzag) sequence traversal of binary tree
Upload pictures to the IIS server of this machine, and the results are returned in the form of web address, which can be accessed directly
牛客2022暑期集训第一场I题 Chiitoitsu 题解
How does the 2022 social e-commerce model split marketing? -- Share purchase
Statistics, calculate the data ratio of each department in SQL
Can you still find records in browser traceless browsing, and how to turn on traceless mode
信息系统项目管理师必背核心考点(四十八)合同类型的选择
Deep learning 8 deep model optimization and regularization
2022社交电商模式怎么裂变营销?—分享购
深度卷积和普通卷积的对比
C语言力扣第38题之外观数列。三种方法(遍历法、递归法与狼灭法)
欢乐的彝族火把节Joyous Torch Festival of the Yi Nationality
Deep learning 8 deep model optimization and regularization 2
ROS2自学笔记:TF坐标管理
【一起学Rust】Rust学习前准备——注释和格式化输出
NiFi 1.16.3 生产使用的更新及BUG。
包裹DNA和光敏剂Ce6的白蛋白纳米粒/棉酚白蛋白纳米粒/拉帕替尼白蛋白纳米粒
Rotation matrix_ Baidu Encyclopedia