Skip to content

storage: Add block device API #3449

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

Closed
wants to merge 7 commits into from

Conversation

geky
Copy link
Contributor

@geky geky commented Dec 15, 2016

Add prototype c++ block device api to the feature_block_device branch. Provides a simple interface class that can be extended to support different block devices.

Adopted the block device api in the SDBlockDevice and MemBlockDevice classes taken from mbed 2. Also added integration into the FATFileSystem class from mbed 2.

Sorry this is coming in so late, the topic was delayed by spawned discussions and put on hold for the release. I expect this may require changes based on @simonqhughes's requirements, just did not want to lose the work.

cc @simonqhughes, @c1728p9, @theotherjimmy

@geky
Copy link
Contributor Author

geky commented Dec 19, 2016

Note: This is order dependent on #3468. Directory structure will be updated to match when #3468 is merged.

@geky geky changed the base branch from feature_block_device to feature-storage December 19, 2016 23:57
@geky geky changed the title feature_block_device: Add block device API feature-storage: Add block device API Dec 19, 2016
@geky geky changed the title feature-storage: Add block device API storage: Add block device API Dec 19, 2016
Copy link
Contributor

@c1728p9 c1728p9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to keep SDFileSystem around since user are use to using it. It should be straight forward to implement using the existing SDBlockDevice and FATFileSystem.

@@ -157,10 +166,13 @@ int SDFileSystem::initialise_card() {
}
_spi.unlock();

int i = _cmd(0, 0);
printf("%x\n", i);
Copy link
Contributor

@theotherjimmy theotherjimmy Jan 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this printf supposed to be here? maybe debug_if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I was just verifying progress with mbed test so I didn't notice any serial output. will update

Copy link
Contributor

@sg- sg- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! The long typedef error names pushing parameters to a second line is kind of annoying. Especially as the application examples seem to use the native types rather than the classes type.

bd_error_t MemBlockDevice::init()
{
if (!_blocks) {
_blocks = (uint8_t**)malloc(_count*sizeof(uint8_t*));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we decide a while back that out of memory was a programming terminating error? Guessing the intent is to use init for partitioning or multiple instances so new maybe a better choice here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can update to new[], this failure is unlikely relative to the allocation of the actual blocks of memory though it may still fail as a result of the user requesting too large a block of memory.

#include "mbed.h"


/** Lazily allocated heap-backed block device
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heap is usually in RAM so maybe name RAMBlockDevice or HeapBlockDevice to remove ambiguity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking about the name, MemBlockDevice comes from mbed 2 class. HeapBlockDevice seems the least ambiguous since you could have a RAMBlockDevice that is mapped to a region of RAM.

#include "mbed_debug.h"

#define SD_COMMAND_TIMEOUT 5000

#define SD_DBG 0
#define SD_DBG 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this better enabled or disabled by default? I'd hate people not to see the debug member and change this to turn it off and fork the library

virtual int sync();

/**
* Formats a logical drive, FDISK artitioning rule, 512 bytes per cluster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing p?

@geky geky force-pushed the block-device-2 branch 2 times, most recently from 38efe43 to 043028b Compare January 10, 2017 00:35
@geky
Copy link
Contributor Author

geky commented Jan 10, 2017

Sorry about the awful stateof debugging hooks in the pr. They should all be removed now and the directory structure should be updated to match the structure of the feature-branch.

@geky
Copy link
Contributor Author

geky commented Jan 10, 2017

Everything should be updated and good to go besides tests/review.

@c1728p9, Do we still need to keep around the SDFileSystem? From offline discussion it sounded like a no since it was not included in the mbed 2 library. Let me know if you want me to include it with deprecations.

@sg- the long typedef names are a bit ugly to look at, but they are the most clear. We adopted similar names in the nsapi (example) which have worked well for identifying which functions don't return simple error codes. Users don't need to use the long names, and can stick to simple types.

Do you think there is better formatting (all one line? indention to line up parens?).

@c1728p9
Copy link
Contributor

c1728p9 commented Jan 10, 2017

After our discussion no need to keep SDFileSystem in the OS.

One possibly way you could simplify naming is to remove the name prefix from the enum and values and instead have it scoped to the class, similar to I2C and Serial.

@geky
Copy link
Contributor Author

geky commented Jan 10, 2017

Not so sure about moving the type names into class scope. The namespacing works fine for inlined functions, but explodes in any external functions:

BlockDevice::count_or_error_t HeapBlockDevice::write(const void *b,
    BlockDevice::block_t block, BlockDevice::count_t count)
{
    blablabla;
}

The types declared in Serial/I2C see little use for this reason. A separate namespace would be more practical, but I'm worried about aggressive namespacing since we would loose the grepability and compatiblity with C. I'm not really sure the 3-character savings helps as much as just reformatting the functions anyways (should be updated to reflect this).

@theotherjimmy
Copy link
Contributor

👍 for getting the testing in with the feature.

@theotherjimmy
Copy link
Contributor

Certainly the 3 character prefix is hard to beat with a namespace.

geky added 4 commits January 10, 2017 15:18
Adopted in the SDBlockDevice and MemBlockDevice taken from mbed 2
Enables persistant storage between de/reinitialization cycles
Relatively unmodified, except for the addition of support for
interchangeable block devices
options:
MemBlockDevice - Same as mbed 2 class, but ambiguous
RAMBlockDevice - May be ambiguous with BD on unmanaged RAM
HeapBlockDevice - Seems the most reasonable name
@adbridge
Copy link
Contributor

/morph test-nightly

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 1388

Build failed!

@geky geky force-pushed the block-device-2 branch 2 times, most recently from 1474b75 to 5219a72 Compare January 13, 2017 21:27
@geky geky force-pushed the block-device-2 branch 2 times, most recently from 0964775 to f17c7dc Compare January 17, 2017 20:39
@geky
Copy link
Contributor Author

geky commented Jan 31, 2017

Continued over here #3671

@geky geky closed this Jan 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants