📄 obj_svcdataflash.c
字号:
pSvcDataFlash->DataFlashDesc.rx_data_size = sizeToRead; pSvcDataFlash->DataFlashDesc.tx_data_pt = dataBuffer; pSvcDataFlash->DataFlashDesc.tx_data_size = sizeToRead; /* Send the command to the dataflash */ return(AT91F_DataFlashSendCommand (pSvcDataFlash, DB_CONTINUOUS_ARRAY_READ, 8, src));}//*-----------------------------------------------------------------------------//* Function Name : AT91F_DataFlashReadBuffer//* Object : Read the dataflash SRAM Buffer 1 or 2//* Input Parameters : DataFlash Service//* : <BufferCommand> = Buffer 1 or 2//* : <*dataBuffer> = data buffer pointer//* : <SizeToRead> = data buffer size//* Return value : State of the dataflash//*-----------------------------------------------------------------------------AT91S_SvcDataFlashStatus AT91F_DataFlashReadBuffer ( AT91PS_SvcDataFlash pSvcDataFlash, u_char BufferCommand, u_int bufferAddress, u_char *dataBuffer, int sizeToRead ){ //* Test if the buffer command is legal if ((BufferCommand != DB_BUF1_READ) && (BufferCommand != DB_BUF2_READ)) return DATAFLASH_BAD_COMMAND; //* buffer address must be lower than page size if (bufferAddress > pSvcDataFlash->pDevice->pages_size) return DATAFLASH_BAD_ADDRESS; if ( (pSvcDataFlash->DataFlashDesc.state) != IDLE) return DATAFLASH_BUSY; /*Format the buffer read command */ pSvcDataFlash->DataFlashDesc.command[0] = BufferCommand; pSvcDataFlash->DataFlashDesc.command[1] = 0; pSvcDataFlash->DataFlashDesc.command[2] = (u_char)(((u_int)(bufferAddress & pSvcDataFlash->pDevice->byte_mask)) >> 8) ; pSvcDataFlash->DataFlashDesc.command[3] = (u_char)((u_int)bufferAddress & 0x00FF) ; pSvcDataFlash->DataFlashDesc.command[4] = 0; pSvcDataFlash->DataFlashDesc.tx_cmd_pt = pSvcDataFlash->DataFlashDesc.command ; pSvcDataFlash->DataFlashDesc.tx_cmd_size = 5 ; pSvcDataFlash->DataFlashDesc.rx_cmd_pt = pSvcDataFlash->DataFlashDesc.command ; pSvcDataFlash->DataFlashDesc.rx_cmd_size = 5 ; pSvcDataFlash->DataFlashDesc.rx_data_pt = dataBuffer ; pSvcDataFlash->DataFlashDesc.tx_data_pt = dataBuffer ; pSvcDataFlash->DataFlashDesc.rx_data_size = sizeToRead ; pSvcDataFlash->DataFlashDesc.tx_data_size = sizeToRead ; AT91F_SpiWrite(&(pSvcDataFlash->DataFlashDesc)) ; return DATAFLASH_OK;}//*-----------------------------------------------------------------------------//* Function Name : AT91F_MainMemoryToBufferTransfert//* Object : Read a page in the SRAM Buffer 1 or 2//* Input Parameters : DataFlash Service//* : Page concerned//* : //* Return value : State of the dataflash//*-----------------------------------------------------------------------------AT91S_SvcDataFlashStatus AT91F_MainMemoryToBufferTransfert( AT91PS_SvcDataFlash pSvcDataFlash, u_char BufferCommand, u_int page){ //* Test if the buffer command is legal if ((BufferCommand != DB_PAGE_2_BUF1_TRF) && (BufferCommand != DB_PAGE_2_BUF2_TRF)) return DATAFLASH_BAD_COMMAND; //* no data to transmit or receive pSvcDataFlash->DataFlashDesc.tx_data_size = 0; return(AT91F_DataFlashSendCommand (pSvcDataFlash, BufferCommand, 4, page*pSvcDataFlash->pDevice->pages_size));}///////////////////////////////////////////////////////////////////////////////////////////// Write Functions/////////////////////////////////////////////////////////////////////////////////////////////*-----------------------------------------------------------------------------//* Function Name : AT91F_DataFlashPagePgmBuf//* Object : Main memory page program through buffer 1 or buffer 2//* Input Parameters : DataFlash Service//* : <*src> = Source buffer//* : <dest> = dataflash destination address//* : <SizeToWrite> = data buffer size//* Return value : State of the dataflash//*-----------------------------------------------------------------------------AT91S_SvcDataFlashStatus AT91F_DataFlashPagePgmBuf( AT91PS_SvcDataFlash pSvcDataFlash, u_char BufferCommand, u_char *src, u_int dest, u_int SizeToWrite){ //* Test if the buffer command is legal if ((BufferCommand != DB_PAGE_PGM_BUF1) && (BufferCommand != DB_PAGE_PGM_BUF2)) return DATAFLASH_BAD_COMMAND; pSvcDataFlash->DataFlashDesc.tx_data_pt = src ; pSvcDataFlash->DataFlashDesc.tx_data_size = SizeToWrite ; pSvcDataFlash->DataFlashDesc.rx_data_pt = src; pSvcDataFlash->DataFlashDesc.rx_data_size = SizeToWrite; /* Send the command to the dataflash */ return(AT91F_DataFlashSendCommand (pSvcDataFlash, BufferCommand, 4, dest));}//*-----------------------------------------------------------------------------//* Function Name : AT91F_DataFlashWriteBuffer//* Object : Write data to the internal sram buffer 1 or 2//* Input Parameters : DataFlash Service//* : <BufferCommand> = command to write buffer1 or buffer2//* : <*dataBuffer> = data buffer to write//* : <bufferAddress> = address in the internal buffer//* : <SizeToWrite> = data buffer size//* Return value : State of the dataflash//*-----------------------------------------------------------------------------AT91S_SvcDataFlashStatus AT91F_DataFlashWriteBuffer ( AT91PS_SvcDataFlash pSvcDataFlash, u_char BufferCommand, u_char *dataBuffer, u_int bufferAddress, int SizeToWrite ){ //* Test if the buffer command is legal if ((BufferCommand != DB_BUF1_WRITE) && (BufferCommand != DB_BUF2_WRITE)) return DATAFLASH_BAD_COMMAND; //* buffer address must be lower than page size if (bufferAddress > pSvcDataFlash->pDevice->pages_size) return DATAFLASH_BAD_ADDRESS; if ( (pSvcDataFlash->DataFlashDesc.state) != IDLE) return DATAFLASH_BUSY; //* Send first Write Command pSvcDataFlash->DataFlashDesc.command[0] = BufferCommand; pSvcDataFlash->DataFlashDesc.command[1] = 0; pSvcDataFlash->DataFlashDesc.command[2] = (u_char)(((u_int)(bufferAddress & pSvcDataFlash->pDevice->byte_mask)) >> 8) ; pSvcDataFlash->DataFlashDesc.command[3] = (u_char)((u_int)bufferAddress & 0x00FF) ; pSvcDataFlash->DataFlashDesc.tx_cmd_pt = pSvcDataFlash->DataFlashDesc.command ; pSvcDataFlash->DataFlashDesc.tx_cmd_size = 4 ; pSvcDataFlash->DataFlashDesc.rx_cmd_pt = pSvcDataFlash->DataFlashDesc.command ; pSvcDataFlash->DataFlashDesc.rx_cmd_size = 4 ; pSvcDataFlash->DataFlashDesc.rx_data_pt = dataBuffer ; pSvcDataFlash->DataFlashDesc.tx_data_pt = dataBuffer ; pSvcDataFlash->DataFlashDesc.rx_data_size = SizeToWrite ; pSvcDataFlash->DataFlashDesc.tx_data_size = SizeToWrite ; AT91F_SpiWrite( &pSvcDataFlash->DataFlashDesc ); return DATAFLASH_OK;}//*-----------------------------------------------------------------------------//* Function Name : AT91F_WriteBufferToMain//* Object : Write buffer to the main memory//* Input Parameters : DataFlash Service//* : <BufferCommand> = command to send to buffer1 or buffer2//* : <dest> = main memory address//* Return value : State of the dataflash//*-----------------------------------------------------------------------------AT91S_SvcDataFlashStatus AT91F_WriteBufferToMain ( AT91PS_SvcDataFlash pSvcDataFlash, u_char BufferCommand, u_int dest ){ //* Test if the buffer command is correct if ((BufferCommand != DB_BUF1_PAGE_PGM) && (BufferCommand != DB_BUF1_PAGE_ERASE_PGM) && (BufferCommand != DB_BUF2_PAGE_PGM) && (BufferCommand != DB_BUF2_PAGE_ERASE_PGM) ) return DATAFLASH_BAD_COMMAND; //* no data to transmit or receive pSvcDataFlash->DataFlashDesc.tx_data_size = 0; /* Send the command to the dataflash */ return(AT91F_DataFlashSendCommand (pSvcDataFlash, BufferCommand, 4, dest));}///////////////////////////////////////////////////////////////////////////////////////////// Erase Functions/////////////////////////////////////////////////////////////////////////////////////////////*-----------------------------------------------------------------------------//* Function Name : AT91F_PageErase//* Object : Erase a page in dataflash//* Input Parameters : DataFlash Service//* : <PageNumber> = Number of the page to erase//* : //* Return value : State of the dataflash//*-----------------------------------------------------------------------------AT91S_SvcDataFlashStatus AT91F_PageErase ( AT91PS_SvcDataFlash pSvcDataFlash, u_int PageNumber){ pSvcDataFlash->DataFlashDesc.tx_data_size = 0; /* Send the command to the dataflash */ return(AT91F_DataFlashSendCommand (pSvcDataFlash, DB_PAGE_ERASE, 4, PageNumber*pSvcDataFlash->pDevice->pages_size));}//*-----------------------------------------------------------------------------//* Function Name : AT91F_BlockErase//* Object : Erase a block of 8 pages//* Input Parameters : DataFlash Service//* : <BlockNumber> = number of the block to erase//* : //* Return value : State of the dataflash//*-----------------------------------------------------------------------------AT91S_SvcDataFlashStatus AT91F_BlockErase ( AT91PS_SvcDataFlash pSvcDataFlash, u_int BlockNumber ){ pSvcDataFlash->DataFlashDesc.tx_data_size = 0; /* Send the command to the dataflash */ return(AT91F_DataFlashSendCommand (pSvcDataFlash, DB_BLOCK_ERASE, 4, BlockNumber*8*pSvcDataFlash->pDevice->pages_size));}///////////////////////////////////////////////////////////////////////////////////////////// Compare Functions/////////////////////////////////////////////////////////////////////////////////////////////*-----------------------------------------------------------------------------//* Function Name : AT91F_MainMemoryToBufferCompare//* Object : Compare the contents of a page and one of the sram buffer//* Input Parameters : DataFlash Service//* : <BufferCommand> :specify the sram buffer to compare//* : <page> : specify the page to compare//* : then after that operation, check the 6th bit of the status register//* Return value : State of the dataflash//*-----------------------------------------------------------------------------AT91S_SvcDataFlashStatus AT91F_MainMemoryToBufferCompare( AT91PS_SvcDataFlash pSvcDataFlash, u_char BufferCommand, u_int page){ //* Test if the buffer command is legal if ((BufferCommand != DB_PAGE_2_BUF1_CMP ) && (BufferCommand != DB_PAGE_2_BUF2_CMP )) return DATAFLASH_BAD_COMMAND; //* no data to transmit or receive pSvcDataFlash->DataFlashDesc.tx_data_size = 0; return(AT91F_DataFlashSendCommand (pSvcDataFlash, BufferCommand, 4, page*pSvcDataFlash->pDevice->pages_size)); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -