Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements in block storage API #1446

Merged
merged 3 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions src/PAL/BlockStorage/nanoPAL_BlockStorage.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <nanoPAL_BlockStorage.h>
#include <nanoWeak.h>

#include <nanoHAL_v2.h>

BlockStorageList g_BlockStorage;

Expand Down Expand Up @@ -503,14 +503,17 @@ BlockStorageDevice* BlockStorageDevice_Prev(BlockStorageDevice* device)
// Initializes a given block device for use
//
// Returns:
// true if succesful; false if not
// true if successful; false if not
//
// Remarks:
// No other functions in this interface may be called
// until after Init returns.
//
bool BlockStorageDevice_InitializeDevice(BlockStorageDevice* device)
{
ASSERT(device != NULL);
ASSERT(device->m_context != NULL);

return device->m_BSD->InitializeDevice(device->m_context);
}

Expand All @@ -519,13 +522,16 @@ bool BlockStorageDevice_InitializeDevice(BlockStorageDevice* device)
// Initializes a given block device for use
//
// Returns:
// true if succesful; false if not
// true if successful; false if not
//
// Remarks:
// De initializes the device when no longer needed
//
bool BlockStorageDevice_UninitializeDevice(BlockStorageDevice* device)
{
ASSERT(device != NULL);
ASSERT(device->m_context != NULL);

return device->m_BSD->UninitializeDevice(device->m_context);
}

Expand All @@ -535,6 +541,9 @@ bool BlockStorageDevice_UninitializeDevice(BlockStorageDevice* device)
//
DeviceBlockInfo* BlockStorageDevice_GetDeviceInfo(BlockStorageDevice* device)
{
ASSERT(device != NULL);
ASSERT(device->m_context != NULL);

return device->m_BSD->GetDeviceInfo(device->m_context);
}

Expand All @@ -553,7 +562,7 @@ DeviceBlockInfo* BlockStorageDevice_GetDeviceInfo(BlockStorageDevice* device)
// for the extra sector information.
//
// Returns:
// true if succesful; false if not
// true if successful; false if not
//
// Remarks:
// This function reads the number of sectors specified from the device.
Expand All @@ -568,6 +577,9 @@ DeviceBlockInfo* BlockStorageDevice_GetDeviceInfo(BlockStorageDevice* device)
//
bool BlockStorageDevice_Read(BlockStorageDevice* device, unsigned int startAddress, unsigned int numBytes, unsigned char* buffer)
{
ASSERT(device != NULL);
ASSERT(device->m_context != NULL);

return device->m_BSD->Read(device->m_context, startAddress, numBytes, buffer);
}

