RTOS, FuncCallBacks, AP_HAL_MAIN(), C wrapper, Scheduler, Nuttx, Code Flow, Build Own Minimal autopilot

The ardupilot is a multi-threaded based application.
I would like to know the Code Flow - The callbacks from AP_HAL_MAIN() and the AP_HAL_MAIN_CALLBACKS() in the Arducopter.
or How the RTOS is scheduling the multiple mains – AP_HAL_MAIN() wrappers to call setup() and loop() as callbacks.
Please assist me in learning the software architecture of the ardupilot as a multithreaded application.
How drivers are classified as timer, IO?
What can be registered to the periodic callbacks, timer process, io process.?
The HAL and the running of AP_HAL::Scheduler and
finally the RTOS - Nuttx scheduling the tasks and threads on Pixhawk Hardware.
How is code run on the platform Pixhawk v1. ?
After the nuttx starts the Arducopter, where does it loop over the codes. ?
Does the setup() in the source files of the application called every time ?
Please assist me in filling the gaps of the insights gained in understanding the code base with respect to the architecture and not the application.
I am interested in the software flow from the power on of the board.