HW abstraction layer (#19530)

* start hw refactor

* move that

* pins

* put that back
albatross
Adeeb Shihadeh 2020-12-16 21:30:23 -08:00 committed by GitHub
parent 3b8ca39554
commit 8674b023ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 87 additions and 81 deletions

View File

@ -1,7 +1,7 @@
import os
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../"))
from common.hardware import PC
from selfdrive.hardware import PC
if PC:
PERSIST = os.path.join(BASEDIR, "persist")
else:

View File

@ -1,11 +1,3 @@
GPIO_HUB_RST_N = 30
GPIO_UBLOX_RST_N = 32
GPIO_UBLOX_SAFEBOOT_N = 33
GPIO_UBLOX_PWR_EN = 34
GPIO_STM_RST_N = 124
GPIO_STM_BOOT0 = 134
def gpio_init(pin, output):
try:
with open(f"/sys/class/gpio/gpio{pin}/direction", 'wb') as f:

View File

@ -4,8 +4,8 @@ import os
import time
import multiprocessing
from common.hardware import PC, TICI
from common.clock import sec_since_boot # pylint: disable=no-name-in-module, import-error
from selfdrive.hardware import PC, TICI
# time step for each process

View File

@ -1,7 +1,7 @@
import numpy as np
import common.transformations.orientation as orient
from common.hardware import TICI
from selfdrive.hardware import TICI
## -- hardcoded hardware params --
eon_f_focal_length = 910.0

View File

@ -74,6 +74,12 @@ function two_init {
chrt -f -p 52 $pid
done
# the flippening!
LD_LIBRARY_PATH="" content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1
# disable bluetooth
service call bluetooth_manager 8
# Check for NEOS update
if [ $(< /VERSION) != "$REQUIRED_NEOS_VERSION" ]; then
if [ -f "$DIR/scripts/continue.sh" ]; then

View File

@ -18,10 +18,6 @@ apk/ai.comma*.apk
common/.gitignore
common/__init__.py
common/hardware.py
common/hardware_android.py
common/hardware_tici.py
common/hardware_base.py
common/gpio.py
common/realtime.py
common/clock.pyx
@ -41,7 +37,6 @@ common/stat_live.py
common/spinner.py
common/text_window.py
common/cython_hacks.py
common/apk.py
common/SConscript
common/kalman/.gitignore
@ -274,6 +269,17 @@ selfdrive/controls/lib/longitudinal_mpc_model/generator.cpp
selfdrive/controls/lib/longitudinal_mpc_model/libmpc_py.py
selfdrive/controls/lib/longitudinal_mpc_model/longitudinal_mpc.c
selfdrive/hardware/__init__.py
selfdrive/hardware/base.py
selfdrive/hardware/eon/__init__.py
selfdrive/hardware/eon/apk.py
selfdrive/hardware/eon/hardware.py
selfdrive/hardware/tici/__init__.py
selfdrive/hardware/tici/hardware.py
selfdrive/hardware/tici/pins.py
selfdrive/hardware/pc/__init__.py
selfdrive/hardware/pc/hardware.py
selfdrive/locationd/__init__.py
selfdrive/locationd/.gitignore
selfdrive/locationd/SConscript

View File

@ -20,11 +20,11 @@ from websocket import ABNF, WebSocketTimeoutException, create_connection
import cereal.messaging as messaging
from cereal.services import service_list
from common.hardware import HARDWARE
from common.api import Api
from common.basedir import PERSIST
from common.params import Params
from common.realtime import sec_since_boot
from selfdrive.hardware import HARDWARE
from selfdrive.loggerd.config import ROOT
from selfdrive.swaglog import cloudlog

View File

@ -9,8 +9,8 @@ import cereal.messaging as messaging
from selfdrive.test.helpers import with_processes
from selfdrive.camerad.snapshot.visionipc import VisionIPC
from common.hardware import EON, TICI
# only tests for EON and TICI
from selfdrive.hardware import EON, TICI
TEST_TIMESPAN = random.randint(60, 180) # seconds
SKIP_FRAME_TOLERANCE = 0

View File

@ -1,11 +1,11 @@
import os
from common.params import Params
from common.basedir import BASEDIR
from common.hardware import ANDROID
from selfdrive.version import comma_remote, tested_branch
from selfdrive.car.fingerprints import eliminate_incompatible_cars, all_known_cars
from selfdrive.car.vin import get_vin, VIN_UNKNOWN
from selfdrive.car.fw_versions import get_fw_versions, match_fw_to_car
from selfdrive.hardware import EON
from selfdrive.swaglog import cloudlog
import cereal.messaging as messaging
from selfdrive.car import gen_empty_fingerprint
@ -24,7 +24,7 @@ def get_startup_event(car_recognized, controller_available):
event = EventName.startupNoCar
elif car_recognized and not controller_available:
event = EventName.startupNoControl
elif ANDROID and "letv" not in open("/proc/cmdline").read():
elif EON and "letv" not in open("/proc/cmdline").read():
event = EventName.startupOneplus
return event

View File

@ -1,7 +1,6 @@
#!/usr/bin/env python3
import os
from cereal import car, log
from common.hardware import HARDWARE
from common.numpy_fast import clip
from common.realtime import sec_since_boot, config_realtime_process, Priority, Ratekeeper, DT_CTRL
from common.profiler import Profiler
@ -21,6 +20,7 @@ from selfdrive.controls.lib.alertmanager import AlertManager
from selfdrive.controls.lib.vehicle_model import VehicleModel
from selfdrive.controls.lib.planner import LON_MPC_STEP
from selfdrive.locationd.calibrationd import Calibration
from selfdrive.hardware import HARDWARE
LDW_MIN_SPEED = 31 * CV.MPH_TO_MS
LANE_DEPARTURE_THRESHOLD = 0.1

View File

@ -5,8 +5,8 @@ import threading
import capnp
from selfdrive.version import version, dirty, origin, branch
from selfdrive.hardware import PC
from selfdrive.swaglog import cloudlog
from common.hardware import PC
if os.getenv("NOLOG") or os.getenv("NOCRASH") or PC:
def capture_exception(*args, **kwargs):

View File

@ -0,0 +1,19 @@
import os
from typing import cast
from selfdrive.hardware.base import HardwareBase
from selfdrive.hardware.eon.hardware import Android
from selfdrive.hardware.tici.hardware import Tici
from selfdrive.hardware.pc.hardware import Pc
EON = os.path.isfile('/EON')
TICI = os.path.isfile('/TICI')
PC = not (EON or TICI)
if EON:
HARDWARE = cast(HardwareBase, Android())
elif TICI:
HARDWARE = cast(HardwareBase, Tici())
else:
HARDWARE = cast(HardwareBase, Pc())

View File

@ -6,7 +6,7 @@ import struct
import subprocess
from cereal import log
from common.hardware_base import HardwareBase
from selfdrive.hardware.base import HardwareBase
NetworkType = log.ThermalData.NetworkType
NetworkStrength = log.ThermalData.NetworkStrength

View File

View File

@ -1,17 +1,7 @@
import os
import random
from typing import cast
from cereal import log
from common.hardware_android import Android
from common.hardware_tici import Tici
from common.hardware_base import HardwareBase
EON = os.path.isfile('/EON')
TICI = os.path.isfile('/TICI')
PC = not (EON or TICI)
ANDROID = EON
from selfdrive.hardware.base import HardwareBase
NetworkType = log.ThermalData.NetworkType
NetworkStrength = log.ThermalData.NetworkStrength
@ -71,11 +61,3 @@ class Pc(HardwareBase):
def get_current_power_draw(self):
return 0
if EON:
HARDWARE = cast(HardwareBase, Android())
elif TICI:
HARDWARE = cast(HardwareBase, Tici())
else:
HARDWARE = cast(HardwareBase, Pc())

View File

@ -1,7 +1,8 @@
from common.hardware_base import HardwareBase
from cereal import log
import subprocess
from cereal import log
from selfdrive.hardware.base import HardwareBase
NM = 'org.freedesktop.NetworkManager'
NM_CON_ACT = NM + '.Connection.Active'
NM_DEV_WL = NM + '.Device.Wireless'

View File

@ -0,0 +1,8 @@
# TODO: these are also defined in a header
# GPIO pin definitions
GPIO_HUB_RST_N = 30
GPIO_UBLOX_RST_N = 32
GPIO_UBLOX_SAFEBOOT_N = 33
GPIO_UBLOX_PWR_EN = 34
GPIO_STM_RST_N = 124
GPIO_STM_BOOT0 = 134

View File

@ -11,8 +11,8 @@ from pathlib import Path
from tqdm import trange
from common.params import Params
from common.hardware import EON, TICI
from common.timeout import Timeout
from selfdrive.hardware import EON, TICI
from selfdrive.test.helpers import with_processes
from selfdrive.loggerd.config import ROOT, CAMERA_FPS

View File

@ -10,9 +10,9 @@ import time
import traceback
from cereal import log
from common.hardware import HARDWARE
from common.api import Api
from common.params import Params
from selfdrive.hardware import HARDWARE
from selfdrive.loggerd.xattr_cache import getxattr, setxattr
from selfdrive.loggerd.config import ROOT
from selfdrive.swaglog import cloudlog

View File

@ -14,7 +14,7 @@ from selfdrive.swaglog import cloudlog, add_logentries_handler
from common.basedir import BASEDIR
from common.hardware import HARDWARE, ANDROID, PC
from selfdrive.hardware import HARDWARE, EON, PC
WEBCAM = os.getenv("WEBCAM") is not None
sys.path.append(os.path.join(BASEDIR, "pyextra"))
os.environ['BASEDIR'] = BASEDIR
@ -30,7 +30,7 @@ except FileExistsError:
except PermissionError:
print("WARNING: failed to make /dev/shm")
if ANDROID:
if EON:
os.chmod("/dev/shm", 0o777)
def unblock_stdout():
@ -157,7 +157,7 @@ from selfdrive.registration import register
from selfdrive.version import version, dirty
from selfdrive.loggerd.config import ROOT
from selfdrive.launcher import launcher
from common.apk import update_apks, pm_apply_packages, start_offroad
from selfdrive.hardware.eon.apk import update_apks, pm_apply_packages, start_offroad
ThermalStatus = cereal.log.ThermalData.ThermalStatus
@ -258,7 +258,7 @@ if not PC:
'dmonitoringmodeld',
]
if ANDROID:
if EON:
car_started_processes += [
'gpsd',
'rtshield',
@ -385,7 +385,7 @@ def kill_managed_process(name):
def cleanup_all_processes(signal, frame):
cloudlog.info("caught ctrl-c %s %s" % (signal, frame))
if ANDROID:
if EON:
pm_apply_packages('disable')
for name in list(running.keys()):
@ -433,7 +433,7 @@ def manager_init(should_register=True):
pass
# ensure shared libraries are readable by apks
if ANDROID:
if EON:
os.chmod(BASEDIR, 0o755)
os.chmod(os.path.join(BASEDIR, "cereal"), 0o755)
os.chmod(os.path.join(BASEDIR, "cereal", "libmessaging_shared.so"), 0o755)
@ -459,7 +459,7 @@ def manager_thread():
start_managed_process(p)
# start offroad
if ANDROID:
if EON:
pm_apply_packages('enable')
start_offroad()
@ -534,13 +534,6 @@ def uninstall():
HARDWARE.reboot(reason="recovery")
def main():
if ANDROID:
# the flippening!
os.system('LD_LIBRARY_PATH="" content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1')
# disable bluetooth
os.system('service call bluetooth_manager 8')
params = Params()
params.manager_start()
@ -572,7 +565,7 @@ def main():
if params.get("Passive") is None:
raise Exception("Passive must be set to continue")
if ANDROID:
if EON:
update_apks()
manager_init()
manager_prepare(spinner)

View File

@ -3,9 +3,10 @@
import os
import time
from common.hardware import TICI
from common.gpio import GPIO_HUB_RST_N, GPIO_STM_BOOT0, GPIO_STM_RST_N, gpio_init, gpio_set
from panda import BASEDIR, Panda, PandaDFU, build_st
from common.gpio import gpio_init, gpio_set
from selfdrive.hardware import TICI
from selfdrive.hardware.tici.pins import GPIO_HUB_RST_N, GPIO_STM_BOOT0, GPIO_STM_RST_N
from selfdrive.swaglog import cloudlog
def is_legacy_panda_reset():

View File

@ -2,13 +2,14 @@ import os
import json
from datetime import datetime, timedelta
from selfdrive.swaglog import cloudlog
from selfdrive.version import version, terms_version, training_version, get_git_commit, get_git_branch, get_git_remote
from common.hardware import HARDWARE
from common.api import api_get
from common.params import Params
from common.file_helpers import mkdirs_exists_ok
from common.basedir import PERSIST
from selfdrive.hardware import HARDWARE
from selfdrive.swaglog import cloudlog
from selfdrive.version import version, terms_version, training_version, get_git_commit, \
get_git_branch, get_git_remote
def register():

View File

@ -3,8 +3,8 @@ import subprocess
from functools import wraps
from nose.tools import nottest
from common.hardware import PC
from common.apk import update_apks, start_offroad, pm_apply_packages, android_packages
from selfdrive.hardware.eon.apk import update_apks, start_offroad, pm_apply_packages, android_packages
from selfdrive.hardware import PC
from selfdrive.version import training_version, terms_version
from selfdrive.manager import start_managed_process, kill_managed_process, get_running

View File

@ -5,10 +5,7 @@ import time
from typing import Any
from tqdm import tqdm
from common.hardware import ANDROID
os.environ['CI'] = "1"
if ANDROID:
os.environ['QCOM_REPLAY'] = "1"
os.environ['QCOM_REPLAY'] = '1'
from common.spinner import Spinner
from common.timeout import Timeout

View File

@ -5,8 +5,8 @@ import subprocess
from cereal import log, car
import cereal.messaging as messaging
from selfdrive.test.helpers import phone_only, with_processes
from common.hardware import HARDWARE
from common.realtime import DT_CTRL
from selfdrive.hardware import HARDWARE
AudibleAlert = car.CarControl.HUDControl.AudibleAlert

View File

@ -4,9 +4,9 @@ import time
from statistics import mean
from cereal import log
from common.realtime import sec_since_boot
from common.params import Params, put_nonblocking
from common.hardware import HARDWARE
from common.realtime import sec_since_boot
from selfdrive.hardware import HARDWARE
from selfdrive.swaglog import cloudlog
CAR_VOLTAGE_LOW_PASS_K = 0.091 # LPF gain for 5s tau (dt/tau / (dt/tau + 1))

View File

@ -11,11 +11,11 @@ from smbus2 import SMBus
import cereal.messaging as messaging
from cereal import log
from common.filter_simple import FirstOrderFilter
from common.hardware import EON, HARDWARE, TICI
from common.numpy_fast import clip, interp
from common.params import Params
from common.realtime import DT_TRML, sec_since_boot
from selfdrive.controls.lib.alertmanager import set_offroad_alert
from selfdrive.hardware import EON, HARDWARE, TICI
from selfdrive.loggerd.config import get_available_percent
from selfdrive.pandad import get_expected_signature
from selfdrive.swaglog import cloudlog

View File

@ -34,9 +34,9 @@ import threading
from pathlib import Path
from typing import List, Tuple, Optional
from common.hardware import ANDROID, TICI
from common.basedir import BASEDIR
from common.params import Params
from selfdrive.hardware import EON, TICI
from selfdrive.swaglog import cloudlog
from selfdrive.controls.lib.alertmanager import set_offroad_alert
@ -292,7 +292,7 @@ def fetch_update(wait_helper: WaitTimeHelper) -> bool:
]
cloudlog.info("git reset success: %s", '\n'.join(r))
if ANDROID:
if EON:
handle_neos_update(wait_helper)
# Create the finalized, ready-to-swap update
@ -312,10 +312,10 @@ def main():
# TODO: enable this before 0.8.1 release
#leon = "letv" in open("/proc/cmdline").read()
#if ANDROID and not leon:
#if EON and not leon:
# raise RuntimeError("updates are disabled due to device deprecation")
if ANDROID and os.geteuid() != 0:
if EON and os.geteuid() != 0:
raise RuntimeError("updated must be launched as root!")
# Set low io priority

View File

@ -1,7 +1,7 @@
import json
import os
from common.hardware import PC
from common.file_helpers import mkdirs_exists_ok
from selfdrive.hardware import PC
class MissingAuthConfigError(Exception):