Project: SPI_MSTransfer

probably have to deal with 16x buffers with an array of pointers, and do a little mathwork with the pointers
sounds complex but fun lol
 
yup, his code helped me setup the registers

now, regarding the buffers, i have somewhat of an idea on how to implement them using static buffers (just off top of my head)

i could create 16x 1k buffers (size optional)
then using an array of 16 pointers...

master sends a transfer, the isr looks up the pointers starting at position 0, and increments if needed until a 0 is located at the first dword (considered free buffer), then it writes array to it and sets +1 position as 0 as a safety net

next, if the loop cycles events, callback is fired, boom, position 0 is checked, valid data? process it and shift all pointers to the left

system continues

what do you think?
 
Ok. You made me look. My thoughts. Ok, sounds like what you are doing is some sort of circular or ring buffer? Came across this awhile ago - not sure what I was working on, never did implement one though :).

Anyway the approach sounds like it should work. You may want to check this out - https://accu.org/index.php/journals/389. There's a ton of stuff out there on circular/ring buffers if you are interested. Lots of work ahead. :)
 
Yeah. I saw that boost had a circular buffer implementation. Would definitely make your life easier.

Here is some more lite reading for you, maybe it will help, but it's interesting reading :)

Now I have to go and crash. Pretty much done for the night..
 
One thing there from Paul notes:
In slave mode, SPI is limited to F_BUS / 4. Master mode can go up to F_BUS / 2.

When Teensy runs at 96 or 48 MHz, F_BUS is 48 MHz.

I wanted to assume the Slave could follow any clock - but there seems to be a limit lower than Master. The Master knows what is going down - the Slave has to make ready and respond.

My T_3.1 at 96 MHz is running seemingly fine [ F&F @500 Hz and 10 Hz Toggle] against the T_3.6 pushing 30 MHz SPI - for long times - ran 24+ hours and still running since the earlier noted reset. Maybe this is running on the hairy edge - and why it only works setting PRI to Max/0 - and goes bad when USB consumes any bandwidth?
 
actually, it wouldnt be that hard to keep the buffers last 16 updated entries, it would increment and go back and continue forever, we could just scan the buffers until we hit the first 0 of a given array, then look ahead to find one that has data, pull it, and set the header to 0 to flag it done

so ISR has a dedicated “position” thats incremented 0-15 and back to 0-15 etc

the loop will scan from 0-15 till it hits first unset array (0), then scan for a valid array,
lets say it reaches buffer3, it captures the buffer and when its done it sets the first dword back to 0

if the events scans all buffers at 0, it continues loop normally

????????? :)
 
theoretically it would guarentee 15 of 16 buffers (+1 auto flagged as 0)

the scan method will skip the first and consecutive 0 buffers till it reaches a valid one and boom, process callback set 0 call it a day
 
Lots of ways to handle it. FIFO with known current Head & Tail is more deterministic - as long as things are done FIFO.

Update the tail when adding, update the head when removing. Always wrap on the limit. If the limit is a power of 2 like 16 then: " Head++; Head &= 15" always keeps it in bounds without a conditional. When Head==Tail it is empty, which renders one less usable space, unless a COUNT is kept updated of used entries - then Head==Tail can mean empty or full depending on the count.

PJRC Serial# FIFO leaves one unused and doesn't count when Head==Tail means Emtpy.
 
can the fifo handle pointer entries?

lets say isr writes to a pointed buffer , can it drop the pointer in the fifo?
 
Noted earlier ... FIFO entry is what you make it a BYTE or a STRUCT, or set of POINTERS.

It is just 'an array' of things of constant known size indexed to starting empty with Head=Tail=0;

First Add uses HEAD [0] element - fills it - then indexes Head++. Checking it for empty finds Head != Tail so the Tail entry [0] is populated. When Pulled Tail++ moves forward.

If you scan the prior linked code in Serial1 you can see that in practice.

The only gotcha is that Adds can come from TWO places ( isr and Sketch ) so the system needs a safe way to handle that. With the Transfer Speed - consider how many messages can arrive for storage - or be queued to send in 1 ms or so before they can be consumed. Once you make one FIFO code you can make two and size them based on the expected usage. Each would have one writer and one reader - One would be an Rx FIFO and one a Tx FIFO - which is how Serial1 works.
 
Last edited:
the size of the given array is the 2nd dword [1], so getting a length from a big buffer to use only whats needed wont be hard either, all the isr needs to do is update the buffer location and queue a pointer to the last one it wrote to

then we also gotta be cafeful if the buffer is writing more entries than being pulled, the corcular buffer should be in sync as well (i think)

i usually like to test ide demos before implementing them in the library, it removes headaches while testing :)
 
Is there a github repository for this new library? (....please forgive me for not reading more than the last page of this lengthy thread....)

If so, I'd like to make a quick link to it from the SPI page. Hopefully that'll help people interested in slave mode and microcontroller-to-microcontroller transfers find it.
 
no paul im not a github expert, im sure tim will work on one though, im just a free spirit code writer for teensy :)
 
Truth is, I'm not a github expert either. I just use 3 commands on my PC (clone, pull, push) and click the buttons on their site for stuff like merging. It's pretty easy if you only do those and avoid stuff like branches.
 
yeah maybe but im redesigning the queue system without stl containers for this project so thats another learning experience github is for another day, but i hope to release teensquitto also in near future after its tested out, but you know me my documentation and lack of disclaimers and those licencing options on github make me cringe haha, hopefully others will help out on that stuff, i need help too sometimes ;/
 
If you are using Windows, than simply use github Desktop for windows: https://desktop.github.com/

It works pretty simple. I am not an Git expert, but can do a few things. I do google a lot to remember more advanced things like yesterday I merged 5 partial commits into one, before I issued a Pull Request (USBHost_T36).

If you are simply creating your own stuff, you typically can simply create a new project and then push it up to github as the master branch.

If you are wanting to make updates to be pulled into some other projects like: Core or USBHost... It is not too difficult:

Sometimes depending on what you wish to do: Simply look at or use someone elses project:
a) Go to github... to the project you wish to download to your machine and up there example: https://github.com/PaulStoffregen/cores
There you will see a Clone or download button (green), you can go to the clone in desktop button, which should bring up the github desktop app, which allows you to choose where to put it on your machine...

b) If you are going to want to make changes, when looking at Pauls project up on github, you should click on the FORK button near upper right, which will create a fork of it in your Github account. From there you can clone in desktop to get it to your machine...

If you are making changes to other persons projects, what I do is SYNC my fork of the project up to the master version (more on this if interested). Then for the change, I create a new BRANCH of the project, I then make my changes in the new branch and push them up to github. When you are happy with your changes, you can issue a Pull Request (In the branch menu), which should generate the Pull request on github. When the change is accepted, you receive email, from which you can then close out your temporary branch and sync back your main branch to the master...
 
This came from another thread - I asked about posting to github 2/24 . . .

Nice :). I can post on my GitHub if you don't have one - or if you do I can manage updates if you have one and we both get write access,

... rushed off ... given the license to be used ( Paul's Favorite? ) and tonton81's go ahead ....
 
Last edited:
yeah i dont mind delegating, my contributions are for the teensy forums anyways, tim, you can both up if you want after the test*wink* just not the credential parts :)
 
This Repository now exists :: github.com ... SPI_MSTransfer

It is the Master to Slave I have seen work - without the current alterations for working out the Slave to Master.

Tonton81 - if you create a Github Account I can add you as a 'writer' or you can FORK/CLONE and work on your own or with this copy.

Scanning this leads to Help on essential commands: help . github.com/
 
Back
Top