Re-using the SPI FLASH port

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
boeserbaer
Active Member
Posts: 51
Joined: Fri Jan 29, 2010 4:36 pm

Re-using the SPI FLASH port

Post by boeserbaer »

I need to use the SPI Flash port for both my boot/data flash, and also for a real-time-clock chip. Each time I use the ports associated, I init and shutdown, in an attempt to make them available to the flash library. If my program only accesses the RTC during thread initialization (before select loop), I am able to upgrade the flash, but then I cannot access the RTC. If I never access the flash, then I can access the RTC. If I can figure out how to leave the ports, and init them for RTC use I would be OK, or better yet access to the flash lib to modify it to use the RTC select line. Any help greatly appreciated.
From flash.h:
typedef struct {
#ifdef __XC__
in buffered port:8 spiMISO; /**< Master input, slave output (MISO) port. */
out port spiSS; /**< Slave select (SS) port. */
out port spiCLK; /**< Serial clock (SCLK) port. */
out buffered port:8 spiMOSI; /**< Master output, slave input (MOSI) port. */
clock spiClkblk; /**< Clock block for use with SPI ports. */
#else
unsigned spiMISO;
unsigned spiSS;
unsigned spiCLK;
unsigned spiMOSI;
unsigned spiClkblk;
#endif
} fl_SPIPorts;

From my usage of the pins:

void spi_init( unsigned rate,
unsigned clk_div,
unsigned clk_delay,
unsigned clk_pad_delay,
unsigned miso_pad_delay,
unsigned mosi_pad_delay) {


//set_port_inv(SPI.spiCLK);
configure_clock_src(blk2, SPI.spiCLK);
configure_out_port(SPI.spiMOSI, blk2, 0);
configure_in_port(SPI.spiMISO, blk2);
set_clock_fall_delay(blk2, clk_delay); // need to understand this better
set_clock_rise_delay(blk2, clk_delay); // need to understand this better
// set_pad_delay(spi1_sclk, 5);
set_pad_delay(SPI.spiMISO, miso_pad_delay);
set_pad_delay(SPI.spiMOSI, mosi_pad_delay);
clearbuf(SPI.spiMOSI);
start_clock(blk2);
SPI.spiCLK <: 0;
}

void spi_shutdown() {
// need clock ticks in order to stop clock blocks
timer t;
unsigned int time;

SPI.spiCLK <: 0;
t :> time;
time += M41T93_BIT_TIME;

for (int i=0;i<16;i++)
{
t when timerafter ( time ) :> void;
time += M41T93_BIT_TIME;
SPI.spiCLK <: 1;
t when timerafter ( time ) :> void;
time += M41T93_BIT_TIME;
SPI.spiCLK <: 0;
}
stop_clock(blk2);
stop_port(SPI.spiMOSI);
stop_port(SPI.spiMISO);
}


Using the RTC:

spi_init(100,20,0,0,0,0); // ADC max clck = 2.5Mhz
rtcWrite((unsigned char)channel, (unsigned char)charToUint(cData,0,dataSize), status, rtc_ss);
spi_shutdown();

Flash Usage:

case INIT_FLASH:
fl_connect(SPI);
psize = fl_getPageSize();
fl_getFactoryImage(b);
fl_getNextBootImage(b);
imageSize = charToUint(cData,0,dataSize);
while(fl_startImageReplace(b,imageSize));
dataSize=0;
break;
case PAGE_FLASH:
fl_writeImagePage(cData);
dataSize=0;
break;
case FINISH_FLASH:
fl_endWriteImage();
fl_disconnect();
dataSize=0;
break;


User avatar
boeserbaer
Active Member
Posts: 51
Joined: Fri Jan 29, 2010 4:36 pm

Post by boeserbaer »

I added:


set_port_use_off(SPI.spiCLK);
set_port_use_on(SPI.spiCLK);
To the top of my spi_init routine.