+#endif
+
+ /* too slow (less than 1 tr/s) */
+ if (icr_cpt >= CPT_ICR_MAX)
+ return 1000L;
+
+ /* too fast (more than 100 tr/s) */
+ if (icr_cpt <= CPT_ICR_MIN)
+ return 100000L;
+
+ /* XXX test */
+ if (icr_cpt > 25)
+ return icr_cpt * 8192UL;
+
+ return TIM3_UNIT/icr_diff;
+}
+
+static int8_t check_sta_frame(uint16_t frame, uint16_t time)
+{
+ int8_t beacon_id;
+
+ /* ignore bad cksum */
+ if (verify_cksum(frame) == 0xFFFF)
+ goto fail;
+
+ beacon_id = (frame >> TSOP_STA_BEACON_ID_SHIFT) & TSOP_STA_BEACON_ID_MASK;
+
+ if (beacon_id != TSOP_STA_BEACON_ID0 &&
+ beacon_id != TSOP_STA_BEACON_ID1)
+ goto fail;
+
+ /* if motor speed is not good, skip values */
+ if (current_motor_period < MOTOR_PERIOD_MIN)
+ goto fail;
+ if (current_motor_period > MOTOR_PERIOD_MAX)
+ goto fail;
+
+ return beacon_id;
+
+ fail:
+ /* display if needed */
+ if (beacon_tsop.debug_frame) {
+ printf("STA ID=%d frame=%x time=%d\r\n",
+ beacon_id, frame, time);
+ }
+ return -1;