Files
hpsg5-controller_v2-stm32g4/Core/Advance_Control/ckp_acquisition.h

45 lines
1.7 KiB
C

/*
* ckp_acquisition.h (variant/t06211/compact_src)
*
* CKP-zero acquisition chain for t06211. Mirrors ROM Stage-1 caller @
* 0x65c7 (LCALL FUN_6b67) → FUN_6b67 @ 0x6b67. Body verbatim from T06235;
* cal-field bindings differ — see pwm_addr_map / cal_offsets.py.
*/
#ifndef PWM_T06211_CKP_ACQUISITION_H
#define PWM_T06211_CKP_ACQUISITION_H
#include <stdint.h>
extern int16_t B_CKP_OFFSET;
extern uint8_t commitCKP_offset;
extern int16_t CKP_RAM_TRIM_0430;
extern int8_t CKP_RAM_TRIM_0404;
extern int16_t dCKP_OFFSET; /* DAT_0434 */
extern int16_t CKP_ZERO_OFFSET; /* DAT_0152 */
int16_t get_ckp_zero(void);
/* Get the next process-tooth index — mirrors the byte stored to R90
* in ROM FUN_6d4a @ 0x6d4a (analog of T06215 FUN_7293 / default
* FUN_87ea). Same body shape as T06215; the only difference is the
* cal slot for `ckp_advance_per_tick` (cal+0x124 in t06211 vs cal+0x12C
* in T06215). cal+0x124 is **aliased** with pi_high_clamp — same flash
* word, value 1707, used both as the PI Block-4 ceiling and the
* per-tick CKP angular advance.
*
* advanced = CKP_ZERO_OFFSET + ckp_advance_per_tick (16-bit ADD)
* tooth = (advanced >> 8) + 1 (byte INC of high)
* if (tooth > ckp_seg_wrap_threshold) (t06211: 29)
* tooth -= (ckp_modulus >> 8) (= 30 — angular wrap)
* else if (tooth > ckp_teeth_per_seg) (t06211: 26)
* tooth = 0 (hard reset)
* return tooth;
*
* No side-effects on CKP_ZERO_OFFSET or dCKP_OFFSET.
*/
uint8_t get_ckp_process_tooth(void);
#endif /* PWM_T06211_CKP_ACQUISITION_H */