]>
git.proxmox.com Git - mirror_qemu.git/blob - tests/tmp105-test.c
2 * QTest testcase for the TMP105 temperature sensor
4 * Copyright (c) 2012 Andreas Färber
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
13 #include "libqos/i2c.h"
14 #include "hw/misc/tmp105_regs.h"
16 #define OMAP2_I2C_1_BASE 0x48070000
18 #define TMP105_TEST_ID "tmp105-test"
19 #define TMP105_TEST_ADDR 0x49
21 static I2CAdapter
*i2c
;
23 static uint16_t tmp105_get16(I2CAdapter
*i2c
, uint8_t addr
, uint8_t reg
)
26 i2c_send(i2c
, addr
, ®
, 1);
27 i2c_recv(i2c
, addr
, resp
, 2);
28 return (resp
[0] << 8) | resp
[1];
31 static void tmp105_set8(I2CAdapter
*i2c
, uint8_t addr
, uint8_t reg
,
39 i2c_send(i2c
, addr
, cmd
, 2);
40 i2c_recv(i2c
, addr
, resp
, 1);
41 g_assert_cmphex(resp
[0], ==, cmd
[1]);
44 static void tmp105_set16(I2CAdapter
*i2c
, uint8_t addr
, uint8_t reg
,
53 i2c_send(i2c
, addr
, cmd
, 3);
54 i2c_recv(i2c
, addr
, resp
, 2);
55 g_assert_cmphex(resp
[0], ==, cmd
[1]);
56 g_assert_cmphex(resp
[1], ==, cmd
[2]);
60 static void send_and_receive(void)
64 value
= tmp105_get16(i2c
, TMP105_TEST_ADDR
, TMP105_REG_TEMPERATURE
);
65 g_assert_cmpuint(value
, ==, 0);
68 tmp105_set8(i2c
, TMP105_TEST_ADDR
, TMP105_REG_CONFIG
, 0);
70 tmp105_set16(i2c
, TMP105_TEST_ADDR
, TMP105_REG_T_LOW
, 0x1234);
71 tmp105_set16(i2c
, TMP105_TEST_ADDR
, TMP105_REG_T_HIGH
, 0x4231);
74 int main(int argc
, char **argv
)
79 g_test_init(&argc
, &argv
, NULL
);
81 s
= qtest_start("-machine n800 "
82 "-device tmp105,bus=i2c-bus.0,id=" TMP105_TEST_ID
84 i2c
= omap_i2c_create(OMAP2_I2C_1_BASE
);
86 qtest_add_func("/tmp105/tx-rx", send_and_receive
);