Skip to content

Commit

Permalink
remove RTC time pull (#31829)
Browse files Browse the repository at this point in the history
* remove RTC time pull

* and syncing

* bump panda

* bump panda
  • Loading branch information
adeebshihadeh committed Mar 12, 2024
1 parent 0e92097 commit 78d72d7
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 129 deletions.
2 changes: 1 addition & 1 deletion panda
Submodule panda updated 48 files
+3 −3 SConscript
+0 −3 board/boards/black.h
+0 −1 board/boards/board_declarations.h
+0 −1 board/boards/cuatro.h
+0 −3 board/boards/dos.h
+0 −1 board/boards/grey.h
+0 −3 board/boards/red.h
+0 −2 board/boards/red_chiplet.h
+0 −1 board/boards/tres.h
+0 −3 board/boards/uno.h
+0 −3 board/boards/white.h
+1 −1 board/config.h
+0 −79 board/drivers/rtc.h
+0 −0 board/jungle/stm32f4/board.h
+0 −22 board/main.c
+0 −53 board/main_comms.h
+2 −4 board/stm32f4/board.h
+0 −0 board/stm32f4/clock.h
+0 −0 board/stm32f4/inc/cmsis_compiler.h
+0 −0 board/stm32f4/inc/cmsis_gcc.h
+0 −0 board/stm32f4/inc/cmsis_version.h
+0 −0 board/stm32f4/inc/core_cm3.h
+0 −0 board/stm32f4/inc/core_cm4.h
+0 −0 board/stm32f4/inc/mpu_armv7.h
+0 −0 board/stm32f4/inc/stm32f413xx.h
+0 −0 board/stm32f4/inc/stm32f4xx.h
+0 −0 board/stm32f4/inc/stm32f4xx_hal_def.h
+0 −0 board/stm32f4/inc/stm32f4xx_hal_gpio_ex.h
+0 −0 board/stm32f4/inc/system_stm32f4xx.h
+0 −0 board/stm32f4/interrupt_handlers.h
+0 −0 board/stm32f4/lladc.h
+0 −0 board/stm32f4/llbxcan.h
+0 −0 board/stm32f4/llexti.h
+0 −0 board/stm32f4/llfan.h
+0 −0 board/stm32f4/llflash.h
+0 −0 board/stm32f4/llspi.h
+0 −0 board/stm32f4/lluart.h
+0 −0 board/stm32f4/llusb.h
+0 −0 board/stm32f4/peripherals.h
+0 −0 board/stm32f4/startup_stm32f413xx.s
+12 −12 board/stm32f4/stm32f4_config.h
+0 −0 board/stm32f4/stm32f4_flash.ld
+0 −69 board/stm32fx/llrtc.h
+0 −2 board/stm32h7/board.h
+0 −69 board/stm32h7/llrtc.h
+0 −16 python/__init__.py
+4 −4 tests/misra/test_mutation.py
+0 −10 tests/rtc_test.py
1 change: 0 additions & 1 deletion release/files_common
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ selfdrive/boardd/panda.h
selfdrive/boardd/spi.cc
selfdrive/boardd/panda_comms.h
selfdrive/boardd/panda_comms.cc
selfdrive/boardd/set_time.py
selfdrive/boardd/pandad.py
selfdrive/boardd/tests/test_boardd_loopback.py

Expand Down
42 changes: 0 additions & 42 deletions selfdrive/boardd/boardd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ std::atomic<bool> ignition(false);

ExitHandler do_exit;

static std::string get_time_str(const struct tm &time) {
char s[30] = {'\0'};
std::strftime(s, std::size(s), "%Y-%m-%d %H:%M:%S", &time);
return s;
}

bool check_all_connected(const std::vector<Panda *> &pandas) {
for (const auto& panda : pandas) {
if (!panda->connected()) {
Expand All @@ -65,36 +59,6 @@ bool check_all_connected(const std::vector<Panda *> &pandas) {
return true;
}

enum class SyncTimeDir { TO_PANDA, FROM_PANDA };

void sync_time(Panda *panda, SyncTimeDir dir) {
if (!panda->has_rtc) return;

setenv("TZ", "UTC", 1);
struct tm sys_time = util::get_time();
struct tm rtc_time = panda->get_rtc();

if (dir == SyncTimeDir::TO_PANDA) {
if (util::time_valid(sys_time)) {
// Write time to RTC if it looks reasonable
double seconds = difftime(mktime(&rtc_time), mktime(&sys_time));
if (std::abs(seconds) > 1.1) {
panda->set_rtc(sys_time);
LOGW("Updating panda RTC. dt = %.2f System: %s RTC: %s",
seconds, get_time_str(sys_time).c_str(), get_time_str(rtc_time).c_str());
}
}
} else if (dir == SyncTimeDir::FROM_PANDA) {
LOGW("System time: %s, RTC time: %s", get_time_str(sys_time).c_str(), get_time_str(rtc_time).c_str());

if (!util::time_valid(sys_time) && util::time_valid(rtc_time)) {
const struct timeval tv = {mktime(&rtc_time), 0};
settimeofday(&tv, 0);
LOGE("System time wrong, setting from RTC.");
}
}
}

bool safety_setter_thread(std::vector<Panda *> pandas) {
LOGD("Starting safety setter thread");

Expand Down Expand Up @@ -195,7 +159,6 @@ Panda *connect(std::string serial="", uint32_t index=0) {
throw std::runtime_error("Panda firmware out of date. Run pandad.py to update.");
}

sync_time(panda.get(), SyncTimeDir::FROM_PANDA);
return panda.release();
}

Expand Down Expand Up @@ -581,11 +544,6 @@ void peripheral_control_thread(Panda *panda, bool no_fan_control) {
panda->set_ir_pwr(ir_pwr);
prev_ir_pwr = ir_pwr;
}

// Write to rtc once per minute when no ignition present
if (!ignition && (sm.frame % 120 == 1)) {
sync_time(panda, SyncTimeDir::TO_PANDA);
}
}
}

Expand Down
39 changes: 0 additions & 39 deletions selfdrive/boardd/panda.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ Panda::Panda(std::string serial, uint32_t bus_offset) : bus_offset(bus_offset) {
}

hw_type = get_hw_type();
has_rtc = (hw_type == cereal::PandaState::PandaType::UNO) ||
(hw_type == cereal::PandaState::PandaType::DOS) ||
(hw_type == cereal::PandaState::PandaType::TRES);

can_reset_communications();

return;
Expand Down Expand Up @@ -77,41 +73,6 @@ cereal::PandaState::PandaType Panda::get_hw_type() {
return (cereal::PandaState::PandaType)(hw_query[0]);
}

void Panda::set_rtc(struct tm sys_time) {
// tm struct has year defined as years since 1900
handle->control_write(0xa1, (uint16_t)(1900 + sys_time.tm_year), 0);
handle->control_write(0xa2, (uint16_t)(1 + sys_time.tm_mon), 0);
handle->control_write(0xa3, (uint16_t)sys_time.tm_mday, 0);
// handle->control_write(0xa4, (uint16_t)(1 + sys_time.tm_wday), 0);
handle->control_write(0xa5, (uint16_t)sys_time.tm_hour, 0);
handle->control_write(0xa6, (uint16_t)sys_time.tm_min, 0);
handle->control_write(0xa7, (uint16_t)sys_time.tm_sec, 0);
}

struct tm Panda::get_rtc() {
struct __attribute__((packed)) timestamp_t {
uint16_t year; // Starts at 0
uint8_t month;
uint8_t day;
uint8_t weekday;
uint8_t hour;
uint8_t minute;
uint8_t second;
} rtc_time = {0};

handle->control_read(0xa0, 0, 0, (unsigned char*)&rtc_time, sizeof(rtc_time));

struct tm new_time = { 0 };
new_time.tm_year = rtc_time.year - 1900; // tm struct has year defined as years since 1900
new_time.tm_mon = rtc_time.month - 1;
new_time.tm_mday = rtc_time.day;
new_time.tm_hour = rtc_time.hour;
new_time.tm_min = rtc_time.minute;
new_time.tm_sec = rtc_time.second;

return new_time;
}

void Panda::set_fan_speed(uint16_t fan_speed) {
handle->control_write(0xb1, fan_speed, 0);
}
Expand Down
3 changes: 0 additions & 3 deletions selfdrive/boardd/panda.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Panda {
Panda(std::string serial="", uint32_t bus_offset=0);

cereal::PandaState::PandaType hw_type = cereal::PandaState::PandaType::UNKNOWN;
bool has_rtc = false;
const uint32_t bus_offset;

bool connected();
Expand All @@ -64,8 +63,6 @@ class Panda {
cereal::PandaState::PandaType get_hw_type();
void set_safety_model(cereal::CarParams::SafetyModel safety_model, uint16_t safety_param=0U);
void set_alternative_experience(uint16_t alternative_experience);
void set_rtc(struct tm sys_time);
struct tm get_rtc();
void set_fan_speed(uint16_t fan_speed);
uint16_t get_fan_speed();
void set_ir_pwr(uint16_t ir_pwr);
Expand Down
5 changes: 0 additions & 5 deletions selfdrive/boardd/pandad.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from panda import Panda, PandaDFU, PandaProtocolMismatch, FW_PATH
from openpilot.common.basedir import BASEDIR
from openpilot.common.params import Params
from openpilot.selfdrive.boardd.set_time import set_time
from openpilot.system.hardware import HARDWARE
from openpilot.common.swaglog import cloudlog

Expand Down Expand Up @@ -154,10 +153,6 @@ def main() -> NoReturn:
cloudlog.event("panda.som_reset_triggered", health=health, serial=panda.get_usb_serial())

if first_run:
if panda.is_internal():
# update time from RTC
set_time(cloudlog)

# reset panda to ensure we're in a good state
cloudlog.info(f"Resetting panda {panda.get_usb_serial()}")
if panda.is_internal():
Expand Down
38 changes: 0 additions & 38 deletions selfdrive/boardd/set_time.py

This file was deleted.

0 comments on commit 78d72d7

Please sign in to comment.