feat: add seat firmware workbench and OTA delivery

This commit is contained in:
vee
2026-09-16 17:55:30 +08:00
parent 3eeca2ea75
commit ab8e43050c
70 changed files with 22594 additions and 316 deletions
@@ -0,0 +1,155 @@
#ifndef SEAT_BACKREST_HEATER_CONFIG_H
#define SEAT_BACKREST_HEATER_CONFIG_H
#include "cy_project.h"
#include "cy_device_headers.h"
/*
* Schematic-confirmed backrest-heater path:
* P16.7 / KBJRD -> R126 (1 kOhm) -> BTS7010-1EPA IN -> backrest heater.
* The rev_d SDK maps P16.7 to TCPWM1 line 65.
*/
#define SEAT_BACKREST_HEATER_PWM_PORT GPIO_PRT16
#define SEAT_BACKREST_HEATER_PWM_PIN (7u)
#define SEAT_BACKREST_HEATER_PWM_GPIO_HSIOM P16_7_GPIO
#define SEAT_BACKREST_HEATER_PWM_HSIOM P16_7_TCPWM1_LINE65
#define SEAT_BACKREST_HEATER_PWM_TCPWM TCPWM1_GRP0_CNT65
#define SEAT_BACKREST_HEATER_PWM_PCLK PCLK_TCPWM1_CLOCKS65
#define SEAT_BACKREST_HEATER_PWM_DIVIDER_NUMBER (3u)
#define SEAT_BACKREST_HEATER_COUNTER_CLOCK_HZ (2000000u)
#define SEAT_BACKREST_HEATER_PWM_FREQUENCY_HZ (100u)
#define SEAT_BACKREST_HEATER_PWM_PERIOD_TICKS \
(SEAT_BACKREST_HEATER_COUNTER_CLOCK_HZ / \
SEAT_BACKREST_HEATER_PWM_FREQUENCY_HZ)
/* Three open-loop power levels. Tune only after thermal validation. */
#define SEAT_BACKREST_HEATER_LOW_DUTY_PERCENT (30u)
#define SEAT_BACKREST_HEATER_MEDIUM_DUTY_PERCENT (60u)
#define SEAT_BACKREST_HEATER_HIGH_DUTY_PERCENT (90u)
#define SEAT_BACKREST_HEATER_DEFAULT_LEVEL (0u)
#define SEAT_BACKREST_HEATER_TASK_PERIOD_US (1000u)
/*
* Do not sample at the 10 ms PWM period. Equal periods phase-lock the ADC
* to one PWM point and can report zero current continuously for a healthy
* low-duty heater. Seven milliseconds walks through every PWM phase while
* remaining slow enough for the existing SAR ADC service.
*/
#define SEAT_BACKREST_HEATER_SENSE_SAMPLE_MS (7u)
#define SEAT_BACKREST_HEATER_SENSE_MAX_ERRORS (3u)
#define SEAT_BACKREST_HEATER_MAX_ACTIVE_TIME_MS (600000u)
/*
* Vehicle CAN4 wiring proven by D:\wcl\can and Seat_Fan_demo:
* P3.7 RX, P3.6 TX, P3.1 high enables the board TJA1044 circuit.
*/
#define SEAT_BACKREST_HEATER_CAN_TYPE CY_CANFD1_2_TYPE
#define SEAT_BACKREST_HEATER_CAN_RX_PORT GPIO_PRT3
#define SEAT_BACKREST_HEATER_CAN_RX_PIN (7u)
#define SEAT_BACKREST_HEATER_CAN_RX_MUX P3_7_CANFD1_TTCAN_RX2
#define SEAT_BACKREST_HEATER_CAN_TX_PORT GPIO_PRT3
#define SEAT_BACKREST_HEATER_CAN_TX_PIN (6u)
#define SEAT_BACKREST_HEATER_CAN_TX_MUX P3_6_CANFD1_TTCAN_TX2
#define SEAT_BACKREST_HEATER_CAN_TRANSCEIVER_PORT GPIO_PRT3
#define SEAT_BACKREST_HEATER_CAN_TRANSCEIVER_PIN (1u)
#define SEAT_BACKREST_HEATER_CAN_TRANSCEIVER_GPIO_HSIOM P3_1_GPIO
#define SEAT_BACKREST_HEATER_CAN_TRANSCEIVER_ENABLE (1u)
#define SEAT_BACKREST_HEATER_CAN_PCLK PCLK_CANFD1_CLOCK_CAN2
#define SEAT_BACKREST_HEATER_CAN_IRQN canfd_1_interrupts0_2_IRQn
#define SEAT_BACKREST_HEATER_CAN_CPU_IRQ CPUIntIdx2_IRQn
#define SEAT_BACKREST_HEATER_CAN_DIVIDER_NUMBER (0u)
#define SEAT_BACKREST_HEATER_CAN_CLOCK_HZ (40000000u)
#define SEAT_BACKREST_HEATER_CAN_TX_BUFFER_COUNT (4u)
#define SEAT_BACKREST_HEATER_CAN_RX_FIFO0_ELEMENTS (8u)
#define SEAT_BACKREST_HEATER_CAN_RX_QUEUE_DEPTH (8u)
/* Classic CAN matrix messages, 11-bit IDs, 8-byte payloads, Intel bit order. */
#define SEAT_BACKREST_HEATER_CAN_CONTROL_29E_ID (0x29Eu)
#define SEAT_BACKREST_HEATER_CAN_CONFIG_2AA_ID (0x2AAu)
#define SEAT_BACKREST_HEATER_CAN_MODE_3CE_ID (0x3CEu)
#define SEAT_BACKREST_HEATER_CAN_SWITCH_42A_ID (0x42Au)
#define SEAT_BACKREST_HEATER_CAN_FEEDBACK_4FA_ID (0x4FAu)
#define SEAT_BACKREST_HEATER_CAN_DLC (8u)
#define SEAT_BACKREST_HEATER_CAN_FEEDBACK_PERIOD_MS (100u)
#define SEAT_BACKREST_HEATER_CAN_ACCEPT_42A_COMMAND (1u)
#define SEAT_BACKREST_HEATER_DEFAULT_CAN_GEAR (2u)
/* Safety watchdog and retained C-SPY session latch, derived from Seat_Fan_demo. */
#define SEAT_BACKREST_HEATER_WDT_TIMEOUT_TICKS (3200u)
#define SEAT_BACKREST_HEATER_DEBUG_BREG_INDEX (3u)
#define SEAT_BACKREST_HEATER_DEBUG_ACTIVE_MAGIC (0x48444247u) /* "HDBG" */
#define SEAT_BACKREST_HEATER_DEBUG_EXIT_MAGIC (0x484F4646u) /* "HOFF" */
/*
* Schematic-confirmed diagnostic current-sense path:
* KBJRD-AD -> P12.2 / ADC[1]_6. The BTS7010 IS pin uses a 1.2 kOhm
* sense resistor and the schematic annotates K=5000. The calculated current
* is for bench visibility only; production thresholds require calibration.
*/
#define SEAT_BACKREST_HEATER_SENSE_ENABLE (1u)
#define SEAT_BACKREST_HEATER_SENSE_PORT GPIO_PRT12
#define SEAT_BACKREST_HEATER_SENSE_PIN (2u)
#define SEAT_BACKREST_HEATER_SENSE_GPIO_HSIOM P12_2_GPIO
#define SEAT_BACKREST_HEATER_SENSE_RESISTOR_OHM (1200u)
#define SEAT_BACKREST_HEATER_SENSE_KILIS (5000u)
/* BTS7010 control facts confirmed on the power-driver schematic page. */
#define SEAT_BACKREST_HEATER_BTS7010_IN_ACTIVE_HIGH (1u)
#define SEAT_BACKREST_HEATER_BTS7010_DEN_MCU_CONTROLLED (0u)
#if !defined(CYT4BFBCJE) || !defined(CY_MCU_rev_d)
#error "Seat_Controller_demo requires CYT4BFBCJE rev_d headers."
#endif
#if ((SEAT_BACKREST_HEATER_COUNTER_CLOCK_HZ % \
SEAT_BACKREST_HEATER_PWM_FREQUENCY_HZ) != 0u)
#error "The heater counter clock must divide evenly by the PWM frequency."
#endif
#if ((SEAT_BACKREST_HEATER_PWM_PERIOD_TICKS == 0u) || \
(SEAT_BACKREST_HEATER_PWM_PERIOD_TICKS > 65535u))
#error "The heater PWM period does not fit TCPWM1 group 0 counter 65."
#endif
#if ((SEAT_BACKREST_HEATER_LOW_DUTY_PERCENT == 0u) || \
(SEAT_BACKREST_HEATER_LOW_DUTY_PERCENT >= \
SEAT_BACKREST_HEATER_MEDIUM_DUTY_PERCENT) || \
(SEAT_BACKREST_HEATER_MEDIUM_DUTY_PERCENT >= \
SEAT_BACKREST_HEATER_HIGH_DUTY_PERCENT) || \
(SEAT_BACKREST_HEATER_HIGH_DUTY_PERCENT > 100u))
#error "Heater duties must be ordered LOW < MEDIUM < HIGH <= 100."
#endif
#if (SEAT_BACKREST_HEATER_DEFAULT_LEVEL > 3u)
#error "Default heater level must be 0 (off) through 3 (high)."
#endif
#if ((SEAT_BACKREST_HEATER_CAN_CONTROL_29E_ID > 0x7FFu) || \
(SEAT_BACKREST_HEATER_CAN_CONFIG_2AA_ID > 0x7FFu) || \
(SEAT_BACKREST_HEATER_CAN_MODE_3CE_ID > 0x7FFu) || \
(SEAT_BACKREST_HEATER_CAN_SWITCH_42A_ID > 0x7FFu) || \
(SEAT_BACKREST_HEATER_CAN_FEEDBACK_4FA_ID > 0x7FFu))
#error "Seat heating CAN IDs must be 11-bit standard identifiers."
#endif
#if (SEAT_BACKREST_HEATER_CAN_RX_QUEUE_DEPTH < 5u)
#error "The heater CAN receive queue must hold at least five frames."
#endif
#if ((SEAT_BACKREST_HEATER_DEFAULT_CAN_GEAR == 0u) || \
(SEAT_BACKREST_HEATER_DEFAULT_CAN_GEAR > 3u))
#error "Default heater CAN gear must be in the range 1 through 3."
#endif
#if ((SEAT_BACKREST_HEATER_SENSE_SAMPLE_MS == 0u) || \
(SEAT_BACKREST_HEATER_SENSE_MAX_ERRORS == 0u) || \
(SEAT_BACKREST_HEATER_MAX_ACTIVE_TIME_MS == 0u))
#error "Heater sample period and maximum active time must be non-zero."
#endif
#if (SEAT_BACKREST_HEATER_DEBUG_BREG_INDEX >= SRSS_BACKUP_NUM_BREG)
#error "The selected heater backup register is not present on this device."
#endif
#endif /* SEAT_BACKREST_HEATER_CONFIG_H */
@@ -0,0 +1,71 @@
#ifndef SEAT_CURRENT_ADC_CONFIG_H
#define SEAT_CURRENT_ADC_CONFIG_H
#include "cy_project.h"
#include "cy_device_headers.h"
/*
* PASS0 SAR1 is shared by all seat-current measurements. The schematic
* connects VREFH and the DRV8718 AREF rail to filtered 5 V, so raw-to-voltage
* calculations must use 5000 mV rather than the GPIO-domain 3.3 V supply.
*
* Logical motor mapping:
* M0 horizontal : ZYTTKZDY-AD, P10.6, ADC[1]_2
* M1 seat pan : JXBKZDY-AD, P12.1, ADC[1]_5
* M2 backrest : ZYKBKZDY-AD, P10.7, ADC[1]_3
* M3 legrest : ZYGDKZDY-AD, P10.5, ADC[1]_1
* heater current : KBJRD-AD, P12.2, ADC[1]_6
* fan current : FSDY-AD, P12.6, ADC[1]_10
*/
#define SEAT_CURRENT_ADC_INSTANCE PASS0_SAR1
#define SEAT_CURRENT_ADC_PCLK PCLK_PASS0_CLOCK_SAR1
#define SEAT_CURRENT_ADC_DIVIDER_NUMBER (4u)
#define SEAT_CURRENT_ADC_REFERENCE_MV (5000u)
#define SEAT_CURRENT_ADC_FULL_SCALE (4095u)
#define SEAT_CURRENT_ADC_OPERATION_FREQ_MAX_HZ (13340000u)
#define SEAT_CURRENT_ADC_SAMPLE_TIME_MIN_NS (600ull)
#define SEAT_CURRENT_ADC_POLL_TIMEOUT (100000u)
#define SEAT_CURRENT_M0_PORT GPIO_PRT10
#define SEAT_CURRENT_M0_PIN (6u)
#define SEAT_CURRENT_M0_GPIO_HSIOM P10_6_GPIO
#define SEAT_CURRENT_M0_CHANNEL PASS0_SAR1_CH2
#define SEAT_CURRENT_M0_PIN_ADDRESS CY_ADC_PIN_ADDRESS_AN2
#define SEAT_CURRENT_M1_PORT GPIO_PRT12
#define SEAT_CURRENT_M1_PIN (1u)
#define SEAT_CURRENT_M1_GPIO_HSIOM P12_1_GPIO
#define SEAT_CURRENT_M1_CHANNEL PASS0_SAR1_CH5
#define SEAT_CURRENT_M1_PIN_ADDRESS CY_ADC_PIN_ADDRESS_AN5
#define SEAT_CURRENT_M2_PORT GPIO_PRT10
#define SEAT_CURRENT_M2_PIN (7u)
#define SEAT_CURRENT_M2_GPIO_HSIOM P10_7_GPIO
#define SEAT_CURRENT_M2_CHANNEL PASS0_SAR1_CH3
#define SEAT_CURRENT_M2_PIN_ADDRESS CY_ADC_PIN_ADDRESS_AN3
#define SEAT_CURRENT_M3_PORT GPIO_PRT10
#define SEAT_CURRENT_M3_PIN (5u)
#define SEAT_CURRENT_M3_GPIO_HSIOM P10_5_GPIO
#define SEAT_CURRENT_M3_CHANNEL PASS0_SAR1_CH1
#define SEAT_CURRENT_M3_PIN_ADDRESS CY_ADC_PIN_ADDRESS_AN1
#define SEAT_CURRENT_HEATER_PORT GPIO_PRT12
#define SEAT_CURRENT_HEATER_PIN (2u)
#define SEAT_CURRENT_HEATER_GPIO_HSIOM P12_2_GPIO
#define SEAT_CURRENT_HEATER_CHANNEL PASS0_SAR1_CH6
#define SEAT_CURRENT_HEATER_PIN_ADDRESS CY_ADC_PIN_ADDRESS_AN6
#define SEAT_CURRENT_FAN_PORT GPIO_PRT12
#define SEAT_CURRENT_FAN_PIN (6u)
#define SEAT_CURRENT_FAN_GPIO_HSIOM P12_6_GPIO
#define SEAT_CURRENT_FAN_CHANNEL PASS0_SAR1_CH10
#define SEAT_CURRENT_FAN_PIN_ADDRESS CY_ADC_PIN_ADDRESS_AN10
#define SEAT_CURRENT_ADC_PORT_ADDRESS CY_ADC_PORT_ADDRESS_SARMUX0
#if !defined(CYT4BFBCJE) || !defined(CY_MCU_rev_d)
#error "Seat current ADC mapping requires CYT4BFBCJE rev_d headers."
#endif
#endif /* SEAT_CURRENT_ADC_CONFIG_H */
@@ -0,0 +1,139 @@
#ifndef SEAT_FAN_CONFIG_H
#define SEAT_FAN_CONFIG_H
#include "cy_project.h"
#include "cy_device_headers.h"
/*
* Backrest fan:
* P11.1 -> KBFSDY-PWM-IN -> BTS7030 IN0 -> backrest fan.
* The schematic name "PWM0-60" maps to TCPWM1 group 0 counter 60 in SDL.
*/
#define SEAT_FAN_PWM_PORT GPIO_PRT11
#define SEAT_FAN_PWM_PIN (1u)
#define SEAT_FAN_PWM_GPIO_HSIOM P11_1_GPIO
#define SEAT_FAN_PWM_HSIOM P11_1_TCPWM1_LINE60
#define SEAT_FAN_PWM_TCPWM TCPWM1_GRP0_CNT60
#define SEAT_FAN_PWM_PCLK PCLK_TCPWM1_CLOCKS60
/*
* Seat-cushion fan output is unused in this first version and must stay low:
* P11.2 -> ZDFSDY-PWM-IN.
*/
#define SEAT_FAN_UNUSED_PORT GPIO_PRT11
#define SEAT_FAN_UNUSED_PIN (2u)
#define SEAT_FAN_UNUSED_GPIO_HSIOM P11_2_GPIO
#define SEAT_FAN_PWM_DIVIDER_NUMBER (0u)
#define SEAT_FAN_COUNTER_CLOCK_HZ (2000000u)
#define SEAT_FAN_PWM_FREQUENCY_HZ (100u)
#define SEAT_FAN_PWM_PERIOD_TICKS \
(SEAT_FAN_COUNTER_CLOCK_HZ / SEAT_FAN_PWM_FREQUENCY_HZ)
#define SEAT_FAN_STARTUP_DUTY_PERCENT (100u)
#define SEAT_FAN_RUNNING_DUTY_PERCENT (70u)
#define SEAT_FAN_STARTUP_TIME_US (2000000u)
#define SEAT_FAN_DEBUG_POLL_TIME_US (1000u)
#define SEAT_FAN_WDT_TIMEOUT_TICKS (3200u)
/* CAN-controlled application timing and the three physical fan levels. */
#define SEAT_FAN_TASK_PERIOD_US (1000u)
#define SEAT_FAN_STARTUP_TIME_MS (SEAT_FAN_STARTUP_TIME_US / 1000u)
#define SEAT_FAN_GEAR1_DUTY_PERCENT (50u)
#define SEAT_FAN_GEAR2_DUTY_PERCENT (70u)
#define SEAT_FAN_GEAR3_DUTY_PERCENT (100u)
#define SEAT_FAN_DEFAULT_GEAR (2u)
/*
* Vehicle CAN4 wiring proven by D:\wcl\can:
* P3.7 RX, P3.6 TX, P3.1 high enables the board TJA1044 circuit.
*/
#define SEAT_FAN_CAN_TYPE CY_CANFD1_2_TYPE
#define SEAT_FAN_CAN_RX_PORT GPIO_PRT3
#define SEAT_FAN_CAN_RX_PIN (7u)
#define SEAT_FAN_CAN_RX_MUX P3_7_CANFD1_TTCAN_RX2
#define SEAT_FAN_CAN_TX_PORT GPIO_PRT3
#define SEAT_FAN_CAN_TX_PIN (6u)
#define SEAT_FAN_CAN_TX_MUX P3_6_CANFD1_TTCAN_TX2
#define SEAT_FAN_CAN_TRANSCEIVER_PORT GPIO_PRT3
#define SEAT_FAN_CAN_TRANSCEIVER_PIN (1u)
#define SEAT_FAN_CAN_TRANSCEIVER_GPIO_HSIOM P3_1_GPIO
#define SEAT_FAN_CAN_TRANSCEIVER_ENABLE (1u)
#define SEAT_FAN_CAN_PCLK PCLK_CANFD1_CLOCK_CAN2
#define SEAT_FAN_CAN_IRQN canfd_1_interrupts0_2_IRQn
#define SEAT_FAN_CAN_CPU_IRQ CPUIntIdx2_IRQn
#define SEAT_FAN_CAN_DIVIDER_NUMBER (0u)
#define SEAT_FAN_CAN_CLOCK_HZ (40000000u)
#define SEAT_FAN_CAN_TX_BUFFER_COUNT (4u)
#define SEAT_FAN_CAN_RX_FIFO0_ELEMENTS (8u)
#define SEAT_FAN_CAN_RX_QUEUE_DEPTH (8u)
/* Classic CAN matrix messages, 11-bit IDs, 8-byte payloads, Intel bit order. */
#define SEAT_FAN_CAN_CONTROL_29E_ID (0x29Eu)
#define SEAT_FAN_CAN_CONFIG_2AA_ID (0x2AAu)
#define SEAT_FAN_CAN_SWITCH_42A_ID (0x42Au)
#define SEAT_FAN_CAN_FEEDBACK_4FA_ID (0x4FAu)
#define SEAT_FAN_CAN_DLC (8u)
#define SEAT_FAN_CAN_FEEDBACK_PERIOD_MS (100u)
#define SEAT_FAN_CAN_ACCEPT_42A_COMMAND (1u)
/* FSDY-AD is P12.6 / ADC[1]_10 on the shared seat-current ADC. */
#define SEAT_FAN_CURRENT_SAMPLE_MS (10u)
/*
* BREG3 retains the debug-session state through debug/XRES/WDT resets.
* DEBUG_ACTIVE is written by firmware as soon as it observes C_DEBUGEN, so a
* debugger-induced reset cannot accidentally restart the fan even if the
* C-SPY exit hook was skipped. DEBUG_EXIT is written when detach is observed
* or by the C-SPY exit hook. A genuine POR releases either marker.
*/
#define SEAT_FAN_DEBUG_SESSION_BREG_INDEX (3u)
#define SEAT_FAN_DEBUG_ACTIVE_MAGIC (0x44424741u) /* ASCII "DBGA" */
#define SEAT_FAN_DEBUG_EXIT_MAGIC (0x5346414Eu) /* ASCII "SFAN" */
#if !defined(CYT4BFBCJE) || !defined(CY_MCU_rev_d)
#error "Seat_Controller_demo must be built for CYT4BFBCJE with the rev_d headers."
#endif
#if ((SEAT_FAN_COUNTER_CLOCK_HZ % SEAT_FAN_PWM_FREQUENCY_HZ) != 0u)
#error "The TCPWM counter clock must divide evenly by the requested PWM frequency."
#endif
#if ((SEAT_FAN_PWM_PERIOD_TICKS == 0u) || (SEAT_FAN_PWM_PERIOD_TICKS > 65535u))
#error "The PWM period does not fit TCPWM1 group 0 counter 60."
#endif
#if ((SEAT_FAN_STARTUP_TIME_US % SEAT_FAN_DEBUG_POLL_TIME_US) != 0u)
#error "The startup duration must be an integer number of debug polling periods."
#endif
#if ((SEAT_FAN_STARTUP_TIME_US % 1000u) != 0u)
#error "The fan startup time must be an integer number of milliseconds."
#endif
#if ((SEAT_FAN_GEAR1_DUTY_PERCENT > SEAT_FAN_GEAR2_DUTY_PERCENT) || \
(SEAT_FAN_GEAR2_DUTY_PERCENT > SEAT_FAN_GEAR3_DUTY_PERCENT) || \
(SEAT_FAN_GEAR3_DUTY_PERCENT > 100u))
#error "Fan gear duty percentages must be monotonic and no greater than 100."
#endif
#if ((SEAT_FAN_DEFAULT_GEAR == 0u) || (SEAT_FAN_DEFAULT_GEAR > 3u))
#error "The default physical fan gear must be in the range 1 through 3."
#endif
#if ((SEAT_FAN_CAN_CONTROL_29E_ID > 0x7FFu) || \
(SEAT_FAN_CAN_CONFIG_2AA_ID > 0x7FFu) || \
(SEAT_FAN_CAN_SWITCH_42A_ID > 0x7FFu) || \
(SEAT_FAN_CAN_FEEDBACK_4FA_ID > 0x7FFu))
#error "Seat ventilation CAN IDs must be 11-bit standard identifiers."
#endif
#if (SEAT_FAN_CAN_RX_QUEUE_DEPTH < 4u)
#error "The CAN receive queue must hold at least four frames."
#endif
#if (SEAT_FAN_DEBUG_SESSION_BREG_INDEX >= SRSS_BACKUP_NUM_BREG)
#error "The selected backup register is not present on this device."
#endif
#endif /* SEAT_FAN_CONFIG_H */
@@ -0,0 +1,150 @@
#ifndef SEAT_MOVE_CONFIG_H
#define SEAT_MOVE_CONFIG_H
#include "cy_project.h"
#include "cy_device_headers.h"
/* This configuration is intentionally tied to the timed-only IAR target. */
#if !defined(PASSENGER_SEAT_TIMED_ONLY)
#error "Build this source only from Passenger_Seat_Timed_Controller_demo."
#endif
#define SEAT_MOVE_MOTOR_COUNT (4u)
#define SEAT_MOVE_ACTIVE_MOTOR_MASK (0x0Fu)
#define SEAT_MOVE_TASK_PERIOD_US (1000u)
#define SEAT_MOVE_START_STAGGER_MS (100u)
#define SEAT_MOVE_MAX_CONCURRENT_MOTORS (4u)
/* Timed-only CAN limits. ParamA is duration in ms. */
#define SEAT_TIMED_MIN_DURATION_MS (300u)
#define SEAT_TIMED_M0_MAX_DURATION_MS (30000u) /* horizontal */
#define SEAT_TIMED_M1_MAX_DURATION_MS (20000u) /* seat-pan */
#define SEAT_TIMED_M2_MAX_DURATION_MS (30000u) /* backrest */
#define SEAT_TIMED_M3_MAX_DURATION_MS (25000u) /* legrest */
#define SEAT_TIMED_LEVEL_MIN_X10 (300u)
#define SEAT_TIMED_LEVEL_MAX_X10 (1000u)
/* Logical MotorID and connected DRV8718 channel are identical. */
#define SEAT_MOVE_LOGICAL_M0_PHYSICAL_MODE (0u)
#define SEAT_MOVE_LOGICAL_M1_PHYSICAL_MODE (1u)
#define SEAT_MOVE_LOGICAL_M2_PHYSICAL_MODE (2u)
#define SEAT_MOVE_LOGICAL_M3_PHYSICAL_MODE (3u)
/* Retained by the verified motor manager; timed requests provide duty. */
#define SEAT_MOVE_M0_DEFAULT_TIMEOUT_MS (12000u)
#define SEAT_MOVE_M1_DEFAULT_TIMEOUT_MS (8000u)
#define SEAT_MOVE_M2_DEFAULT_TIMEOUT_MS (12000u)
#define SEAT_MOVE_M3_DEFAULT_TIMEOUT_MS (30000u)
#define SEAT_MOVE_M0_DEFAULT_DUTY_PERCENT (90u)
#define SEAT_MOVE_M1_DEFAULT_DUTY_PERCENT (90u)
#define SEAT_MOVE_M2_DEFAULT_DUTY_PERCENT (90u)
#define SEAT_MOVE_M3_DEFAULT_DUTY_PERCENT (50u)
#define SEAT_MOVE_M3_BREAKAWAY_DUTY_PERCENT (50u)
#define SEAT_MOVE_POSITION_TARGET_HALL_TOLERANCE (4u)
/* CAN4, classic CAN, 500 kbit/s. */
#define SEAT_MOVE_CAN_TYPE CY_CANFD1_2_TYPE
#define SEAT_MOVE_CAN_RX_PORT GPIO_PRT3
#define SEAT_MOVE_CAN_RX_PIN (7u)
#define SEAT_MOVE_CAN_RX_MUX P3_7_CANFD1_TTCAN_RX2
#define SEAT_MOVE_CAN_TX_PORT GPIO_PRT3
#define SEAT_MOVE_CAN_TX_PIN (6u)
#define SEAT_MOVE_CAN_TX_MUX P3_6_CANFD1_TTCAN_TX2
#define SEAT_MOVE_CAN_TRANSCEIVER_PORT GPIO_PRT3
#define SEAT_MOVE_CAN_TRANSCEIVER_PIN (1u)
#define SEAT_MOVE_CAN_TRANSCEIVER_GPIO_HSIOM P3_1_GPIO
#define SEAT_MOVE_CAN_TRANSCEIVER_ENABLE (1u)
#define SEAT_MOVE_CAN_PCLK PCLK_CANFD1_CLOCK_CAN2
#define SEAT_MOVE_CAN_IRQN canfd_1_interrupts0_2_IRQn
#define SEAT_MOVE_CAN_CPU_IRQ CPUIntIdx2_IRQn
#define SEAT_MOVE_CAN_DIVIDER_NUMBER (0u)
#define SEAT_MOVE_CAN_CLOCK_HZ (40000000u)
#define SEAT_MOVE_CAN_TX_BUFFER_COUNT (8u)
#define SEAT_MOVE_CAN_RX_FIFO0_ELEMENTS (8u)
#define SEAT_MOVE_CAN_RX_QUEUE_DEPTH (16u)
#define SEAT_MOVE_CAN_DLC (8u)
#define SEAT_MOVE_CAN_PROTOCOL_VERSION (1u)
#define SEAT_MOVE_CAN_COMMAND_ID (0x300u)
#define SEAT_MOVE_CAN_SYSTEM_STATUS_ID (0x301u)
#define SEAT_MOVE_CAN_MOTOR_STATUS_ID (0x302u)
#define SEAT_MOVE_CAN_DIAGNOSTIC_ID (0x303u)
#define SEAT_MOVE_CAN_CURRENT_DIAGNOSTIC_ID (0x304u)
#define SEAT_MOVE_CAN_FIRMWARE_ID_ID (0x307u)
#define SEAT_MOVE_FIRMWARE_REVISION (15u)
#define SEAT_MOVE_FIRMWARE_BUILD_ID (17u)
#define SEAT_MOVE_SYSTEM_STATUS_PERIOD_MS (100u)
#define SEAT_MOVE_MOTOR_STATUS_POLL_MS (25u)
#define SEAT_MOVE_DIAGNOSTIC_POLL_MS (25u)
#define SEAT_MOVE_FIRMWARE_ID_PERIOD_MS (500u)
/* Current-aware stall detection remains active for timed movement. */
#define SEAT_MOVE_MOTOR_CURRENT_SAMPLE_MS (10u)
#define SEAT_MOVE_MOTOR_CURRENT_MAX_AGE_MS (100u)
#define SEAT_MOVE_MOTOR_CURRENT_BASELINE_FILTER_SHIFT (3u)
#define SEAT_MOVE_MOTOR_STALL_CURRENT_CONFIRM_MS (200u)
#define SEAT_MOVE_MOTOR_NO_MOTION_TIMEOUT_MS (5000u)
#define SEAT_MOVE_M0_STALL_CURRENT_DELTA_RAW (500u)
#define SEAT_MOVE_M1_STALL_CURRENT_DELTA_RAW (500u)
#define SEAT_MOVE_M2_STALL_CURRENT_DELTA_RAW (500u)
#define SEAT_MOVE_M3_STALL_CURRENT_DELTA_RAW (500u)
#define SEAT_MOVE_MOTOR_CURRENT_MAX_ERRORS (3u)
/* Debug-detach and watchdog safety. HIL registers remain internal to the
* reused safety manager; this image exposes no HIL CAN command/filter. */
#define SEAT_MOVE_DEBUG_SESSION_BREG_INDEX (3u)
#define SEAT_MOVE_DEBUG_ACTIVE_MAGIC (0x4D4F5641u)
#define SEAT_MOVE_DEBUG_EXIT_MAGIC (0x4D4F5645u)
#define SEAT_MOVE_WDT_TIMEOUT_TICKS (3200u)
#define SEAT_MOVE_HIL_WDT_MAGIC_BREG_INDEX (0u)
#define SEAT_MOVE_HIL_WDT_TOKEN_BREG_INDEX (1u)
#define SEAT_MOVE_HIL_WDT_CHECK_BREG_INDEX (2u)
#define SEAT_MOVE_HIL_WDT_MARKER (0x48494C36u)
#if !defined(CYT4BFBCJE) || !defined(CY_MCU_rev_d)
#error "Timed passenger-seat firmware requires CYT4BFBCJE rev_d."
#endif
#if (SEAT_MOVE_ACTIVE_MOTOR_MASK != 0x0Fu)
#error "All four passenger-seat motor outputs must be enabled."
#endif
#if (SEAT_MOVE_MAX_CONCURRENT_MOTORS == 0u) || \
(SEAT_MOVE_MAX_CONCURRENT_MOTORS > SEAT_MOVE_MOTOR_COUNT)
#error "Concurrent motor budget must be between one and four."
#endif
#if ((SEAT_TIMED_MIN_DURATION_MS == 0u) || \
(SEAT_TIMED_M0_MAX_DURATION_MS > 65535u) || \
(SEAT_TIMED_M1_MAX_DURATION_MS > 65535u) || \
(SEAT_TIMED_M2_MAX_DURATION_MS > 65535u) || \
(SEAT_TIMED_M3_MAX_DURATION_MS > 65535u))
#error "Timed-command duration limits must fit ParamA."
#endif
#if ((SEAT_MOVE_CAN_COMMAND_ID > 0x7FFu) || \
(SEAT_MOVE_CAN_SYSTEM_STATUS_ID > 0x7FFu) || \
(SEAT_MOVE_CAN_MOTOR_STATUS_ID > 0x7FFu) || \
(SEAT_MOVE_CAN_DIAGNOSTIC_ID > 0x7FFu) || \
(SEAT_MOVE_CAN_CURRENT_DIAGNOSTIC_ID > 0x7FFu) || \
(SEAT_MOVE_CAN_FIRMWARE_ID_ID > 0x7FFu))
#error "Seat movement CAN identifiers must be 11-bit standard IDs."
#endif
#if (SEAT_MOVE_FIRMWARE_REVISION > 0x0Fu) || \
(SEAT_MOVE_FIRMWARE_BUILD_ID > 0xFFu)
#error "Firmware identity fields exceed their CAN encoding."
#endif
#if ((SEAT_MOVE_MOTOR_CURRENT_SAMPLE_MS == 0u) || \
(SEAT_MOVE_MOTOR_CURRENT_MAX_AGE_MS < \
SEAT_MOVE_MOTOR_CURRENT_SAMPLE_MS) || \
(SEAT_MOVE_MOTOR_STALL_CURRENT_CONFIRM_MS == 0u) || \
(SEAT_MOVE_MOTOR_NO_MOTION_TIMEOUT_MS <= \
SEAT_MOVE_MOTOR_STALL_CURRENT_CONFIRM_MS) || \
(SEAT_MOVE_MOTOR_CURRENT_MAX_ERRORS == 0u))
#error "Motor current/stall timing configuration is invalid."
#endif
#endif /* SEAT_MOVE_CONFIG_H */