@@ -215,6 +215,98 @@ static void test_edges_overflow(void *obj, void *data, QGuestAllocator *alloc)
g_assert_cmphex(i2c_get16(dev, REG_MASK_ENABLE) & ME_OVF, ==, ME_OVF);
}
+/* Shunt over-limit alert (transparent mode) sets the AFF flag */
+static void test_alert_shunt_over(void *obj, void *data,
+ QGuestAllocator *alloc)
+{
+ QI2CDevice *dev = (QI2CDevice *)obj;
+
+ i2c_set16(dev, REG_CONFIG, CONFIG_RST);
+
+ i2c_set16(dev, REG_ALERT_LIMIT, 0x1000);
+ i2c_set16(dev, REG_MASK_ENABLE, ME_SOL);
+
+ qmp_ina230_set("shunt-voltage", 2500000);
+ g_assert_cmphex(i2c_get16(dev, REG_MASK_ENABLE) & ME_AFF, ==, 0);
+
+ qmp_ina230_set("shunt-voltage", 20000000);
+ g_assert_cmphex(i2c_get16(dev, REG_MASK_ENABLE) & ME_AFF, ==, ME_AFF);
+
+ qmp_ina230_set("shunt-voltage", 2500000);
+ g_assert_cmphex(i2c_get16(dev, REG_MASK_ENABLE) & ME_AFF, ==, 0);
+}
+
+/* Latch mode holds the alert until the Mask/Enable register is read */
+static void test_alert_latch(void *obj, void *data, QGuestAllocator *alloc)
+{
+ QI2CDevice *dev = (QI2CDevice *)obj;
+ uint16_t me;
+
+ i2c_set16(dev, REG_CONFIG, CONFIG_RST);
+
+ i2c_set16(dev, REG_ALERT_LIMIT, 0x1000);
+ i2c_set16(dev, REG_MASK_ENABLE, ME_SOL | ME_LEN);
+
+ qmp_ina230_set("shunt-voltage", 20000000);
+ qmp_ina230_set("shunt-voltage", 2500000);
+
+ me = i2c_get16(dev, REG_MASK_ENABLE);
+ g_assert_cmphex(me & ME_AFF, ==, ME_AFF);
+
+ g_assert_cmphex(i2c_get16(dev, REG_MASK_ENABLE) & ME_AFF, ==, 0);
+}
+
+/* Bus over-limit alert */
+static void test_alert_bus(void *obj, void *data, QGuestAllocator *alloc)
+{
+ QI2CDevice *dev = (QI2CDevice *)obj;
+
+ i2c_set16(dev, REG_CONFIG, CONFIG_RST);
+
+ i2c_set16(dev, REG_ALERT_LIMIT, 0x2000);
+ i2c_set16(dev, REG_MASK_ENABLE, ME_BOL);
+
+ qmp_ina230_set("bus-voltage", 5000000);
+ g_assert_cmphex(i2c_get16(dev, REG_MASK_ENABLE) & ME_AFF, ==, 0);
+
+ qmp_ina230_set("bus-voltage", 12000000);
+ g_assert_cmphex(i2c_get16(dev, REG_MASK_ENABLE) & ME_AFF, ==, ME_AFF);
+}
+
+/* Power over-limit alert */
+static void test_alert_power(void *obj, void *data, QGuestAllocator *alloc)
+{
+ QI2CDevice *dev = (QI2CDevice *)obj;
+
+ i2c_set16(dev, REG_CONFIG, CONFIG_RST);
+
+ qmp_ina230_set("shunt-voltage", 20000000);
+ qmp_ina230_set("bus-voltage", 11980000);
+ i2c_set16(dev, REG_CALIBRATION, 0x0A00);
+
+ i2c_set16(dev, REG_ALERT_LIMIT, 0x1000);
+ i2c_set16(dev, REG_MASK_ENABLE, ME_POL);
+ g_assert_cmphex(i2c_get16(dev, REG_MASK_ENABLE) & ME_AFF, ==, ME_AFF);
+
+ i2c_set16(dev, REG_ALERT_LIMIT, 0x2000);
+ g_assert_cmphex(i2c_get16(dev, REG_MASK_ENABLE) & ME_AFF, ==, 0);
+}
+
+/* Conversion Ready Flag: set on conversion, cleared by reading Mask/Enable */
+static void test_cvrf(void *obj, void *data, QGuestAllocator *alloc)
+{
+ QI2CDevice *dev = (QI2CDevice *)obj;
+
+ i2c_set16(dev, REG_CONFIG, CONFIG_RST);
+
+ /* A conversion (triggered by injection) sets CVRF */
+ qmp_ina230_set("shunt-voltage", 20000000);
+ g_assert_cmphex(i2c_get16(dev, REG_MASK_ENABLE) & ME_CVRF, ==, ME_CVRF);
+
+ /* The previous read cleared CVRF; no conversion since, so it stays clear */
+ g_assert_cmphex(i2c_get16(dev, REG_MASK_ENABLE) & ME_CVRF, ==, 0);
+}
+
static void ina230_register_nodes(void)
{
QOSGraphEdgeOptions opts = {
@@ -235,5 +327,10 @@ static void ina230_register_nodes(void)
qos_add_test("power", "ina230", test_power, NULL);
qos_add_test("zero-cal", "ina230", test_zero_cal, NULL);
qos_add_test("edges-overflow", "ina230", test_edges_overflow, NULL);
+ qos_add_test("alert-shunt-over", "ina230", test_alert_shunt_over, NULL);
+ qos_add_test("alert-latch", "ina230", test_alert_latch, NULL);
+ qos_add_test("alert-bus", "ina230", test_alert_bus, NULL);
+ qos_add_test("alert-power", "ina230", test_alert_power, NULL);
+ qos_add_test("cvrf", "ina230", test_cvrf, NULL);
}
libqos_init(ina230_register_nodes);