135 lines
4.1 KiB
C
135 lines
4.1 KiB
C
/*=====================================================================
|
|
File name : SPISE2P.H
|
|
|
|
Originator : Settu Duraisamy
|
|
C2000 Applications Team
|
|
Texas Instruments
|
|
|
|
Description :
|
|
Header file containing object definitions, proto type
|
|
declaration and default object initializers for
|
|
SPI Serial EEPROM driver using VSPI
|
|
|
|
Date : 30/6/2003 (DD/MM/YYYY)
|
|
=======================================================================*/
|
|
|
|
#ifndef __SPISE2P_H__
|
|
|
|
#define __SPISE2P_H__
|
|
|
|
// ¨ìêîñòü ïàìàòè â áàéòàõ
|
|
#define SEEPROM_LEN 0x10000
|
|
|
|
#define NULL 0
|
|
|
|
#define SIXTEEN_BIT 15
|
|
#define EIGHT_BIT 07
|
|
|
|
/***************************************************************/
|
|
/* Configurable Parameter for SPI bus Serial EEPROM */
|
|
/***************************************************************/
|
|
#define SPISE2P_DATA_WIDTH SIXTEEN_BIT//EIGHT_BIT
|
|
#define SPISE2P_ADDR_WIDTH SIXTEEN_BIT
|
|
#define SPIBAUD_REG_VAL 1//12
|
|
#define SPICLK_PHASE 1
|
|
#define SPICLK_POLARITY 0
|
|
|
|
#define SPIBAUD_RATE 100000
|
|
//10000000
|
|
|
|
/**************************************************************/
|
|
/**************************************************************/
|
|
|
|
/* Serial EEPROM Command words, left justified */
|
|
#define SPISE2P_READ_CMD 0x0300
|
|
#define SPISE2P_WRITE_CMD 0x0200
|
|
#define SPISE2P_WRDI_CMD 0x0400
|
|
#define SPISE2P_WREN_CMD 0x0600
|
|
#define SPISE2P_RDSR_CMD 0x0500
|
|
#define SPISE2P_WRSR_CMD 0x0100
|
|
|
|
#define SPISE2P_RDID_CMD 0x0A00
|
|
|
|
#define SPISE2P_DUMMY_DATA 0x0000
|
|
#define SPISE2P_BUSY_MASK 0x01
|
|
|
|
/* Symbolic constant for SPICCR to transfer 8bit or 16 bit value*/
|
|
#define SPISE2P_TFR16BIT 0x80|(SPICLK_POLARITY<<6)|SIXTEEN_BIT
|
|
#define SPISE2P_TFR8BIT 0x80|(SPICLK_POLARITY<<6)|EIGHT_BIT
|
|
|
|
/* Status valus */
|
|
#define SPISE2P_WRRQ 1 /* Write Requset */
|
|
#define SPISE2P_RDRQ 2 /* Read request */
|
|
#define SPISE2P_WRIP 4 /* Write in progress */
|
|
#define SPISE2P_RDIP 8 /* Read in progress */
|
|
|
|
/* Message declaration */
|
|
typedef struct {
|
|
unsigned int *dataPtr; /* Data pointer */
|
|
unsigned long nrData; /* number of data */
|
|
unsigned long se2pAddr; /* se2pAddr */
|
|
}SE2P_DATA;
|
|
|
|
|
|
/* Object declaration */
|
|
typedef struct {
|
|
SE2P_DATA *msgPtr;
|
|
unsigned int csr; /* control/status register */
|
|
void (*init)(void *);
|
|
void (*tick)(void *);
|
|
void (*csset)(void);
|
|
void (*csclr)(void);
|
|
}SPISE2P_DRV;
|
|
|
|
#define SPISE2P_DRV_DEFAULTS { NULL,\
|
|
0,\
|
|
(void (*)(void *))SPISE2P_DRV_init,\
|
|
(void (*)(void *))SPISE2P_DRV_tick,\
|
|
(void (*)(void))SPISE2P_DRV_csset,\
|
|
(void (*)(void))SPISE2P_DRV_csclr}
|
|
|
|
typedef SPISE2P_DRV *SPISE2P_DRV_handle;
|
|
|
|
void SPISE2P_DRV_init(SPISE2P_DRV * );
|
|
void SPISE2P_DRV_tick(SPISE2P_DRV *);
|
|
void SPISE2P_DRV_csset(void);
|
|
void SPISE2P_DRV_csclr(void);
|
|
|
|
unsigned int spiSe2pFree(SPISE2P_DRV *se2p);
|
|
void spiSe2pWrite(SPISE2P_DRV *se2p, SE2P_DATA *data);
|
|
void spiSe2pRead(SPISE2P_DRV *se2p, SE2P_DATA *data);
|
|
|
|
#if(SPISE2P_DATA_WIDTH==SIXTEEN_BIT)
|
|
#define PROM_LEN 0x8000
|
|
#define PAGE_LEN 0x20
|
|
#define WORD_LEN 2
|
|
#else
|
|
#define PROM_LEN 0x4000
|
|
#define PAGE_LEN 0x40
|
|
#define WORD_LEN 1
|
|
#endif
|
|
|
|
/* Óñòàíîâêà äðàéâåðà ñåðèàëüíîé EEPROM. **
|
|
** Èíèöèàëèçàöèà SPI è ïðî÷. Òàêæå íàñòðîéêà òàéìåðà. **
|
|
** Äðàéâåð ðàáîòàåò íà ïðåðûâàíèàõ îò òàéìåðà 2! */
|
|
void Init_Seeprom(void);
|
|
|
|
/* Çàïèñü áëîêà â SEEPROM. Ïàðàìåòðû òàêîâû: **
|
|
** adres - àäðåñ â åïðîìêå, êóäà ïèñàòü. **
|
|
** adres = 0..0x8000, åñëè äëèíà ñëîâà 8 áèò **
|
|
** adres = 0..0x4000, åñëè äëèíà ñëîâà 16 áèò **
|
|
** buf - óêàçàòåëü íà ïàìàòü, îòêóäà ïèñàòü. **
|
|
** size - äëèíà áëîêà â áàéòàõ. Ïî-ëþáîìó â áàéòàõ! */
|
|
void Seeprom_write(unsigned int adres, unsigned int buf[], unsigned int size);
|
|
|
|
/* ×òåíèå áëîêà èç SEEPROM. Ïàðàìåòðû òàêîâû: **
|
|
** adres - àäðåñ â åïðîìêå, îòêóäà ÷èòàòü. **
|
|
** adres = 0..0x8000, åñëè äëèíà ñëîâà 8 áèò **
|
|
** adres = 0..0x4000, åñëè äëèíà ñëîâà 16 áèò **
|
|
** buf - óêàçàòåëü íà ïàìàòü, êóäà ÷èòàòü. **
|
|
** size - äëèíà áëîêà â áàéòàõ. Ïî-ëþáîìó â áàéòàõ! */
|
|
void Seeprom_read(unsigned int adres, unsigned int buf[], unsigned int size);
|
|
|
|
#endif
|
|
|