Renamed SPI_WAITFOREOTxBUF to SPI_WAITFORTxREADY for clarity and generalized SPI transmission status checks to work with both AVR and MSP430

This commit is contained in:
nifi 2009-09-07 11:31:26 +00:00
parent 9d7bdad864
commit d4b619bcc5
4 changed files with 33 additions and 19 deletions

View file

@ -1,9 +1,22 @@
/* -*- C -*- */
/* @(#)$Id: spi.h,v 1.5 2009/08/31 12:06:34 nifi Exp $ */
/* @(#)$Id: spi.h,v 1.6 2009/09/07 11:31:26 nifi Exp $ */
#ifndef SPI_H
#define SPI_H
/* Define macros to use for checking SPI transmission status depending
on if it is possible to wait for TX buffer ready. This is possible
on for example MSP430 but not on AVR. */
#ifdef SPI_WAITFORTxREADY
#define SPI_WAITFORTx_BEFORE() SPI_WAITFORTxREADY()
#define SPI_WAITFORTx_AFTER()
#define SPI_WAITFORTx_ENDED() SPI_WAITFOREOTx()
#else /* SPI_WAITFORTxREADY */
#define SPI_WAITFORTx_BEFORE()
#define SPI_WAITFORTx_AFTER() SPI_WAITFOREOTx()
#define SPI_WAITFORTx_ENDED()
#endif /* SPI_WAITFORTxREADY */
extern unsigned char spi_busy;
void spi_init(void);
@ -20,8 +33,9 @@ void spi_init(void);
#define FASTSPI_TX(x)\
do {\
SPI_WAITFOREOTxBUF();\
SPI_WAITFORTx_BEFORE();\
SPI_TXBUF = x;\
SPI_WAITFORTx_AFTER();\
} while(0)
#define FASTSPI_RX(x)\
@ -46,7 +60,7 @@ void spi_init(void);
for (spiCnt = 0; spiCnt < (c); spiCnt++) {\
FASTSPI_TX(((u8_t*)(p))[spiCnt]);\
}\
SPI_WAITFOREOTx();\
SPI_WAITFORTx_ENDED();\
} while(0)
@ -94,7 +108,7 @@ void spi_init(void);
FASTSPI_TX_ADDR(a);\
FASTSPI_TX((u8_t) ((v) >> 8));\
FASTSPI_TX((u8_t) (v));\
SPI_WAITFOREOTx();\
SPI_WAITFORTx_ENDED();\
SPI_DISABLE();\
} while (0)
@ -135,7 +149,7 @@ void spi_init(void);
for (i = 0; i < (c); i++) {\
FASTSPI_TX(((u8_t*)(p))[i]);\
}\
SPI_WAITFOREOTx();\
SPI_WAITFORTx_ENDED();\
SPI_DISABLE();\
} while (0)
@ -145,7 +159,7 @@ void spi_init(void);
for (u8_t spiCnt = 0; spiCnt < (c); spiCnt++) {\
FASTSPI_TX(((u8_t*)(p))[spiCnt]);\
}\
SPI_WAITFOREOTx();\
SPI_WAITFORTx_ENDED();\
} while (0)
#define FASTSPI_READ_FIFO_BYTE(b)\
@ -212,7 +226,7 @@ void spi_init(void);
for (n = 0; n < (c); n++) {\
FASTSPI_TX(((u8_t*)(p))[n]);\
}\
SPI_WAITFOREOTx();\
SPI_WAITFORTx_ENDED();\
SPI_DISABLE();\
} while (0)

View file

