📄 lh7a400_lcd_evb_eeprom_driver.c
字号:
* Outputs: None
*
* Returns: Nothing
*
* Notes:
*
**********************************************************************/
/* write/erase protection */
void lcd_eeprom_lock(void)
{
/* wait for SSP to be not busy */
while (ssp_busy() )
;
ssp_transmit(EE_WDS );
}
/**********************************************************************
*
* Function: lcd_eeprom_unlock
*
* Purpose:
* Allow EEPROM write or erase commands to work
*
* Processing:
* Wait for all pending SSP transmissions to complete. Transmit
* the unlock command.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes:
* The EEPROM is locked on power-up. You must call this function
* before attempting to write or erase the EEPROM.
*
**********************************************************************/
void lcd_eeprom_unlock(void)
{
/* wait for SSP to be not busy */
while (ssp_busy() )
;
ssp_transmit(EE_WEN );
}
/**********************************************************************
*
* Function: lcd_eeprom_read
*
* Purpose:
* Return an EEPROM word from a specifed address
*
* Processing:
* Wait for the last SSP transaction to complete, and flush the
* receive FIFO. Send the read command bit sequence plus a 0 of
* turn-around time, and then send a 0 to keep the chip select
* active and shift in the data read back. Wait for the writes
* to complete by polling the busy bit in the status register.
* Read and discard the first word in the receive FIFO. Read
* and return the EEPROM data that is in the SSP receive FIFO.
*
* Parameters:
* adr: The address of the word to erase (0-63)
*
* Outputs: None
*
* Returns:
* 0 if the address is out of range. Otherwise, return the
* the word read.
*
* Notes:
*
**********************************************************************/
UNS_16 lcd_eeprom_read(INT_32 adr)
{
if (adr < 0 || adr > EEPROM_ADR_MAX)
return 0;
/* wait for SSP to be not busy */
while (ssp_busy() )
;
/* flush the receive FIFO */
while (ssp_receive_fifo_not_empty() )
ssp_receive();
/*
command and address is shifted left to account
for one bit clock cycle of 0 transmitted.
*/
ssp_transmit(EE_READ(adr) << 1);
ssp_transmit(0);
/* wait for transfer to complete */
while (ssp_busy() )
;
/* discard the first word in the buffer */
ssp_receive();
/* return the data read */
return ssp_receive();
}
/**********************************************************************
*
* Function: lcd_eeprom_block_read
*
* Purpose:
*
* Processing:
* If nwords is negative, return 0. If adr is out of range, return 0
* If adr + nwords exceedes the number of words in the EEPROM, clip
* nwords to the most words that can be read from the EEPROM starting
* at the given start address of the block.
* Wait for the last SSP transaction to complete, and flush the
* receive FIFO. Send the read command bit sequence plus a 0 of
* turn-around time, and then send a 0 to keep the chip select
* active and shift in the data read back. Wait for the
* read command transmission to the EEPROM to complete by
* polling the SSP receive FIFO not empty bit in the status
* register. Read and discard the data returned on the read
* command transmission. For every word to be read except 1,
* send a 0 to request the next word and then read the current
* word from the receive FIFO. Then read the last word from
* the receive FIFO. Return nwords.
*
* Parameters:
* adr: the starting address of the block to read
* buffer: an array for storing the SSP receive words
* nwords: the number of words to read
*
* Outputs:
* buffer filled with nwords read from the EEPROM.
*
* Returns:
* 0 if adr or nwords are illegal. Otherwise, return the number of
* words read.
*
* Notes:
*
**********************************************************************/
INT_32 lcd_eeprom_block_read(INT_32 adr, UNS_16 * buffer, INT_32 nwords)
{
int i;
if (nwords <= 0)
return 0;
if (adr < 0 || adr > EEPROM_ADR_MAX)
return 0;
if (adr + nwords > (EEPROM_ADR_MAX + 1) )
nwords = EEPROM_ADR_MAX - adr + 1;
/* wait for SSP to be not busy */
while (ssp_busy() )
;
/* flush the receive FIFO */
while (ssp_receive_fifo_not_empty() )
ssp_receive();
/*
command and address is shifted left to account
for one bit clock cycle of 0 transmitted.
*/
ssp_transmit(EE_READ(adr) << 1 );
ssp_transmit(0);
/* wait for transfer to complete */
while (ssp_receive_fifo_not_empty() )
;
/* discard the first word in the buffer */
ssp_receive();
/*
receive all words (an extra word is in the transmit
FIFO to keep the chip select active
*/
for (i = 1; i < nwords; i++)
{
ssp_transmit(0);
*buffer++ = ssp_receive();
}
*buffer++ = ssp_receive();
/* wait for SSP to be not busy */
while (ssp_busy() )
;
/* flush the receive FIFO */
while (ssp_receive_fifo_not_empty() )
ssp_receive();
return nwords;
}
/**********************************************************************
*
* Function: lcd_eeprom_write
*
* Purpose:
* Write a single EEPROM word at a specifed EEPROM address
*
* Processing:
* Wait for the last SSP transaction to complete, and flush the
* receive FIFO. Send the write command bit sequence followed
* by the data to write. Return the result of eeprom_busy_poll()
*
* Parameters:
* data: The data to be written
* adr: The address of the word to erase (0-63)
* timeout_in_milliseconds: number of milliseconds to wait for erase
* operation to complete
*
* Outputs: None
*
* Returns:
* 0 if the write times out
* 1 if the write is successful
*
* Notes:
* This command will fail if the EEPROM is locked.
*
**********************************************************************/
INT_32 lcd_eeprom_write(INT_32 adr, UNS_16 data,
INT_32 timeout_in_milliseconds)
{
if (adr < 0 || adr > EEPROM_ADR_MAX)
return 0;
/* wait for SSP to be not busy */
while (ssp_busy() )
;
/* flush the receive FIFO */
while (ssp_receive_fifo_not_empty() )
ssp_receive();
ssp_transmit(EE_WRITE(adr) );
ssp_transmit(data );
return eeprom_busy_poll(timeout_in_milliseconds);
}
/**********************************************************************
*
* Function: lcd_eeprom_fill
*
* Purpose:
* Fill the entire EEPROM with a specified data value
*
* Processing:
* Wait for the last SSP transaction to complete, and flush the
* receive FIFO. Send the write all command bit sequence followed
* by the data to write. Return the result of eeprom_busy_poll()
*
* Parameters:
* data: The data to be written
* timeout_in_milliseconds: number of milliseconds to wait for erase
* operation to complete
*
* Outputs: None
*
* Returns:
* 0 if the write times out
* 1 if the write is successful
*
* Notes:
* This command will fail if the EEPROM is locked.
*
**********************************************************************/
INT_32 lcd_eeprom_fill(UNS_16 data,
INT_32 timeout_in_milliseconds)
{
/* wait for SSP to be not busy */
while (ssp_busy() )
;
/* flush the receive FIFO */
while (ssp_receive_fifo_not_empty() )
ssp_receive();
ssp_transmit(EE_WRAL);
ssp_transmit(data );
return eeprom_busy_poll(timeout_in_milliseconds);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -