SPI RAM interface functions

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
User avatar
Jubatian
Posts: 1561
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

SPI RAM interface functions

Post by Jubatian »

Let's start using that 128KBytes of SPI RAM!

I coded a pack of interface functions for it, currently they are on my fork of the Uzebox repo.

Like CunningFellow's sdBase, it is not included in the main kernel. You have to add it to your project as an assembly source (spiram.s in the kernel root accompanyed by an spiram.h header file). You should also add sdBase to the project as well to init the SD card (otherwise if you use the bootloader to start the game from the SD card, it will likely interfere with the SPI RAM).

In your project, do an sdCardInitNoBuffer(); (or anything else to init the SD card if you plan to run the game with one inserted), and SpiRamInit(); to initialize the SPI RAM. Then by the descriptions provided in the header you should be able to use the SPI RAM.

Functions are provided for both one-shot accesses and sequential accesses, you should use which is appropriate for your project (use sequential access where possible to maximize performance). You may load / store structures for example like SpiRamWriteFrom(0, address, &my_structure, sizeof(my_structure)); (writes my_structure at address in the lower 64K of the SPI RAM).

I used camel case for the function names to match the kernel's style.

I tested only some of the functions verifying that I can read & write from / to the SPI RAM (real hardware and CUzeBox). It should work, but for now I say don't be surprised if something turns out to be buggy. Hope this little package can be useful!
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: SPI RAM interface functions

Post by D3thAdd3r »

Jubatian wrote:Let's start using that 128KBytes of SPI RAM!
Awesome, this is a pleasant surprise! This is a good implementation.

I think we need this before most are going to think about using SPI ram in their game(with the SD card, only becoming common in the following years after usage examples were plentiful). This in particular is so exciting to me as I am working on an emulator that uses the SPI ram and in general am trying to develop for the expansion devices. uberlinuxguy had an implementation, but it did not work for me with some strange issues. Alec did a quick early version of it in C which works, and that is what I ended up basing my stuff off but it is all C and does not have the nice struct filling capabilities. Having everything in a well optimized assembly is way better, especially since these functions can be called quite a lot.

Hats off to you Sandor, I say this goes into the kernel straight away. There is no other real solution for it, and I don't see a way there could be a better version written in the end. If there are bugs they will only be discovered once these are tested more by using in some projects. I will be using this a lot so I will report if I find any bugs.

Man you are so good at this stuff, maybe I can pick your brain on it, or maybe it is just something that needs to be determined by experimentation on my part. I think you will agree, SPI ram will generally be used in conjunction with the SD card....I am at a point where I have an emulator working(which will now be much better with your library here) using the SPI ram as it's memory. I only runs stuff that I store in flash and copy to the ram, because so far maybe because of some silly oversight, I cannot get switching between SD enabled and SPI ram enabled to work well. Do you have any ideas on this, like if someone wanted to use your library in conjunction with Cunning's, is there some reliable way to have 1 function switch between the 2? What I mean is, if you are streaming bytes from SD, can disable SD and enable SPI ram to write something, and then reliably switch back and continue reading SD bytes?
User avatar
Jubatian
Posts: 1561
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: SPI RAM interface functions

Post by Jubatian »

The SD card and the SPI RAM coexists happily both in emulator and real hardware.

I did a test loading stuff from the SD card, then doing some SPI RAM access, then again SD card. It works fine. You only have to pay attention to how the routines work: CunningFellow's sdBase is a streaming oriented library: the sdCardCueSectorAddress() function starts a streaming session and sdCardStopTransmission() terminates it. You can not access the SPI RAM between these. Likewise you can not access the SD card while streaming to / from the SPI RAM (SpiRamSeqRead...() and SpiRamSeqWrite...() functions).

To load / store between the SD card and the SPI RAM you will ideally need a 512 byte buffer to load a complete SD sector. I think you could most economically get this by reusing space normally used for RAM tiles (if you display a loading screen which keeps 512 bytes worth of RAM tiles free, then you have the space necessary for this buffer).
User avatar
Jubatian
Posts: 1561
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: SPI RAM interface functions

Post by Jubatian »

I did some further testing with the library, ending up with the decision to merge it into the master kernel. So from now it is in.

D3thAdd3r: Did you try making the SD card and the SPI RAM coexist? Did it work? Just asking (it should work, at least it does for me).
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: SPI RAM interface functions

Post by D3thAdd3r »

Did not try it yet but I am going to soon. I am having a rather bizarre problem where nothing using SD is working right for me. Installed a new version of MinGW and even tutorialSD doesn't work, but once that mystery is solved your library will breathe life into a project rather quickly.
User avatar
Jubatian
Posts: 1561
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: SPI RAM interface functions

Post by Jubatian »

Just a small example for the usage of the SPI RAM library together with the CunningFellow's SDBase. You can see an example of how to make the two interacting, doing stuff with the SPI RAM and the SD Card simultaneously. It simply uses its own .uze file to access by the SD lib, so if you are running the .hex, make sure the .uze is also there.
Attachments
spiram_lib_test.tar.bz2
SPI RAM library small test.
(23.53 KiB) Downloaded 318 times
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: SPI RAM interface functions

Post by D3thAdd3r »

Nice, looking at that I figured out exactly what my problem was instantly. That might be a good demo for the main branch. Loading up the whole 128K is surprisingly fast even 1K chunk from SD at a time.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: SPI RAM interface functions

Post by nicksen782 »

This may have already been answered somewhere...

SPI-RAM sounds great but of course the Uzebox console would need to also have SPI-RAM installed. What if the console doesn't? How does the emulator handle this?

Or is this more of an "Uzebox 2" thing?
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: SPI RAM interface functions

Post by D3thAdd3r »

I don't consider it Uzebox 2 as it is well supported for older revisions(Uzenet module..a couple dollars each, I will literally pay to have a fully loaded one shipped to anyone that PMs me complaining of hardware fragmentation!) and the new kits shipping out are all ready made for it. Or the most common case probably CUzeBox. That is just my opinion, but I will not release any games from here out that are not SPI ram and/or ESP8266 games.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: SPI RAM interface functions

Post by nicksen782 »

Then it seems that I need to get with the program.

So, how do I get the spiram and esp? I'd like to get one right away.
Post Reply