forked from commaai/panda
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deep sleep(stop) mode for pandas (commaai#832)
* Add RTC with LSI for BP, GP, WP * disable jenkins temporarily, REVERT! * experiments * cleanup is still needed * cppcheck unused suppress * raise deepsleep limit timeout to 120sec * more experiments on usb_enumerated * continue * soft_disconnect * almost done * not enough * no ignition * still don't like it.. * rename to has_rtc_battery * clock_source on the way!? * delay 3 sec * works on C3, needs test on C2 * And this is for C2 * disable bootkick * misra 10.4 * .. * .. * set power state the right way * change that * seems don't need that? check on C2/C3 * partially works on RP... * comments (will work after rebase) * change fault name * switch to manual activation mode * Revert "disable jenkins temporarily, REVERT!" This reverts commit 578d425. * my dear pedal!
- Loading branch information
1 parent
e8e9d84
commit de7e1e7
Showing
13 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
void EXTI_IRQ_Handler(void); | ||
|
||
void exti_irq_init(void) { | ||
SYSCFG->EXTICR[2] &= ~(SYSCFG_EXTICR3_EXTI8_Msk); | ||
if (car_harness_status == HARNESS_STATUS_FLIPPED) { | ||
// CAN2_RX | ||
current_board->enable_can_transceiver(3U, false); | ||
SYSCFG->EXTICR[2] |= (SYSCFG_EXTICR3_EXTI8_PA); | ||
|
||
// IRQ on falling edge for PC3 (SBU2, EXTI3) | ||
SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI3_Msk); | ||
SYSCFG->EXTICR[0] |= (SYSCFG_EXTICR1_EXTI3_PC); | ||
EXTI->IMR |= EXTI_IMR_MR3; | ||
EXTI->RTSR &= ~EXTI_RTSR_TR3; // rising edge | ||
EXTI->FTSR |= EXTI_FTSR_TR3; // falling edge | ||
REGISTER_INTERRUPT(EXTI3_IRQn, EXTI_IRQ_Handler, 100U, FAULT_INTERRUPT_RATE_EXTI) | ||
NVIC_EnableIRQ(EXTI3_IRQn); | ||
} else { | ||
// CAN0_RX | ||
current_board->enable_can_transceiver(1U, false); | ||
SYSCFG->EXTICR[2] |= (SYSCFG_EXTICR3_EXTI8_PB); | ||
|
||
// IRQ on falling edge for PC0 (SBU1, EXTI0) | ||
SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI0_Msk); | ||
SYSCFG->EXTICR[0] |= (SYSCFG_EXTICR1_EXTI0_PC); | ||
EXTI->IMR |= EXTI_IMR_MR0; | ||
EXTI->RTSR &= ~EXTI_RTSR_TR0; // rising edge | ||
EXTI->FTSR |= EXTI_FTSR_TR0; // falling edge | ||
REGISTER_INTERRUPT(EXTI0_IRQn, EXTI_IRQ_Handler, 100U, FAULT_INTERRUPT_RATE_EXTI) | ||
NVIC_EnableIRQ(EXTI0_IRQn); | ||
} | ||
// CAN0 or CAN2 IRQ on falling edge (EXTI8) | ||
EXTI->IMR |= EXTI_IMR_MR8; | ||
EXTI->RTSR &= ~EXTI_RTSR_TR8; // rising edge | ||
EXTI->FTSR |= EXTI_FTSR_TR8; // falling edge | ||
REGISTER_INTERRUPT(EXTI9_5_IRQn, EXTI_IRQ_Handler, 100U, FAULT_INTERRUPT_RATE_EXTI) | ||
NVIC_EnableIRQ(EXTI9_5_IRQn); | ||
} | ||
|
||
bool check_exti_irq(void) { | ||
return ((EXTI->PR & EXTI_PR_PR8) || (EXTI->PR & EXTI_PR_PR3) || (EXTI->PR & EXTI_PR_PR0)); | ||
} | ||
|
||
void exti_irq_clear(void) { | ||
// Clear pending bits | ||
EXTI->PR |= EXTI_PR_PR8; | ||
EXTI->PR |= EXTI_PR_PR0; | ||
EXTI->PR |= EXTI_PR_PR3; | ||
EXTI->PR |= EXTI_PR_PR22; | ||
|
||
// Disable all active EXTI IRQs | ||
EXTI->IMR &= ~EXTI_IMR_MR8; | ||
EXTI->IMR &= ~EXTI_IMR_MR0; | ||
EXTI->IMR &= ~EXTI_IMR_MR3; | ||
EXTI->IMR &= ~EXTI_IMR_MR22; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
void EXTI_IRQ_Handler(void); | ||
|
||
void exti_irq_init(void) { | ||
if (car_harness_status == HARNESS_STATUS_FLIPPED) { | ||
// CAN2_RX IRQ on falling edge (EXTI10) | ||
current_board->enable_can_transceiver(3U, false); | ||
SYSCFG->EXTICR[2] &= ~(SYSCFG_EXTICR3_EXTI10_Msk); | ||
SYSCFG->EXTICR[2] |= (SYSCFG_EXTICR3_EXTI10_PG); | ||
EXTI->IMR1 |= EXTI_IMR1_IM10; | ||
EXTI->RTSR1 &= ~EXTI_RTSR1_TR10; // rising edge | ||
EXTI->FTSR1 |= EXTI_FTSR1_TR10; // falling edge | ||
|
||
// IRQ on falling edge for PA1 (SBU2, EXTI1) | ||
SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI1_Msk); | ||
SYSCFG->EXTICR[0] |= (SYSCFG_EXTICR1_EXTI1_PA); | ||
EXTI->IMR1 |= EXTI_IMR1_IM1; | ||
EXTI->RTSR1 &= ~EXTI_RTSR1_TR1; // rising edge | ||
EXTI->FTSR1 |= EXTI_FTSR1_TR1; // falling edge | ||
REGISTER_INTERRUPT(EXTI1_IRQn, EXTI_IRQ_Handler, 100U, FAULT_INTERRUPT_RATE_EXTI) | ||
NVIC_EnableIRQ(EXTI1_IRQn); | ||
REGISTER_INTERRUPT(EXTI15_10_IRQn, EXTI_IRQ_Handler, 100U, FAULT_INTERRUPT_RATE_EXTI) | ||
NVIC_EnableIRQ(EXTI15_10_IRQn); | ||
} else { | ||
// CAN0_RX IRQ on falling edge (EXTI8) | ||
current_board->enable_can_transceiver(1U, false); | ||
SYSCFG->EXTICR[2] &= ~(SYSCFG_EXTICR3_EXTI8_Msk); | ||
SYSCFG->EXTICR[2] |= (SYSCFG_EXTICR3_EXTI8_PB); | ||
EXTI->IMR1 |= EXTI_IMR1_IM8; | ||
EXTI->RTSR1 &= ~EXTI_RTSR1_TR8; // rising edge | ||
EXTI->FTSR1 |= EXTI_FTSR1_TR8; // falling edge | ||
|
||
// IRQ on falling edge for PC4 (SBU1, EXTI4) | ||
SYSCFG->EXTICR[1] &= ~(SYSCFG_EXTICR2_EXTI4_Msk); | ||
SYSCFG->EXTICR[1] |= (SYSCFG_EXTICR2_EXTI4_PC); | ||
EXTI->IMR1 |= EXTI_IMR1_IM4; | ||
EXTI->RTSR1 &= ~EXTI_RTSR1_TR4; // rising edge | ||
EXTI->FTSR1 |= EXTI_FTSR1_TR4; // falling edge | ||
REGISTER_INTERRUPT(EXTI4_IRQn, EXTI_IRQ_Handler, 100U, FAULT_INTERRUPT_RATE_EXTI) | ||
NVIC_EnableIRQ(EXTI4_IRQn); | ||
REGISTER_INTERRUPT(EXTI9_5_IRQn, EXTI_IRQ_Handler, 100U, FAULT_INTERRUPT_RATE_EXTI) | ||
NVIC_EnableIRQ(EXTI9_5_IRQn); | ||
} | ||
} | ||
|
||
bool check_exti_irq(void) { | ||
return ((EXTI->PR1 & EXTI_PR1_PR8) || (EXTI->PR1 & EXTI_PR1_PR10) || (EXTI->PR1 & EXTI_PR1_PR1) || (EXTI->PR1 & EXTI_PR1_PR4)); | ||
} | ||
|
||
void exti_irq_clear(void) { | ||
// Clear pending bits | ||
EXTI->PR1 |= EXTI_PR1_PR8; | ||
EXTI->PR1 |= EXTI_PR1_PR10; | ||
EXTI->PR1 |= EXTI_PR1_PR4; | ||
EXTI->PR1 |= EXTI_PR1_PR1; // works | ||
EXTI->PR1 |= EXTI_PR1_PR19; // works | ||
|
||
// Disable all active EXTI IRQs | ||
EXTI->IMR1 &= ~EXTI_IMR1_IM8; | ||
EXTI->IMR1 &= ~EXTI_IMR1_IM10; | ||
EXTI->IMR1 &= ~EXTI_IMR1_IM4; | ||
EXTI->IMR1 &= ~EXTI_IMR1_IM1; | ||
EXTI->IMR1 &= ~EXTI_IMR1_IM19; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters