The MRF49XA signals an (external interrupt on the PIC24) interrupt when it's FIFO is filled up past a certain point. That is currently set at 1 byte, which is half of the FIFO size. At that point, it's interrupt routine will read the byte.
I have data coming (so the PIC24 is receiving) from another node. I view it as a random, spurious event, with no clear indication "now someone is going to send me something". The node may be waking up from sleep, read a sensor, send the packet, and go back to sleep.
That's why I don't want it to disrupt the ethernet process (because that may also be doing something), moreover also not the other way around like I see now: when there is (a decent amount of) ethernet activity the RF communication shouldn't fail. The failure type is that there is a packet recognized, but there is not enough data (so it must have lost a few bytes somewhere).
In my view RF has the highest priority, because after 0.5ms it will start losing data (FIFO overrun). The ethernet cihp can wait a while, because the ENC28J60 has 8kB worth of buffers, so it has plenty before it will run out. Moreover, I wouldn't necessarily care if an ethernet packet is lost.. TCP is robust enough to cope.
Now because both parts of the system will go their own way, there will inevitably a conflict at some time on SPI1.
What I've done now is disable interrupts when ethernet is busy in SPI1, but is turned on/off between calls. I've tried to minimize the time ISR's are off by reducing the size of long block transfers. But the stutters are still occurring. The external interrupt has the highest priority of all interrupts I've configured.
I don't see many other ways doing the SPI transfer. This part does not support DMA. I could use the enhanced buffer mode, which could shorten the delay between bytes; but the protocol to the ENC28J60 is semi-random; one register needs writing, the other needs reading, needs to change banks, etc.
However, it almost seems like the SPI problem is not the issue anymore, as I can see a similar effect happening when I , for example, do a large-ish printf in the RF section. For example printing the last read MRF49XA STSREG value.
