Skip to content

Commit eabdf8f

Browse files
committed
Fix style: BufferedBlockDevice
1 parent 896c215 commit eabdf8f

File tree

1 file changed

+28
-44
lines changed
  • APIs_Storage/BufferedBlockDevice

1 file changed

+28
-44
lines changed
Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,35 @@
1-
/* mbed Microcontroller Library
2-
* Copyright (c) 2019 ARM Limited
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
#include "BufferedBlockDevice.h"
182
#include "HeapBlockDevice.h"
193
#include <cstdio>
204

215
int main()
226
{
23-
// Define a HeapBlockDevice with program size 512 bytes and read size 256
24-
HeapBlockDevice heap_bd(1024, 256, 512, 512);
25-
// BufferedBlockDevice is used to program or read a much smaller amount of data than the minimum program or read size supported by the underlying block device
26-
BufferedBlockDevice buf_bd(&heap_bd);
27-
28-
// This initializes the buffered block device (as well as the underlying heap block device)
29-
int err = buf_bd.init();
30-
31-
uint8_t buf[8];
32-
for (uint8_t i = 0; i < sizeof(buf); i++) {
33-
buf[i] = i;
34-
}
35-
36-
// Now we can program an 8-byte buffer (we couldn't do that in the underlying block device, which had a 512-byte program size)
37-
err = buf_bd.program(buf, 0, sizeof(buf));
38-
39-
40-
// Now read any amount of data from any address (for example, the last three bytes of data from address 5)
41-
memset(buf,0,8);
42-
err = buf_bd.read(buf, 5, 3);
43-
44-
printf("Read Data (Expected 5,6,7): %d %d %d\n", (int)(buf[0]), (int)(buf[1]), (int)(buf[2]));
45-
46-
// Ensure programmed data is flushed to the underlying block device
47-
err = buf_bd.sync();
48-
49-
// Finally, deinint the BufferedBlockDevice (which also deinits its underlying block device)
50-
err = buf_bd.deinit();
7+
// Define a HeapBlockDevice with program size 512 bytes and read size 256
8+
HeapBlockDevice heap_bd(1024, 256, 512, 512);
9+
// BufferedBlockDevice is used to program or read a much smaller amount of data than the minimum program or read size supported by the underlying block device
10+
BufferedBlockDevice buf_bd(&heap_bd);
11+
12+
// This initializes the buffered block device (as well as the underlying heap block device)
13+
int err = buf_bd.init();
14+
15+
uint8_t buf[8];
16+
for (uint8_t i = 0; i < sizeof(buf); i++) {
17+
buf[i] = i;
18+
}
19+
20+
// Now we can program an 8-byte buffer (we couldn't do that in the underlying block device, which had a 512-byte program size)
21+
err = buf_bd.program(buf, 0, sizeof(buf));
22+
23+
24+
// Now read any amount of data from any address (for example, the last three bytes of data from address 5)
25+
memset(buf, 0, 8);
26+
err = buf_bd.read(buf, 5, 3);
27+
28+
printf("Read Data (Expected 5,6,7): %d %d %d\n", (int)(buf[0]), (int)(buf[1]), (int)(buf[2]));
29+
30+
// Ensure programmed data is flushed to the underlying block device
31+
err = buf_bd.sync();
32+
33+
// Finally, deinint the BufferedBlockDevice (which also deinits its underlying block device)
34+
err = buf_bd.deinit();
5135
}

0 commit comments

Comments
 (0)