Skip to content

Commit

Permalink
Work on DeviceBlockInfo_FindRegionFromAddress (#357)
Browse files Browse the repository at this point in the history
- add code to this PAL block as it's OK for reuse on any target

Signed-off-by: José Simões <[email protected]>
  • Loading branch information
josesimoes authored Jun 19, 2017
1 parent df15ecf commit f0dc82c
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/PAL/BlockStorage/nanoPAL_BlockStorage.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,35 @@ __nfweak SectorAddress DeviceBlockInfo_PhysicalToSectorAddress(DeviceBlockInfo*
return phyAddress;
}

__nfweak bool DeviceBlockInfo_FindRegionFromAddress(DeviceBlockInfo* blockInfo, ByteAddress address, unsigned int* blockRegionIndex, unsigned int* blockRangeIndex)
bool DeviceBlockInfo_FindRegionFromAddress(DeviceBlockInfo* blockInfo, ByteAddress address, unsigned int* blockRegionIndex, unsigned int* blockRangeIndex)
{
return false;
const BlockRegionInfo *pRegion;

*blockRegionIndex = 0;

for(uint32_t i = 0; i < blockInfo->NumRegions; i++)
{
pRegion = &blockInfo->Regions[i];

if(pRegion->Start <= address && address < (pRegion->Start + pRegion->NumBlocks * pRegion->BytesPerBlock))
{
uint32_t endRangeAddr = pRegion->Start + pRegion->BytesPerBlock * pRegion->BlockRanges[0].StartBlock;

for(uint32_t j =0; j < pRegion->NumBlockRanges; j++)
{
endRangeAddr += pRegion->BytesPerBlock * BlockRange_GetBlockCount(pRegion->BlockRanges[j]);

if(address < endRangeAddr)
{
*blockRegionIndex = i;
*blockRangeIndex = j;
return true;
}
}
}
}

return false;
}

__nfweak bool DeviceBlockInfo_FindNextUsageBlock(DeviceBlockInfo* blockInfo, unsigned int blockUsage, unsigned int* address, unsigned int* blockRegionIndex, unsigned int* blockRangeIndex)
Expand Down

0 comments on commit f0dc82c

Please sign in to comment.