-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
There was a problem hiding this 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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*)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing p?
38efe43
to
043028b
Compare
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. |
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?). |
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). |
👍 for getting the testing in with the feature. |
Certainly the 3 character prefix is hard to beat with a namespace. |
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
per @sg- on mbed-os#3449
options: MemBlockDevice - Same as mbed 2 class, but ambiguous RAMBlockDevice - May be ambiguous with BD on unmanaged RAM HeapBlockDevice - Seems the most reasonable name
/morph test-nightly |
Result: FAILUREYour command has finished executing! Here's what you wrote!
OutputBuild failed! |
1474b75
to
5219a72
Compare
0964775
to
f17c7dc
Compare
Continued over here #3671 |
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