Chibios arducopter 学习

28 篇文章 2 订阅
22 篇文章 0 订阅

Chibios 启动 run 学习

参考 九天揽月带你学习系列

Chibios 启动代码在 startup_stm32f7xx.mk中:

img

HAL_ChibiOS的run() 函数

void HAL_ChibiOS::run(int argc, char * const argv[], Callbacks* callbacks)const {
 //前面省略
 //接管执行main------------Takeover main
 main_loop();
}

HAL_ChibiOS的main_loop()函数

static void main_loop() {
 hal.scheduler->init(); //初始化任务init线程 /*
 g_callbacks->setup();  //调用应用层的setup()函数
 while (true) {
     g_callbacks->loop(); //调用APP的loop线程 /* 
 } 
}

HAL_ChibiOS的init()函数

img

void Scheduler::init() {
chBSemObjectInit(&_timer_semaphore, false); //信号量创建
chBSemObjectInit(&_io_semaphore, false); //信号量创建
 //设置定时器进程-这将调用任务在1kHz---- setup the timer thread - this will call tasks at 1kHz
 //设置RCIN进程-这将调用任务在1kHz---- setup the RCIN thread - this will call tasks at 1kHz
 //IO进程以较低优先级运行--------- the IO thread runs at lower priority 
 //存储进程在IO优先级之上运行。-------- the storage thread runs at just above IO priority
}

g_callbacks->setup();

void Copter::setup() {
 //从参数表中加载默认参数----------Load the default values of variables listed in var_info[]s 
 AP_Param::setup_sketch_defaults(); 
 //初始化储存的多旋翼布局-----------setup storage layout for copter 
 StorageManager::set_layout_copter(); 
 //传感器初始化,注册 
 init_ardupilot(); 
 //初始化整个主loop任务调度-------initialise the main loop scheduler 
 scheduler.init(&scheduler_tasks[0], ARRAY_SIZE(scheduler_tasks), MASK_LOG_PM); 
}
void Copter::init_ardupilot(){
 
}
const AP_Scheduler::Task Copter::scheduler_tasks[]{
 
}

g_callbacks->loop() (核心循环函数)

void Copter::loop()
{
 scheduler.loop();
 G_Dt = scheduler.get_last_loop_time_s();
}
void AP_Scheduler::loop(){
if (_fastloop_fn) {
  us _fastloop_fn(); //该函数会通过指针函数知识,调用fast_loop()函数
}
 //运行run()函数,运行数组表任务
	run(time_available > loop_us ? 0u : time_available); //运行函数,上面计算剩	余的时间都留给任务表中的任务去用。

}

运行fast_loop()(快速函数)

void Copter::fast_loop(){
 
}

运行run()函数

void AP_Scheduler::run(uint32_t time_available){
 
}

arducopter 的电路板定义

为ChibiOS_HAL 生成所需的#defines的方式为:命名一个hwdef.dat的电路板文件,然后用chibios_hwdef.py去重新生成一个hwdef.h文件。接下来看下引脚定义。
[ArduPilot port to ChibiOS]: http://www.chibios.com/forum/viewtopic.php?t=4463
[Porting to a new flight controller board]: http://ardupilot.org/dev/docs/porting.html
[ArduPilot porting guide for ChibiOS + STM microcontrollers]: https://discuss.ardupilot.org/t/ardupilot-porting-guide-for-chibios-stm-microcontrollers/26415

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gkbytes

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值