If the current knock voltage is greater than the average knock voltage for the current cylinder plus the CYLINDER KNOCK VOLTAGE LIMIT for that cylinder at the curent RPM, the Knock Count is incremented, otherwise the weighted average knock voltage for that cylinder is updated.
Basically the ECU maintains a weighted average noise level (average knock voltage) for each cylinder, and when the noise from a cylinder goes above this level plus the "knock noise limit", knock is detected and the Knock Count is incremented.
If knock_adjustment indicates retarded timing, Knock Trim is then set based on knock_adjustment. If engine operation takes it outside the knock analysis zone, and the throttle is still open, Knock Trim is set to the average knock_adjustment while operating in the knock analysis zone.
Finally Knock Trim is checked against the previous adjustment to keep the maximum delta below MAX RETARD DELTA. It is then compared and limited to the knock retard limit from the KNOCK RETARD LIMIT table.
Note that Knock Trim is applied AFTER the IGN RETARD MAX limit is checked!
TPSITA occurs in 2 phases. The first phase is called "Tip-In Retard" and is based on TPS opening rate of change (dTPS). This reduces spark knock at throttle tip-in. The second phase is called "Tip-In dRPM Ignition Trim" and is based on RPM rate of change (dRPM). This helps maitain engine power while the RPM is fluctuating as the clutch is engaged.
There are a number of criteria that must be met to activate the "Tip-In Retard" phase. If ECT is at least MIN ECT, and vehicle speed is below MAX SPEED, and engine load is below either MAX MAF LOAD or MAX MAP LOAD (depending on the current load source), and the change in TPS percent is at least dTPS DEADBAND, and rpm is above MIN RPM, and no more than MAX RPM, and gear is below or equal MAX GEAR, the "Tip-In Retard" phase is initiated. This initializes the tpsita_decay_factor to its maximum value and starts the tpsita_timer. If the transmission is shifted above MAX GEAR, TPSITA is canceled.
This phase continues until tpsita_timer = DURATION TIMER, at which point TPS Trim is reset to 0.