diff --git a/VERSION b/VERSION index 0c76f1991..4279ff22f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v1.5.8 \ No newline at end of file +v1.5.9 \ No newline at end of file diff --git a/board/board_declarations.h b/board/board_declarations.h index 99b8c8cc9..2fd3976a0 100644 --- a/board/board_declarations.h +++ b/board/board_declarations.h @@ -62,3 +62,11 @@ struct board { // ********************* Globals ********************** uint8_t usb_power_mode = USB_POWER_NONE; + +// ************ Board function prototypes ************* +bool board_has_gps(void); +bool board_has_gmlan(void); +bool board_has_obd(void); +bool board_has_lin(void); +bool board_has_rtc(void); +bool board_has_relay(void); \ No newline at end of file diff --git a/board/boards/uno.h b/board/boards/uno.h index e57038f58..f5765c226 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -182,6 +182,9 @@ void uno_init(void) { // Initialize harness harness_init(); + // Initialize RTC + rtc_init(); + // Enable CAN transcievers uno_enable_can_transcievers(true); diff --git a/board/drivers/rtc.h b/board/drivers/rtc.h index 84670ffe0..25190ea76 100644 --- a/board/drivers/rtc.h +++ b/board/drivers/rtc.h @@ -22,72 +22,78 @@ uint16_t from_bcd(uint8_t value){ } void rtc_init(void){ - // Initialize RTC module and clock if not done already. - if((RCC->BDCR & RCC_BDCR_MASK) != RCC_BDCR_OPTIONS){ - puts("Initializing RTC\n"); - // Reset backup domain - RCC->BDCR |= RCC_BDCR_BDRST; + if(board_has_rtc()){ + // Initialize RTC module and clock if not done already. + if((RCC->BDCR & RCC_BDCR_MASK) != RCC_BDCR_OPTIONS){ + puts("Initializing RTC\n"); + // Reset backup domain + RCC->BDCR |= RCC_BDCR_BDRST; - // Disable write protection - PWR->CR |= PWR_CR_DBP; + // Disable write protection + PWR->CR |= PWR_CR_DBP; - // Clear backup domain reset - RCC->BDCR &= ~(RCC_BDCR_BDRST); + // Clear backup domain reset + RCC->BDCR &= ~(RCC_BDCR_BDRST); - // Set RTC options - RCC->BDCR = RCC_BDCR_OPTIONS | (RCC->BDCR & (~RCC_BDCR_MASK)); + // Set RTC options + RCC->BDCR = RCC_BDCR_OPTIONS | (RCC->BDCR & (~RCC_BDCR_MASK)); - // Enable write protection - PWR->CR &= ~(PWR_CR_DBP); + // Enable write protection + PWR->CR &= ~(PWR_CR_DBP); + } } } void rtc_set_time(timestamp_t time){ - puts("Setting RTC time\n"); + if(board_has_rtc()){ + puts("Setting RTC time\n"); - // Disable write protection - PWR->CR |= PWR_CR_DBP; - RTC->WPR = 0xCA; - RTC->WPR = 0x53; + // Disable write protection + PWR->CR |= PWR_CR_DBP; + RTC->WPR = 0xCA; + RTC->WPR = 0x53; - // Enable initialization mode - RTC->ISR |= RTC_ISR_INIT; - while((RTC->ISR & RTC_ISR_INITF) == 0){} - - // Set time - RTC->TR = (to_bcd(time.hour) << RTC_TR_HU_Pos) | (to_bcd(time.minute) << RTC_TR_MNU_Pos) | (to_bcd(time.second) << RTC_TR_SU_Pos); - RTC->DR = (to_bcd(time.year - YEAR_OFFSET) << RTC_DR_YU_Pos) | (time.weekday << RTC_DR_WDU_Pos) | (to_bcd(time.month) << RTC_DR_MU_Pos) | (to_bcd(time.day) << RTC_DR_DU_Pos); + // Enable initialization mode + RTC->ISR |= RTC_ISR_INIT; + while((RTC->ISR & RTC_ISR_INITF) == 0){} + + // Set time + RTC->TR = (to_bcd(time.hour) << RTC_TR_HU_Pos) | (to_bcd(time.minute) << RTC_TR_MNU_Pos) | (to_bcd(time.second) << RTC_TR_SU_Pos); + RTC->DR = (to_bcd(time.year - YEAR_OFFSET) << RTC_DR_YU_Pos) | (time.weekday << RTC_DR_WDU_Pos) | (to_bcd(time.month) << RTC_DR_MU_Pos) | (to_bcd(time.day) << RTC_DR_DU_Pos); - // Set options - RTC->CR = 0U; - - // Disable initalization mode - RTC->ISR &= ~(RTC_ISR_INIT); + // Set options + RTC->CR = 0U; + + // Disable initalization mode + RTC->ISR &= ~(RTC_ISR_INIT); - // Wait for synchronization - while((RTC->ISR & RTC_ISR_RSF) == 0){} + // Wait for synchronization + while((RTC->ISR & RTC_ISR_RSF) == 0){} - // Re-enable write protection - RTC->WPR = 0x00; - PWR->CR &= ~(PWR_CR_DBP); + // Re-enable write protection + RTC->WPR = 0x00; + PWR->CR &= ~(PWR_CR_DBP); + } } timestamp_t rtc_get_time(void){ - // Wait until the register sync flag is set - while((RTC->ISR & RTC_ISR_RSF) == 0){} - - // Read time and date registers. Since our HSE > 7*LSE, this should be fine. - uint32_t time = RTC->TR; - uint32_t date = RTC->DR; - - // Parse values timestamp_t result; - result.year = from_bcd((date & (RTC_DR_YT | RTC_DR_YU)) >> RTC_DR_YU_Pos) + YEAR_OFFSET; - result.month = from_bcd((date & (RTC_DR_MT | RTC_DR_MU)) >> RTC_DR_MU_Pos); - result.day = from_bcd((date & (RTC_DR_DT | RTC_DR_DU)) >> RTC_DR_DU_Pos); - result.weekday = ((date & RTC_DR_WDU) >> RTC_DR_WDU_Pos); - result.hour = from_bcd((time & (RTC_TR_HT | RTC_TR_HU)) >> RTC_TR_HU_Pos); - result.minute = from_bcd((time & (RTC_TR_MNT | RTC_TR_MNU)) >> RTC_TR_MNU_Pos); - result.second = from_bcd((time & (RTC_TR_ST | RTC_TR_SU)) >> RTC_TR_SU_Pos); + if(board_has_rtc()){ + // Wait until the register sync flag is set + while((RTC->ISR & RTC_ISR_RSF) == 0){} + + // Read time and date registers. Since our HSE > 7*LSE, this should be fine. + uint32_t time = RTC->TR; + uint32_t date = RTC->DR; + + // Parse values + result.year = from_bcd((date & (RTC_DR_YT | RTC_DR_YU)) >> RTC_DR_YU_Pos) + YEAR_OFFSET; + result.month = from_bcd((date & (RTC_DR_MT | RTC_DR_MU)) >> RTC_DR_MU_Pos); + result.day = from_bcd((date & (RTC_DR_DT | RTC_DR_DU)) >> RTC_DR_DU_Pos); + result.weekday = ((date & RTC_DR_WDU) >> RTC_DR_WDU_Pos); + result.hour = from_bcd((time & (RTC_TR_HT | RTC_TR_HU)) >> RTC_TR_HU_Pos); + result.minute = from_bcd((time & (RTC_TR_MNT | RTC_TR_MNU)) >> RTC_TR_MNU_Pos); + result.second = from_bcd((time & (RTC_TR_ST | RTC_TR_SU)) >> RTC_TR_SU_Pos); + } return result; } \ No newline at end of file diff --git a/board/main.c b/board/main.c index 7dd87c344..3bcae876e 100644 --- a/board/main.c +++ b/board/main.c @@ -727,9 +727,6 @@ int main(void) { // init board current_board->init(); - // Initialize RTC - rtc_init(); - // panda has an FPU, let's use it! enable_fpu();