main
John Lauer Compile read-only STM32 fan tach telemetry with stale-history expiry; preserve locked-off output 810c9b8
#include "../firmware/fan_tach.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
int main(void){
 fan_tach f;float rpm;fan_tach_init(&f);assert(!fan_tach_read(&f,0,&rpm));
 uint32_t t=0;fan_tach_edge(&f,t);
 for(int i=0;i<7;i++){t+=4286;fan_tach_edge(&f,t);assert(!fan_tach_read(&f,t,&rpm));}
 t+=4286;fan_tach_edge(&f,t);assert(fan_tach_read(&f,t,&rpm));assert(fabsf(rpm-7000)<1);
 assert(!fan_tach_read(&f,t+15001,&rpm)&&rpm==0); /* stale/stuck wire */
 t+=100;fan_tach_edge(&f,t);assert(!fan_tach_read(&f,t,&rpm)); /* glitch resets */
 for(int i=0;i<8;i++){t+=4286;fan_tach_edge(&f,t);}assert(fan_tach_read(&f,t,&rpm));
 t+=7000;fan_tach_edge(&f,t);assert(!fan_tach_read(&f,t,&rpm)); /* below window */
 fan_tach_init(&f);t=UINT32_MAX-1000;fan_tach_edge(&f,t);
 for(int i=0;i<8;i++){t+=4286;fan_tach_edge(&f,t);}assert(fan_tach_read(&f,t,&rpm)); /* wrap */
 uint32_t old=t;fan_tach_expire(&f,t+15001);assert(!f.seen);
 /* Same timer value after a complete wrap must not resurrect old RPM. */
 assert(!fan_tach_read(&f,old,&rpm));
 t+=20000;fan_tach_edge(&f,t);assert(!fan_tach_read(&f,t,&rpm));
 for(int i=0;i<8;i++){t+=4286;fan_tach_edge(&f,t);}assert(fan_tach_read(&f,t,&rpm));
 puts("fan_tach: qualification, RPM, stale input, noise, slow fan, timer wrap and stale-history expiry passed");
}