Expand All @@ -586,7 +598,7 @@ bool BlockStorageDevice_Read(BlockStorageDevice* device, unsigned int startAddre
// for the extra sector information.
//
// Returns:
// true if succesful; false if not
// true if successful; false if not
//
// Remarks:
// This function reads the number of sectors specified from the device.
Expand All @@ -604,11 +616,17 @@ bool BlockStorageDevice_Read(BlockStorageDevice* device, unsigned int startAddre
//
bool BlockStorageDevice_Write(BlockStorageDevice* device, unsigned int startAddress, unsigned int numBytes, unsigned char* buffer, bool readModifyWrite)
{
ASSERT(device != NULL);
ASSERT(device->m_context != NULL);

return device->m_BSD->Write(device->m_context, startAddress, numBytes, buffer, readModifyWrite);
}

bool BlockStorageDevice_Memset(BlockStorageDevice* device, unsigned int startAddress, unsigned char buffer, unsigned int numBytes)
{
ASSERT(device != NULL);
ASSERT(device->m_context != NULL);

return device->m_BSD->Memset(device->m_context, startAddress, buffer, numBytes);
}

Expand All @@ -630,6 +648,9 @@ bool BlockStorageDevice_Memset(BlockStorageDevice* device, unsigned int startAdd
//
bool BlockStorageDevice_IsBlockErased(BlockStorageDevice* device, unsigned int blockStartAddress, unsigned int length)
{
ASSERT(device != NULL);
ASSERT(device->m_context != NULL);

return device->m_BSD->IsBlockErased(device->m_context, blockStartAddress, length);
}

Expand All @@ -641,13 +662,16 @@ bool BlockStorageDevice_IsBlockErased(BlockStorageDevice* device, unsigned int b
// Address - Logical Sector Address
//
// Returns:
// true if succesful; false if not
// true if successful; false if not
//
// Remarks:
// Erases the block containing the sector address specified.
//
bool BlockStorageDevice_EraseBlock(BlockStorageDevice* device, unsigned int address)
{
ASSERT(device != NULL);
ASSERT(device->m_context != NULL);

return device->m_BSD->EraseBlock(device->m_context, address);
}

Expand All @@ -665,32 +689,44 @@ bool BlockStorageDevice_EraseBlock(BlockStorageDevice* device, unsigned int addr
//
void BlockStorageDevice_SetPowerState(BlockStorageDevice* device, unsigned int state)
{
ASSERT(device != NULL);
ASSERT(device->m_context != NULL);

device->m_BSD->SetPowerState(device->m_context, state);
}

bool BlockStorageDevice_FindRegionFromAddress(BlockStorageDevice* device, unsigned int address, unsigned int* blockRegionIndex, unsigned int* blockRangeIndex)
{
ASSERT(device != NULL);

DeviceBlockInfo* deviceInfo = BlockStorageDevice_GetDeviceInfo(device);

return DeviceBlockInfo_FindRegionFromAddress(deviceInfo, address, blockRegionIndex, blockRangeIndex);
}

bool BlockStorageDevice_FindForBlockUsage(BlockStorageDevice* device, unsigned int blockUsage, unsigned int* address, unsigned int* blockRegionIndex, unsigned int* blockRangeIndex)
{
ASSERT(device != NULL);

DeviceBlockInfo* deviceInfo = BlockStorageDevice_GetDeviceInfo(device);

return DeviceBlockInfo_FindForBlockUsage(deviceInfo, blockUsage, address, blockRegionIndex, blockRangeIndex);
}

bool BlockStorageDevice_FindNextUsageBlock(BlockStorageDevice* device, unsigned int blockUsage, unsigned int* address, unsigned int* blockRegionIndex, unsigned int* blockRangeIndex)
{
ASSERT(device != NULL);

DeviceBlockInfo* deviceInfo = BlockStorageDevice_GetDeviceInfo(device);

return DeviceBlockInfo_FindNextUsageBlock(deviceInfo, blockUsage, address, blockRegionIndex, blockRangeIndex);
}

bool BlockStorageDevice_GetMemoryMappedAddress(BlockStorageDevice* device, unsigned int blockRegionIndex, unsigned int blockRangeIndex, unsigned int* address)
{
ASSERT(device != NULL);
ASSERT(device->m_context != NULL);

return device->m_BSD->GetMemoryMappedAddress(device->m_context, blockRegionIndex, blockRangeIndex, address);
}

Expand Down Expand Up @@ -743,7 +779,7 @@ bool BlockStorageList_AddDevice(BlockStorageDevice* pBSD, IBlockStorageDevice* v
success = BlockStorageDevice_InitializeDevice(pBSD);
}

// add device to list only init was succesfull
// add device to list only init was successful
if(success)
{
// add the BSD
Expand All @@ -762,7 +798,6 @@ bool BlockStorageList_AddDevice(BlockStorageDevice* pBSD, IBlockStorageDevice* v

bool BlockStorageList_RemoveDevice(BlockStorageDevice* pBSD, bool unInit)
{

// find device
for(int i = 0; i < TARGET_BLOCKSTORAGE_COUNT; i++)
{
Expand Down
10 changes: 5 additions & 5 deletions src/PAL/Include/nanoPAL_BlockStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ struct IBLOCKSTORAGEDEVICE
// Input:
//
// Returns:
// true if succesful; false if not
// true if successful; false if not
//
// Remarks:
// No other functions in this interface may be called
Expand Down Expand Up @@ -325,7 +325,7 @@ struct IBLOCKSTORAGEDEVICE
// for the extra sector information.
//
// Returns:
// true if succesful; false if not
// true if successful; false if not
//
// Remarks:
// This function reads the number of sectors specified from the device.
Expand Down Expand Up @@ -355,7 +355,7 @@ struct IBLOCKSTORAGEDEVICE
// for the extra sector information.
//
// Returns:
// true if succesful; false if not
// true if successful; false if not
//
// Remarks:
// This function reads the number of sectors specified from the device.
Expand Down Expand Up @@ -387,7 +387,7 @@ struct IBLOCKSTORAGEDEVICE
// blockStartAddress - Logical Sector Address
//
// Returns:
// true if it is erassed, otherwise false
// true if it is erased, otherwise false
//
// Remarks:
// Check the block containing the sector address specified.
Expand All @@ -402,7 +402,7 @@ struct IBLOCKSTORAGEDEVICE
// address - Logical Sector Address
//
// Returns:
// true if succesful; false if not
// true if successful; false if not
//
// Remarks:
// Erases the block containing the sector address specified.
Expand Down