How setup SPI lib for 100Mbit
Posted: Mon Feb 07, 2022 6:02 pm
Can anybody explain how this code can do 100M???
#pragma unsafe arrays
static uint32_t transfer32_sync_zero_clkblk(
out buffered port:32 sclk,
out buffered port:32 ?mosi,
in buffered port:32 ?miso,
uint32_t data, const unsigned period,
const unsigned cpol, const unsigned cpha){
unsigned time;
uint32_t d;
time = partout_timestamped(sclk, 1, cpol);
time += 100;
//bitrev the data
for(unsigned j=0;j<2;j++){
unsigned c = 0xaaaaaaaa>>(cpol ^ cpha);
for(unsigned i=0;i<16;i++){
partout_timed(sclk, 1, c, time);
if(!isnull(mosi)){
partout_timed(mosi, 1, data>>31, time);
data<<=1;
}
c>>=1;
time += period / 2;
partout_timed(sclk, 1, c, time);
c>>=1;
if(!isnull(miso)){
unsigned t;
miso @ time - 1 :> t;
d = (d<<1) + (t&1);
}
time += (period + 1)/2;
}
time += 80;
}
partout_timed(sclk, 1, cpol, time);
sync(sclk);
return d;
}
https://github.com/xmos/lib_spi
Features
SPI master and SPI slave modes.
Supports speed of up to 100 Mbit.
Multiple slave device support
All clock polarity and phase configurations supported.
#pragma unsafe arrays
static uint32_t transfer32_sync_zero_clkblk(
out buffered port:32 sclk,
out buffered port:32 ?mosi,
in buffered port:32 ?miso,
uint32_t data, const unsigned period,
const unsigned cpol, const unsigned cpha){
unsigned time;
uint32_t d;
time = partout_timestamped(sclk, 1, cpol);
time += 100;
//bitrev the data
for(unsigned j=0;j<2;j++){
unsigned c = 0xaaaaaaaa>>(cpol ^ cpha);
for(unsigned i=0;i<16;i++){
partout_timed(sclk, 1, c, time);
if(!isnull(mosi)){
partout_timed(mosi, 1, data>>31, time);
data<<=1;
}
c>>=1;
time += period / 2;
partout_timed(sclk, 1, c, time);
c>>=1;
if(!isnull(miso)){
unsigned t;
miso @ time - 1 :> t;
d = (d<<1) + (t&1);
}
time += (period + 1)/2;
}
time += 80;
}
partout_timed(sclk, 1, cpol, time);
sync(sclk);
return d;
}
https://github.com/xmos/lib_spi
Features
SPI master and SPI slave modes.
Supports speed of up to 100 Mbit.
Multiple slave device support
All clock polarity and phase configurations supported.