Chibios 启动 run 学习
参考 九天揽月带你学习系列
Chibios 启动代码在 startup_stm32f7xx.mk中:
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()函数
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