02 Crazyflie Source Preview
Crazyflie源码分析
一、源代码结构
./ | Root, contains the Makefile
+ init | 主文件目录,很简单 Contains the main.c
+ config | 配置文件,包括系统任务配置文件,freertos配置文件, stm32配置文件 Configuration files
+ drivers | 传感器底层访问驱动 Hardware driver layer
| + src | Drivers source code
| + interface | Drivers header files. Interface to the HAL layer
+ hal | 硬件抽象层 Hardware abstraction layer 主要包括sensors
| + src | HAL source code
| + interface | HAL header files. Interface with the other parts of the program
+ modules | 主要飞控代码 Firmware operating code and headers 角度计算 pid 等
| + src | Firmware tasks source code and main.c
| + interface | Operating headers. Configure the firmware environment
+ utils | CRC校验 IIR滤波器等 Utils code. Implement utility block like the console.
| + src | Utils source code
| + interface | Utils header files. Interface with the other parts of the program
+ platform | 平台信息 Platform specific files. Not really used yet
+ tools | Misc. scripts for LD, OpenOCD, make, version control, ...
| | *** The two following folders contains the unmodified files ***
+ lib | Libraries
| + FreeRTOS | Source FreeRTOS folder. Cleaned up from the useless files
| + STM32... | STM32外设库 Library folders of the ST STM32 peripheral libs
| + CMSIS | ARM标准库 Core abstraction layer二、运行任务
系统启动时主要运行的任务有,adcTask,crtpTxTask,crtpRxTask,eskylinkTask,infoTask,logTask,memTask,paramTask,pmTask,stabilizerTask,syslinkTask,systemTask,prvIdleTask,prvTimerTask和usblinkTask等任务.分析链接
三、源码风格总结
Crazyflie项目中有很多巧妙的类型定义,可以很方便的解决问题,也可能是本人才疏学浅表示第一看看到这么用
1. 两种方式检索同一区域(union)
以下可以实现两种检索方式检索同一片内存区域,可以使用
2. 使用枚举类型计数
以下枚举类型成员SensorImplementation_COUNT,始终可以代表枚举类型中成员的个数.巧妙利用了枚举类型第一个成员默认为0的特点
3. 紧凑的数据类型
attribute ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐,是GCC特有的语法.这个功能是跟操作系统没关系,跟编译器有关,gcc编译器不是紧凑模式的,我在windows下,用vc的编译器也不是紧凑的,用tc的编译器就是紧凑的.例如:
4. git工程中如何引用其他仓库
使用将其他仓库一起clone
5. 在makefile中添加宏定义
在Crazyflie的固件代码中,宏一般都定义在文件Makefile中.可以使用CFLAGS += -D的方式配置固件功能
相当于编译时
相当于文件中添加
最后更新于
这有帮助吗?