@ -1,5 +1,5 @@
/* -*- C -*- */
/* @(#)$Id: contiki-conf.h,v 1.5 2009/09/01 09:29:40 nifi Exp $ */
/* @(#)$Id: contiki-conf.h,v 1.6 2009/09/07 11:31:26 nifi Exp $ */
#ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H
@ -108,10 +108,10 @@ typedef unsigned long off_t;
/* USART0 Tx ready? */
#define SPI_WAITFOREOTx() while ((U0TCTL & TXEPT) == 0)
/* USART0 Rx buffer ready? */
/* USART0 Rx ready? */
#define SPI_WAITFOREORx() while ((IFG1 & URXIFG0) == 0)
/* USART0 Tx buffer ready? */
#define SPI_WAITFOREOTxBUF() while ((IFG1 & UTXIFG0) == 0)
#define SPI_WAITFORTxREADY() while ((IFG1 & UTXIFG0) == 0)
#define SCK 1 /* P3.1 - Output: SPI Serial Clock (SCLK) */
#define MOSI 2 /* P3.2 - Output: SPI Master out - slave in (MOSI) */

View file

@ -1,5 +1,5 @@
/* -*- C -*- */
/* @(#)$Id: contiki-conf.h,v 1.58 2009/08/31 12:06:35 nifi Exp $ */
/* @(#)$Id: contiki-conf.h,v 1.59 2009/09/07 11:31:26 nifi Exp $ */
#ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H
@ -172,10 +172,10 @@ typedef unsigned long off_t;
/* USART0 Tx ready? */
#define SPI_WAITFOREOTx() while ((U0TCTL & TXEPT) == 0)
/* USART0 Rx buffer ready? */
/* USART0 Rx ready? */
#define SPI_WAITFOREORx() while ((IFG1 & URXIFG0) == 0)
/* USART0 Tx buffer ready? */
#define SPI_WAITFOREOTxBUF() while ((IFG1 & UTXIFG0) == 0)
#define SPI_WAITFORTxREADY() while ((IFG1 & UTXIFG0) == 0)
#define SCK 1 /* P3.1 - Output: SPI Serial Clock (SCLK) */
#define MOSI 2 /* P3.2 - Output: SPI Master out - slave in (MOSI) */

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)$Id: xmem.c,v 1.9 2009/08/31 12:06:35 nifi Exp $
* @(#)$Id: xmem.c,v 1.10 2009/09/07 11:31:26 nifi Exp $
*/
/**
@ -78,7 +78,7 @@ write_enable(void)
SPI_FLASH_ENABLE();
FASTSPI_TX(SPI_FLASH_INS_WREN);
SPI_WAITFOREOTx();
SPI_WAITFORTx_ENDED();
SPI_FLASH_DISABLE();
splx(s);
@ -95,7 +95,7 @@ read_status_register(void)
SPI_FLASH_ENABLE();
FASTSPI_TX(SPI_FLASH_INS_RDSR);
SPI_WAITFOREOTx();
SPI_WAITFORTx_ENDED();
FASTSPI_CLEAR_RX();
FASTSPI_RX(u);
@ -137,7 +137,7 @@ erase_sector(unsigned long offset)
FASTSPI_TX(offset >> 16); /* MSB */
FASTSPI_TX(offset >> 8);
FASTSPI_TX(offset >> 0); /* LSB */
SPI_WAITFOREOTx();
SPI_WAITFORTx_ENDED();
SPI_FLASH_DISABLE();
splx(s);
@ -175,7 +175,7 @@ xmem_pread(void *_p, int size, unsigned long offset)
FASTSPI_TX(offset >> 16); /* MSB */
FASTSPI_TX(offset >> 8);
FASTSPI_TX(offset >> 0); /* LSB */
SPI_WAITFOREOTx();
SPI_WAITFORTx_ENDED();
FASTSPI_CLEAR_RX();
for(; p < end; p++) {
@ -213,7 +213,7 @@ program_page(unsigned long offset, const unsigned char *p, int nbytes)
for(; p < end; p++) {
FASTSPI_TX(~*p);
}
SPI_WAITFOREOTx();
SPI_WAITFORTx_ENDED();
SPI_FLASH_DISABLE();
splx(s);