>
>
>
>>
>> I'm emulating a bunch of sensors/actuators.
>>>
>>> If I virtualize my sensors and attach them to the i2c-dev with -device,
>>> how do I get those data on the host then ?
>>>
>>
>> It depends on your use case.
>>
>> It could be that you can make them return a constant value.
>>
>> Otherwise, you may want to use a chardev for that purpose, or finally a
>> QOM (QEMU Object Model) property. For example, add
>>
>> CONFIG_TMP105=y
>>
>> to default-configs/x86_64-softmmu.mak before building QEMU, then do the
>> following (indented = in the guest):
>>
>> $ x86_64-softmmu/qemu-system-x86_64 --enable-kvm ~/test2.img -m 256 \
>> -device tmp105,id=sensor,address=0x50 \
>> -qmp unix:$HOME/qmp.sock,server,nowait
>> $ qmp/qom-list -s ~/qmp.sock /machine/peripheral/sensor
>> temperature
>> @parent_bus/
>> address
>> hotpluggable
>> realized
>> type
>> $ scripts/qmp/qmp-shell ~/qmp.sock
>> (QEMU) qom-get path=/machine/peripheral/sensor property=temperature
>> {u'return': 0}
>> (QEMU) qom-get path=sensor property=address
>> {u'return': 80}
>>
>> # modprobe i2c-dev
>> # i2cget -y 0 0x50 0 w
>> 0x0000
>>
>> (QEMU) qom-set path=sensor property=temperature value=20000
>> {u'return': {}}
>>
>> # i2cget -y 0 0x50 0 w
>> 0x0014
>>
>> For this particular sensor, you have to swap the two bytes and the result
>> is 8.8 fixed-point.
>>
>> Paolo
>>
>>
>> Thanks for your help. As you may see, I'm not that experienced in
>>> QEMU/Linux kernel.
>>>
>>
>>
> Ok, I'm gonna try these things. I might try to use a chardev also. Thanks
> for your help !
>
I've tried using tmp105. As my linux isn't 64bits, i'm using
qemu-system-i386... It crashes my computer when I use it with my linux
image (it's a debian .qcow2..., easy to do some tests...).
I will most probably need a chardev anyways, I will need to read/write data
when I want to. I'm gonna be annoying and ask another basic question : I
wrote this in my i2c_device_test.c (QEMU device) :
static const TypeInfo mydevice_i2c_type_info = {
.name = TYPE_MYDEVICE_I2C,
.parent = TYPE_I2C_SLAVE,
.instance_size = sizeof(MYDEVICEI2CState),
.instance_init = MYDEVICE_i2c_init,
.class_init = mydevice_i2c_class_init,
};
I will be able to add a chardev using the properties, right ?
static void mydevice_i2c_class_init(ObjectClass *klass, void *data)
{
printf("Test init2\n");
I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
sc->init = mydevice_i2c_init;
sc->event = mydevice_i2c_event;
sc->recv = mydevice_i2c_recv;
sc->send = mydevice_i2c_send;
dc->vmsd = &mydevice_i2c_vmstate;
dc->props = mydevice_i2c_properties;
dc->realize = mydevice_i2c_realize;
}
Does this seems ok for you ? So far, I understood the "props" are needed
for when I'm gonna declare the device at QEMU launch.
I am not sure if it's needed (my i2c-0 should be created anyways), but in
that case, how do I "plug" it on my socket on the host ?
Thanks !