Description
Source
Call Graph
Start Line: 195
unsigned char NandFlashModel_TranslateAccess(const struct NandFlashModel *model, unsigned int address, unsigned int size, unsigned short *block, unsigned short *page, unsigned short *offset)
{
// Check that access is not too big
#if !defined(OP_BOOTSTRAP_on)
if ((address + size) > NandFlashModel_GetDeviceSizeInBytes(model)) {
TRACE_DEBUG("NandFlashModel_TranslateAccess: out-of-bounds access.\n\r");
return NandCommon_ERROR_OUTOFBOUNDS;
}
#endif
// Get Nand info
unsigned int blockSize = NandFlashModel_GetBlockSizeInBytes(model);
unsigned int pageSize = NandFlashModel_GetPageDataSize(model);
// Translate address
#if !defined(OP_BOOTSTRAP_on)
unsigned short tmpBlock = address / blockSize;
address -= tmpBlock * blockSize;
unsigned short tmpPage = address / pageSize;
address -= tmpPage * pageSize;
unsigned short tmpOffset = address;
#else
unsigned short tmpBlock = CALINT(address, blockSize);
address -= tmpBlock * blockSize;
unsigned short tmpPage = CALINT(address, pageSize);
address -= tmpPage * pageSize;
unsigned short tmpOffset= address;
#endif
// Save results
if (block) {
*block = tmpBlock;
}
if (page) {
*page = tmpPage;
}
if (offset) {
*offset = tmpOffset;
}
return 0;
}