Real Input and Output on the Pi emulation

Everything about Andy Key's great Emulator MEMU
TimoHartong
Posts: 28
Joined: 23 Sep 2024 16:11

Re: Real Input and Output on the Pi emulation

Post by TimoHartong »

Bill B wrote: 10 Dec 2024 22:12 It will probably be the weekend before I set up the hardware needed to test the MCP23017 interface.

I have committed a software update which may resolve the issue, if you would like to try it.
<knip>
I have tested the code and no joy ;-(
TimoHartong
Posts: 28
Joined: 23 Sep 2024 16:11

Re: Real Input and Output on the Pi emulation

Post by TimoHartong »

The issue is that init already goes not correctly:
timoh@raspberrypi:~ $ i2cdump -y 1 0x20
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
10: 00 00 bc bc bc 50 00 00 00 00 00 00 00 00 00 00 ..???P..........
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
I would expect on 0x00 : 0x00 and on 0x01 : 0xff
Bill B
Posts: 641
Joined: 26 Jan 2014 16:31

Re: Real Input and Output on the Pi emulation

Post by Bill B »

TimoHartong wrote: 11 Dec 2024 16:31 I have tested the code and no joy ;-(
OK. I will have to get some hardware set up and test properly.

Have you tried the alternate method using the kernel driver?
TimoHartong
Posts: 28
Joined: 23 Sep 2024 16:11

Re: Real Input and Output on the Pi emulation

Post by TimoHartong »

No but I have done some hacking in your code ( added logging in the code ) and I see BOOLEAN hw_options (int *pargc, const char ***pargv, int *pi) in hardware.c is never called it also means that hw_read is never called so I2C and GPIO is never configured as it is should ;-(
TimoHartong
Posts: 28
Joined: 23 Sep 2024 16:11

Re: Real Input and Output on the Pi emulation

Post by TimoHartong »

Bill B wrote: 11 Dec 2024 16:40
TimoHartong wrote: 11 Dec 2024 16:31 I have tested the code and no joy ;-(
OK. I will have to get some hardware set up and test properly.

Have you tried the alternate method using the kernel driver?
Bill B wrote: 11 Dec 2024 16:40
TimoHartong wrote: 11 Dec 2024 16:31 I have tested the code and no joy ;-(
OK. I will have to get some hardware set up and test properly.

Have you tried the alternate method using the kernel driver?
To get your current code working I have done the following things:
in hardware.c line comment out gio_output (8, pinPOT, 0xFF); ( around line 428 )
in gpio.c
Changed the line if ( ( pdev->fd > 0 ) && ( pdev->iData ) ) xio_put (pdev, pdev->iMask, pdev->iData); into
if ( pdev->fd > 0 )
xio_put (pdev, pdev->iMask, pdev->iData);
( around line 754 in function gio_put

in gpio.c in the function xio_put I have changed the regiters addresses from 0x14 into 0x12

in gpio.c in the function i2c_get changed the line msg[0].len = iLen + 1; into msg[0].len = sizeof(bAddr);

in memu.c
I ihave added the lines under
diag_message(DIAG_ALWAYS, "=== memu started at %s ===", buf);
hw_read ("hardware.cfg");
hw_init ();
around line 3625
TimoHartong
Posts: 28
Joined: 23 Sep 2024 16:11

Re: Real Input and Output on the Pi emulation

Post by TimoHartong »

Hello I have made a page with software I have written to test the emulator and some photos of the print
https://timohartong.riscos.fr/memotech/
Bill B
Posts: 641
Joined: 26 Jan 2014 16:31

Re: Real Input and Output on the Pi emulation

Post by Bill B »

Thanks, that will be most helpful when I get my test hardware setup.
TimoHartong
Posts: 28
Joined: 23 Sep 2024 16:11

Re: Real Input and Output on the Pi emulation

Post by TimoHartong »

Your efforts are highly appreciated I hope to place schematics also today.
TimoHartong
Posts: 28
Joined: 23 Sep 2024 16:11

Re: Real Input and Output on the Pi emulation

Post by TimoHartong »

Another update : when the unit starts up completely fresh the lines in hardware.c :
gio_input (8, pinPIN, 0xFF);
gio_output (8, pinPOT, 0xFF);
Do work so I have put them back. It is really a bit looking
Bill B
Posts: 641
Joined: 26 Jan 2014 16:31

Re: Real Input and Output on the Pi emulation

Post by Bill B »

I have not yet got hardware set-up for testing, however I have been reviewing the code following your comments:
TimoHartong wrote: 11 Dec 2024 19:05 No but I have done some hacking in your code ( added logging in the code ) and I see BOOLEAN hw_options (int *pargc, const char ***pargv, int *pi) in hardware.c is never called it also means that hw_read is never called so I2C and GPIO is never configured as it is should ;-(
It is called, but not obvious from the source code. Note the following line in the CMakeLists.txt file, which is only enabled if HW_GPIO or HW_MCP23017 is defined:

Code: Select all

-DALT_OPTIONS=hw_options
As a result of that definition line 2559 of memu.c becomes a call to hw_options.
TimoHartong wrote: 11 Dec 2024 16:31 in gpio.c
Changed the line if ( ( pdev->fd > 0 ) && ( pdev->iData ) ) xio_put (pdev, pdev->iMask, pdev->iData); into
if ( pdev->fd > 0 )
xio_put (pdev, pdev->iMask, pdev->iData);
( around line 754 in function gio_put
A typo (copy / paste error) on my part. The line should be as follows, replacing iData by iMask in the condition:

Code: Select all

            if ( ( pdev->fd > 0 ) && ( pdev->iMask ) )	  xio_put (pdev, pdev->iMask, pdev->iData);
TimoHartong wrote: 11 Dec 2024 16:31 in gpio.c in the function xio_put I have changed the regiters addresses from 0x14 into 0x12
Address 0x12 is the GPIO register while 0x14 is the OLAT register. From the MCP23017 datasheet:
The GPIO register reflects the value on the port. Reading from this register reads the port. Writing to this register modifies the Output Latch (OLAT) register.

The OLAT register provides access to the output latches. A read from this register results in a read of the OLAT and not the port itself. A write to this register modifies the output latches that modifies the pins configured as outputs.
Since xio_put is reading and updating the output values, the OLAT register is the correct one to use. The update should not be affected by values on any input pins.
TimoHartong wrote: 11 Dec 2024 16:31 in gpio.c in the function i2c_get changed the line msg[0].len = iLen + 1; into msg[0].len = sizeof(bAddr);
Good spot. I agree.
TimoHartong wrote: 11 Dec 2024 16:31 in memu.c
I ihave added the lines under
diag_message(DIAG_ALWAYS, "=== memu started at %s ===", buf);
hw_read ("hardware.cfg");
hw_init ();
around line 3625
As above, this is done in hw_options which is called if and only if hardware interfacing is selected as a compilation option.

I have pushed an update which includes my version of these changes.
Post Reply