altos: Compute igniter good/bad thresholds using 3.5V value
[fw/altos] / src / kernel / ao.h
index 9ca2c60eac711c94734d199eca9603ac98ec5169..edfbbb871de6416bdd0303bbe994b2215b39fd5d 100644 (file)
@@ -40,6 +40,11 @@ extern char ao_getchar(void);
 #define HAS_TASK       1
 #endif
 
+#ifndef AO_GPIO_TYPE
+#define AO_GPIO_TYPE void *
+#endif
+
+typedef AO_GPIO_TYPE ao_gpio_t;
 typedef AO_PORT_TYPE ao_port_t;
 
 #ifndef AO_TICK_TYPE
@@ -113,6 +118,7 @@ extern volatile AO_TICK_TYPE ao_tick_count;
 #endif
 #define AO_MS_TO_TICKS(ms)     ((ms) / (1000 / AO_HERTZ))
 #define AO_SEC_TO_TICKS(s)     ((AO_TICK_TYPE) (s) * AO_HERTZ)
+#define AO_NS_TO_TICKS(ns)     ((ns) / (1000000000L / AO_HERTZ))
 
 /* Returns the current time in ticks */
 AO_TICK_TYPE
@@ -390,6 +396,7 @@ ao_spi_slave(void);
 
 extern uint8_t ao_gps_new;
 extern AO_TICK_TYPE ao_gps_tick;
+extern AO_TICK_TYPE ao_gps_utc_tick;
 extern uint8_t ao_gps_mutex;
 extern struct ao_telemetry_location ao_gps_data;
 extern struct ao_telemetry_satellite ao_gps_tracking_data;
@@ -975,4 +982,26 @@ void ao_ms5607_init(void);
 
 #include <ao_arch_funcs.h>
 
+/*
+ * dv = (sensor * (p+m) * ref_dv)/ (max * m)
+ * value * (max * m) = (sensor * (p+m) * ref)
+ * value * (max * m) / ((p+m) * ref) = sensor
+ */
+
+#define AO_DV_MUL(p,m) ((int32_t) AO_ADC_MAX * (m))
+#define AO_DV_DIV(p,m) ((int32_t) AO_ADC_REFERENCE_DV * ((p) + (m)))
+#define AO_DV_ADD(p,m) (AO_DV_DIV(p,m) / 2)
+
+#define ao_decivolt_to_adc(dv, p, m) \
+       ((int16_t) (((int32_t) (dv) * AO_DV_MUL(p,m) + AO_DV_ADD(p,m)) / AO_DV_DIV(p,m)))
+
+#define AO_IGNITER_CLOSED_DV   35
+#define AO_IGNITER_OPEN_DV     10
+
+#undef AO_IGNITER_OPEN
+#undef AO_IGNITER_CLOSED
+
+#define AO_IGNITER_OPEN ao_decivolt_to_adc(AO_IGNITER_OPEN_DV, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS)
+#define AO_IGNITER_CLOSED ao_decivolt_to_adc(AO_IGNITER_CLOSED_DV, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS)
+
 #endif /* _AO_H_ */