/** * \brief Writes data on the At45 at the specified address. Only one page of * data is written that way; if the address is not at the beginning of the * page, the data is written starting from this address and wraps around to * the beginning of the page. * \param pAt45 Pointer to an AT45 driver instance. * \param pBuffer Data buffer. * \param size Number of bytes to write. * \param address Destination address on the At45. */ void AT45D_Write( At45 *pAt45, uint8_t *pBuffer, uint32_t size, uint32_t address) { uint8_t error; SANITY_CHECK(pAt45); SANITY_CHECK(pBuffer); SANITY_CHECK(size <= pAt45->pDesc->pageSize); /* Issue a page write through buffer 1 command. */ error = AT45_SendCommand(pAt45, AT45_PAGE_WRITE_BUF1, 4, pBuffer, size, address, 0, 0); ASSERT(!error, "-F- AT45_Write: Could not issue command.\n\r"); /* Wait until the command is sent. */ while (AT45_IsBusy(pAt45)) { AT45D_Wait(pAt45); } /* Wait until the At45 becomes ready again.*/ AT45D_WaitReady(pAt45); }
/** * \brief Reads data from the At45 inside the provided buffer. Since a continuous * read command is used, there is no restriction on the buffer size and read address. * * \param pAt45 Pointer to an AT45 driver instance. * \param pBuffer Data buffer. * \param size Number of bytes to read. * \param address Address at which data shall be read. */ extern void AT45D_Read( At45* pAt45, uint8_t* pucBuffer, uint32_t dwSize, uint32_t dwAddress ) { uint32_t dwError ; assert( pAt45 != NULL ) ; assert( pucBuffer != NULL ) ; /* Issue a continuous read array command. */ dwError = AT45_SendCommand( pAt45, AT45_CONTINUOUS_READ_LEG, 8, pucBuffer, dwSize, dwAddress, 0, 0 ) ; assert( !dwError ) ; /* Wait for the read command to execute. */ while ( AT45_IsBusy( pAt45 ) ) { AT45D_Wait( pAt45 ) ; } }
//------------------------------------------------------------------------------ /// Erases a page of data at the given address in the At45. /// \param pAt45 Pointer to a At45 driver instance. /// \param address Address of page to erase. //------------------------------------------------------------------------------ void AT45D_Erase(At45 *pAt45, unsigned int address) { unsigned char error; SANITY_CHECK(pAt45); // Issue a page erase command. error = AT45_SendCommand(pAt45, AT45_PAGE_ERASE, 4, 0, 0, address, 0, 0); ASSERT(!error, "-F- AT45_Erase: Could not issue command.\n\r"); // Wait for end of transfer while (AT45_IsBusy(pAt45)) AT45D_Wait(pAt45); // Poll until the At45 has completed the erase operation AT45D_WaitReady(pAt45); }
/** * \brief Retrieves and returns the At45 current status, or 0 if an error happened. * * \param pAt45 Pointer to an AT45 driver instance. */ uint8_t AT45D_GetStatus(At45 *pAt45) { uint8_t error; uint8_t status; SANITY_CHECK(pAt45); /* Issue a status register read command*/ error = AT45_SendCommand(pAt45, AT45_STATUS_READ, 1, &status, 1, 0, 0, 0); ASSERT(!error, "-F- AT45_GetStatus: Failed to issue command.\n\r"); /* Wait for command to terminate*/ while (AT45_IsBusy(pAt45)) { AT45D_Wait(pAt45); } return status; }
//------------------------------------------------------------------------------ /// Retrieves and returns the At45 current status, or 0 if an error /// happened. /// \param pAt45 Pointer to a At45 driver instance. //------------------------------------------------------------------------------ unsigned char AT45D_GetStatus(At45 *pAt45) { unsigned char error; unsigned char status; SANITY_CHECK(pAt45); // Issue a status register read command error = AT45_SendCommand(pAt45, AT45_STATUS_READ, 1, &status, 1, 0, 0, 0); ASSERT(!error, "-F- AT45_GetStatus: Failed to issue command.\n\r"); // Wait for command to terminate while (AT45_IsBusy(pAt45)) AT45D_Wait(pAt45); return status; }
/** * \brief Erases a page of data at the given address in the At45. * * \param pAt45 Pointer to an AT45 driver instance. * \param dwAddress Address of page to erase. */ extern void AT45D_Erase( At45* pAt45, uint32_t dwAddress ) { uint32_t dwError ; assert( pAt45 != NULL ) ; /* Issue a page erase command. */ dwError = AT45_SendCommand( pAt45, AT45_PAGE_ERASE, 4, 0, 0, dwAddress, 0, 0 ) ; assert( !dwError ) ; /* Wait for end of transfer. */ while ( AT45_IsBusy(pAt45 ) ) { AT45D_Wait( pAt45 ) ; } /* Poll until the At45 has completed the erase operation. */ AT45D_WaitReady( pAt45 ) ; }
/** * \brief Retrieves and returns the At45 current status, or 0 if an error happened. * * \param pAt45 Pointer to an AT45 driver instance. */ extern uint32_t AT45D_GetStatus( At45* pAt45 ) { uint32_t dwError ; uint8_t ucStatus ; assert( pAt45 != NULL ) ; /* Issue a status register read command */ dwError = AT45_SendCommand( pAt45, AT45_STATUS_READ, 1, &ucStatus, 1, 0, 0, 0 ) ; assert( !dwError ) ; /* Wait for command to terminate */ while ( AT45_IsBusy( pAt45 ) ) { AT45D_Wait( pAt45 ) ; } return ucStatus ; }
/** * \brief Erases a page of data at the given address in the At45. * * \param pAt45 Pointer to an AT45 driver instance. * \param address Address of page to erase. */ void AT45D_Erase(At45 *pAt45, uint32_t address) { uint8_t error; SANITY_CHECK(pAt45); /* Issue a page erase command. */ error = AT45_SendCommand(pAt45, AT45_PAGE_ERASE, 4, 0, 0, address, 0, 0); ASSERT(!error, "-F- AT45_Erase: Could not issue command.\n\r"); /* Wait for end of transfer. */ while (AT45_IsBusy(pAt45)) { AT45D_Wait(pAt45); } /* Poll until the At45 has completed the erase operation.*/ AT45D_WaitReady(pAt45); }
/** * \brief Configure power-of-2 binary page size in the At45. * * \param pAt45 Pointer to an AT45 driver instance. */ extern void AT45D_BinaryPage( At45* pAt45 ) { uint8_t dwError ; uint8_t opcode[3]= {AT45_BINARY_PAGE}; assert( pAt45 != NULL ) ; /* Issue a binary page command. */ dwError = AT45_SendCommand( pAt45, AT45_BINARY_PAGE_FIRST_OPCODE, 1, opcode, 3, 0, 0, 0 ) ; assert( !dwError ) ; /* Wait for end of transfer.*/ while ( AT45_IsBusy( pAt45 ) ) { AT45D_Wait( pAt45 ) ; } /* Wait until the At45 becomes ready again.*/ AT45D_WaitReady( pAt45 ) ; }
/** * \brief Writes data on the At45 at the specified address. Only one page of * data is written that way; if the address is not at the beginning of the * page, the data is written starting from this address and wraps around to * the beginning of the page. * * \param pAt45 Pointer to an AT45 driver instance. * \param pucBuffer Data buffer. * \param dwSize Number of bytes to write. * \param dwAddress Destination address on the At45. */ extern void AT45D_Write( At45* pAt45, uint8_t *pucBuffer, uint32_t dwSize, uint32_t dwAddress ) { uint8_t dwError ; assert( pAt45 != NULL ) ; assert( pucBuffer != NULL ) ; assert( dwSize <= pAt45->pDesc->pageSize ) ; /* Issue a page write through buffer 1 command. */ dwError = AT45_SendCommand( pAt45, AT45_PAGE_WRITE_BUF1, 4, pucBuffer, dwSize, dwAddress, 0, 0 ) ; assert( !dwError ) ; /* Wait until the command is sent. */ while ( AT45_IsBusy( pAt45 ) ) { AT45D_Wait( pAt45 ) ; } /* Wait until the At45 becomes ready again.*/ AT45D_WaitReady( pAt45 ) ; }
void AT45D_BinaryPage(At45 *pAt45) { unsigned char error; unsigned char opcode[3] = {AT45_BINARY_PAGE}; SANITY_CHECK(pAt45); // Issue a binary page command. error = AT45_SendCommand( pAt45, AT45_BINARY_PAGE_FIRST_OPCODE, 1, opcode, 3, 0, 0, 0); ASSERT(!error, "-F- AT45_Erase: Could not issue command.\n\r"); // Wait for end of transfer while (AT45_IsBusy(pAt45)) AT45D_Wait(pAt45); // Wait until the At45 becomes ready again AT45D_WaitReady(pAt45); }
//------------------------------------------------------------------------------ /// Reads data from the At45 inside the provided buffer. Since a continuous /// read command is used, there is no restriction on the buffer size and read /// address. /// \param pAt45 Pointer to a At45 driver instance. /// \param pBuffer Data buffer. /// \param size Number of bytes to read. /// \param address Address at which data shall be read. //------------------------------------------------------------------------------ void AT45D_Read( At45 *pAt45, unsigned char *pBuffer, unsigned int size, unsigned int address) { unsigned char error; SANITY_CHECK(pAt45); SANITY_CHECK(pBuffer); // Issue a continuous read array command error = AT45_SendCommand( pAt45, AT45_CONTINUOUS_READ_LEG, 8, pBuffer, size, address, 0, 0); ASSERT(!error, "-F- AT45_Read: Failed to issue command\n\r"); // Wait for the read command to execute while (AT45_IsBusy(pAt45)) AT45D_Wait(pAt45); }
/** * \brief Configure power-of-2 binary page size in the At45. * * \param pAt45 Pointer to an AT45 driver instance. */ void AT45D_BinaryPage(At45 *pAt45) { uint8_t error; uint8_t opcode[3]= {AT45_BINARY_PAGE}; SANITY_CHECK(pAt45); /* Issue a binary page command. */ error = AT45_SendCommand(pAt45, AT45_BINARY_PAGE_FIRST_OPCODE, 1, opcode, 3, 0, 0, 0); ASSERT(!error, "-F- AT45_Erase: Could not issue command.\n\r"); /* Wait for end of transfer.*/ while (AT45_IsBusy(pAt45)) { AT45D_Wait(pAt45); } /* Wait until the At45 becomes ready again.*/ AT45D_WaitReady(pAt45); }
/** * \brief Reads data from the At45 inside the provided buffer. Since a continuous * read command is used, there is no restriction on the buffer size and read address. * * \param pAt45 Pointer to an AT45 driver instance. * \param pBuffer Data buffer. * \param size Number of bytes to read. * \param address Address at which data shall be read. */ void AT45D_Read( At45 *pAt45, uint8_t *pBuffer, uint32_t size, uint32_t address) { uint8_t error; SANITY_CHECK(pAt45); SANITY_CHECK(pBuffer); /* Issue a continuous read array command.*/ error = AT45_SendCommand(pAt45, AT45_CONTINUOUS_READ_LEG, 8, pBuffer, size, address, 0, 0); ASSERT(!error, "-F- AT45_Read: Failed to issue command\n\r"); /* Wait for the read command to execute.*/ while (AT45_IsBusy(pAt45)) { AT45D_Wait(pAt45); } }
//------------------------------------------------------------------------------ /// Writes data on the At45 at the specified address. Only one page of /// data is written that way; if the address is not at the beginning of the /// page, the data is written starting from this address and wraps around to /// the beginning of the page. /// \param pAt45 Pointer to a At45 driver instance. /// \param pBuffer Buffer containing the data to write. /// \param size Number of bytes to write. /// \param address Destination address on the At45. //------------------------------------------------------------------------------ void AT45D_Write( At45 *pAt45, unsigned char *pBuffer, unsigned int size, unsigned int address) { unsigned char error; SANITY_CHECK(pAt45); SANITY_CHECK(pBuffer); SANITY_CHECK(size <= pAt45->pDesc->pageSize); // Issue a page write through buffer 1 command error = AT45_SendCommand( pAt45, AT45_PAGE_WRITE_BUF1, 4, pBuffer, size, address, 0, 0); ASSERT(!error, "-F- AT45_Write: Could not issue command.\n\r"); // Wait until the command is sent while (AT45_IsBusy(pAt45)) AT45D_Wait(pAt45); // Wait until the At45 becomes ready again AT45D_WaitReady(pAt45); }