Skip to content

Commit

Permalink
Merge branch 'commaai:master' into ccnc-port
Browse files Browse the repository at this point in the history
  • Loading branch information
royjr authored Jan 24, 2025
2 parents a1c3090 + 1290588 commit dfcc97b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 39 deletions.
35 changes: 15 additions & 20 deletions board/safety/safety_ford.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,42 +363,33 @@ static safety_config ford_init(uint16_t param) {
{.msg = {{FORD_DesiredTorqBrk, 0, 8, .frequency = 50U}, { 0 }, { 0 }}},
};

#define FORD_COMMON_TX_MSGS \
{FORD_Steering_Data_FD1, 0, 8}, \
{FORD_Steering_Data_FD1, 2, 8}, \
{FORD_ACCDATA_3, 0, 8}, \
{FORD_Lane_Assist_Data1, 0, 8}, \
{FORD_IPMA_Data, 0, 8}, \

static const CanMsg FORD_CANFD_LONG_TX_MSGS[] = {
{FORD_Steering_Data_FD1, 0, 8},
{FORD_Steering_Data_FD1, 2, 8},
FORD_COMMON_TX_MSGS
{FORD_ACCDATA, 0, 8},
{FORD_ACCDATA_3, 0, 8},
{FORD_Lane_Assist_Data1, 0, 8},
{FORD_LateralMotionControl2, 0, 8},
{FORD_IPMA_Data, 0, 8},
};

static const CanMsg FORD_CANFD_STOCK_TX_MSGS[] = {
{FORD_Steering_Data_FD1, 0, 8},
{FORD_Steering_Data_FD1, 2, 8},
{FORD_ACCDATA_3, 0, 8},
{FORD_Lane_Assist_Data1, 0, 8},
FORD_COMMON_TX_MSGS
{FORD_LateralMotionControl2, 0, 8},
{FORD_IPMA_Data, 0, 8},
};

static const CanMsg FORD_STOCK_TX_MSGS[] = {
{FORD_Steering_Data_FD1, 0, 8},
{FORD_Steering_Data_FD1, 2, 8},
{FORD_ACCDATA_3, 0, 8},
{FORD_Lane_Assist_Data1, 0, 8},
FORD_COMMON_TX_MSGS
{FORD_LateralMotionControl, 0, 8},
{FORD_IPMA_Data, 0, 8},
};

static const CanMsg FORD_LONG_TX_MSGS[] = {
{FORD_Steering_Data_FD1, 0, 8},
{FORD_Steering_Data_FD1, 2, 8},
FORD_COMMON_TX_MSGS
{FORD_ACCDATA, 0, 8},
{FORD_ACCDATA_3, 0, 8},
{FORD_Lane_Assist_Data1, 0, 8},
{FORD_LateralMotionControl, 0, 8},
{FORD_IPMA_Data, 0, 8},
};

UNUSED(param);
Expand All @@ -409,6 +400,9 @@ static safety_config ford_init(uint16_t param) {
ford_canfd = GET_FLAG(param, FORD_PARAM_CANFD);
#endif

// Longitudinal is the default for CAN, and optional for CAN FD w/ ALLOW_DEBUG
ford_longitudinal = !ford_canfd || ford_longitudinal;

safety_config ret;
// FIXME: cppcheck thinks that ford_canfd is always false. This is not true
// if ALLOW_DEBUG is defined but cppcheck is run without ALLOW_DEBUG
Expand All @@ -417,6 +411,7 @@ static safety_config ford_init(uint16_t param) {
ret = ford_longitudinal ? BUILD_SAFETY_CFG(ford_rx_checks, FORD_CANFD_LONG_TX_MSGS) : \
BUILD_SAFETY_CFG(ford_rx_checks, FORD_CANFD_STOCK_TX_MSGS);
} else {
// cppcheck-suppress knownConditionTrueFalse
ret = ford_longitudinal ? BUILD_SAFETY_CFG(ford_rx_checks, FORD_LONG_TX_MSGS) : \
BUILD_SAFETY_CFG(ford_rx_checks, FORD_STOCK_TX_MSGS);
}
Expand Down
4 changes: 2 additions & 2 deletions board/stm32h7/lladc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ static uint16_t adc_get_raw(uint8_t channel) {
ADC1->SQR1 &= ~(ADC_SQR1_L);
ADC1->SQR1 = (uint32_t)channel << 6U;

ADC1->SMPR1 = 0x2UL << (channel * 3UL);
ADC1->SMPR1 = 0x4UL << (channel * 3UL);
ADC1->PCSEL_RES0 = (0x1UL << channel);
ADC1->CFGR2 = (127UL << ADC_CFGR2_OVSR_Pos) | (0x7U << ADC_CFGR2_OVSS_Pos) | ADC_CFGR2_ROVSE;
ADC1->CFGR2 = (63UL << ADC_CFGR2_OVSR_Pos) | (0x6U << ADC_CFGR2_OVSS_Pos) | ADC_CFGR2_ROVSE;

ADC1->CR |= ADC_CR_ADSTART;
while (!(ADC1->ISR & ADC_ISR_EOC));
Expand Down
19 changes: 2 additions & 17 deletions tests/safety/test_ford.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class Buttons:


# Ford safety has four different configurations tested here:
# * CAN with stock longitudinal
# * CAN with openpilot longitudinal
# * CAN FD with stock longitudinal
# * CAN FD with openpilot longitudinal
Expand Down Expand Up @@ -355,21 +354,6 @@ def test_acc_buttons(self):
self.assertEqual(enabled, self._tx(self._acc_button_msg(Buttons.CANCEL, bus)))


class TestFordStockSafety(TestFordSafetyBase):
STEER_MESSAGE = MSG_LateralMotionControl

TX_MSGS = [
[MSG_Steering_Data_FD1, 0], [MSG_Steering_Data_FD1, 2], [MSG_ACCDATA_3, 0], [MSG_Lane_Assist_Data1, 0],
[MSG_LateralMotionControl, 0], [MSG_IPMA_Data, 0],
]

def setUp(self):
self.packer = CANPackerPanda("ford_lincoln_base_pt")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_FORD, 0)
self.safety.init_tests()


class TestFordCANFDStockSafety(TestFordSafetyBase):
STEER_MESSAGE = MSG_LateralMotionControl2

Expand Down Expand Up @@ -457,7 +441,8 @@ class TestFordLongitudinalSafety(TestFordLongitudinalSafetyBase):
def setUp(self):
self.packer = CANPackerPanda("ford_lincoln_base_pt")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_FORD, Panda.FLAG_FORD_LONG_CONTROL)
# Make sure we enforce long safety even without long flag for CAN
self.safety.set_safety_hooks(Panda.SAFETY_FORD, 0)
self.safety.init_tests()


Expand Down

0 comments on commit dfcc97b

Please sign in to comment.