Skip to content

Instantly share code, notes, and snippets.

@rming
Last active January 4, 2020 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rming/6b32a1b370ab5b7a025e51e8da6eb817 to your computer and use it in GitHub Desktop.
Save rming/6b32a1b370ab5b7a025e51e8da6eb817 to your computer and use it in GitHub Desktop.
panda start logical

main()
https://github.com/commaai/panda/blob/7bd01a5f04/board/main.c#L746

init_interrupts(true);
https://github.com/commaai/panda/blob/7bd01a5f04/board/main.c#L748
初始化定时器中断

REGISTER_INTERRUPT(TIM1_BRK_TIM9_IRQn, TIM1_BRK_TIM9_IRQ_Handler, 2U, FAULT_INTERRUPT_RATE_TIM1)
https://github.com/commaai/panda/blob/7bd01a5f04/board/main.c#L751
https://github.com/commaai/panda/blob/7bd01a5f04/board/main.c#L671
注册定时器中断TIM9服务函数 TIM1_BRK_TIM9_IRQ_Handler
TIM9_IRQ 服务函数的主要内容是检查车子是否启动
这里只注册,未启用

current_board = detect_board_type()
看是什么板子, 得到 struct board
https://github.com/commaai/panda/blob/7bd01a5f04/board/board.h#L20
https://github.com/commaai/panda/blob/7bd01a5f04/board/main.c#L760
https://github.com/commaai/panda/blob/7bd01a5f04/board/board_declarations.h#L16

current_board->init();
以 black panda 为例

black_init()
https://github.com/commaai/panda/blob/7bd01a5f04/board/boards/black.h#L153
设置PC0、PC3 口为 ADC 模式,检测电压和充电方向
设置PC10、PC11 口输出模式,控制继电器开闭
开启 USB 供电

harness_init()
设置PC0、PC3 口输入模式,检测汽车启动
https://github.com/commaai/panda/blob/7bd01a5f04/board/drivers/harness.h#L77
所以 PC0、PC3 分别检测是 车 和 EON?
没看电路的情况下是这么猜的

set_safety_mode(SAFETY_SILENT, 0);
https://github.com/commaai/panda/blob/7bd01a5f04/board/main.c#L109

current_board->set_can_mode(CAN_MODE_NORMAL);
https://github.com/commaai/panda/blob/7bd01a5f04/board/boards/black.h#L98

set_intercept_relay(false)
https://github.com/commaai/panda/blob/7bd01a5f04/board/drivers/harness.h#L24
初始化是安全模式,禁用 OBD,继电器通原车

NVIC_EnableIRQ(TIM1_BRK_TIM9_IRQn);
https://github.com/commaai/panda/blob/7bd01a5f04/board/main.c#L825
https://github.com/commaai/panda/blob/7bd01a5f04/board/main.c#L671
启用 TIM9_IRQ 每秒检测一次车子的启动状态

check_started()
https://github.com/commaai/panda/blob/7bd01a5f04/board/main.c#L709

harness_check_ignition()
以 black panda 举例,最终会调用 harness_check_ignition
是通过 PC0、PC3 口输入状态检测的
https://github.com/commaai/panda/blob/7bd01a5f04/board/drivers/harness.h#L40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment