Jump to content
IGNORED

Eeprom write with timeout?


karri

Recommended Posts

Most of my code appears to hang on various systems that lack the eeprom.

I wonder if anyone has written a driver for 93c46 chip with a built-in timeout?

 

Currently the driver waits for a handshake signal to see that the write cycle is complete. But according to the datasheet the maximum time for a write is 2ms. So I was thinking of just adding a few NOP's to delay the process slightly and skip the polling.

 

The tick is 62.5 ns so I may need to sleep for 32000 ticks.
What is the best way? Interrupt after 32000 ticks, use a timer, NOPs, listen on VBL interrupts and write one word per VBL?

 

This could also be handled in user space.

write(addr, val);
delay();

if (read(addr) != val)
    return NO_EEPROM;
return OK;

 

Any ideas?

Link to comment
Share on other sites

3 minutes ago, laoo said:

One word per VBL should be bulletproof. And given that you won't write more than 60 words also unnoticeable for users.

 

Makes sense. Usually I just may need to write two bytes at the end of a level (high score).

Link to comment
Share on other sites

I might go with the cc65 clock() function. It maintains something called clock_count. It is a 3 byte data that gets incremented at every VBL.

So if I just wait for the lowest byte to change twice I should be safe. Always.

 

... bad thinking ...

It requires the game to actually use clock().

 

Perhaps I go with HBL after all...

Link to comment
Share on other sites

I hope this is the way to do the 2ms wait in asm.

 

; 2ms wait
        ldx #20
EE_wait1:
        lda HTIMCNT
EE_wait2:
        cmp HTIMCNT
        beq EE_wait2
        dex
        bpl EE_wait1

At least it compiles...

 

On a side note I may maintain a master copy of the eeprom in RAM and if the eeprom fails I just don't care.

static unsigned int eepromdata[64]; 
unsigned char haseeprom = 1;

unsigned int eeprom_read(unsigned char pos)
{
        if (haseeprom) {
                eepromdata[pos] = lynx_eeread_93c46(pos);
        }
        return eepromdata[pos];
}

void eeprom_write(unsigned char pos, int val)
{
        eepromdata[pos] = val;
        if (haseeprom) {
                lynx_eewrite_93c46(pos, val);
                if (val != lynx_eeread_93c46(pos)) {
                    haseeprom = 0;
                }
        }
}


 

 

Link to comment
Share on other sites

Yeah, a value of vcount should polled, not hcount. One line take 159 us for 60 fps refresh rate so 20 lines is 3.18 ms.

 

You can try running it in Felix with logging on (running through lua file with logging set). It can tell about eeprom status. And you could test emulation in Felix at the same time ;)

Edited by laoo
Link to comment
Share on other sites

1 hour ago, laoo said:

Yeah, a value of vcount should polled, not hcount. One line take 159 us for 60 fps refresh rate so 20 lines is 3.18 ms.

 

You can try running it in Felix with logging on (running through lua file with logging set). It can tell about eeprom status. And you could test emulation in Felix at the same time ;)

The vcount way works ok in Mednafen and on a real Lynx with an eeprom chip. But it still freeze when it tries to read the eeprom on Felix.
I am a bit new for Windows. Currently I have a Win 11 installed in my laptop but I tend to use Ubuntu over VMware.

I should probably start looking for lua and compilers for running something on Win11.
Currently I am running some Epic Unreal. But it is high level stuff - no code.

Link to comment
Share on other sites

You don't need anything. Felix has embedded lua interpteter. To "debug" in Felix you just need to create a lua file with the content:

 

lnx = "full/path/to/image/file";

Log{ path = "full/path/to/trace/file.log" };

Run Felix for a while (with this file instead of given lnx image) and close it. You will end up with HUGE trace file in given location.

 

Search in trace for lines with "EEPROM" text within.

 

Edited by laoo
Link to comment
Share on other sites

  • 1 month later...

Dear Karri,

I have not yet tackled eeproms but intend to do so now :)

Why are there so many eprom*.s files in that folder and is there a source for eeprom access code (or is that THE best document/source already?)

Speaking of your branch of PCBs (of course!) ;-)

Thank you very much!

I have been absent from Lynx land for a while but never abandoned it, of course.

Link to comment
Share on other sites

35 minutes ago, enthusi said:

Dear Karri,

I have not yet tackled eeproms but intend to do so now :)

Why are there so many eprom*.s files in that folder and is there a source for eeprom access code (or is that THE best document/source already?)

Speaking of your branch of PCBs (of course!) ;-)

Thank you very much!

I have been absent from Lynx land for a while but never abandoned it, of course.

@sage created a bunch of support files to lots of different eeproms. But currently everyone is mainly using the smallest one. 93c46

It has 16-bit words by default. And can hold 64 of them.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...