/*
 * ckp_acquisition.h
 *
 *  Created on: May 5, 2026
 *      Author: herli
 *
 * Translates the CAN-supplied raw CKP offset (B_CKP_OFFSET, RW134 /
 * DAT_0134) into the ROM-equivalent runtime delta dCKP_OFFSET (DAT_0434)
 * and then into the canonical CKP zero-crossing offset CKP_ZERO_OFFSET
 * (DAT_0152). Mirrors ROM FUN_55e0 @ 0x55e0 → FUN_6a4b @ 0x6a4b.
 */

#ifndef ADVANCE_CONTROL_CKP_ACQUISITION_H_
#define ADVANCE_CONTROL_CKP_ACQUISITION_H_

#include <stdint.h>

/* Inputs */
extern int16_t  B_CKP_OFFSET;        /* RW134 / DAT_0134 — CAN raw input */
extern uint8_t  commitCKP_offset;    /* unused for now (commit gate hook) */

/* Internal RAM trims (DAT_0430 word, DAT_0404 signed byte). No runtime
 * writer was found in this ROM/car (project memory:
 * project_t06235_ckp_processing.md), so they sit at 0 unless a future
 * step wires them up. Exposed for diagnostic poking. */
extern int16_t  CKP_RAM_TRIM_0430;
extern int8_t   CKP_RAM_TRIM_0404;

/* Outputs */
extern int16_t  dCKP_OFFSET;         /* DAT_0434 — output of FUN_55e0 */
extern int16_t  CKP_ZERO_OFFSET;     /* DAT_0152 — output of FUN_6a4b */

/* Recompute dCKP_OFFSET from B_CKP_OFFSET (FUN_55e0), then recompute
 * CKP_ZERO_OFFSET (FUN_6a4b core derivation), then return
 * CKP_ZERO_OFFSET. The commit/flash-persist side-effects (FUN_56d8
 * sequence + DAT_01e7 bit-7) are stubbed via commitCKP_offset for a
 * future wiring step.
 */
int16_t get_ckp_zero(void);
uint8_t get_ckp_process_tooth(void);

#endif /* ADVANCE_CONTROL_CKP_ACQUISITION_H_ */
