mirror of https://github.com/ARMmbed/mbed-os.git
Moving SD, SPIF and FLASHIAP into mbedos and refactoring features storage directory structure.
parent
881929eef7
commit
ed8e170d15
|
@ -187,12 +187,11 @@ matrix:
|
|||
|
||||
- env:
|
||||
- NAME=littlefs
|
||||
- LITTLEFS=features/filesystem/littlefs
|
||||
- LITTLEFS=features/storage/filesystem/littlefs
|
||||
install:
|
||||
# Install dependencies
|
||||
- sudo apt-get install gcc-arm-embedded fuse libfuse-dev
|
||||
- pip install -r requirements.txt
|
||||
- git clone https://github.com/armmbed/spiflash-driver.git
|
||||
# Print versions
|
||||
- arm-none-eabi-gcc --version
|
||||
- gcc --version
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
script:
|
||||
# Check that examples compile
|
||||
- sed -n '/``` cpp/,${/```$/q;/```/d;p}' README.md > main.cpp &&
|
||||
PYTHONPATH=mbed-os python mbed-os/tools/make.py -t GCC_ARM -m K82F
|
||||
--source=. --build=BUILD/K82F/GCC_ARM -j0 &&
|
||||
rm main.cpp
|
||||
- sed -n '/@code/,${/@endcode/q;/@/d;s/^ \*//;p}' DataFlashBlockDevice.h > main.cpp &&
|
||||
PYTHONPATH=mbed-os python mbed-os/tools/make.py -t GCC_ARM -m K82F
|
||||
--source=. --build=BUILD/K82F/GCC_ARM -j0 &&
|
||||
rm main.cpp
|
||||
|
||||
# Check that tests compile
|
||||
- rm -r BUILD && PYTHONPATH=mbed-os python mbed-os/tools/test.py
|
||||
-t GCC_ARM -m K82F --source=. --build=BUILD/TESTS/K82F/GCC_ARM -j0
|
||||
-n tests*
|
||||
|
||||
python:
|
||||
- "2.7"
|
||||
|
||||
install:
|
||||
# Get arm-none-eabi-gcc
|
||||
- sudo add-apt-repository -y ppa:terry.guo/gcc-arm-embedded
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq gcc-arm-none-eabi --force-yes
|
||||
# Get dependencies
|
||||
- git clone https://github.com/armmbed/mbed-os.git
|
||||
# Install python dependencies
|
||||
- sudo pip install -r mbed-os/requirements.txt
|
|
@ -131,11 +131,11 @@ enum dummy {
|
|||
};
|
||||
|
||||
DataFlashBlockDevice::DataFlashBlockDevice(PinName mosi,
|
||||
PinName miso,
|
||||
PinName sclk,
|
||||
PinName cs,
|
||||
int freq,
|
||||
PinName nwp)
|
||||
PinName miso,
|
||||
PinName sclk,
|
||||
PinName cs,
|
||||
int freq,
|
||||
PinName nwp)
|
||||
: _spi(mosi, miso, sclk),
|
||||
_cs(cs, 1),
|
||||
_nwp(nwp),
|
||||
|
@ -244,7 +244,7 @@ int DataFlashBlockDevice::init()
|
|||
|
||||
/* adjust device size */
|
||||
_device_size = (_device_size / DATAFLASH_PAGE_SIZE_256) *
|
||||
DATAFLASH_PAGE_SIZE_264;
|
||||
DATAFLASH_PAGE_SIZE_264;
|
||||
}
|
||||
break;
|
||||
case DATAFLASH_ID_DENSITY_16_MBIT:
|
||||
|
@ -258,7 +258,7 @@ int DataFlashBlockDevice::init()
|
|||
|
||||
/* adjust device size */
|
||||
_device_size = (_device_size / DATAFLASH_PAGE_SIZE_512) *
|
||||
DATAFLASH_PAGE_SIZE_528;
|
||||
DATAFLASH_PAGE_SIZE_528;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -361,7 +361,7 @@ int DataFlashBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t
|
|||
/* check parameters are valid and the write is within bounds */
|
||||
if (is_valid_program(addr, size) && buffer) {
|
||||
|
||||
const uint8_t * external_buffer = static_cast<const uint8_t*>(buffer);
|
||||
const uint8_t *external_buffer = static_cast<const uint8_t *>(buffer);
|
||||
|
||||
/* Each write command can only cover one page at a time.
|
||||
Find page and current page offset for handling unaligned writes.
|
||||
|
@ -577,7 +577,7 @@ void DataFlashBlockDevice::_write_enable(bool enable)
|
|||
|
||||
/* enable writing, disable write protection */
|
||||
if (enable) {
|
||||
/* if not-write-protected pin is connected, select it */
|
||||
/* if not-write-protected pin is connected, select it */
|
||||
if (_nwp.is_connected()) {
|
||||
_nwp = 1;
|
||||
}
|
||||
|
@ -612,8 +612,8 @@ int DataFlashBlockDevice::_sync(void)
|
|||
The polling interval is based on the typical page program time.
|
||||
*/
|
||||
for (uint32_t timeout = 0;
|
||||
timeout < DATAFLASH_TIMEOUT;
|
||||
timeout += DATAFLASH_TIMING_ERASE_PROGRAM_PAGE) {
|
||||
timeout < DATAFLASH_TIMEOUT;
|
||||
timeout += DATAFLASH_TIMING_ERASE_PROGRAM_PAGE) {
|
||||
|
||||
/* get status register */
|
||||
uint16_t status = _get_register(DATAFLASH_OP_STATUS);
|
||||
|
@ -622,12 +622,12 @@ int DataFlashBlockDevice::_sync(void)
|
|||
if (status & DATAFLASH_BIT_ERASE_PROGRAM_ERROR) {
|
||||
DEBUG_PRINTF("DATAFLASH_BIT_ERASE_PROGRAM_ERROR\r\n");
|
||||
break;
|
||||
/* device ready, set OK code set */
|
||||
/* device ready, set OK code set */
|
||||
} else if (status & DATAFLASH_BIT_READY) {
|
||||
DEBUG_PRINTF("DATAFLASH_BIT_READY\r\n");
|
||||
result = BD_ERROR_OK;
|
||||
break;
|
||||
/* wait the typical write period before trying again */
|
||||
/* wait the typical write period before trying again */
|
||||
} else {
|
||||
DEBUG_PRINTF("wait_ms: %d\r\n", DATAFLASH_TIMING_ERASE_PROGRAM_PAGE);
|
||||
wait_ms(DATAFLASH_TIMING_ERASE_PROGRAM_PAGE);
|
||||
|
@ -647,9 +647,9 @@ int DataFlashBlockDevice::_sync(void)
|
|||
* @return BlockDevice error code.
|
||||
*/
|
||||
int DataFlashBlockDevice::_write_page(const uint8_t *buffer,
|
||||
uint32_t page,
|
||||
uint32_t offset,
|
||||
uint32_t size)
|
||||
uint32_t page,
|
||||
uint32_t offset,
|
||||
uint32_t size)
|
||||
{
|
||||
DEBUG_PRINTF("_write_page: %p %" PRIX32 " %" PRIX32 "\r\n", buffer, page, size);
|
||||
|
||||
|
|
|
@ -71,11 +71,11 @@ public:
|
|||
* @param freq Clock speed of the SPI bus (defaults to 40MHz)
|
||||
*/
|
||||
DataFlashBlockDevice(PinName mosi,
|
||||
PinName miso,
|
||||
PinName sclk,
|
||||
PinName csel,
|
||||
int freq = 40000000,
|
||||
PinName nowp = NC);
|
||||
PinName miso,
|
||||
PinName sclk,
|
||||
PinName csel,
|
||||
int freq = 40000000,
|
||||
PinName nowp = NC);
|
||||
|
||||
/** Initialize a block device
|
||||
*
|
||||
|
|
|
@ -1,165 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and
|
||||
distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||
owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
||||
that control, are controlled by, or are under common control with that entity.
|
||||
For the purposes of this definition, "control" means (i) the power, direct or
|
||||
indirect, to cause the direction or management of such entity, whether by
|
||||
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
||||
permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including
|
||||
but not limited to software source code, documentation source, and configuration
|
||||
files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or
|
||||
translation of a Source form, including but not limited to compiled object code,
|
||||
generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
||||
available under the License, as indicated by a copyright notice that is included
|
||||
in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
||||
is based on (or derived from) the Work and for which the editorial revisions,
|
||||
annotations, elaborations, or other modifications represent, as a whole, an
|
||||
original work of authorship. For the purposes of this License, Derivative Works
|
||||
shall not include works that remain separable from, or merely link (or bind by
|
||||
name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version
|
||||
of the Work and any modifications or additions to that Work or Derivative Works
|
||||
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
||||
by the copyright owner or by an individual or Legal Entity authorized to submit
|
||||
on behalf of the copyright owner. For the purposes of this definition,
|
||||
"submitted" means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems, and
|
||||
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
||||
the purpose of discussing and improving the Work, but excluding communication
|
||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||
owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||
of whom a Contribution has been received by Licensor and subsequently
|
||||
incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the Work and such
|
||||
Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable (except as stated in this section) patent license to make, have
|
||||
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
||||
such license applies only to those patent claims licensable by such Contributor
|
||||
that are necessarily infringed by their Contribution(s) alone or by combination
|
||||
of their Contribution(s) with the Work to which such Contribution(s) was
|
||||
submitted. If You institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
||||
Contribution incorporated within the Work constitutes direct or contributory
|
||||
patent infringement, then any patent licenses granted to You under this License
|
||||
for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution.
|
||||
|
||||
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
||||
in any medium, with or without modifications, and in Source or Object form,
|
||||
provided that You meet the following conditions:
|
||||
|
||||
You must give any other recipients of the Work or Derivative Works a copy of
|
||||
this License; and
|
||||
You must cause any modified files to carry prominent notices stating that You
|
||||
changed the files; and
|
||||
You must retain, in the Source form of any Derivative Works that You distribute,
|
||||
all copyright, patent, trademark, and attribution notices from the Source form
|
||||
of the Work, excluding those notices that do not pertain to any part of the
|
||||
Derivative Works; and
|
||||
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
||||
Derivative Works that You distribute must include a readable copy of the
|
||||
attribution notices contained within such NOTICE file, excluding those notices
|
||||
that do not pertain to any part of the Derivative Works, in at least one of the
|
||||
following places: within a NOTICE text file distributed as part of the
|
||||
Derivative Works; within the Source form or documentation, if provided along
|
||||
with the Derivative Works; or, within a display generated by the Derivative
|
||||
Works, if and wherever such third-party notices normally appear. The contents of
|
||||
the NOTICE file are for informational purposes only and do not modify the
|
||||
License. You may add Your own attribution notices within Derivative Works that
|
||||
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
||||
provided that such additional attribution notices cannot be construed as
|
||||
modifying the License.
|
||||
You may add Your own copyright statement to Your modifications and may provide
|
||||
additional or different license terms and conditions for use, reproduction, or
|
||||
distribution of Your modifications, or for any such Derivative Works as a whole,
|
||||
provided Your use, reproduction, and distribution of the Work otherwise complies
|
||||
with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions.
|
||||
|
||||
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
||||
for inclusion in the Work by You to the Licensor shall be under the terms and
|
||||
conditions of this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
||||
any separate license agreement you may have executed with Licensor regarding
|
||||
such Contributions.
|
||||
|
||||
6. Trademarks.
|
||||
|
||||
This License does not grant permission to use the trade names, trademarks,
|
||||
service marks, or product names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, Licensor provides the
|
||||
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
||||
including, without limitation, any warranties or conditions of TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
||||
solely responsible for determining the appropriateness of using or
|
||||
redistributing the Work and assume any risks associated with Your exercise of
|
||||
permissions under this License.
|
||||
|
||||
8. Limitation of Liability.
|
||||
|
||||
In no event and under no legal theory, whether in tort (including negligence),
|
||||
contract, or otherwise, unless required by applicable law (such as deliberate
|
||||
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special, incidental,
|
||||
or consequential damages of any character arising as a result of this License or
|
||||
out of the use or inability to use the Work (including but not limited to
|
||||
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
||||
any and all other commercial damages or losses), even if such Contributor has
|
||||
been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability.
|
||||
|
||||
While redistributing the Work or Derivative Works thereof, You may choose to
|
||||
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
||||
other liability obligations and/or rights consistent with this License. However,
|
||||
in accepting such obligations, You may act only on Your own behalf and on Your
|
||||
sole responsibility, not on behalf of any other Contributor, and only if You
|
||||
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason of your
|
||||
accepting any such warranty or additional liability.
|
|
@ -1,54 +0,0 @@
|
|||
# DataFlash Driver
|
||||
|
||||
Block device driver for I2C based EEPROM devices such as the Adesto AT45DB
|
||||
series of devices.
|
||||
|
||||
DataFlash is a memory protocol that combines flash with SRAM buffers for a
|
||||
simple programming interface. DataFlash supports byte-sized read and writes,
|
||||
with an erase size of around 528 bytes or sometimes 1056 bytes. DataFlash
|
||||
provides erase sizes with and extra 16 bytes for error correction codes (ECC)
|
||||
so that a flash translation layer (FTL) may still present 512 byte erase sizes.
|
||||
|
||||
The DataFlashBlockDevice can be configured to force the underlying device
|
||||
to use either the binary size (ie 512 bytes) or the raw DataFlash size
|
||||
(ie 528 bytes).
|
||||
|
||||
More info on DataFlash can be found on wikipedia:
|
||||
https://en.wikipedia.org/wiki/DataFlash
|
||||
|
||||
``` cpp
|
||||
// Here's an example using the AT45DB on the K64F
|
||||
#include "mbed.h"
|
||||
#include "DataFlashBlockDevice.h"
|
||||
|
||||
// Create DataFlash on SPI bus with PTE5 as chip select
|
||||
DataFlashBlockDevice dataflash(PTE2, PTE4, PTE1, PTE5);
|
||||
|
||||
// Create DataFlash on SPI bus with PTE6 as write-protect
|
||||
DataFlashBlockDevice dataflash2(PTE2, PTE4, PTE1, PTE5, PTE6);
|
||||
|
||||
int main() {
|
||||
printf("dataflash test\n");
|
||||
|
||||
// Initialize the SPI flash device and print the memory layout
|
||||
dataflash.init();
|
||||
printf("dataflash size: %llu\n", dataflash.size());
|
||||
printf("dataflash read size: %llu\n", dataflash.get_read_size());
|
||||
printf("dataflash program size: %llu\n", dataflash.get_program_size());
|
||||
printf("dataflash erase size: %llu\n", dataflash.get_erase_size());
|
||||
|
||||
// Write "Hello World!" to the first block
|
||||
char *buffer = (char*)malloc(dataflash.get_erase_size());
|
||||
sprintf(buffer, "Hello World!\n");
|
||||
dataflash.erase(0, dataflash.get_erase_size());
|
||||
dataflash.program(buffer, 0, dataflash.get_erase_size());
|
||||
|
||||
// Read back what was stored
|
||||
dataflash.read(buffer, 0, dataflash.get_erase_size());
|
||||
printf("%s", buffer);
|
||||
|
||||
// Deinitialize the device
|
||||
dataflash.deinit();
|
||||
}
|
||||
```
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
#include "DataFlashBlockDevice.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
#define TEST_PINS PTB22, PTB23, PTB21, PTB20
|
||||
#define TEST_FREQ 40000000
|
||||
|
||||
#define TEST_BLOCK_COUNT 10
|
||||
#define TEST_ERROR_MASK 16
|
||||
|
||||
const struct {
|
||||
const char *name;
|
||||
bd_size_t (BlockDevice::*method)() const;
|
||||
} ATTRS[] = {
|
||||
{"read size", &BlockDevice::get_read_size},
|
||||
{"program size", &BlockDevice::get_program_size},
|
||||
{"erase size", &BlockDevice::get_erase_size},
|
||||
{"total size", &BlockDevice::size},
|
||||
};
|
||||
|
||||
|
||||
void test_read_write() {
|
||||
DataFlashBlockDevice bd(TEST_PINS, TEST_FREQ);
|
||||
|
||||
int err = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
for (unsigned a = 0; a < sizeof(ATTRS)/sizeof(ATTRS[0]); a++) {
|
||||
static const char *prefixes[] = {"", "k", "M", "G"};
|
||||
for (int i = 3; i >= 0; i--) {
|
||||
bd_size_t size = (bd.*ATTRS[a].method)();
|
||||
if (size >= (1ULL << 10*i)) {
|
||||
printf("%s: %llu%sbytes (%llubytes)\n",
|
||||
ATTRS[a].name, size >> 10*i, prefixes[i], size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bd_size_t block_size = bd.get_erase_size();
|
||||
uint8_t *write_block = new uint8_t[block_size];
|
||||
uint8_t *read_block = new uint8_t[block_size];
|
||||
uint8_t *error_mask = new uint8_t[TEST_ERROR_MASK];
|
||||
unsigned addrwidth = ceil(log(float(bd.size()-1)) / log(float(16)))+1;
|
||||
|
||||
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
|
||||
// Find a random block
|
||||
bd_addr_t block = (rand()*block_size) % bd.size();
|
||||
|
||||
// Use next random number as temporary seed to keep
|
||||
// the address progressing in the pseudorandom sequence
|
||||
unsigned seed = rand();
|
||||
|
||||
// Fill with random sequence
|
||||
srand(seed);
|
||||
for (bd_size_t i = 0; i < block_size; i++) {
|
||||
write_block[i] = 0xff & rand();
|
||||
}
|
||||
|
||||
// Write, sync, and read the block
|
||||
printf("test %0*llx:%llu...\n", addrwidth, block, block_size);
|
||||
|
||||
err = bd.erase(block, block_size);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
err = bd.program(write_block, block, block_size);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("write %0*llx:%llu ", addrwidth, block, block_size);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
printf("%02x", write_block[i]);
|
||||
}
|
||||
printf("...\n");
|
||||
|
||||
err = bd.read(read_block, block, block_size);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("read %0*llx:%llu ", addrwidth, block, block_size);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
printf("%02x", read_block[i]);
|
||||
}
|
||||
printf("...\n");
|
||||
|
||||
// Find error mask for debugging
|
||||
memset(error_mask, 0, TEST_ERROR_MASK);
|
||||
bd_size_t error_scale = block_size / (TEST_ERROR_MASK*8);
|
||||
|
||||
srand(seed);
|
||||
for (bd_size_t i = 0; i < TEST_ERROR_MASK*8; i++) {
|
||||
for (bd_size_t j = 0; j < error_scale; j++) {
|
||||
if ((0xff & rand()) != read_block[i*error_scale + j]) {
|
||||
error_mask[i/8] |= 1 << (i%8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("error %0*llx:%llu ", addrwidth, block, block_size);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
printf("%02x", error_mask[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Check that the data was unmodified
|
||||
srand(seed);
|
||||
for (bd_size_t i = 0; i < block_size; i++) {
|
||||
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
|
||||
}
|
||||
}
|
||||
|
||||
err = bd.deinit();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
}
|
||||
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP(30, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("Testing read write random blocks", test_read_write),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
return !Harness::run(specification);
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
util/*
|
||||
|
|
@ -19,14 +19,11 @@
|
|||
|
||||
#ifdef DEVICE_FLASH
|
||||
|
||||
#include "FlashIAP.h"
|
||||
#include "BlockDevice.h"
|
||||
#include <mbed.h>
|
||||
#include "platform/mbed_toolchain.h"
|
||||
|
||||
/** BlockDevice using the FlashIAP API
|
||||
*
|
||||
* @code
|
||||
* #include "mbed.h"
|
||||
* #include "FlashIAPBlockDevice.h"
|
||||
*
|
||||
*/
|
||||
class FlashIAPBlockDevice : public BlockDevice {
|
||||
|
@ -117,7 +114,7 @@ public:
|
|||
|
||||
private:
|
||||
// Device configuration
|
||||
FlashIAP _flash;
|
||||
mbed::FlashIAP _flash;
|
||||
bd_addr_t _base;
|
||||
bd_size_t _size;
|
||||
bool _is_initialized;
|
||||
|
|
|
@ -1,165 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and
|
||||
distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||
owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
||||
that control, are controlled by, or are under common control with that entity.
|
||||
For the purposes of this definition, "control" means (i) the power, direct or
|
||||
indirect, to cause the direction or management of such entity, whether by
|
||||
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
||||
permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including
|
||||
but not limited to software source code, documentation source, and configuration
|
||||
files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or
|
||||
translation of a Source form, including but not limited to compiled object code,
|
||||
generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
||||
available under the License, as indicated by a copyright notice that is included
|
||||
in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
||||
is based on (or derived from) the Work and for which the editorial revisions,
|
||||
annotations, elaborations, or other modifications represent, as a whole, an
|
||||
original work of authorship. For the purposes of this License, Derivative Works
|
||||
shall not include works that remain separable from, or merely link (or bind by
|
||||
name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version
|
||||
of the Work and any modifications or additions to that Work or Derivative Works
|
||||
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
||||
by the copyright owner or by an individual or Legal Entity authorized to submit
|
||||
on behalf of the copyright owner. For the purposes of this definition,
|
||||
"submitted" means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems, and
|
||||
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
||||
the purpose of discussing and improving the Work, but excluding communication
|
||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||
owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||
of whom a Contribution has been received by Licensor and subsequently
|
||||
incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the Work and such
|
||||
Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable (except as stated in this section) patent license to make, have
|
||||
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
||||
such license applies only to those patent claims licensable by such Contributor
|
||||
that are necessarily infringed by their Contribution(s) alone or by combination
|
||||
of their Contribution(s) with the Work to which such Contribution(s) was
|
||||
submitted. If You institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
||||
Contribution incorporated within the Work constitutes direct or contributory
|
||||
patent infringement, then any patent licenses granted to You under this License
|
||||
for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution.
|
||||
|
||||
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
||||
in any medium, with or without modifications, and in Source or Object form,
|
||||
provided that You meet the following conditions:
|
||||
|
||||
You must give any other recipients of the Work or Derivative Works a copy of
|
||||
this License; and
|
||||
You must cause any modified files to carry prominent notices stating that You
|
||||
changed the files; and
|
||||
You must retain, in the Source form of any Derivative Works that You distribute,
|
||||
all copyright, patent, trademark, and attribution notices from the Source form
|
||||
of the Work, excluding those notices that do not pertain to any part of the
|
||||
Derivative Works; and
|
||||
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
||||
Derivative Works that You distribute must include a readable copy of the
|
||||
attribution notices contained within such NOTICE file, excluding those notices
|
||||
that do not pertain to any part of the Derivative Works, in at least one of the
|
||||
following places: within a NOTICE text file distributed as part of the
|
||||
Derivative Works; within the Source form or documentation, if provided along
|
||||
with the Derivative Works; or, within a display generated by the Derivative
|
||||
Works, if and wherever such third-party notices normally appear. The contents of
|
||||
the NOTICE file are for informational purposes only and do not modify the
|
||||
License. You may add Your own attribution notices within Derivative Works that
|
||||
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
||||
provided that such additional attribution notices cannot be construed as
|
||||
modifying the License.
|
||||
You may add Your own copyright statement to Your modifications and may provide
|
||||
additional or different license terms and conditions for use, reproduction, or
|
||||
distribution of Your modifications, or for any such Derivative Works as a whole,
|
||||
provided Your use, reproduction, and distribution of the Work otherwise complies
|
||||
with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions.
|
||||
|
||||
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
||||
for inclusion in the Work by You to the Licensor shall be under the terms and
|
||||
conditions of this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
||||
any separate license agreement you may have executed with Licensor regarding
|
||||
such Contributions.
|
||||
|
||||
6. Trademarks.
|
||||
|
||||
This License does not grant permission to use the trade names, trademarks,
|
||||
service marks, or product names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, Licensor provides the
|
||||
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
||||
including, without limitation, any warranties or conditions of TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
||||
solely responsible for determining the appropriateness of using or
|
||||
redistributing the Work and assume any risks associated with Your exercise of
|
||||
permissions under this License.
|
||||
|
||||
8. Limitation of Liability.
|
||||
|
||||
In no event and under no legal theory, whether in tort (including negligence),
|
||||
contract, or otherwise, unless required by applicable law (such as deliberate
|
||||
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special, incidental,
|
||||
or consequential damages of any character arising as a result of this License or
|
||||
out of the use or inability to use the Work (including but not limited to
|
||||
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
||||
any and all other commercial damages or losses), even if such Contributor has
|
||||
been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability.
|
||||
|
||||
While redistributing the Work or Derivative Works thereof, You may choose to
|
||||
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
||||
other liability obligations and/or rights consistent with this License. However,
|
||||
in accepting such obligations, You may act only on Your own behalf and on Your
|
||||
sole responsibility, not on behalf of any other Contributor, and only if You
|
||||
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason of your
|
||||
accepting any such warranty or additional liability.
|
|
@ -1,18 +0,0 @@
|
|||
# Block Device driver build on top of FlashIAP API
|
||||
|
||||
## Warning
|
||||
This driver is **EXPERIMENTAL** and improper usage could kill your board's flash.
|
||||
|
||||
This driver should only be used on platforms where the FlashIAP implementation is using external flash or in conjunction with a filesystem with wear leveling, that can operate on a page size granularity.
|
||||
|
||||
Additional concerns:
|
||||
- The FlashIAP may freeze code execution for a long period of time while writing to flash. Not even high-priority irqs will be allowed to run, which may interrupt background processes.
|
||||
|
||||
|
||||
## Configuration
|
||||
None.
|
||||
|
||||
## Tested on
|
||||
|
||||
* K82F
|
||||
* K64F
|
|
@ -1,132 +0,0 @@
|
|||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
#include "FlashIAPBlockDevice.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
#define TEST_BLOCK_COUNT 10
|
||||
#define TEST_ERROR_MASK 16
|
||||
|
||||
const struct {
|
||||
const char *name;
|
||||
bd_size_t (BlockDevice::*method)() const;
|
||||
} ATTRS[] = {
|
||||
{"read size", &BlockDevice::get_read_size},
|
||||
{"program size", &BlockDevice::get_program_size},
|
||||
{"erase size", &BlockDevice::get_erase_size},
|
||||
{"total size", &BlockDevice::size},
|
||||
};
|
||||
|
||||
|
||||
void test_read_write() {
|
||||
FlashIAPBlockDevice bd;
|
||||
|
||||
int err = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
for (unsigned a = 0; a < sizeof(ATTRS)/sizeof(ATTRS[0]); a++) {
|
||||
static const char *prefixes[] = {"", "k", "M", "G"};
|
||||
for (int i = 3; i >= 0; i--) {
|
||||
bd_size_t size = (bd.*ATTRS[a].method)();
|
||||
if (size >= (1ULL << 10*i)) {
|
||||
printf("%s: %llu%sbytes (%llubytes)\n",
|
||||
ATTRS[a].name, size >> 10*i, prefixes[i], size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bd_size_t block_size = bd.get_erase_size();
|
||||
uint8_t *write_block = new uint8_t[block_size];
|
||||
uint8_t *read_block = new uint8_t[block_size];
|
||||
uint8_t *error_mask = new uint8_t[TEST_ERROR_MASK];
|
||||
unsigned addrwidth = ceil(log(float(bd.size()-1)) / log(float(16)))+1;
|
||||
|
||||
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
|
||||
// Find a random block
|
||||
bd_addr_t block = (rand()*block_size) % bd.size();
|
||||
|
||||
// Use next random number as temporary seed to keep
|
||||
// the address progressing in the pseudorandom sequence
|
||||
unsigned seed = rand();
|
||||
|
||||
// Fill with random sequence
|
||||
srand(seed);
|
||||
for (bd_size_t i = 0; i < block_size; i++) {
|
||||
write_block[i] = 0xff & rand();
|
||||
}
|
||||
|
||||
// Write, sync, and read the block
|
||||
printf("test %0*llx:%llu...\n", addrwidth, block, block_size);
|
||||
|
||||
err = bd.erase(block, block_size);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
err = bd.program(write_block, block, block_size);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("write %0*llx:%llu ", addrwidth, block, block_size);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
printf("%02x", write_block[i]);
|
||||
}
|
||||
printf("...\n");
|
||||
|
||||
err = bd.read(read_block, block, block_size);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("read %0*llx:%llu ", addrwidth, block, block_size);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
printf("%02x", read_block[i]);
|
||||
}
|
||||
printf("...\n");
|
||||
|
||||
// Find error mask for debugging
|
||||
memset(error_mask, 0, TEST_ERROR_MASK);
|
||||
bd_size_t error_scale = block_size / (TEST_ERROR_MASK*8);
|
||||
|
||||
srand(seed);
|
||||
for (bd_size_t i = 0; i < TEST_ERROR_MASK*8; i++) {
|
||||
for (bd_size_t j = 0; j < error_scale; j++) {
|
||||
if ((0xff & rand()) != read_block[i*error_scale + j]) {
|
||||
error_mask[i/8] |= 1 << (i%8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("error %0*llx:%llu ", addrwidth, block, block_size);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
printf("%02x", error_mask[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Check that the data was unmodified
|
||||
srand(seed);
|
||||
for (bd_size_t i = 0; i < block_size; i++) {
|
||||
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
|
||||
}
|
||||
}
|
||||
|
||||
err = bd.deinit();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
}
|
||||
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP(30, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("Testing read write random blocks", test_read_write),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
return !Harness::run(specification);
|
||||
}
|
|
@ -1,926 +0,0 @@
|
|||
/*
|
||||
* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2016 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/* The following copyright notice is reproduced from the glibc project
|
||||
* REF_LICENCE_GLIBC
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||
* This file is part of the GNU C Library.
|
||||
*
|
||||
* The GNU C Library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* The GNU C Library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with the GNU C Library; see the file COPYING.LIB. If
|
||||
* not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
* Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
/** @file basic.cpp POSIX File API (stdio) test cases
|
||||
*
|
||||
* Consult the documentation under the test-case functions for
|
||||
* a description of the individual test case.
|
||||
*
|
||||
* this file includes ports for the mbed 2 test cases from the following locations:
|
||||
* - https://github.com:/armmbed/mbed-os/features/unsupported/tests/mbed/dir_sd/main.cpp.
|
||||
* - https://github.com:/armmbed/mbed-os/features/unsupported/tests/mbed/file/main.cpp.
|
||||
* - https://github.com:/armmbed/mbed-os/features/unsupported/tests/mbed/sd/main.cpp
|
||||
* - https://github.com:/armmbed/mbed-os/features/unsupported/tests/mbed/sd_perf_handle/main.cpp
|
||||
* - https://github.com:/armmbed/mbed-os/features/unsupported/tests/mbed/sd_perf_stdio/main.cpp.
|
||||
*/
|
||||
|
||||
#include "mbed.h"
|
||||
#include "mbed_config.h"
|
||||
#include "FATFileSystem.h"
|
||||
#include "test_env.h"
|
||||
#include "fsfat_debug.h"
|
||||
#include "fsfat_test.h"
|
||||
#include "utest/utest.h"
|
||||
#include "unity/unity.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <algorithm>
|
||||
/* retarget.h is included after errno.h so symbols are mapped to
|
||||
* consistent values for all toolchains */
|
||||
#include "platform/mbed_retarget.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
/* DEVICE_SPI
|
||||
* This symbol is defined in targets.json if the target has a SPI interface, which is required for SDCard support.
|
||||
*
|
||||
* MBED_CONF_APP_FSFAT_SDCARD_INSTALLED
|
||||
* For testing purposes, an SDCard must be installed on the target for the test cases in this file to succeed.
|
||||
* If the target has an SD card installed then the MBED_CONF_APP_FSFAT_SDCARD_INSTALLED will be generated
|
||||
* from the mbed_app.json, which includes the line
|
||||
* {
|
||||
* "config": {
|
||||
* "UART_RX": "D0",
|
||||
* <<< lines removed >>>
|
||||
* "DEVICE_SPI": 1,
|
||||
* "MBED_CONF_APP_FSFAT_SDCARD_INSTALLED": 1
|
||||
* },
|
||||
* <<< lines removed >>>
|
||||
*/
|
||||
|
||||
//#include "SDBlockDevice.h"
|
||||
//SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
|
||||
|
||||
#include "FlashIAPBlockDevice.h"
|
||||
|
||||
FlashIAPBlockDevice sd;
|
||||
FATFileSystem fs("sd", &sd);
|
||||
|
||||
#define FSFAT_BASIC_TEST_ fsfat_basic_test_
|
||||
#define FSFAT_BASIC_TEST_00 fsfat_basic_test_00
|
||||
#define FSFAT_BASIC_TEST_01 fsfat_basic_test_01
|
||||
#define FSFAT_BASIC_TEST_02 fsfat_basic_test_02
|
||||
#define FSFAT_BASIC_TEST_03 fsfat_basic_test_03
|
||||
#define FSFAT_BASIC_TEST_04 fsfat_basic_test_04
|
||||
#define FSFAT_BASIC_TEST_05 fsfat_basic_test_05
|
||||
#define FSFAT_BASIC_TEST_06 fsfat_basic_test_06
|
||||
#define FSFAT_BASIC_TEST_07 fsfat_basic_test_07
|
||||
#define FSFAT_BASIC_TEST_08 fsfat_basic_test_08
|
||||
#define FSFAT_BASIC_TEST_09 fsfat_basic_test_09
|
||||
#define FSFAT_BASIC_TEST_10 fsfat_basic_test_10
|
||||
|
||||
#define FSFAT_BASIC_MSG_BUF_SIZE 256
|
||||
#define FSFAT_BASIC_TEST_05_TEST_STRING "Hello World!"
|
||||
|
||||
static const char *sd_file_path = "/sd/out.txt";
|
||||
static const int FSFAT_BASIC_DATA_SIZE = 256;
|
||||
static char fsfat_basic_msg_g[FSFAT_BASIC_MSG_BUF_SIZE];
|
||||
static char fsfat_basic_buffer[1024];
|
||||
static const int FSFAT_BASIC_KIB_RW = 128;
|
||||
static Timer fsfat_basic_timer;
|
||||
static const char *fsfat_basic_bin_filename = "/sd/testfile.bin";
|
||||
static const char *fsfat_basic_bin_filename_test_08 = "testfile.bin";
|
||||
static const char *fsfat_basic_bin_filename_test_10 = "0:testfile.bin";
|
||||
|
||||
#define FSFAT_BASIC_MSG(_buf, _max_len, _fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
snprintf((_buf), (_max_len), (_fmt), __VA_ARGS__); \
|
||||
}while(0);
|
||||
|
||||
/** @brief test for operation of SDFileSystem::format()
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
control_t fsfat_basic_test_(const size_t call_count)
|
||||
{
|
||||
|
||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||
(void) call_count;
|
||||
int32_t ret = -1;
|
||||
|
||||
/* the allocation_unit of 0 means chanFS will use the default for the card (varies according to capacity). */
|
||||
fs.unmount();
|
||||
ret = fs.format(&sd);
|
||||
FSFAT_TEST_UTEST_MESSAGE(fsfat_basic_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, "%s:Error: failed to format sdcard (ret=%d)\n", __func__, (int) ret);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
fs.mount(&sd);
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
/** @brief fopen test case
|
||||
*
|
||||
* - open a file
|
||||
* - generate random data items, write the item to the file and store a coy in a buffer for later use.
|
||||
* - close the file.
|
||||
* - open the file.
|
||||
* - read the data items from the file and check they are the same as write.
|
||||
* - close the file.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_00()
|
||||
{
|
||||
uint8_t data_written[FSFAT_BASIC_DATA_SIZE] = { 0 };
|
||||
bool read_result = false;
|
||||
bool write_result = false;
|
||||
|
||||
// Fill data_written buffer with random data
|
||||
// Write these data into the file
|
||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||
{
|
||||
FSFAT_DBGLOG("%s:SD: Writing ... ", __func__);
|
||||
FILE *f = fopen(sd_file_path, "w");
|
||||
if (f) {
|
||||
for (int i = 0; i < FSFAT_BASIC_DATA_SIZE; i++) {
|
||||
data_written[i] = rand() % 0XFF;
|
||||
fprintf(f, "%c", data_written[i]);
|
||||
}
|
||||
write_result = true;
|
||||
fclose(f);
|
||||
}
|
||||
FSFAT_DBGLOG("[%s]\n", write_result ? "OK" : "FAIL");
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(write_result == true, "Error: write_result is set to false.");
|
||||
|
||||
// Read back the data from the file and store them in data_read
|
||||
{
|
||||
FSFAT_DBGLOG("%s:SD: Reading data ... ", __func__);
|
||||
FILE *f = fopen(sd_file_path, "r");
|
||||
if (f) {
|
||||
read_result = true;
|
||||
for (int i = 0; i < FSFAT_BASIC_DATA_SIZE; i++) {
|
||||
uint8_t data = fgetc(f);
|
||||
if (data != data_written[i]) {
|
||||
read_result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
FSFAT_DBGLOG("[%s]\n", read_result ? "OK" : "FAIL");
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(read_result == true, "Error: read_result is set to false.");
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
/** @brief test-fseek.c test ported from glibc project. See the licence at REF_LICENCE_GLIBC.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_01()
|
||||
{
|
||||
FILE *fp, *fp1;
|
||||
int i, j;
|
||||
int ret = 0;
|
||||
|
||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||
fp = fopen (sd_file_path, "w+");
|
||||
if (fp == NULL) {
|
||||
FSFAT_DBGLOG("errno=%d\n", errno);
|
||||
TEST_ASSERT_MESSAGE(false, "error");
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
putc (i, fp);
|
||||
}
|
||||
/* FIXME: freopen() should open the specified file closing the first stream. As can be seen from the
|
||||
* code below, the old file descriptor fp can still be used, and this should not happen.
|
||||
*/
|
||||
fp1 = freopen (sd_file_path, "r", fp);
|
||||
TEST_ASSERT_MESSAGE(fp1 == fp, "Error: cannot open file for reading");
|
||||
|
||||
for (i = 1; i <= 255; i++) {
|
||||
ret = fseek (fp, (long) -i, SEEK_END);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s:Error: fseek() failed (ret=%d).\n", __func__, (int) ret);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
if ((j = getc (fp)) != 256 - i) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: SEEK_END failed (j=%d)\n", __func__, j);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
ret = fseek (fp, (long) i, SEEK_SET);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot SEEK_SET (ret=%d).\n", __func__, (int) ret);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
if ((j = getc (fp)) != i) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot SEEK_SET (j=%d).\n", __func__, j);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
}
|
||||
if ((ret = fseek (fp, (long) i, SEEK_SET))) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot SEEK_SET (ret=%d).\n", __func__, (int) ret);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
}
|
||||
if ((ret = fseek (fp, (long) (i >= 128 ? -128 : 128), SEEK_CUR))) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot SEEK_CUR (ret=%d).\n", __func__, (int) ret);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
}
|
||||
if ((j = getc (fp)) != (i >= 128 ? i - 128 : i + 128)) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot SEEK_CUR (j=%d).\n", __func__, j);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
remove(sd_file_path);
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
/** @brief test_rdwr.c test ported from glibc project. See the licence at REF_LICENCE_GLIBC.
|
||||
*
|
||||
* WARNING: this test does not currently work. See WARNING comments below.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_02()
|
||||
{
|
||||
static const char hello[] = "Hello, world.\n";
|
||||
static const char replace[] = "Hewwo, world.\n";
|
||||
static const size_t replace_from = 2, replace_to = 4;
|
||||
const char *filename = sd_file_path;
|
||||
char buf[BUFSIZ];
|
||||
FILE *f;
|
||||
int lose = 0;
|
||||
int32_t ret = 0;
|
||||
char *rets = NULL;
|
||||
|
||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||
f = fopen(filename, "w+");
|
||||
if (f == NULL) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot open file for writing (filename=%s).\n", __func__, filename);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
|
||||
ret = fputs(hello, f);
|
||||
if (ret == EOF) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fputs() failed to write string to file (filename=%s, string=%s).\n", __func__, filename, hello);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
|
||||
rewind(f);
|
||||
rets = fgets(buf, sizeof(buf), f);
|
||||
if (rets == NULL) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fgets() failed to get string from file (filename=%s).\n", __func__, filename);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
rets = NULL;
|
||||
|
||||
rewind(f);
|
||||
ret = fputs(buf, f);
|
||||
if (ret == EOF) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fputs() failed to write string to file (filename=%s, string=%s).\n", __func__, filename, buf);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
|
||||
rewind(f);
|
||||
{
|
||||
register size_t i;
|
||||
for (i = 0; i < replace_from; ++i)
|
||||
{
|
||||
int c = getc(f);
|
||||
if (c == EOF)
|
||||
{
|
||||
FSFAT_DBGLOG("EOF at %u.\n", i);
|
||||
lose = 1;
|
||||
break;
|
||||
}
|
||||
else if (c != hello[i])
|
||||
{
|
||||
FSFAT_DBGLOG("Got '%c' instead of '%c' at %u.\n",
|
||||
(unsigned char) c, hello[i], i);
|
||||
lose = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* WARNING: printf("%s: here1. (lose = %d)\n", __func__, lose); */
|
||||
{
|
||||
long int where = ftell(f);
|
||||
if (where == replace_from)
|
||||
{
|
||||
register size_t i;
|
||||
for (i = replace_from; i < replace_to; ++i) {
|
||||
if (putc(replace[i], f) == EOF) {
|
||||
FSFAT_DBGLOG("putc('%c') got %s at %u.\n",
|
||||
replace[i], strerror(errno), i);
|
||||
lose = 1;
|
||||
break;
|
||||
}
|
||||
/* WARNING: The problem seems to be that putc() is not writing the 'w' chars into the file
|
||||
* FSFAT_DBGLOG("%s: here1.5. (char = %c, char as int=%d, ret=%d) \n", __func__, replace[i], (int) replace[i], ret);
|
||||
*/
|
||||
}
|
||||
}
|
||||
else if (where == -1L)
|
||||
{
|
||||
FSFAT_DBGLOG("ftell got %s (should be at %u).\n",
|
||||
strerror(errno), replace_from);
|
||||
lose = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
FSFAT_DBGLOG("ftell returns %ld; should be %u.\n", where, replace_from);
|
||||
lose = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lose)
|
||||
{
|
||||
rewind(f);
|
||||
memset(buf, 0, BUFSIZ);
|
||||
if (fgets(buf, sizeof(buf), f) == NULL)
|
||||
{
|
||||
FSFAT_DBGLOG("fgets got %s.\n", strerror(errno));
|
||||
lose = 1;
|
||||
}
|
||||
else if (strcmp(buf, replace))
|
||||
{
|
||||
FSFAT_DBGLOG("Read \"%s\" instead of \"%s\".\n", buf, replace);
|
||||
lose = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (lose) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Test Failed. Losing file (filename=%s).\n", __func__, filename);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
remove(filename);
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
/** @brief temptest.c test ported from glibc project. See the licence at REF_LICENCE_GLIBC.
|
||||
*
|
||||
* tmpnam() is currently not implemented
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_03()
|
||||
{
|
||||
char *fn = NULL;
|
||||
|
||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||
fn = tmpnam((char *) NULL);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: appeared to generate a filename when function is not implemented.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(fn == NULL, fsfat_basic_msg_g);
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
static bool fsfat_basic_fileno_check(const char *name, FILE *stream, int fd)
|
||||
{
|
||||
/* ARMCC stdio.h currently does not define fileno() */
|
||||
#ifndef __ARMCC_VERSION
|
||||
int sfd = fileno (stream);
|
||||
FSFAT_DBGLOG("(fileno (%s) = %d) %c= %d\n", name, sfd, sfd == fd ? '=' : '!', fd);
|
||||
|
||||
if (sfd == fd) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
/* For ARMCC behave as though test had passed. */
|
||||
return true;
|
||||
#endif /* __ARMCC_VERSION */
|
||||
}
|
||||
|
||||
/* defines for next test case */
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FILENO
|
||||
#define STDOUT_FILENO 1
|
||||
#endif
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
|
||||
/** @brief tst-fileno.c test ported from glibc project. See the licence at REF_LICENCE_GLIBC.
|
||||
*
|
||||
* WARNING: this test does not currently work. See WARNING comments below.
|
||||
*
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_04()
|
||||
{
|
||||
/* ARMCC stdio.h currently does not define fileno() */
|
||||
#ifndef __ARMCC_VERSION
|
||||
int ret = -1;
|
||||
ret = fsfat_basic_fileno_check("stdin", stdin, STDIN_FILENO);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: stdin does not have expected file number (expected=%d, fileno=%d.\n", __func__, (int) stdin, fileno(stdin));
|
||||
TEST_ASSERT_MESSAGE(ret == true, fsfat_basic_msg_g);
|
||||
|
||||
ret = fsfat_basic_fileno_check("stdout", stdout, STDOUT_FILENO);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: stdout does not have expected file number (expected=%d, fileno=%d.\n", __func__, (int) stdout, fileno(stdout));
|
||||
TEST_ASSERT_MESSAGE(ret == true, fsfat_basic_msg_g);
|
||||
|
||||
ret = fsfat_basic_fileno_check("stderr", stderr, STDERR_FILENO);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: stderr does not have expected file number (expected=%d, fileno=%d.\n", __func__, (int) stderr, fileno(stderr));
|
||||
TEST_ASSERT_MESSAGE(ret == true, fsfat_basic_msg_g);
|
||||
#endif /* __ARMCC_VERSION */
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
/** @brief basic test to opendir() on a directory.
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/dir_sd/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_05()
|
||||
{
|
||||
FILE *f;
|
||||
const char *str = FSFAT_BASIC_TEST_05_TEST_STRING;
|
||||
int ret = 0;
|
||||
|
||||
FSFAT_DBGLOG("%s:Write files\n", __func__);
|
||||
char filename[32];
|
||||
for (int i = 0; i < 10; i++) {
|
||||
sprintf(filename, "/sd/test_%d.txt", i);
|
||||
FSFAT_DBGLOG("Creating file: %s\n", filename);
|
||||
f = fopen(filename, "w");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fopen() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(f != NULL, fsfat_basic_msg_g);
|
||||
|
||||
ret = fprintf(f, str);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: writing file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == (int) strlen(str), fsfat_basic_msg_g);
|
||||
|
||||
ret = fclose(f);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fclose() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
}
|
||||
|
||||
FSFAT_DBGLOG("%s:List files:\n", __func__);
|
||||
DIR *d = opendir("/sd");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: opendir() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(d != NULL, fsfat_basic_msg_g);
|
||||
|
||||
struct dirent *p;
|
||||
while ((p = readdir(d)) != NULL)
|
||||
FSFAT_DBGLOG("%s\n", p->d_name);
|
||||
closedir(d);
|
||||
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
/** @brief basic test to write a file to sd card, and read it back again
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/file/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_06()
|
||||
{
|
||||
int ret = -1;
|
||||
char mac[16];
|
||||
mbed_mac_address(mac);
|
||||
FSFAT_DBGLOG("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
FILE *f;
|
||||
const char *str = FSFAT_BASIC_TEST_05_TEST_STRING;
|
||||
int str_len = strlen(FSFAT_BASIC_TEST_05_TEST_STRING);
|
||||
|
||||
f = fopen(sd_file_path, "w");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fopen() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(f != NULL, fsfat_basic_msg_g);
|
||||
|
||||
ret = fprintf(f, str);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: writing file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == (int) strlen(str), fsfat_basic_msg_g);
|
||||
|
||||
ret = fclose(f);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fclose() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
// Read
|
||||
f = fopen(sd_file_path, "r");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fopen() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(f != NULL, fsfat_basic_msg_g);
|
||||
|
||||
int n = fread(fsfat_basic_buffer, sizeof(unsigned char), str_len, f);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fread() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(n == str_len, fsfat_basic_msg_g);
|
||||
|
||||
ret = fclose(f);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fclose() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
/** @brief basic test to write a file to sd card.
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/sd/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_07()
|
||||
{
|
||||
uint8_t data_written[FSFAT_BASIC_DATA_SIZE] = { 0 };
|
||||
|
||||
// Fill data_written buffer with random data
|
||||
// Write these data into the file
|
||||
bool write_result = false;
|
||||
{
|
||||
FSFAT_DBGLOG("%s:SD: Writing ... ", __func__);
|
||||
FILE *f = fopen(sd_file_path, "w");
|
||||
if (f) {
|
||||
for (int i = 0; i < FSFAT_BASIC_DATA_SIZE; i++) {
|
||||
data_written[i] = rand() % 0XFF;
|
||||
fprintf(f, "%c", data_written[i]);
|
||||
}
|
||||
write_result = true;
|
||||
fclose(f);
|
||||
}
|
||||
FSFAT_DBGLOG("[%s]\n", write_result ? "OK" : "FAIL");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: unexpected write failure.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(write_result == true, fsfat_basic_msg_g);
|
||||
}
|
||||
|
||||
// Read back the data from the file and store them in data_read
|
||||
bool read_result = false;
|
||||
{
|
||||
FSFAT_DBGLOG("%s:SD: Reading data ... ", __func__);
|
||||
FILE *f = fopen(sd_file_path, "r");
|
||||
if (f) {
|
||||
read_result = true;
|
||||
for (int i = 0; i < FSFAT_BASIC_DATA_SIZE; i++) {
|
||||
uint8_t data = fgetc(f);
|
||||
if (data != data_written[i]) {
|
||||
read_result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
FSFAT_DBGLOG("[%s]\n", read_result ? "OK" : "FAIL");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: unexpected read failure.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(read_result == true, fsfat_basic_msg_g);
|
||||
}
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
static bool fsfat_basic_test_file_write_fhandle(const char *filename, const int kib_rw)
|
||||
{
|
||||
int ret = -1;
|
||||
File file;
|
||||
|
||||
ret = file.open(&fs, filename, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
int byte_write = 0;
|
||||
fsfat_basic_timer.start();
|
||||
for (int i = 0; i < kib_rw; i++) {
|
||||
ret = file.write(fsfat_basic_buffer, sizeof(fsfat_basic_buffer));
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to write to file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == sizeof(fsfat_basic_buffer), fsfat_basic_msg_g);
|
||||
byte_write++;
|
||||
}
|
||||
fsfat_basic_timer.stop();
|
||||
file.close();
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB write in %.3f sec with speed of %.4f KiB/s\n", byte_write, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool fsfat_basic_test_file_read_fhandle(const char *filename, const int kib_rw)
|
||||
{
|
||||
int ret = -1;
|
||||
File file;
|
||||
ret = file.open(&fs, filename, O_RDONLY);
|
||||
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
fsfat_basic_timer.start();
|
||||
int byte_read = 0;
|
||||
while (file.read(fsfat_basic_buffer, sizeof(fsfat_basic_buffer)) == sizeof(fsfat_basic_buffer)) {
|
||||
byte_read++;
|
||||
}
|
||||
fsfat_basic_timer.stop();
|
||||
file.close();
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB read in %.3f sec with speed of %.4f KiB/s\n", byte_read, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static char fsfat_basic_test_random_char()
|
||||
{
|
||||
return rand() % 100;
|
||||
}
|
||||
|
||||
|
||||
/** @brief basic sd card performance test
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/sd_perf_handle/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_08()
|
||||
{
|
||||
// Test header
|
||||
FSFAT_DBGLOG("\n%s:SD Card FileHandle Performance Test\n", __func__);
|
||||
FSFAT_DBGLOG("File name: %s\n", fsfat_basic_bin_filename);
|
||||
FSFAT_DBGLOG("Buffer size: %d KiB\n", (FSFAT_BASIC_KIB_RW * sizeof(fsfat_basic_buffer)) / 1024);
|
||||
|
||||
// Initialize buffer
|
||||
srand(0);
|
||||
char *buffer_end = fsfat_basic_buffer + sizeof(fsfat_basic_buffer);
|
||||
std::generate (fsfat_basic_buffer, buffer_end, fsfat_basic_test_random_char);
|
||||
|
||||
bool result = true;
|
||||
for (;;) {
|
||||
FSFAT_DBGLOG("%s:Write test...\n", __func__);
|
||||
if (fsfat_basic_test_file_write_fhandle(fsfat_basic_bin_filename_test_08, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
FSFAT_DBGLOG("%s:Read test...\n", __func__);
|
||||
if (fsfat_basic_test_file_read_fhandle(fsfat_basic_bin_filename_test_08, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(result == true, "something went wrong");
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
bool fsfat_basic_test_sf_file_write_stdio(const char *filename, const int kib_rw)
|
||||
{
|
||||
int ret = -1;
|
||||
FILE* file = fopen(filename, "w");
|
||||
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(file != NULL, fsfat_basic_msg_g);
|
||||
|
||||
int byte_write = 0;
|
||||
fsfat_basic_timer.start();
|
||||
for (int i = 0; i < kib_rw; i++) {
|
||||
ret = fwrite(fsfat_basic_buffer, sizeof(char), sizeof(fsfat_basic_buffer), file);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to write to file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == sizeof(fsfat_basic_buffer), fsfat_basic_msg_g);
|
||||
byte_write++;
|
||||
}
|
||||
fsfat_basic_timer.stop();
|
||||
fclose(file);
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB write in %.3f sec with speed of %.4f KiB/s\n", byte_write, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool fsfat_basic_test_sf_file_read_stdio(const char *filename, const int kib_rw)
|
||||
{
|
||||
FILE* file = fopen(filename, "r");
|
||||
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(file != NULL, fsfat_basic_msg_g);
|
||||
fsfat_basic_timer.start();
|
||||
int byte_read = 0;
|
||||
while (fread(fsfat_basic_buffer, sizeof(char), sizeof(fsfat_basic_buffer), file) == sizeof(fsfat_basic_buffer)) {
|
||||
byte_read++;
|
||||
}
|
||||
fsfat_basic_timer.stop();
|
||||
fclose(file);
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB read in %.3f sec with speed of %.4f KiB/s\n", byte_read, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/** @brief basic test to write a file to sd card.
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/sd_perf_stdio/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_09()
|
||||
{
|
||||
// Test header
|
||||
FSFAT_DBGLOG("\n%s:SD Card Stdio Performance Test\n", __func__);
|
||||
FSFAT_DBGLOG("File name: %s\n", fsfat_basic_bin_filename);
|
||||
FSFAT_DBGLOG("Buffer size: %d KiB\n", (FSFAT_BASIC_KIB_RW * sizeof(fsfat_basic_buffer)) / 1024);
|
||||
|
||||
// Initialize buffer
|
||||
srand(0);
|
||||
char *buffer_end = fsfat_basic_buffer + sizeof(fsfat_basic_buffer);
|
||||
std::generate (fsfat_basic_buffer, buffer_end, fsfat_basic_test_random_char);
|
||||
|
||||
bool result = true;
|
||||
for (;;) {
|
||||
FSFAT_DBGLOG("%s:Write test...\n", __func__);
|
||||
if (fsfat_basic_test_sf_file_write_stdio(fsfat_basic_bin_filename, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
FSFAT_DBGLOG("%s:Read test...\n", __func__);
|
||||
if (fsfat_basic_test_sf_file_read_stdio(fsfat_basic_bin_filename, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(result == true, "Expected true result not found");
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
bool fsfat_basic_test_file_write_fatfs(const char *filename, const int kib_rw)
|
||||
{
|
||||
FIL file;
|
||||
FRESULT res = f_open(&file, filename, FA_WRITE | FA_CREATE_ALWAYS);
|
||||
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(res == FR_OK, fsfat_basic_msg_g);
|
||||
|
||||
int byte_write = 0;
|
||||
unsigned int bytes = 0;
|
||||
fsfat_basic_timer.start();
|
||||
for (int i = 0; i < kib_rw; i++) {
|
||||
res = f_write(&file, fsfat_basic_buffer, sizeof(fsfat_basic_buffer), &bytes);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to write to file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(res == FR_OK, fsfat_basic_msg_g);
|
||||
byte_write++;
|
||||
}
|
||||
fsfat_basic_timer.stop();
|
||||
f_close(&file);
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB write in %.3f sec with speed of %.4f KiB/s\n", byte_write, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fsfat_basic_test_file_read_fatfs(const char *filename, const int kib_rw)
|
||||
{
|
||||
FIL file;
|
||||
FRESULT res = f_open(&file, filename, FA_READ | FA_OPEN_EXISTING);
|
||||
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(res == FR_OK, fsfat_basic_msg_g);
|
||||
|
||||
fsfat_basic_timer.start();
|
||||
int byte_read = 0;
|
||||
unsigned int bytes = 0;
|
||||
do {
|
||||
res = f_read(&file, fsfat_basic_buffer, sizeof(fsfat_basic_buffer), &bytes);
|
||||
byte_read++;
|
||||
} while (res == FR_OK && bytes == sizeof(fsfat_basic_buffer));
|
||||
fsfat_basic_timer.stop();
|
||||
f_close(&file);
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB read in %.3f sec with speed of %.4f KiB/s\n", byte_read, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @brief basic test to write a file to sd card.
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/sd_perf_stdio/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_10()
|
||||
{
|
||||
// Test header
|
||||
FSFAT_DBGLOG("\n%sSD Card FatFS Performance Test\n", __func__);
|
||||
FSFAT_DBGLOG("File name: %s\n", fsfat_basic_bin_filename_test_10);
|
||||
FSFAT_DBGLOG("Buffer size: %d KiB\n", (FSFAT_BASIC_KIB_RW * sizeof(fsfat_basic_buffer)) / 1024);
|
||||
|
||||
// Initialize buffer
|
||||
srand(1);
|
||||
char *buffer_end = fsfat_basic_buffer + sizeof(fsfat_basic_buffer);
|
||||
std::generate (fsfat_basic_buffer, buffer_end, fsfat_basic_test_random_char);
|
||||
|
||||
bool result = true;
|
||||
for (;;) {
|
||||
FSFAT_DBGLOG("%s:Write test...\n", __func__);
|
||||
if (fsfat_basic_test_file_write_fatfs(fsfat_basic_bin_filename_test_10, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
FSFAT_DBGLOG("%s:Read test...\n", __func__);
|
||||
if (fsfat_basic_test_file_read_fatfs(fsfat_basic_bin_filename_test_10, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(result == true, "Expected true result not found");
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
utest::v1::status_t greentea_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(300, "default_auto");
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
/* 1 2 3 4 5 6 7 */
|
||||
/* 1234567890123456789012345678901234567890123456789012345678901234567890 */
|
||||
Case("FSFAT_BASIC_TEST_ : format() test.", FSFAT_BASIC_TEST_),
|
||||
Case("FSFAT_BASIC_TEST_00: fopen()/fgetc()/fprintf()/fclose() test.", FSFAT_BASIC_TEST_00),
|
||||
Case("FSFAT_BASIC_TEST_01: fopen()/fseek()/fclose() test.", FSFAT_BASIC_TEST_01),
|
||||
/* WARNING: Test case not working but currently not required for PAL support
|
||||
* Case("FSFAT_BASIC_TEST_02: fopen()/fgets()/fputs()/ftell()/rewind()/remove() test.", FSFAT_BASIC_TEST_02) */
|
||||
Case("FSFAT_BASIC_TEST_03: tmpnam() test.", FSFAT_BASIC_TEST_03),
|
||||
Case("FSFAT_BASIC_TEST_04: fileno() test.", FSFAT_BASIC_TEST_04),
|
||||
Case("FSFAT_BASIC_TEST_05: opendir() basic test.", FSFAT_BASIC_TEST_05),
|
||||
Case("FSFAT_BASIC_TEST_06: fread()/fwrite() file to sdcard.", FSFAT_BASIC_TEST_06),
|
||||
Case("FSFAT_BASIC_TEST_07: sdcard fwrite() file test.", FSFAT_BASIC_TEST_07),
|
||||
Case("FSFAT_BASIC_TEST_08: FATFileSystem::read()/write() test.", FSFAT_BASIC_TEST_08),
|
||||
Case("FSFAT_BASIC_TEST_09: POSIX FILE API fread()/fwrite() test.", FSFAT_BASIC_TEST_09),
|
||||
Case("FSFAT_BASIC_TEST_10: ChanFS read()/write()) test.", FSFAT_BASIC_TEST_10),
|
||||
};
|
||||
|
||||
|
||||
/* Declare your test specification with a custom setup handler */
|
||||
Specification specification(greentea_setup, cases);
|
||||
|
||||
int main()
|
||||
{
|
||||
return !Harness::run(specification);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,88 +0,0 @@
|
|||
/** @file fsfat_debug.h
|
||||
*
|
||||
* component debug header file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __FSFAT_DEBUG
|
||||
#define __FSFAT_DEBUG
|
||||
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/* Debug Support */
|
||||
|
||||
#define FSFAT_LOG_NONE 0
|
||||
#define FSFAT_LOG_ERR 1
|
||||
#define FSFAT_LOG_WARN 2
|
||||
#define FSFAT_LOG_NOTICE 3
|
||||
#define FSFAT_LOG_INFO 4
|
||||
#define FSFAT_LOG_DEBUG 5
|
||||
#define FSFAT_LOG_FENTRY 6
|
||||
|
||||
#define FSFAT_LOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
}while(0);
|
||||
|
||||
#define noFSFAT_DEBUG
|
||||
#ifdef FSFAT_DEBUG
|
||||
|
||||
extern uint32_t fsfat_optDebug_g;
|
||||
extern uint32_t fsfat_optLogLevel_g;
|
||||
|
||||
|
||||
/* uncomment for asserts to work */
|
||||
/* #undef NDEBUG */
|
||||
// todo: port to mbedOSV3++ #include <core-util/assert.h>
|
||||
|
||||
#define FSFAT_INLINE
|
||||
// todo: port to mbedOSV3++ #define FSFAT_ASSERT CORE_UTIL_ASSERT
|
||||
#define FSFAT_ASSERT(...)
|
||||
|
||||
#define FSFAT_DBGLOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if(fsfat_optDebug_g && (fsfat_optLogLevel_g >= FSFAT_LOG_DEBUG)) \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
} \
|
||||
}while(0);
|
||||
|
||||
|
||||
#define FSFAT_ERRLOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if(fsfat_optDebug_g && (fsfat_optLogLevel_g >= FSFAT_LOG_ERR)) \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
} \
|
||||
}while(0);
|
||||
|
||||
|
||||
#define FSFAT_FENTRYLOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if(fsfat_optDebug_g && (fsfat_optLogLevel_g >= FSFAT_LOG_FENTRY)) \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
} \
|
||||
}while(0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
#define FSFAT_ASSERT(_x) do { } while(0)
|
||||
#define FSFAT_INLINE inline
|
||||
#define FSFAT_DBGLOG(_fmt, ...) do { } while(0)
|
||||
#define FSFAT_ERRLOG(_fmt, ...) do { } while(0)
|
||||
#define FSFAT_FENTRYLOG(_fmt, ...) do { } while(0)
|
||||
#endif /* FSFAT_DEBUG */
|
||||
|
||||
|
||||
#endif /*__FSFAT_DEBUG*/
|
|
@ -1,74 +0,0 @@
|
|||
/** @file fsfat_test.h
|
||||
*
|
||||
* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2016 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Header file for test support data structures and function API.
|
||||
*/
|
||||
#ifndef __FSFAT_TEST_H
|
||||
#define __FSFAT_TEST_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Defines */
|
||||
//#define FSFAT_INIT_1_TABLE_HEAD { "a", ""}
|
||||
#define FSFAT_INIT_1_TABLE_MID_NODE { "/sd/01234567.txt", "abcdefghijklmnopqrstuvwxyz"}
|
||||
//#define FSFAT_INIT_1_TABLE_TAIL { "/sd/fopentst/hello/world/animal/wobbly/dog/foot/backrght.txt", "present"}
|
||||
#define FSFAT_TEST_RW_TABLE_SENTINEL 0xffffffff
|
||||
#define FSFAT_TEST_BYTE_DATA_TABLE_SIZE 256
|
||||
#define FSFAT_UTEST_MSG_BUF_SIZE 256
|
||||
#define FSFAT_UTEST_DEFAULT_TIMEOUT_MS 10000
|
||||
#define FSFAT_MBED_HOSTTEST_TIMEOUT 60
|
||||
#define FSFAT_MAX_FILE_BASENAME 8
|
||||
#define FSFAT_MAX_FILE_EXTNAME 3
|
||||
#define FSFAT_BUF_MAX_LENGTH 64
|
||||
#define FSFAT_FILENAME_MAX_LENGTH 255
|
||||
|
||||
|
||||
/* support macro for make string for utest _MESSAGE macros, which dont support formatted output */
|
||||
#define FSFAT_TEST_UTEST_MESSAGE(_buf, _max_len, _fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
snprintf((_buf), (_max_len), (_fmt), __VA_ARGS__); \
|
||||
}while(0);
|
||||
|
||||
|
||||
/*
|
||||
* Structures
|
||||
*/
|
||||
|
||||
/* kv data for test */
|
||||
typedef struct fsfat_kv_data_t {
|
||||
const char* filename;
|
||||
const char* value;
|
||||
} fsfat_kv_data_t;
|
||||
|
||||
|
||||
extern const uint8_t fsfat_test_byte_data_table[FSFAT_TEST_BYTE_DATA_TABLE_SIZE];
|
||||
|
||||
int32_t fsfat_test_create(const char* filename, const char* data, size_t len);
|
||||
int32_t fsfat_test_delete(const char* key_name);
|
||||
int32_t fsfat_test_filename_gen(char* name, const size_t len);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FSFAT_TEST_H */
|
|
@ -0,0 +1,104 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2016 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/** @file fslittle_debug.h
|
||||
*
|
||||
* component debug header file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __FSLITTLE_DEBUG
|
||||
#define __FSLITTLE_DEBUG
|
||||
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/* Debug Support */
|
||||
|
||||
#define FSLITTLE_LOG_NONE 0
|
||||
#define FSLITTLE_LOG_ERR 1
|
||||
#define FSLITTLE_LOG_WARN 2
|
||||
#define FSLITTLE_LOG_NOTICE 3
|
||||
#define FSLITTLE_LOG_INFO 4
|
||||
#define FSLITTLE_LOG_DEBUG 5
|
||||
#define FSLITTLE_LOG_FENTRY 6
|
||||
|
||||
#define FSLITTLE_LOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
}while(0);
|
||||
|
||||
#define noFSLITTLE_DEBUG
|
||||
#ifdef FSLITTLE_DEBUG
|
||||
|
||||
extern uint32_t fslittle_optDebug_g;
|
||||
extern uint32_t fslittle_optLogLevel_g;
|
||||
|
||||
|
||||
/* uncomment for asserts to work */
|
||||
/* #undef NDEBUG */
|
||||
// todo: port to mbedOSV3++ #include <core-util/assert.h>
|
||||
|
||||
#define FSLITTLE_INLINE
|
||||
// todo: port to mbedOSV3++ #define FSLITTLE_ASSERT CORE_UTIL_ASSERT
|
||||
#define FSLITTLE_ASSERT(...)
|
||||
|
||||
#define FSLITTLE_DBGLOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if(fslittle_optDebug_g && (fslittle_optLogLevel_g >= FSLITTLE_LOG_DEBUG)) \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
} \
|
||||
}while(0);
|
||||
|
||||
|
||||
#define FSLITTLE_ERRLOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if(fslittle_optDebug_g && (fslittle_optLogLevel_g >= FSLITTLE_LOG_ERR)) \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
} \
|
||||
}while(0);
|
||||
|
||||
|
||||
#define FSLITTLE_FENTRYLOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if(fslittle_optDebug_g && (fslittle_optLogLevel_g >= FSLITTLE_LOG_FENTRY)) \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
} \
|
||||
}while(0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
#define FSLITTLE_ASSERT(_x) do { } while(0)
|
||||
#define FSLITTLE_INLINE inline
|
||||
#define FSLITTLE_DBGLOG(_fmt, ...) do { } while(0)
|
||||
#define FSLITTLE_ERRLOG(_fmt, ...) do { } while(0)
|
||||
#define FSLITTLE_FENTRYLOG(_fmt, ...) do { } while(0)
|
||||
#endif /* FSLITTLE_DEBUG */
|
||||
|
||||
|
||||
#endif /*__FSLITTLE_DEBUG*/
|
|
@ -1,4 +1,4 @@
|
|||
/* @file fsfat_test.c
|
||||
/* @file fslittle_test.c
|
||||
*
|
||||
* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2016 ARM Limited
|
||||
|
@ -18,8 +18,8 @@
|
|||
* test support code implementation file.
|
||||
*/
|
||||
|
||||
#include "fsfat_debug.h"
|
||||
#include "fsfat_test.h"
|
||||
#include "fslittle_debug.h"
|
||||
#include "fslittle_test.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -29,9 +29,9 @@
|
|||
#include <ctype.h>
|
||||
|
||||
|
||||
#ifdef FSFAT_DEBUG
|
||||
uint32_t fsfat_optDebug_g = 1;
|
||||
uint32_t fsfat_optLogLevel_g = FSFAT_LOG_NONE; /*FSFAT_LOG_NONE|FSFAT_LOG_ERR|FSFAT_LOG_DEBUG|FSFAT_LOG_FENTRY; */
|
||||
#ifdef FSLITTLE_DEBUG
|
||||
uint32_t fslittle_optDebug_g = 1;
|
||||
uint32_t fslittle_optLogLevel_g = FSLITTLE_LOG_NONE; /*FSLITTLE_LOG_NONE|FSLITTLE_LOG_ERR|FSLITTLE_LOG_DEBUG|FSLITTLE_LOG_FENTRY; */
|
||||
#endif
|
||||
|
||||
/* ruler for measuring text strings */
|
||||
|
@ -39,7 +39,7 @@ uint32_t fsfat_optLogLevel_g = FSFAT_LOG_NONE; /*FSFAT_LOG_NONE|FSFAT_LOG_ERR|FS
|
|||
/* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 */
|
||||
/* 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
|
||||
|
||||
const uint8_t fsfat_test_byte_data_table[FSFAT_TEST_BYTE_DATA_TABLE_SIZE] = {
|
||||
const uint8_t fslittle_test_byte_data_table[FSLITTLE_TEST_BYTE_DATA_TABLE_SIZE] = {
|
||||
0x2d, 0xf3, 0x31, 0x4c, 0x11, 0x4f, 0xde, 0x0d, 0xbd, 0xbc, 0xa6, 0x78, 0x36, 0x5c, 0x1d, 0x28,
|
||||
0x5f, 0xa9, 0x10, 0x65, 0x54, 0x45, 0x21, 0x1a, 0x88, 0xfe, 0x76, 0x45, 0xb9, 0xac, 0x65, 0x9a,
|
||||
0x34, 0x9d, 0x73, 0x10, 0xb4, 0xa9, 0x2e, 0x90, 0x95, 0x68, 0xac, 0xfe, 0xc5, 0x2d, 0x15, 0x03,
|
||||
|
@ -61,9 +61,9 @@ const uint8_t fsfat_test_byte_data_table[FSFAT_TEST_BYTE_DATA_TABLE_SIZE] = {
|
|||
|
||||
/* @brief test utility function to delete the file identified by filename
|
||||
*/
|
||||
int32_t fsfat_test_delete(const char* filename)
|
||||
int32_t fslittle_test_delete(const char* filename)
|
||||
{
|
||||
FSFAT_FENTRYLOG("%s:entered.\r\n", __func__);
|
||||
FSLITTLE_FENTRYLOG("%s:entered.\r\n", __func__);
|
||||
return remove(filename);
|
||||
}
|
||||
|
||||
|
@ -74,12 +74,12 @@ int32_t fsfat_test_delete(const char* filename)
|
|||
* @param data data to store in file
|
||||
* @param len number of bytes of data present in the data buffer.
|
||||
*/
|
||||
int32_t fsfat_test_create(const char* filename, const char* data, size_t len)
|
||||
int32_t fslittle_test_create(const char* filename, const char* data, size_t len)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
FILE *fp = NULL;
|
||||
|
||||
FSFAT_FENTRYLOG("%s:entered (filename=%s, len=%d).\n", __func__, filename, (int) len);
|
||||
FSLITTLE_FENTRYLOG("%s:entered (filename=%s, len=%d).\n", __func__, filename, (int) len);
|
||||
fp = fopen(filename, "w+");
|
||||
if(fp == NULL){
|
||||
return ret;
|
||||
|
@ -99,14 +99,14 @@ int32_t fsfat_test_create(const char* filename, const char* data, size_t len)
|
|||
* @param len length of kv name to generate
|
||||
*
|
||||
*/
|
||||
int32_t fsfat_test_filename_gen(char* name, const size_t len)
|
||||
int32_t fslittle_test_filename_gen(char* name, const size_t len)
|
||||
{
|
||||
size_t i;
|
||||
uint32_t pos = 0;
|
||||
|
||||
const char* buf = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!$-_@";
|
||||
const int buf_len = strlen(buf);
|
||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||
FSLITTLE_FENTRYLOG("%s:entered\n", __func__);
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
pos = rand() % (buf_len);
|
|
@ -0,0 +1,74 @@
|
|||
/** @file fslittle_test.h
|
||||
*
|
||||
* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2016 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Header file for test support data structures and function API.
|
||||
*/
|
||||
#ifndef __FSLITTLE_TEST_H
|
||||
#define __FSLITTLE_TEST_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Defines */
|
||||
//#define FSLITTLE_INIT_1_TABLE_HEAD { "a", ""}
|
||||
#define FSLITTLE_INIT_1_TABLE_MID_NODE { "/sd/01234567.txt", "abcdefghijklmnopqrstuvwxyz"}
|
||||
//#define FSLITTLE_INIT_1_TABLE_TAIL { "/sd/fopentst/hello/world/animal/wobbly/dog/foot/backrght.txt", "present"}
|
||||
#define FSLITTLE_TEST_RW_TABLE_SENTINEL 0xffffffff
|
||||
#define FSLITTLE_TEST_BYTE_DATA_TABLE_SIZE 256
|
||||
#define FSLITTLE_UTEST_MSG_BUF_SIZE 256
|
||||
#define FSLITTLE_UTEST_DEFAULT_TIMEOUT_MS 10000
|
||||
#define FSLITTLE_MBED_HOSTTEST_TIMEOUT 60
|
||||
#define FSLITTLE_MAX_FILE_BASENAME 8
|
||||
#define FSLITTLE_MAX_FILE_EXTNAME 3
|
||||
#define FSLITTLE_BUF_MAX_LENGTH 64
|
||||
#define FSLITTLE_FILENAME_MAX_LENGTH 255
|
||||
|
||||
|
||||
/* support macro for make string for utest _MESSAGE macros, which dont support formatted output */
|
||||
#define FSLITTLE_TEST_UTEST_MESSAGE(_buf, _max_len, _fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
snprintf((_buf), (_max_len), (_fmt), __VA_ARGS__); \
|
||||
}while(0);
|
||||
|
||||
|
||||
/*
|
||||
* Structures
|
||||
*/
|
||||
|
||||
/* kv data for test */
|
||||
typedef struct fslittle_kv_data_t {
|
||||
const char *filename;
|
||||
const char *value;
|
||||
} fslittle_kv_data_t;
|
||||
|
||||
|
||||
extern const uint8_t fslittle_test_byte_data_table[FSLITTLE_TEST_BYTE_DATA_TABLE_SIZE];
|
||||
|
||||
int32_t fslittle_test_create(const char *filename, const char *data, size_t len);
|
||||
int32_t fslittle_test_delete(const char *key_name);
|
||||
int32_t fslittle_test_filename_gen(char *name, const size_t len);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FSLITTLE_TEST_H */
|
|
@ -1,24 +0,0 @@
|
|||
script:
|
||||
# Check that examples compile
|
||||
- sed -n '/``` cpp/,${/```$/q;/```/d;p}' README.md > main.cpp &&
|
||||
PYTHONPATH=mbed-os python mbed-os/tools/make.py -t GCC_ARM -m K64F
|
||||
--source=. --build=BUILD/K64F/GCC_ARM -j0 &&
|
||||
rm main.cpp
|
||||
|
||||
# Check that tests compile
|
||||
- rm -rf BUILD && PYTHONPATH=mbed-os python mbed-os/tools/test.py
|
||||
-t GCC_ARM -m K64F --source=. --build=BUILD/TESTS/K64F/GCC_ARM -j0
|
||||
-n tests*
|
||||
|
||||
python:
|
||||
- "2.7"
|
||||
|
||||
install:
|
||||
# Get arm-none-eabi-gcc
|
||||
- sudo add-apt-repository -y ppa:terry.guo/gcc-arm-embedded
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq gcc-arm-none-eabi --force-yes
|
||||
# Get dependencies
|
||||
- git clone https://github.com/armmbed/mbed-os.git
|
||||
# Install python dependencies
|
||||
- pip install --user -r mbed-os/requirements.txt
|
|
@ -1,165 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and
|
||||
distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||
owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
||||
that control, are controlled by, or are under common control with that entity.
|
||||
For the purposes of this definition, "control" means (i) the power, direct or
|
||||
indirect, to cause the direction or management of such entity, whether by
|
||||
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
||||
permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including
|
||||
but not limited to software source code, documentation source, and configuration
|
||||
files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or
|
||||
translation of a Source form, including but not limited to compiled object code,
|
||||
generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
||||
available under the License, as indicated by a copyright notice that is included
|
||||
in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
||||
is based on (or derived from) the Work and for which the editorial revisions,
|
||||
annotations, elaborations, or other modifications represent, as a whole, an
|
||||
original work of authorship. For the purposes of this License, Derivative Works
|
||||
shall not include works that remain separable from, or merely link (or bind by
|
||||
name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version
|
||||
of the Work and any modifications or additions to that Work or Derivative Works
|
||||
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
||||
by the copyright owner or by an individual or Legal Entity authorized to submit
|
||||
on behalf of the copyright owner. For the purposes of this definition,
|
||||
"submitted" means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems, and
|
||||
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
||||
the purpose of discussing and improving the Work, but excluding communication
|
||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||
owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||
of whom a Contribution has been received by Licensor and subsequently
|
||||
incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the Work and such
|
||||
Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable (except as stated in this section) patent license to make, have
|
||||
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
||||
such license applies only to those patent claims licensable by such Contributor
|
||||
that are necessarily infringed by their Contribution(s) alone or by combination
|
||||
of their Contribution(s) with the Work to which such Contribution(s) was
|
||||
submitted. If You institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
||||
Contribution incorporated within the Work constitutes direct or contributory
|
||||
patent infringement, then any patent licenses granted to You under this License
|
||||
for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution.
|
||||
|
||||
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
||||
in any medium, with or without modifications, and in Source or Object form,
|
||||
provided that You meet the following conditions:
|
||||
|
||||
You must give any other recipients of the Work or Derivative Works a copy of
|
||||
this License; and
|
||||
You must cause any modified files to carry prominent notices stating that You
|
||||
changed the files; and
|
||||
You must retain, in the Source form of any Derivative Works that You distribute,
|
||||
all copyright, patent, trademark, and attribution notices from the Source form
|
||||
of the Work, excluding those notices that do not pertain to any part of the
|
||||
Derivative Works; and
|
||||
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
||||
Derivative Works that You distribute must include a readable copy of the
|
||||
attribution notices contained within such NOTICE file, excluding those notices
|
||||
that do not pertain to any part of the Derivative Works, in at least one of the
|
||||
following places: within a NOTICE text file distributed as part of the
|
||||
Derivative Works; within the Source form or documentation, if provided along
|
||||
with the Derivative Works; or, within a display generated by the Derivative
|
||||
Works, if and wherever such third-party notices normally appear. The contents of
|
||||
the NOTICE file are for informational purposes only and do not modify the
|
||||
License. You may add Your own attribution notices within Derivative Works that
|
||||
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
||||
provided that such additional attribution notices cannot be construed as
|
||||
modifying the License.
|
||||
You may add Your own copyright statement to Your modifications and may provide
|
||||
additional or different license terms and conditions for use, reproduction, or
|
||||
distribution of Your modifications, or for any such Derivative Works as a whole,
|
||||
provided Your use, reproduction, and distribution of the Work otherwise complies
|
||||
with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions.
|
||||
|
||||
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
||||
for inclusion in the Work by You to the Licensor shall be under the terms and
|
||||
conditions of this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
||||
any separate license agreement you may have executed with Licensor regarding
|
||||
such Contributions.
|
||||
|
||||
6. Trademarks.
|
||||
|
||||
This License does not grant permission to use the trade names, trademarks,
|
||||
service marks, or product names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, Licensor provides the
|
||||
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
||||
including, without limitation, any warranties or conditions of TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
||||
solely responsible for determining the appropriateness of using or
|
||||
redistributing the Work and assume any risks associated with Your exercise of
|
||||
permissions under this License.
|
||||
|
||||
8. Limitation of Liability.
|
||||
|
||||
In no event and under no legal theory, whether in tort (including negligence),
|
||||
contract, or otherwise, unless required by applicable law (such as deliberate
|
||||
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special, incidental,
|
||||
or consequential damages of any character arising as a result of this License or
|
||||
out of the use or inability to use the Work (including but not limited to
|
||||
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
||||
any and all other commercial damages or losses), even if such Contributor has
|
||||
been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability.
|
||||
|
||||
While redistributing the Work or Derivative Works thereof, You may choose to
|
||||
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
||||
other liability obligations and/or rights consistent with this License. However,
|
||||
in accepting such obligations, You may act only on Your own behalf and on Your
|
||||
sole responsibility, not on behalf of any other Contributor, and only if You
|
||||
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason of your
|
||||
accepting any such warranty or additional liability.
|
|
@ -1,618 +0,0 @@
|
|||
# mbed OS SDCard Driver (sd-driver) for FAT32 Filesystem Support
|
||||
|
||||
|
||||
Simon Hughes
|
||||
|
||||
20170329
|
||||
|
||||
Version 0.1.2
|
||||
|
||||
|
||||
# Executive Summary
|
||||
|
||||
The purpose of this document is to describe how to use the mbed OS SDCard
|
||||
driver (sd-driver) so applications can read/write
|
||||
data to flash storage cards using the standard POSIX File API
|
||||
programming interface. The sd-driver uses the SDCard SPI-mode of operation
|
||||
which is a subset of possible SDCard functionality.
|
||||
|
||||
This repository contains the mbed-os SDCard driver for generic SPI
|
||||
SDCard support and other resources, as outlined below:
|
||||
|
||||
- `SDBlockDevice.h` and `SDBlockDevice.cpp`. This is the SDCard driver module presenting
|
||||
a Block Device API (derived from BlockDevice) to the underlying SDCard.
|
||||
- POSIX File API test cases for testing the FAT32 filesystem on SDCard.
|
||||
- basic.cpp, a basic set of functional test cases.
|
||||
- fopen.cpp, more functional tests reading/writing greater volumes of data to SDCard, for example.
|
||||
- `mbed_lib.json` mbed-os application configuration file with SPI pin configurations and overrides for specific targets.
|
||||
This file allows the SPI pins to be specified for the target without having to edit the implementation files.
|
||||
- This README which includes [Summary of POSIX File API Documentation](#summary-posix-api-documentation)
|
||||
including detailed instruction on how to use the FAT filesystem and SDBlockDevice driver.
|
||||
|
||||
The SDCard driver is maintained in this repository as a component separate from the main mbed OS repository.
|
||||
Hence the 2 repositories (mbed-os and sd-driver) have to be used together
|
||||
to deliver the FAT32 Filesystem/SDCard support. This document explains how to do this.
|
||||
|
||||
|
||||
# Introduction
|
||||
|
||||
### Overview
|
||||
|
||||
The scope of this document is to describe how applications use the FAT filesystem and sd-driver
|
||||
components to persistently store data on SDCards. The document is intended to help developers adopt the
|
||||
mbed OS POSIX File API support, and in particular to help explain:
|
||||
|
||||
- How the software components work together to deliver the storage functionality.
|
||||
- How to work with the sd-driver and mbed OS to build the examples. The example code can easily
|
||||
be copied into your new application code.
|
||||
- How to work with the CI Test Shield, which adds an SDCard slot to those targets that do not have already have one.
|
||||
- How to run the POSIX File API mbed Greentea test cases, which provide further example code of how to use
|
||||
the POSIX File API.
|
||||
|
||||
Section 1 provides an Executive Summary, describing the purpose of the sd-driver, the supporting
|
||||
software, examples, test cases and documentation.
|
||||
|
||||
Section 2 provides an an overview of the material covered including descriptions of the major sections.
|
||||
|
||||
Section 3 provides an overview of the mbed OS filesystem software components,
|
||||
including the inter-relationships between the application, POSIX file API, the standard c-library,
|
||||
the mbed OS filesystem and the SDCard driver (sd-driver).
|
||||
|
||||
Section 4 describes how to build and run an example application for reading
|
||||
and writing data to an SDCard using the POSIX File API. The example begins by describing
|
||||
the procedure for building and testing on the K64F target. The final sub-sections
|
||||
describe how to use the test shield to add an SDCard slot to any mbed target,
|
||||
and hence enable the persistent storage of data on any supported target.
|
||||
|
||||
Section 5 describes an example application which uses the raw
|
||||
BlockDevice API to read and write data to the SDCard.
|
||||
|
||||
Section 6 describes how to build and run the SDCard POSIX File API mbed Greentea test cases.
|
||||
There are a number of functional test cases demonstrating how to use the
|
||||
mbed OS POSIX File API.
|
||||
|
||||
Section 7 describes the POSIX File API and provides links to useful API documentation web pages.
|
||||
|
||||
|
||||
### Known mbed-os and sd-driver Compatible Versions
|
||||
|
||||
The following versions of the mbed-os and sd-driver repositories are known to work together:
|
||||
|
||||
- {mbed-os, sd-driver} = {mbed-os-5.4.0-rc2, sd-driver-0.0.1-mbed-os-5.4.0-rc2}.
|
||||
`K64F`, `NUCLEO_F429ZI` and `UBLOX_EVK_ODIN_W2` fopen and basic filesystem tests working.
|
||||
- {mbed-os, sd-driver} = {mbed-os-5.4.0, sd-driver-0.0.2-mbed-os-5.4.0}.
|
||||
`K64F`, `NUCLEO_F429ZI` and `UBLOX_EVK_ODIN_W2` fopen and basic filesystem tests working.
|
||||
- {mbed-os, sd-driver} = {mbed-os-5.4.1, sd-driver-0.0.3-mbed-os-5.4.1}.
|
||||
- {mbed-os, sd-driver} = {mbed-os-5.5.1, sd-driver-0.1.0-mbed-os-5.5.1}.
|
||||
- {mbed-os, sd-driver} = {mbed-os-5.5.4, sd-driver-0.1.1-mbed-os-5.5.4}.
|
||||
- {mbed-os, sd-driver} = {mbed-os-5.6.1, sd-driver-0.1.2-mbed-os-5.6.1}.
|
||||
- {mbed-os, sd-driver} = {mbed-os-5.8.0, sd-driver-0.1.3-mbed-os-5.8.0}.
|
||||
|
||||
To find the latest compatible versions, use the following command to see the messages attached to the tags
|
||||
in the sd-driver repository:
|
||||
|
||||
ex_app7/$ cd sd-driver
|
||||
ex_app7/sd-driver$ git tag -n
|
||||
sd-driver-0.0.1-mbed-os-5.3.4 Version compatible with mbed-os-5.3.4, and private_mbedos_filesystems-0.0.1-mbed-os-5.3.4.
|
||||
sd-driver-0.0.2-mbed-os-5.4.0 Updated README.md to include worked exmaples and restructuring of information.
|
||||
sd-driver-0.0.3-mbed-os-5.4.1 Version compatible with mbed-os-5.4.1.
|
||||
sd-driver-0.1.1-mbed-os-5.5.4 Version compatible with mbed-os-5.5.4
|
||||
sd-driver-0.1.2-mbed-os-5.6.1 Version compatible with mbed-os-5.6.1
|
||||
sd-driver-0.1.3-mbed-os-5.8.0 Version compatible with mbed-os-5.8.0
|
||||
|
||||
### Known Issues With This Document
|
||||
|
||||
There are no known issues with this document.
|
||||
|
||||
|
||||
# Overview of mbed OS Filesystem Software Component Stack
|
||||
|
||||
|
||||
------------------------
|
||||
| |
|
||||
| Application | // This application uses the POSIX File API
|
||||
| | // to read/write data to persistent storage backends.
|
||||
------------------------
|
||||
|
||||
------------------------ // POSIX File API (ISO).
|
||||
|
||||
------------------------
|
||||
| |
|
||||
| libc | // The standard c library implementation
|
||||
| | // e.g. newlib.
|
||||
------------------------
|
||||
|
||||
------------------------ // sys_xxx equivalent API.
|
||||
|
||||
------------------------
|
||||
| |
|
||||
| mbed_retarget.cpp | // Target specific mapping layer.
|
||||
| |
|
||||
------------------------
|
||||
|
||||
------------------------ // Filesystem Upper Edge API.
|
||||
|
||||
------------------------
|
||||
| |
|
||||
| File System | // File system wrappers and implementation.
|
||||
| |
|
||||
------------------------
|
||||
|
||||
------------------------ // FS Lower Edge API (Block Store Interface).
|
||||
|
||||
------------------------
|
||||
| Block API |
|
||||
| Device Driver | // The SDCard driver, for example.
|
||||
| e.g. sd-driver |
|
||||
------------------------
|
||||
|
||||
------------------------ // SPI.h interface.
|
||||
|
||||
------------------------
|
||||
| |
|
||||
| SPI | // SPI subsystem (C++ classes and C-HAL implementation).
|
||||
| |
|
||||
------------------------
|
||||
|
||||
Figure 1. mbedOS generic architecture of filesystem software stack.
|
||||
|
||||
The figure above shows the mbed OS software component stack used for data
|
||||
storage on SDCard:
|
||||
|
||||
- At the top level is the application component which uses the standard POSIX File API
|
||||
to read and write application data to persistent storage.
|
||||
- The newlib standard library (libc) stdio.h interface (POSIX File API)
|
||||
implementation is used as it's optimised for resource limited embedded systems.
|
||||
- mbed_retarget.cpp implements the libc back-end file OS handlers and maps them
|
||||
to the FileSystem.
|
||||
- The File System code (hosted in mbed-os) is composed of 2 parts:
|
||||
- The mbed OS file system wrapper classes (e.g. FileSystem, File, FileBase classes)
|
||||
which are used to present a consistent API to the retarget module for different
|
||||
(third-party) file system implementations.
|
||||
- The FAT filesystem implementation code.
|
||||
The [FATFS: Generic FAT File System Module](http://elm-chan.org/fsw/ff/00index_e.html)
|
||||
(ChanFS) has been integrated within mbed-os.
|
||||
- The Block API Device Driver. The SDCard driver is an example of a persistent storage driver.
|
||||
It's maintained as a separate component from the mbed OS repository (in this repository).
|
||||
- The SPI module provides the mbed OS generic SPI API. This functionality is maintained in
|
||||
mbed OS.
|
||||
|
||||
|
||||
# SDCard POSIX File API Example App for Reading/Writing Data
|
||||
|
||||
Refer to [SD driver Example](https://github.com/ARMmbed/mbed-os-example-sd-driver)
|
||||
|
||||
|
||||
### <a name="testing-with-an-sdcard-on-target-xyx"></a> Testing with an SDCard on Target XYZ
|
||||
|
||||
The standard way to test is with the mbed CI Test Shield plugged into the
|
||||
target board. This pin mapping for this configuration is parameterised in
|
||||
the `mbed_lib.json` file.
|
||||
|
||||
The following is an example of the `mbed_lib.json` file available in the repository:
|
||||
|
||||
{
|
||||
"config": {
|
||||
"SPI_CS": "NC",
|
||||
"SPI_MOSI": "NC",
|
||||
"SPI_MISO": "NC",
|
||||
"SPI_CLK": "NC",
|
||||
"DEVICE_SPI": 1,
|
||||
"FSFAT_SDCARD_INSTALLED": 1
|
||||
},
|
||||
"target_overrides": {
|
||||
"DISCO_F051R8": {
|
||||
"SPI_MOSI": "SPI_MOSI",
|
||||
"SPI_MISO": "SPI_MISO",
|
||||
"SPI_CLK": "SPI_SCK",
|
||||
"SPI_CS": "SPI_CS"
|
||||
},
|
||||
"KL46Z": {
|
||||
"SPI_MOSI": "PTD6",
|
||||
"SPI_MISO": "PTD7",
|
||||
"SPI_CLK": "PTD5",
|
||||
"SPI_CS": "PTD4"
|
||||
},
|
||||
"K64F": {
|
||||
"SPI_MOSI": "PTE3",
|
||||
"SPI_MISO": "PTE1",
|
||||
"SPI_CLK": "PTE2",
|
||||
"SPI_CS": "PTE4"
|
||||
}
|
||||
}
|
||||
|
||||
Note the following things about the `mbed_lib.json` file:
|
||||
|
||||
- The `mbed_lib.json` file is used to define target specific symbols for the SPI pins connecting the SDCard slot to the target MCU:
|
||||
- "SPI\_CS". This is the Chip Select line.
|
||||
- "SPI\_MOSI". This is the Master Out Slave In data line.
|
||||
- "SPI\_MISO". This is the Master In Slave Out data line.
|
||||
- "SPI\_CLK". This is the serial Clock line.
|
||||
- The default configuration defined in the "config" section **is not valid for any platform** (will error at runtime).
|
||||
The "config" section defines a dictionary mapping functional names to target board pins:
|
||||
- "SPI\_CS" causes the MBED\_CONF\_APP\_SPI\_CS symbol to be defined in mbed\_config.h, which is used in the filesystem test implementation.
|
||||
- "SPI\_MOSI" causes the MBED\_CONF\_APP\_SPI\_MOSI symbol to be defined in mbed\_config.h.
|
||||
- "SPI\_MISO" causes the MBED\_CONF\_APP\_SPI\_MISO symbol to be defined in mbed\_config.h.
|
||||
- "SPI\_CLK" causes the MBED\_CONF\_APP\_SPI\_CLK symbol to be defined in mbed\_config.h.
|
||||
- The `"target_overrides"` section is used to override the "SPI\_xxx" symbols for specific target boards, which may have an SDCard slot, for example.
|
||||
This is the case for the K64F, where the "SPI\_xxx" are mapped to the pin names for the on-board SDCard.
|
||||
|
||||
```
|
||||
"K64F": {
|
||||
"SPI_MOSI": "PTE3",
|
||||
"SPI_MISO": "PTE1",
|
||||
"SPI_CLK": "PTE2",
|
||||
"SPI_CS": "PTE4"
|
||||
}
|
||||
```
|
||||
- Thus, in the absence of any target specific definitions in the `"target_overrides"` section, all boards will default to
|
||||
using the invalid configuration (will error at runtime). For those platforms with a `"target_overrides"` section then this configuration
|
||||
will be used in preference.
|
||||
- Hence in the case that you want to test a platform with an SDCard inserted into a
|
||||
fitted CI test shield (rather than the on-board SDCard slot)
|
||||
and there is a `"target_overrides"` section present in the `mbed_lib.json` file, you must provide the correct Arduino pins in the `"target_overrides"`
|
||||
section before building. This will result in the default configuration being used (suitable for the CI
|
||||
Test Shield). The correct pins for the CI test shield are as follows:
|
||||
"<your platform name>": {
|
||||
"SPI_MOSI": "D11",
|
||||
"SPI_MISO": "D12",
|
||||
"SPI_CLK": "D13",
|
||||
"SPI_CS": "D10"
|
||||
}
|
||||
- Note when inserting the v1.0.0 CI Test Shield into the Arduino header of the target platform, the shield pins D0 and
|
||||
D1 should be bent to be parallel to the shield PCB so they are not inserted into the Arduino header. This is because
|
||||
some boards use the same UART on DAPLINK and D0/D1, which means the serial debug channel breaks and hence the mbed greentea
|
||||
test suite will not work correctly. This is mainly on older ST boards and should not be a problem on
|
||||
`K64F`, `NUCLEO_F429ZI` and `UBLOX_EVK_ODIN_W2`. Note also that the v2.0.0 CI Test Shield doesn't suffer from this
|
||||
problem and the pins don't need to be bent.
|
||||
- When inserting the SDCard into the card slot on the CI test shield, make sure the card is fully inserted.
|
||||
On insertion, there should be a small clicking sound when the card registers, and the back edge of the card
|
||||
should protrude no more than ~1mm over the edge of the CI test shield PCB. If the SDCard fails to register,
|
||||
try gently pushing the metal flexible strip in the shape of a spade at the top edge of the SDCard metal slot
|
||||
casing with a pair of tweezers, bending it a little to lower it into the slot casing. This helps with the
|
||||
insertion mechanism.
|
||||
|
||||
### Wiring instructions for target NUCLEO_F429ZI with CI Test Shield
|
||||

|
||||
|
||||
**Figure 3. The figure shows how to connect the NUCLEO_F429ZI platform with the CI shield.**
|
||||
|
||||
The above figure shows how to connect the NUCLEO_F429ZI with the v1.0.0 CI test shield. Note:
|
||||
|
||||
- To get the SD Card to work with this platform the CI test shield cannot be connected directly to this board, instead follow the instructions above.
|
||||
- Any SD-card adapter will work as long as you connect all the relevant pins (MOSI, MISO, SCLK, CS, 3.3V and GND) as illustrated in figure 3.
|
||||
- The SDCard is fully inserted into the slot and overhangs the PCB by ~1mm.
|
||||
|
||||
# SDBlockDevice Example Application
|
||||
|
||||
The following sample code illustrates how to use the sd-driver Block Device API:
|
||||
|
||||
``` cpp
|
||||
#include "mbed.h"
|
||||
#include "SDBlockDevice.h"
|
||||
|
||||
// Instantiate the SDBlockDevice by specifying the SPI pins connected to the SDCard
|
||||
// socket. The PINS are:
|
||||
// MOSI (Master Out Slave In)
|
||||
// MISO (Master In Slave Out)
|
||||
// SCLK (Serial Clock)
|
||||
// CS (Chip Select)
|
||||
SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
|
||||
uint8_t block[512] = "Hello World!\n";
|
||||
|
||||
int main()
|
||||
{
|
||||
// call the SDBlockDevice instance initialisation method.
|
||||
if ( 0 != sd.init()) {
|
||||
printf("Init failed \n");
|
||||
return -1;
|
||||
}
|
||||
printf("sd size: %llu\n", sd.size());
|
||||
printf("sd read size: %llu\n", sd.get_read_size());
|
||||
printf("sd program size: %llu\n", sd.get_program_size());
|
||||
printf("sd erase size: %llu\n", sd.get_erase_size());
|
||||
|
||||
// set the frequency
|
||||
if ( 0 != sd.frequency(5000000)) {
|
||||
printf("Error setting frequency \n");
|
||||
}
|
||||
|
||||
if ( 0 != sd.erase(0, sd.get_erase_size())) {
|
||||
printf("Error Erasing block \n");
|
||||
}
|
||||
|
||||
// Write some the data block to the device
|
||||
if ( 0 == sd.program(block, 0, 512)) {
|
||||
// read the data block from the device
|
||||
if ( 0 == sd.read(block, 0, 512)) {
|
||||
// print the contents of the block
|
||||
printf("%s", block);
|
||||
}
|
||||
}
|
||||
|
||||
// call the SDBlockDevice instance de-initialisation method.
|
||||
sd.deinit();
|
||||
}
|
||||
```
|
||||
|
||||
# SDCard POSIX File API mbed Greentea Test Cases
|
||||
|
||||
This section describes how to build and run the POSIX file API test cases.
|
||||
The following steps are covered:
|
||||
|
||||
- [Create the FAT/SDCard Application Project](#create-fat-sdcard-application-project).
|
||||
This section describes how to git clone the mbed OS and sd-driver repositories containing the
|
||||
code and test cases of interest.
|
||||
- [Build the mbed OS Test Cases](#build-the-mbedos-test-cases). This section
|
||||
describes how to build the mbed OS test cases.
|
||||
- [Insert a microSD Card Into the K64F for Greentea Testing](#greentea-insert-sdcard-into-k64f).This section
|
||||
describes how to format (if required) a microSD card prior to running the tests.
|
||||
- [Run the POSIX File Test Case](#run-the-posix-file-test-cases).This section
|
||||
describes how to run the POSIX file test cases.
|
||||
|
||||
|
||||
### <a name="create-fat-sdcard-application-project"></a> Create the FAT/SDCard Application Project
|
||||
|
||||
This section describes how to create an application project combining the mbed-os and
|
||||
sd-driver repositories into a single project.
|
||||
In summary the following steps will be covered in this section:
|
||||
|
||||
- A top level application project directory is created. The directory name is ex_app1.
|
||||
- In the ex_app1 directory, the mbed-os repository is cloned.
|
||||
- In the ex_app1 directory at the same level as the mbed-os directory, the sd-driver repository is cloned.
|
||||
- The `mbed_lib.json` file is copied from the `sd-driver/config/mbed_lib.json` to the ex_app1 directory.
|
||||
|
||||
First create the top level application directory ex_app1 and move into it:
|
||||
|
||||
shell:/d/demo_area$ mkdir ex_app1
|
||||
shell:/d/demo_area$ pushd ex_app1
|
||||
|
||||
Next, get a clone of public mbed OS repository in the following way:
|
||||
|
||||
shell:/d/demo_area/ex_app1$ git clone git@github.com:/armmbed/mbed-os
|
||||
<trace removed>
|
||||
shell:/d/demo_area/ex_app1$
|
||||
|
||||
Next, get a clone of the sd-driver repository:
|
||||
|
||||
shell:/d/demo_area/ex_app1$ git clone git@github.com:/armmbed/sd-driver
|
||||
<trace removed>
|
||||
shell:/d/demo_area/ex_app1$
|
||||
|
||||
Note: The `mbed_lib.json` file specifies the SPI bus pin configuration for different targets,
|
||||
and is discussed in the [Testing with an SDCard on Target XYZ](#testing-with-an-sdcard-on-target-xyx) section.
|
||||
|
||||
### <a name="build-the-mbedos-test-cases"></a> Build the mbed OS Test Cases
|
||||
|
||||
Build the test cases for the K64F target using the following command:
|
||||
|
||||
shell:/d/demo_area/ex_app1$ mbed -v test --compile -t GCC_ARM -m K64F
|
||||
<trace removed>
|
||||
shell:/d/demo_area/ex_app1$
|
||||
|
||||
The build trace is quite extensive but on a successful build you should see the following output at the end of the log:
|
||||
|
||||
Build successes:
|
||||
* K64F::GCC_ARM::MBED-BUILD
|
||||
* K64F::GCC_ARM::MBED-OS-FEATURES-FEATURE_LWIP-TESTS-MBEDMICRO-NET-CONNECTIVITY
|
||||
<trace removed>
|
||||
* K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-FAT_FILE_SYSTEM
|
||||
* K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-HEAP_BLOCK_DEVICE
|
||||
* K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-UTIL_BLOCK_DEVICE
|
||||
<trace removed>
|
||||
* K64F::GCC_ARM::SD-DRIVER-TESTS-BLOCK_DEVICE-BASIC
|
||||
* K64F::GCC_ARM::SD-DRIVER-TESTS-FILESYSTEM-BASIC
|
||||
* K64F::GCC_ARM::SD-DRIVER-TESTS-FILESYSTEM-DIRS
|
||||
* K64F::GCC_ARM::SD-DRIVER-TESTS-FILESYSTEM-FILES
|
||||
* K64F::GCC_ARM::SD-DRIVER-TESTS-FILESYSTEM-FOPEN
|
||||
* K64F::GCC_ARM::SD-DRIVER-TESTS-FILESYSTEM-PARALLEL
|
||||
* K64F::GCC_ARM::SD-DRIVER-TESTS-FILESYSTEM-SEEK
|
||||
|
||||
Build skips:
|
||||
* K64F::GCC_ARM::MBED-OS-FEATURES-FEATURE_LWIP-TESTS-MBEDMICRO-NET-TCP_PACKET_PRESSURE
|
||||
<trace removed>
|
||||
|
||||
|
||||
Notice the following tests in the sd-driver tree are listed above:
|
||||
|
||||
- `SD-DRIVER-TESTS-BLOCK_DEVICE-BASIC`
|
||||
- `SD-DRIVER-TESTS-FILESYSTEM-BASIC`
|
||||
- `SD-DRIVER-TESTS-FILESYSTEM-DIRS`
|
||||
- `SD-DRIVER-TESTS-FILESYSTEM-FILES`
|
||||
- `SD-DRIVER-TESTS-FILESYSTEM-FOPEN`
|
||||
- `SD-DRIVER-TESTS-FILESYSTEM-PARALLEL`
|
||||
- `SD-DRIVER-TESTS-FILESYSTEM-SEEK`
|
||||
|
||||
The FAT32/SDCard test cases are at following locations in the source code tree:
|
||||
|
||||
/d/demo_area/ex_app1/sd-driver/TESTS/filesystem/basic/basic.cpp
|
||||
/d/demo_area/ex_app1/sd-driver/TESTS/filesystem/fopen/fopen.cpp
|
||||
/d/demo_area/ex_app1/sd-driver/TESTS/block_device/basic/basic.cpp
|
||||
/d/demo_area/ex_app1/sd-driver/TESTS/filesystem/dirs/main.cpp
|
||||
/d/demo_area/ex_app1/sd-driver/TESTS/filesystem/files/main.cpp
|
||||
/d/demo_area/ex_app1/sd-driver/TESTS/filesystem/parallel/main.cpp
|
||||
/d/demo_area/ex_app1/sd-driver/TESTS/filesystem/seek/main.cpp
|
||||
|
||||
#### <a name="settting-repos-to-compatible-versions"></a> Setting mbed-os/sd-driver Repositories To Compatible Versions
|
||||
|
||||
The sd-driver master HEAD and the mbed-os master HEAD should be compatible
|
||||
with one another and therefore no specific tagged versions need to be checked out.
|
||||
However, in the case that you experience problems building, checkout out the compatible
|
||||
tagged version of each repository, as shown below:
|
||||
|
||||
shell:/d/demo_area/ex_app1$ pushd mbed-os
|
||||
shell:/d/demo_area/ex_app1$ git checkout tags/mbed-os-5.4.0
|
||||
shell:/d/demo_area/ex_app1$ popd
|
||||
shell:/d/demo_area/ex_app1$ pushd sd-driver
|
||||
shell:/d/demo_area/ex_app1$ git checkout tags/sd-driver-0.0.2-mbed-os-5.4.0
|
||||
shell:/d/demo_area/ex_app1$ popd
|
||||
|
||||
In the above:
|
||||
|
||||
- `mbed-os-5.4.0` should be replaced with the latest mbed-os release tag.
|
||||
- For an mbed-os release tag `mbed-os-x.y.z`, use the equivalent sd-driver tag `sd-driver-a.b.c-mbed-os-x.y.z`
|
||||
where `a.b.c` is the latest version code for the `mbed-os-x.y.z` tag.
|
||||
|
||||
### <a name="greentea-insert-sdcard-into-k64f"></a> Insert SDCard into K64F for Greentea Testing
|
||||
|
||||
See the previous section for [Insert SDCard into K64F](#insert-sdcard-into-k64f) for details.
|
||||
|
||||
|
||||
### <a name="run-the-posix-file-test-cases"></a> Run the POSIX File Test Case
|
||||
|
||||
To setup for running the test cases, connect the K64F development board to your
|
||||
PC using a suitable USB cable.
|
||||
|
||||
All tests can be run using the following command:
|
||||
|
||||
shell:/d/demo_area/ex_app1$ mbedgt -VS
|
||||
<trace removed>
|
||||
|
||||
However, it's possible to run a particular test case using the following form of the mbedgt command:
|
||||
|
||||
shell:/d/demo_area/ex_app1$ mbedgt -VS --test-by-names=<test-name>
|
||||
|
||||
The names of the tests can be listed using:
|
||||
|
||||
shell:/d/demo_area/ex_app1$ mbedgt -VS --list
|
||||
|
||||
For example, to run the basic test use:
|
||||
|
||||
shell:/d/demo_area/ex_app1$ mbedgt -VS --test-by-names=sd-driver-tests-filesystem-basic
|
||||
|
||||
To run the fopen test use:
|
||||
|
||||
shell:/d/demo_area/ex_app1$ mbedgt -VS --test-by-names=sd-driver-tests-filesystem-fopen
|
||||
|
||||
On a successful run, results similar to the following will be shown:
|
||||
|
||||
mbedgt: test suite report:
|
||||
+--------------+---------------+-------------------------------------------+--------+--------------------+-------------+
|
||||
| target | platform_name | test suite | result | elapsed_time (sec) | copy_method |
|
||||
+--------------+---------------+-------------------------------------------+--------+--------------------+-------------+
|
||||
| K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | OK | 151.46 | shell |
|
||||
+--------------+---------------+-------------------------------------------+--------+--------------------+-------------+
|
||||
mbedgt: test suite results: 1 OK
|
||||
mbedgt: test case report:
|
||||
+--------------+---------------+------------------------------------+----------------------------------------------------------------------------------------+--------+--------+--------+--------------------+
|
||||
| target | platform_name | test suite | test case | passed | failed | result | elapsed_time (sec) |
|
||||
+--------------+---------------+------------------------------------+----------------------------------------------------------------------------------------+--------+--------+--------+--------------------+
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_01: fopen()/fwrite()/fclose() directories/file in multi-dir filepath. | 1 | 0 | OK | 7.57 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_02: fopen(r) pre-existing file try to write it. | 1 | 0 | OK | 0.2 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_03: fopen(w+) pre-existing file try to write it. | 1 | 0 | OK | 0.41 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_04: fopen() with a filename exceeding the maximum length. | 1 | 0 | OK | 0.11 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_06: fopen() with bad filenames (minimal). | 1 | 0 | OK | 0.1 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_07: fopen()/errno handling. | 1 | 0 | OK | 0.07 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_08: ferror()/clearerr()/errno handling. | 1 | 0 | OK | 0.1 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_09: ftell() handling. | 1 | 0 | OK | 0.17 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_10: remove() test. | 1 | 0 | OK | 1.28 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_11: rename(). | 1 | 0 | OK | 2.3 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_12: opendir(), readdir(), closedir() test. | 1 | 0 | OK | 3.57 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_13: mkdir() test. | 1 | 0 | OK | 1.21 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_14: stat() test. | 1 | 0 | OK | 1.47 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_15: format() test. | 1 | 0 | OK | 26.12 |
|
||||
| K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_16: write/check n x 25kB data files. | 1 | 0 | OK | 87.11 |
|
||||
+--------------+---------------+------------------------------------+----------------------------------------------------------------------------------------+--------+--------+--------+--------------------+
|
||||
mbedgt: test case results: 15 OK
|
||||
mbedgt: completed in 152.35 sec
|
||||
|
||||
|
||||
# <a name="summary-posix-api-documentation"></a> Summary of POSIX File API Documentation
|
||||
|
||||
### POSIX File API
|
||||
|
||||
mbed OS supports a subset of the POSIX File API, as outlined below:
|
||||
|
||||
- [clearerr()](https://linux.die.net/man/3/clearerr).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [fclose()](https://linux.die.net/man/3/fclose).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [ferror()](https://linux.die.net/man/3/clearerr).
|
||||
- STATUS: Basic testing implemented.
|
||||
- STATUS: GCC_ARM: Working.
|
||||
- STATUS: ARMCC: ARMCC has problem with ferror(filep) where filep is NULL. Appears to work for non-NULL pointer.
|
||||
- [fgetc()](https://linux.die.net/man/3/fgets).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [fgets()](https://linux.die.net/man/3/fgets).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [fputc()](https://linux.die.net/man/3/fputs).
|
||||
- STATUS: Unknown.
|
||||
- [fputs()](https://linux.die.net/man/3/fputs).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [fprintf()](https://linux.die.net/man/3/fprintf).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [fopen()](https://linux.die.net/man/3/fopen).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [freopen()](https://linux.die.net/man/3/fopen).
|
||||
- STATUS: This is not tested.
|
||||
- [fread()](https://linux.die.net/man/3/fread).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- STATUS: n x 25kB stress test working.
|
||||
- [ftell()](https://linux.die.net/man/3/ftell).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [fwrite()](https://linux.die.net/man/3/fwrite).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- STATUS: n x 25kB stress test working.
|
||||
- [fseek()](https://linux.die.net/man/3/fseek)
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [getc()](https://linux.die.net/man/3/fgets).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [gets()](https://linux.die.net/man/3/fgets).
|
||||
- STATUS: Unknown.
|
||||
- [putc()](https://linux.die.net/man/3/fputs).
|
||||
- STATUS: Unknown.
|
||||
- [puts()](https://linux.die.net/man/3/fputs).
|
||||
- STATUS: Unknown.
|
||||
- [remove()](https://linux.die.net/man/3/remove)
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [rewind()](https://linux.die.net/man/3/rewind).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [stat()](https://linux.die.net/man/2/stat)
|
||||
- STATUS: Implemented. Working.
|
||||
- STATUS: Not supported by ARMCC/IAR libc.
|
||||
- [tmpfile()](https://linux.die.net/man/3/tmpfile).
|
||||
- STATUS: Not implemented.
|
||||
- [tmpnam()](https://linux.die.net/man/3/tmpnam).
|
||||
- STATUS: Not implemented.
|
||||
|
||||
Supported directory related operations are as follows:
|
||||
|
||||
- [closedir()](https://linux.die.net/man/3/closedir).
|
||||
- STATUS: Implemented. Working.
|
||||
- [mkdir()](https://linux.die.net/man/3/mkdir).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [opendir()](https://linux.die.net/man/3/opendir).
|
||||
- STATUS: Implemented. Working.
|
||||
- [readdir()](https://linux.die.net/man/3/readdir).
|
||||
- STATUS: Implemented. Working.
|
||||
- [remove()](https://linux.die.net/man/3/remove).
|
||||
- STATUS: Basic testing implemented. Working.
|
||||
- [rename()](https://linux.die.net/man/3/rename).
|
||||
- STATUS: Implemented. Not tested.
|
||||
- [rewinddir()](https://linux.die.net/man/3/rewinddir).
|
||||
- STATUS: Implemented. Found not to work. Test case not present in repo.
|
||||
- [seekdir()](https://linux.die.net/man/3/seekdir).
|
||||
- STATUS: Implemented. Found not to work. Test case not present in repo.
|
||||
- [telldir()](https://linux.die.net/man/3/telldir).
|
||||
- STATUS: Implemented. Found not to work. Test case not present in repo.
|
||||
|
||||
### errno
|
||||
|
||||
Basic errno reporting is supported, tested and known to be working.
|
||||
|
||||
|
||||
# Related Projects Resources
|
||||
|
||||
The following are related mbed storage projects and useful resources:
|
||||
|
||||
- The [mbed-os](https://github.com/ARMmbed/mbed-os) main repository.
|
||||
- The [mbed-os-example-fat-filesystem](https://github.com/ARMmbed/mbed-os-example-fat-filesystem) repository.
|
||||
This is an example project for the mbed OS FAT filesystem.
|
||||
- The [spiflash-driver](https://github.com/armmbed/spiflash-driver) repository.
|
||||
- The [i2ceeprom-driver](https://github.com/ARMmbed/i2ceeprom-driver.git) repository.
|
||||
- The [ci-test-shield](https://github.com/ARMmbed/ci-test-shield) repository. This is the project describing
|
||||
the mbed-os Continuous Integration test shield, together with standard tests.
|
||||
- The [mbed-HDK](https://github.com/ARMmbed/mbed-HDK) repository containing Hardware Development Kit resources
|
||||
including the schematics for the CI test shield.
|
||||
- [POSIX File Interface ISO/IEC 9899:TC2 Documentation](http://www.eng.utah.edu/~cs5785/slides-f10/n1124.pdf).
|
||||
- [FATFS: Generic FAT File System Module used in mbed OS](http://elm-chan.org/fsw/ff/00index_e.html)
|
|
@ -249,7 +249,7 @@
|
|||
#define SPI_READ_ERROR_OFR (0x1 << 3) /*!< Out of Range */
|
||||
|
||||
SDBlockDevice::SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName cs, uint64_t hz, bool crc_on)
|
||||
: _sectors(0), _spi(mosi, miso, sclk), _cs(cs), _is_initialized(0),
|
||||
: _sectors(0), _spi(mosi, miso, sclk), _cs(cs), _is_initialized(0),
|
||||
_crc_on(crc_on), _init_ref_count(0), _crc16(0, 0, false, false)
|
||||
{
|
||||
_cs = 1;
|
||||
|
@ -447,7 +447,7 @@ int SDBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
|
|||
return SD_BLOCK_DEVICE_ERROR_NO_INIT;
|
||||
}
|
||||
|
||||
const uint8_t *buffer = static_cast<const uint8_t*>(b);
|
||||
const uint8_t *buffer = static_cast<const uint8_t *>(b);
|
||||
int status = BD_ERROR_OK;
|
||||
uint8_t response;
|
||||
|
||||
|
@ -456,7 +456,7 @@ int SDBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
|
|||
|
||||
// SDSC Card (CCS=0) uses byte unit address
|
||||
// SDHC and SDXC Cards (CCS=1) use block unit address (512 Bytes unit)
|
||||
if(SDCARD_V2HC == _card_type) {
|
||||
if (SDCARD_V2HC == _card_type) {
|
||||
addr = addr / _block_size;
|
||||
}
|
||||
|
||||
|
@ -494,7 +494,7 @@ int SDBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
|
|||
break;
|
||||
}
|
||||
buffer += _block_size;
|
||||
}while (--blockCnt); // Receive all blocks of data
|
||||
} while (--blockCnt); // Receive all blocks of data
|
||||
|
||||
/* In a Multiple Block write operation, the stop transmission will be done by
|
||||
* sending 'Stop Tran' token instead of 'Start Block' token at the beginning
|
||||
|
@ -563,9 +563,9 @@ int SDBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
|
|||
bool SDBlockDevice::_is_valid_trim(bd_addr_t addr, bd_size_t size)
|
||||
{
|
||||
return (
|
||||
addr % _erase_size == 0 &&
|
||||
size % _erase_size == 0 &&
|
||||
addr + size <= this->size());
|
||||
addr % _erase_size == 0 &&
|
||||
size % _erase_size == 0 &&
|
||||
addr + size <= this->size());
|
||||
}
|
||||
|
||||
int SDBlockDevice::trim(bd_addr_t addr, bd_size_t size)
|
||||
|
@ -596,7 +596,7 @@ int SDBlockDevice::trim(bd_addr_t addr, bd_size_t size)
|
|||
}
|
||||
|
||||
// End lba = addr+size sent in end addr command
|
||||
if (BD_ERROR_OK != (status = _cmd(CMD33_ERASE_WR_BLK_END_ADDR, addr+size))) {
|
||||
if (BD_ERROR_OK != (status = _cmd(CMD33_ERASE_WR_BLK_END_ADDR, addr + size))) {
|
||||
unlock();
|
||||
return status;
|
||||
}
|
||||
|
@ -617,7 +617,7 @@ bd_size_t SDBlockDevice::get_program_size() const
|
|||
|
||||
bd_size_t SDBlockDevice::size() const
|
||||
{
|
||||
return _block_size*_sectors;
|
||||
return _block_size * _sectors;
|
||||
}
|
||||
|
||||
void SDBlockDevice::debug(bool dbg)
|
||||
|
@ -648,7 +648,8 @@ int SDBlockDevice::_freq(void)
|
|||
}
|
||||
}
|
||||
|
||||
uint8_t SDBlockDevice::_cmd_spi(SDBlockDevice::cmdSupported cmd, uint32_t arg) {
|
||||
uint8_t SDBlockDevice::_cmd_spi(SDBlockDevice::cmdSupported cmd, uint32_t arg)
|
||||
{
|
||||
uint8_t response;
|
||||
char cmdPacket[PACKET_SIZE];
|
||||
uint32_t crc;
|
||||
|
@ -666,7 +667,7 @@ uint8_t SDBlockDevice::_cmd_spi(SDBlockDevice::cmdSupported cmd, uint32_t arg) {
|
|||
} else {
|
||||
// CMD0 is executed in SD mode, hence should have correct CRC
|
||||
// CMD8 CRC verification is always enabled
|
||||
switch(cmd) {
|
||||
switch (cmd) {
|
||||
case CMD0_GO_IDLE_STATE:
|
||||
cmdPacket[5] = 0x95;
|
||||
break;
|
||||
|
@ -701,7 +702,8 @@ uint8_t SDBlockDevice::_cmd_spi(SDBlockDevice::cmdSupported cmd, uint32_t arg) {
|
|||
return response;
|
||||
}
|
||||
|
||||
int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAcmd, uint32_t *resp) {
|
||||
int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAcmd, uint32_t *resp)
|
||||
{
|
||||
int32_t status = BD_ERROR_OK;
|
||||
uint32_t response;
|
||||
|
||||
|
@ -717,7 +719,7 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
|
|||
}
|
||||
|
||||
// Re-try command
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
// Send CMD55 for APP command first
|
||||
if (isAcmd) {
|
||||
response = _cmd_spi(CMD55_APP_CMD, 0x0);
|
||||
|
@ -744,17 +746,17 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
|
|||
// Process the response R1 : Exit on CRC/Illegal command error/No response
|
||||
if (R1_NO_RESPONSE == response) {
|
||||
_deselect();
|
||||
debug_if(SD_DBG, "No response CMD:%d response: 0x%x\n",cmd, response);
|
||||
debug_if(SD_DBG, "No response CMD:%d response: 0x%x\n", cmd, response);
|
||||
return SD_BLOCK_DEVICE_ERROR_NO_DEVICE; // No device
|
||||
}
|
||||
if (response & R1_COM_CRC_ERROR) {
|
||||
_deselect();
|
||||
debug_if(SD_DBG, "CRC error CMD:%d response 0x%x \n",cmd, response);
|
||||
debug_if(SD_DBG, "CRC error CMD:%d response 0x%x \n", cmd, response);
|
||||
return SD_BLOCK_DEVICE_ERROR_CRC; // CRC error
|
||||
}
|
||||
if (response & R1_ILLEGAL_COMMAND) {
|
||||
_deselect();
|
||||
debug_if(SD_DBG, "Illegal command CMD:%d response 0x%x\n",cmd, response);
|
||||
debug_if(SD_DBG, "Illegal command CMD:%d response 0x%x\n", cmd, response);
|
||||
if (CMD8_SEND_IF_COND == cmd) { // Illegal command is for Ver1 or not SD Card
|
||||
_card_type = CARD_UNKNOWN;
|
||||
}
|
||||
|
@ -765,17 +767,17 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
|
|||
// Set status for other errors
|
||||
if ((response & R1_ERASE_RESET) || (response & R1_ERASE_SEQUENCE_ERROR)) {
|
||||
status = SD_BLOCK_DEVICE_ERROR_ERASE; // Erase error
|
||||
}else if ((response & R1_ADDRESS_ERROR) || (response & R1_PARAMETER_ERROR)) {
|
||||
} else if ((response & R1_ADDRESS_ERROR) || (response & R1_PARAMETER_ERROR)) {
|
||||
// Misaligned address / invalid address block length
|
||||
status = SD_BLOCK_DEVICE_ERROR_PARAMETER;
|
||||
}
|
||||
|
||||
// Get rest of the response part for other commands
|
||||
switch(cmd) {
|
||||
switch (cmd) {
|
||||
case CMD8_SEND_IF_COND: // Response R7
|
||||
debug_if(_dbg, "V2-Version Card\n");
|
||||
_card_type = SDCARD_V2;
|
||||
// Note: No break here, need to read rest of the response
|
||||
// Note: No break here, need to read rest of the response
|
||||
case CMD58_READ_OCR: // Response R3
|
||||
response = (_spi.write(SPI_FILL_CHAR) << 24);
|
||||
response |= (_spi.write(SPI_FILL_CHAR) << 16);
|
||||
|
@ -805,9 +807,9 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
|
|||
|
||||
// Do not deselect card if read is in progress.
|
||||
if (((CMD9_SEND_CSD == cmd) || (ACMD22_SEND_NUM_WR_BLOCKS == cmd) ||
|
||||
(CMD24_WRITE_BLOCK == cmd) || (CMD25_WRITE_MULTIPLE_BLOCK == cmd) ||
|
||||
(CMD17_READ_SINGLE_BLOCK == cmd) || (CMD18_READ_MULTIPLE_BLOCK == cmd))
|
||||
&& (BD_ERROR_OK == status)) {
|
||||
(CMD24_WRITE_BLOCK == cmd) || (CMD25_WRITE_MULTIPLE_BLOCK == cmd) ||
|
||||
(CMD17_READ_SINGLE_BLOCK == cmd) || (CMD18_READ_MULTIPLE_BLOCK == cmd))
|
||||
&& (BD_ERROR_OK == status)) {
|
||||
return BD_ERROR_OK;
|
||||
}
|
||||
// Deselect card
|
||||
|
@ -815,7 +817,8 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
|
|||
return status;
|
||||
}
|
||||
|
||||
int SDBlockDevice::_cmd8() {
|
||||
int SDBlockDevice::_cmd8()
|
||||
{
|
||||
uint32_t arg = (CMD8_PATTERN << 0); // [7:0]check pattern
|
||||
uint32_t response = 0;
|
||||
int32_t status = BD_ERROR_OK;
|
||||
|
@ -826,8 +829,7 @@ int SDBlockDevice::_cmd8() {
|
|||
// Verify voltage and pattern for V2 version of card
|
||||
if ((BD_ERROR_OK == status) && (SDCARD_V2 == _card_type)) {
|
||||
// If check pattern is not matched, CMD8 communication is not valid
|
||||
if((response & 0xFFF) != arg)
|
||||
{
|
||||
if ((response & 0xFFF) != arg) {
|
||||
debug_if(SD_DBG, "CMD8 Pattern mismatch 0x%x : 0x%x\n", arg, response);
|
||||
_card_type = CARD_UNKNOWN;
|
||||
status = SD_BLOCK_DEVICE_ERROR_UNUSABLE;
|
||||
|
@ -836,7 +838,8 @@ int SDBlockDevice::_cmd8() {
|
|||
return status;
|
||||
}
|
||||
|
||||
uint32_t SDBlockDevice::_go_idle_state() {
|
||||
uint32_t SDBlockDevice::_go_idle_state()
|
||||
{
|
||||
uint32_t response;
|
||||
|
||||
/* Reseting the MCU SPI master may not reset the on-board SDCard, in which
|
||||
|
@ -846,14 +849,16 @@ uint32_t SDBlockDevice::_go_idle_state() {
|
|||
* the command overcomes this situation. */
|
||||
for (int i = 0; i < SD_CMD0_GO_IDLE_STATE_RETRIES; i++) {
|
||||
_cmd(CMD0_GO_IDLE_STATE, 0x0, 0x0, &response);
|
||||
if (R1_IDLE_STATE == response)
|
||||
if (R1_IDLE_STATE == response) {
|
||||
break;
|
||||
}
|
||||
wait_ms(1);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
int SDBlockDevice::_read_bytes(uint8_t *buffer, uint32_t length) {
|
||||
int SDBlockDevice::_read_bytes(uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
uint16_t crc;
|
||||
|
||||
// read until start byte (0xFE)
|
||||
|
@ -878,7 +883,7 @@ int SDBlockDevice::_read_bytes(uint8_t *buffer, uint32_t length) {
|
|||
_crc16.compute((void *)buffer, length, &crc_result);
|
||||
if ((uint16_t)crc_result != crc) {
|
||||
debug_if(SD_DBG, "_read_bytes: Invalid CRC received 0x%x result of computation 0x%x\n",
|
||||
crc, crc_result);
|
||||
crc, crc_result);
|
||||
_deselect();
|
||||
return SD_BLOCK_DEVICE_ERROR_CRC;
|
||||
}
|
||||
|
@ -888,7 +893,8 @@ int SDBlockDevice::_read_bytes(uint8_t *buffer, uint32_t length) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int SDBlockDevice::_read(uint8_t *buffer, uint32_t length) {
|
||||
int SDBlockDevice::_read(uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
uint16_t crc;
|
||||
|
||||
// read until start byte (0xFE)
|
||||
|
@ -899,7 +905,7 @@ int SDBlockDevice::_read(uint8_t *buffer, uint32_t length) {
|
|||
}
|
||||
|
||||
// read data
|
||||
_spi.write(NULL, 0, (char*)buffer, length);
|
||||
_spi.write(NULL, 0, (char *)buffer, length);
|
||||
|
||||
// Read the CRC16 checksum for the data block
|
||||
crc = (_spi.write(SPI_FILL_CHAR) << 8);
|
||||
|
@ -911,7 +917,7 @@ int SDBlockDevice::_read(uint8_t *buffer, uint32_t length) {
|
|||
_crc16.compute((void *)buffer, length, &crc_result);
|
||||
if ((uint16_t)crc_result != crc) {
|
||||
debug_if(SD_DBG, "_read_bytes: Invalid CRC received 0x%x result of computation 0x%x\n",
|
||||
crc, crc_result);
|
||||
crc, crc_result);
|
||||
return SD_BLOCK_DEVICE_ERROR_CRC;
|
||||
}
|
||||
}
|
||||
|
@ -919,8 +925,9 @@ int SDBlockDevice::_read(uint8_t *buffer, uint32_t length) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint8_t SDBlockDevice::_write(const uint8_t *buffer, uint8_t token, uint32_t length) {
|
||||
|
||||
uint8_t SDBlockDevice::_write(const uint8_t *buffer, uint8_t token, uint32_t length)
|
||||
{
|
||||
|
||||
uint32_t crc = (~0);
|
||||
uint8_t response = 0xFF;
|
||||
|
||||
|
@ -928,7 +935,7 @@ uint8_t SDBlockDevice::_write(const uint8_t *buffer, uint8_t token, uint32_t len
|
|||
_spi.write(token);
|
||||
|
||||
// write the data
|
||||
_spi.write((char*)buffer, length, NULL, 0);
|
||||
_spi.write((char *)buffer, length, NULL, 0);
|
||||
|
||||
if (_crc_on) {
|
||||
// Compute CRC
|
||||
|
@ -951,7 +958,8 @@ uint8_t SDBlockDevice::_write(const uint8_t *buffer, uint8_t token, uint32_t len
|
|||
return (response & SPI_DATA_RESPONSE_MASK);
|
||||
}
|
||||
|
||||
static uint32_t ext_bits(unsigned char *data, int msb, int lsb) {
|
||||
static uint32_t ext_bits(unsigned char *data, int msb, int lsb)
|
||||
{
|
||||
uint32_t bits = 0;
|
||||
uint32_t size = 1 + msb - lsb;
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
|
@ -964,7 +972,8 @@ static uint32_t ext_bits(unsigned char *data, int msb, int lsb) {
|
|||
return bits;
|
||||
}
|
||||
|
||||
bd_size_t SDBlockDevice::_sd_sectors() {
|
||||
bd_size_t SDBlockDevice::_sd_sectors()
|
||||
{
|
||||
uint32_t c_size, c_size_mult, read_bl_len;
|
||||
uint32_t block_len, mult, blocknr;
|
||||
uint32_t hc_c_size;
|
||||
|
@ -995,7 +1004,7 @@ bd_size_t SDBlockDevice::_sd_sectors() {
|
|||
blocks = capacity / _block_size;
|
||||
debug_if(SD_DBG, "Standard Capacity: c_size: %d \n", c_size);
|
||||
debug_if(SD_DBG, "Sectors: 0x%x : %llu\n", blocks, blocks);
|
||||
debug_if(SD_DBG, "Capacity: 0x%x : %llu MB\n", capacity, (capacity/(1024U*1024U)));
|
||||
debug_if(SD_DBG, "Capacity: 0x%x : %llu MB\n", capacity, (capacity / (1024U * 1024U)));
|
||||
|
||||
// ERASE_BLK_EN = 1: Erase in multiple of 512 bytes supported
|
||||
if (ext_bits(csd, 46, 46)) {
|
||||
|
@ -1008,10 +1017,10 @@ bd_size_t SDBlockDevice::_sd_sectors() {
|
|||
|
||||
case 1:
|
||||
hc_c_size = ext_bits(csd, 69, 48); // device size : C_SIZE : [69:48]
|
||||
blocks = (hc_c_size+1) << 10; // block count = C_SIZE+1) * 1K byte (512B is block size)
|
||||
blocks = (hc_c_size + 1) << 10; // block count = C_SIZE+1) * 1K byte (512B is block size)
|
||||
debug_if(SD_DBG, "SDHC/SDXC Card: hc_c_size: %d \n", hc_c_size);
|
||||
debug_if(SD_DBG, "Sectors: 0x%x : %llu\n", blocks, blocks);
|
||||
debug_if(SD_DBG, "Capacity: %llu MB\n", (blocks/(2048U)));
|
||||
debug_if(SD_DBG, "Capacity: %llu MB\n", (blocks / (2048U)));
|
||||
// ERASE_BLK_EN is fixed to 1, which means host can erase one or multiple of 512 bytes.
|
||||
_erase_size = BLOCK_SIZE_HC;
|
||||
break;
|
||||
|
@ -1024,7 +1033,8 @@ bd_size_t SDBlockDevice::_sd_sectors() {
|
|||
}
|
||||
|
||||
// SPI function to wait till chip is ready and sends start token
|
||||
bool SDBlockDevice::_wait_token(uint8_t token) {
|
||||
bool SDBlockDevice::_wait_token(uint8_t token)
|
||||
{
|
||||
_spi_timer.reset();
|
||||
_spi_timer.start();
|
||||
|
||||
|
@ -1041,7 +1051,8 @@ bool SDBlockDevice::_wait_token(uint8_t token) {
|
|||
|
||||
// SPI function to wait till chip is ready
|
||||
// The host controller should wait for end of the process until DO goes high (a 0xFF is received).
|
||||
bool SDBlockDevice::_wait_ready(uint16_t ms) {
|
||||
bool SDBlockDevice::_wait_ready(uint16_t ms)
|
||||
{
|
||||
uint8_t response;
|
||||
_spi_timer.reset();
|
||||
_spi_timer.start();
|
||||
|
@ -1064,7 +1075,8 @@ void SDBlockDevice::_spi_wait(uint8_t count)
|
|||
}
|
||||
}
|
||||
|
||||
void SDBlockDevice::_spi_init() {
|
||||
void SDBlockDevice::_spi_init()
|
||||
{
|
||||
_spi.lock();
|
||||
// Set to SCK for initialization, and clock card with cs = 1
|
||||
_spi.frequency(_init_sck);
|
||||
|
@ -1076,13 +1088,15 @@ void SDBlockDevice::_spi_init() {
|
|||
_spi.unlock();
|
||||
}
|
||||
|
||||
void SDBlockDevice::_select() {
|
||||
void SDBlockDevice::_select()
|
||||
{
|
||||
_spi.lock();
|
||||
_spi.write(SPI_FILL_CHAR);
|
||||
_cs = 0;
|
||||
}
|
||||
|
||||
void SDBlockDevice::_deselect() {
|
||||
void SDBlockDevice::_deselect()
|
||||
{
|
||||
_cs = 1;
|
||||
_spi.write(SPI_FILL_CHAR);
|
||||
_spi.unlock();
|
||||
|
|
|
@ -24,28 +24,15 @@
|
|||
#include "mbed.h"
|
||||
#include "platform/PlatformMutex.h"
|
||||
|
||||
/** Access an SD Card using SPI
|
||||
/** SDBlockDevice class
|
||||
*
|
||||
* @code
|
||||
* #include "mbed.h"
|
||||
* #include "SDBlockDevice.h"
|
||||
*
|
||||
* SDBlockDevice sd(p5, p6, p7, p12); // mosi, miso, sclk, cs
|
||||
* uint8_t block[512] = "Hello World!\n";
|
||||
*
|
||||
* int main() {
|
||||
* sd.init();
|
||||
* sd.write(block, 0, 512);
|
||||
* sd.read(block, 0, 512);
|
||||
* printf("%s", block);
|
||||
* sd.deinit();
|
||||
* }
|
||||
* Access an SD Card using SPI
|
||||
*/
|
||||
class SDBlockDevice : public BlockDevice {
|
||||
public:
|
||||
/** Lifetime of an SD card
|
||||
*/
|
||||
SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName cs, uint64_t hz=1000000, bool crc_on=0);
|
||||
SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName cs, uint64_t hz = 1000000, bool crc_on = 0);
|
||||
virtual ~SDBlockDevice();
|
||||
|
||||
/** Initialize a block device
|
||||
|
@ -114,13 +101,13 @@ public:
|
|||
|
||||
/** Enable or disable debugging
|
||||
*
|
||||
* @param State of debugging
|
||||
* @param dbg State of debugging
|
||||
*/
|
||||
virtual void debug(bool dbg);
|
||||
|
||||
/** Set the transfer frequency
|
||||
*
|
||||
* @param Transfer frequency
|
||||
* @param freq Transfer frequency
|
||||
* @note Max frequency supported is 25MHZ
|
||||
*/
|
||||
virtual int frequency(uint64_t freq);
|
||||
|
@ -168,7 +155,7 @@ private:
|
|||
};
|
||||
|
||||
uint8_t _card_type;
|
||||
int _cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAcmd=0, uint32_t *resp=NULL);
|
||||
int _cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAcmd = 0, uint32_t *resp = NULL);
|
||||
int _cmd8();
|
||||
|
||||
/* Move the SDCard into the SPI Mode idle state
|
||||
|
@ -201,10 +188,10 @@ private:
|
|||
void _spi_wait(uint8_t count);
|
||||
|
||||
bool _wait_token(uint8_t token); /**< Wait for token */
|
||||
bool _wait_ready(uint16_t ms=300); /**< 300ms default wait for card to be ready */
|
||||
int _read(uint8_t * buffer, uint32_t length);
|
||||
int _read_bytes(uint8_t * buffer, uint32_t length);
|
||||
uint8_t _write(const uint8_t *buffer,uint8_t token, uint32_t length);
|
||||
bool _wait_ready(uint16_t ms = 300); /**< 300ms default wait for card to be ready */
|
||||
int _read(uint8_t *buffer, uint32_t length);
|
||||
int _read_bytes(uint8_t *buffer, uint32_t length);
|
||||
uint8_t _write(const uint8_t *buffer, uint8_t token, uint32_t length);
|
||||
int _freq(void);
|
||||
|
||||
/* Chip Select and SPI mode select */
|
||||
|
@ -212,11 +199,13 @@ private:
|
|||
void _select();
|
||||
void _deselect();
|
||||
|
||||
virtual void lock() {
|
||||
virtual void lock()
|
||||
{
|
||||
_mutex.lock();
|
||||
}
|
||||
|
||||
virtual void unlock() {
|
||||
virtual void unlock()
|
||||
{
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,179 +0,0 @@
|
|||
/*
|
||||
* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2016 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/* The following copyright notice is reproduced from the glibc project
|
||||
* REF_LICENCE_GLIBC
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||
* This file is part of the GNU C Library.
|
||||
*
|
||||
* The GNU C Library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* The GNU C Library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with the GNU C Library; see the file COPYING.LIB. If
|
||||
* not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
* Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
/** @file main.cpp Basic SD Driver Test
|
||||
*/
|
||||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
#include "SDBlockDevice.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
#define TEST_BLOCK_COUNT 10
|
||||
#define TEST_ERROR_MASK 16
|
||||
#define TEST_BLOCK_SIZE 2048
|
||||
|
||||
const struct {
|
||||
const char *name;
|
||||
bd_size_t (BlockDevice::*method)() const;
|
||||
} ATTRS[] = {
|
||||
{"read size", &BlockDevice::get_read_size},
|
||||
{"program size", &BlockDevice::get_program_size},
|
||||
{"erase size", &BlockDevice::get_erase_size},
|
||||
{"total size", &BlockDevice::size},
|
||||
};
|
||||
|
||||
void test_read_write() {
|
||||
SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
|
||||
|
||||
int err = sd.init();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
err = sd.frequency(8000000);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
for (unsigned a = 0; a < sizeof(ATTRS)/sizeof(ATTRS[0]); a++) {
|
||||
static const char *prefixes[] = {"", "k", "M", "G"};
|
||||
for (int i = 3; i >= 0; i--) {
|
||||
bd_size_t size = (sd.*ATTRS[a].method)();
|
||||
if (size >= (1ULL << 10*i)) {
|
||||
printf("%s: %llu%sbytes (%llubytes)\n",
|
||||
ATTRS[a].name, size >> 10*i, prefixes[i], size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bd_size_t erase_size = sd.get_erase_size();
|
||||
bd_size_t block_size = erase_size > TEST_BLOCK_SIZE ? erase_size : TEST_BLOCK_SIZE;
|
||||
|
||||
uint8_t *write_block = new uint8_t[block_size];
|
||||
uint8_t *read_block = new uint8_t[block_size];
|
||||
uint8_t *error_mask = new uint8_t[TEST_ERROR_MASK];
|
||||
unsigned addrwidth = ceil(log(float(sd.size()-1)) / log(float(16)))+1;
|
||||
|
||||
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
|
||||
// Find a random block
|
||||
bd_addr_t block = (rand()*block_size) % sd.size();
|
||||
|
||||
// Use next random number as temporary seed to keep
|
||||
// the address progressing in the pseudorandom sequence
|
||||
unsigned seed = rand();
|
||||
|
||||
// Fill with random sequence
|
||||
srand(seed);
|
||||
for (bd_size_t i = 0; i < block_size; i++) {
|
||||
write_block[i] = 0xff & rand();
|
||||
}
|
||||
|
||||
// Write, sync, and read the block
|
||||
printf("test %0*llx:%llu...\n", addrwidth, block, block_size);
|
||||
|
||||
err = sd.trim(block, block_size);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
err = sd.program(write_block, block, block_size);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("write %0*llx:%llu ", addrwidth, block, block_size);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
printf("%02x", write_block[i]);
|
||||
}
|
||||
printf("...\n");
|
||||
|
||||
err = sd.read(read_block, block, block_size);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
printf("read %0*llx:%llu ", addrwidth, block, block_size);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
printf("%02x", read_block[i]);
|
||||
}
|
||||
printf("...\n");
|
||||
|
||||
// Find error mask for debugging
|
||||
memset(error_mask, 0, TEST_ERROR_MASK);
|
||||
bd_size_t error_scale = block_size / (TEST_ERROR_MASK*8);
|
||||
|
||||
srand(seed);
|
||||
for (bd_size_t i = 0; i < TEST_ERROR_MASK*8; i++) {
|
||||
for (bd_size_t j = 0; j < error_scale; j++) {
|
||||
if ((0xff & rand()) != read_block[i*error_scale + j]) {
|
||||
error_mask[i/8] |= 1 << (i%8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("error %0*llx:%llu ", addrwidth, block, block_size);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
printf("%02x", error_mask[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Check that the data was unmodified
|
||||
srand(seed);
|
||||
for (bd_size_t i = 0; i < block_size; i++) {
|
||||
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
|
||||
}
|
||||
}
|
||||
|
||||
err = sd.deinit();
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
}
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP(120, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("Testing read write random blocks", test_read_write),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
return !Harness::run(specification);
|
||||
}
|
|
@ -1,933 +0,0 @@
|
|||
/*
|
||||
* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2016 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/* The following copyright notice is reproduced from the glibc project
|
||||
* REF_LICENCE_GLIBC
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||
* This file is part of the GNU C Library.
|
||||
*
|
||||
* The GNU C Library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* The GNU C Library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with the GNU C Library; see the file COPYING.LIB. If
|
||||
* not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
* Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
/** @file basic.cpp POSIX File API (stdio) test cases
|
||||
*
|
||||
* Consult the documentation under the test-case functions for
|
||||
* a description of the individual test case.
|
||||
*
|
||||
* this file includes ports for the mbed 2 test cases from the following locations:
|
||||
* - https://github.com:/armmbed/mbed-os/features/unsupported/tests/mbed/dir_sd/main.cpp.
|
||||
* - https://github.com:/armmbed/mbed-os/features/unsupported/tests/mbed/file/main.cpp.
|
||||
* - https://github.com:/armmbed/mbed-os/features/unsupported/tests/mbed/sd/main.cpp
|
||||
* - https://github.com:/armmbed/mbed-os/features/unsupported/tests/mbed/sd_perf_handle/main.cpp
|
||||
* - https://github.com:/armmbed/mbed-os/features/unsupported/tests/mbed/sd_perf_stdio/main.cpp.
|
||||
*/
|
||||
|
||||
#include "mbed.h"
|
||||
#include "mbed_config.h"
|
||||
#include "FATFileSystem.h"
|
||||
#include "SDBlockDevice.h"
|
||||
#include "test_env.h"
|
||||
#include "fsfat_debug.h"
|
||||
#include "fsfat_test.h"
|
||||
#include "utest/utest.h"
|
||||
#include "unity/unity.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <algorithm>
|
||||
/* retarget.h is included after errno.h so symbols are mapped to
|
||||
* consistent values for all toolchains */
|
||||
#include "platform/mbed_retarget.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
/* DEVICE_SPI
|
||||
* This symbol is defined in targets.json if the target has a SPI interface, which is required for SDCard support.
|
||||
*
|
||||
* MBED_CONF_APP_FSFAT_SDCARD_INSTALLED
|
||||
* For testing purposes, an SDCard must be installed on the target for the test cases in this file to succeed.
|
||||
* If the target has an SD card installed then the MBED_CONF_APP_FSFAT_SDCARD_INSTALLED will be generated
|
||||
* from the mbed_app.json, which includes the line
|
||||
* {
|
||||
* "config": {
|
||||
* "UART_RX": "D0",
|
||||
* <<< lines removed >>>
|
||||
* "DEVICE_SPI": 1,
|
||||
* "MBED_CONF_APP_FSFAT_SDCARD_INSTALLED": 1
|
||||
* },
|
||||
* <<< lines removed >>>
|
||||
*/
|
||||
#if defined(DEVICE_SPI) && ( defined(MBED_CONF_APP_FSFAT_SDCARD_INSTALLED) || (MBED_CONF_SD_FSFAT_SDCARD_INSTALLED))
|
||||
|
||||
#define FSFAT_BASIC_TEST_00 fsfat_basic_test_00
|
||||
#define FSFAT_BASIC_TEST_01 fsfat_basic_test_01
|
||||
#define FSFAT_BASIC_TEST_02 fsfat_basic_test_02
|
||||
#define FSFAT_BASIC_TEST_03 fsfat_basic_test_03
|
||||
#define FSFAT_BASIC_TEST_04 fsfat_basic_test_04
|
||||
#define FSFAT_BASIC_TEST_05 fsfat_basic_test_05
|
||||
#define FSFAT_BASIC_TEST_06 fsfat_basic_test_06
|
||||
#define FSFAT_BASIC_TEST_07 fsfat_basic_test_07
|
||||
#define FSFAT_BASIC_TEST_08 fsfat_basic_test_08
|
||||
#define FSFAT_BASIC_TEST_09 fsfat_basic_test_09
|
||||
#define FSFAT_BASIC_TEST_10 fsfat_basic_test_10
|
||||
|
||||
#define FSFAT_BASIC_MSG_BUF_SIZE 256
|
||||
#define FSFAT_BASIC_TEST_05_TEST_STRING "Hello World!"
|
||||
|
||||
static const char *sd_file_path = "/sd/out.txt";
|
||||
static const char *sd_mount_pt = "sd";
|
||||
static const int FSFAT_BASIC_DATA_SIZE = 256;
|
||||
static char fsfat_basic_msg_g[FSFAT_BASIC_MSG_BUF_SIZE];
|
||||
static char fsfat_basic_buffer[1024];
|
||||
static const int FSFAT_BASIC_KIB_RW = 128;
|
||||
static Timer fsfat_basic_timer;
|
||||
static const char *fsfat_basic_bin_filename = "/sd/testfile.bin";
|
||||
static const char *fsfat_basic_bin_filename_test_08 = "testfile.bin";
|
||||
static const char *fsfat_basic_bin_filename_test_10 = "0:testfile.bin";
|
||||
|
||||
|
||||
|
||||
SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
|
||||
FATFileSystem fs(sd_mount_pt, &sd);
|
||||
|
||||
#define FSFAT_BASIC_MSG(_buf, _max_len, _fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
snprintf((_buf), (_max_len), (_fmt), __VA_ARGS__); \
|
||||
}while(0);
|
||||
|
||||
/** @brief fopen test case
|
||||
*
|
||||
* - open a file
|
||||
* - generate random data items, write the item to the file and store a coy in a buffer for later use.
|
||||
* - close the file.
|
||||
* - open the file.
|
||||
* - read the data items from the file and check they are the same as write.
|
||||
* - close the file.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_00()
|
||||
{
|
||||
|
||||
uint8_t data_written[FSFAT_BASIC_DATA_SIZE] = { 0 };
|
||||
bool read_result = false;
|
||||
bool write_result = false;
|
||||
|
||||
// Fill data_written buffer with random data
|
||||
// Write these data into the file
|
||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||
{
|
||||
FSFAT_DBGLOG("%s:SD: Writing ... ", __func__);
|
||||
FILE *f = fopen(sd_file_path, "w");
|
||||
if (f) {
|
||||
for (int i = 0; i < FSFAT_BASIC_DATA_SIZE; i++) {
|
||||
data_written[i] = rand() % 0XFF;
|
||||
fprintf(f, "%c", data_written[i]);
|
||||
}
|
||||
write_result = true;
|
||||
fclose(f);
|
||||
}
|
||||
FSFAT_DBGLOG("[%s]\n", write_result ? "OK" : "FAIL");
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(write_result == true, "Error: write_result is set to false.");
|
||||
|
||||
// Read back the data from the file and store them in data_read
|
||||
{
|
||||
FSFAT_DBGLOG("%s:SD: Reading data ... ", __func__);
|
||||
FILE *f = fopen(sd_file_path, "r");
|
||||
if (f) {
|
||||
read_result = true;
|
||||
for (int i = 0; i < FSFAT_BASIC_DATA_SIZE; i++) {
|
||||
uint8_t data = fgetc(f);
|
||||
if (data != data_written[i]) {
|
||||
read_result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
FSFAT_DBGLOG("[%s]\n", read_result ? "OK" : "FAIL");
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(read_result == true, "Error: read_result is set to false.");
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
/** @brief test-fseek.c test ported from glibc project. See the licence at REF_LICENCE_GLIBC.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_01()
|
||||
{
|
||||
FILE *fp, *fp1;
|
||||
int i, j;
|
||||
int ret = 0;
|
||||
|
||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||
fp = fopen (sd_file_path, "w+");
|
||||
if (fp == NULL) {
|
||||
FSFAT_DBGLOG("errno=%d\n", errno);
|
||||
TEST_ASSERT_MESSAGE(false, "error");
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
putc (i, fp);
|
||||
}
|
||||
/* FIXME: freopen() should open the specified file closing the first stream. As can be seen from the
|
||||
* code below, the old file descriptor fp can still be used, and this should not happen.
|
||||
*/
|
||||
fp1 = freopen (sd_file_path, "r", fp);
|
||||
TEST_ASSERT_MESSAGE(fp1 == fp, "Error: cannot open file for reading");
|
||||
|
||||
for (i = 1; i <= 255; i++) {
|
||||
ret = fseek (fp, (long) -i, SEEK_END);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s:Error: fseek() failed (ret=%d).\n", __func__, (int) ret);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
if ((j = getc (fp)) != 256 - i) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: SEEK_END failed (j=%d)\n", __func__, j);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
ret = fseek (fp, (long) i, SEEK_SET);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot SEEK_SET (ret=%d).\n", __func__, (int) ret);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
if ((j = getc (fp)) != i) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot SEEK_SET (j=%d).\n", __func__, j);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
}
|
||||
if ((ret = fseek (fp, (long) i, SEEK_SET))) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot SEEK_SET (ret=%d).\n", __func__, (int) ret);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
}
|
||||
if ((ret = fseek (fp, (long) (i >= 128 ? -128 : 128), SEEK_CUR))) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot SEEK_CUR (ret=%d).\n", __func__, (int) ret);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
}
|
||||
if ((j = getc (fp)) != (i >= 128 ? i - 128 : i + 128)) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot SEEK_CUR (j=%d).\n", __func__, j);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
remove(sd_file_path);
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
/** @brief test_rdwr.c test ported from glibc project. See the licence at REF_LICENCE_GLIBC.
|
||||
*
|
||||
* WARNING: this test does not currently work. See WARNING comments below.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_02()
|
||||
{
|
||||
static const char hello[] = "Hello, world.\n";
|
||||
static const char replace[] = "Hewwo, world.\n";
|
||||
static const size_t replace_from = 2, replace_to = 4;
|
||||
const char *filename = sd_file_path;
|
||||
char buf[BUFSIZ];
|
||||
FILE *f;
|
||||
int lose = 0;
|
||||
int32_t ret = 0;
|
||||
char *rets = NULL;
|
||||
|
||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||
f = fopen(filename, "w+");
|
||||
if (f == NULL) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Cannot open file for writing (filename=%s).\n", __func__, filename);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
|
||||
ret = fputs(hello, f);
|
||||
if (ret == EOF) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fputs() failed to write string to file (filename=%s, string=%s).\n", __func__, filename, hello);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
|
||||
rewind(f);
|
||||
rets = fgets(buf, sizeof(buf), f);
|
||||
if (rets == NULL) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fgets() failed to get string from file (filename=%s).\n", __func__, filename);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
rets = NULL;
|
||||
|
||||
rewind(f);
|
||||
ret = fputs(buf, f);
|
||||
if (ret == EOF) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fputs() failed to write string to file (filename=%s, string=%s).\n", __func__, filename, buf);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
|
||||
rewind(f);
|
||||
{
|
||||
register size_t i;
|
||||
for (i = 0; i < replace_from; ++i)
|
||||
{
|
||||
int c = getc(f);
|
||||
if (c == EOF)
|
||||
{
|
||||
FSFAT_DBGLOG("EOF at %u.\n", i);
|
||||
lose = 1;
|
||||
break;
|
||||
}
|
||||
else if (c != hello[i])
|
||||
{
|
||||
FSFAT_DBGLOG("Got '%c' instead of '%c' at %u.\n",
|
||||
(unsigned char) c, hello[i], i);
|
||||
lose = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* WARNING: printf("%s: here1. (lose = %d)\n", __func__, lose); */
|
||||
{
|
||||
long int where = ftell(f);
|
||||
if (where == replace_from)
|
||||
{
|
||||
register size_t i;
|
||||
for (i = replace_from; i < replace_to; ++i) {
|
||||
if (putc(replace[i], f) == EOF) {
|
||||
FSFAT_DBGLOG("putc('%c') got %s at %u.\n",
|
||||
replace[i], strerror(errno), i);
|
||||
lose = 1;
|
||||
break;
|
||||
}
|
||||
/* WARNING: The problem seems to be that putc() is not writing the 'w' chars into the file
|
||||
* FSFAT_DBGLOG("%s: here1.5. (char = %c, char as int=%d, ret=%d) \n", __func__, replace[i], (int) replace[i], ret);
|
||||
*/
|
||||
}
|
||||
}
|
||||
else if (where == -1L)
|
||||
{
|
||||
FSFAT_DBGLOG("ftell got %s (should be at %u).\n",
|
||||
strerror(errno), replace_from);
|
||||
lose = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
FSFAT_DBGLOG("ftell returns %ld; should be %u.\n", where, replace_from);
|
||||
lose = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lose)
|
||||
{
|
||||
rewind(f);
|
||||
memset(buf, 0, BUFSIZ);
|
||||
if (fgets(buf, sizeof(buf), f) == NULL)
|
||||
{
|
||||
FSFAT_DBGLOG("fgets got %s.\n", strerror(errno));
|
||||
lose = 1;
|
||||
}
|
||||
else if (strcmp(buf, replace))
|
||||
{
|
||||
FSFAT_DBGLOG("Read \"%s\" instead of \"%s\".\n", buf, replace);
|
||||
lose = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (lose) {
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: Test Failed. Losing file (filename=%s).\n", __func__, filename);
|
||||
TEST_ASSERT_MESSAGE(false, fsfat_basic_msg_g);
|
||||
}
|
||||
remove(filename);
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
/** @brief temptest.c test ported from glibc project. See the licence at REF_LICENCE_GLIBC.
|
||||
*
|
||||
* tmpnam() is currently not implemented
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_03()
|
||||
{
|
||||
char *fn = NULL;
|
||||
|
||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||
fn = tmpnam((char *) NULL);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: appeared to generate a filename when function is not implemented.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(fn == NULL, fsfat_basic_msg_g);
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
static bool fsfat_basic_fileno_check(const char *name, FILE *stream, int fd)
|
||||
{
|
||||
/* ARMCC stdio.h currently does not define fileno() */
|
||||
#ifndef __ARMCC_VERSION
|
||||
int sfd = fileno (stream);
|
||||
FSFAT_DBGLOG("(fileno (%s) = %d) %c= %d\n", name, sfd, sfd == fd ? '=' : '!', fd);
|
||||
|
||||
if (sfd == fd) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
/* For ARMCC behave as though test had passed. */
|
||||
return true;
|
||||
#endif /* __ARMCC_VERSION */
|
||||
}
|
||||
|
||||
/* defines for next test case */
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FILENO
|
||||
#define STDOUT_FILENO 1
|
||||
#endif
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
|
||||
/** @brief tst-fileno.c test ported from glibc project. See the licence at REF_LICENCE_GLIBC.
|
||||
*
|
||||
* WARNING: this test does not currently work. See WARNING comments below.
|
||||
*
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_04()
|
||||
{
|
||||
/* ARMCC stdio.h currently does not define fileno() */
|
||||
#ifndef __ARMCC_VERSION
|
||||
int ret = -1;
|
||||
ret = fsfat_basic_fileno_check("stdin", stdin, STDIN_FILENO);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: stdin does not have expected file number (expected=%d, fileno=%d.\n", __func__, (int) stdin, fileno(stdin));
|
||||
TEST_ASSERT_MESSAGE(ret == true, fsfat_basic_msg_g);
|
||||
|
||||
ret = fsfat_basic_fileno_check("stdout", stdout, STDOUT_FILENO);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: stdout does not have expected file number (expected=%d, fileno=%d.\n", __func__, (int) stdout, fileno(stdout));
|
||||
TEST_ASSERT_MESSAGE(ret == true, fsfat_basic_msg_g);
|
||||
|
||||
ret = fsfat_basic_fileno_check("stderr", stderr, STDERR_FILENO);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: stderr does not have expected file number (expected=%d, fileno=%d.\n", __func__, (int) stderr, fileno(stderr));
|
||||
TEST_ASSERT_MESSAGE(ret == true, fsfat_basic_msg_g);
|
||||
#endif /* __ARMCC_VERSION */
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
/** @brief basic test to opendir() on a directory.
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/dir_sd/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_05()
|
||||
{
|
||||
FILE *f;
|
||||
const char *str = FSFAT_BASIC_TEST_05_TEST_STRING;
|
||||
int ret = 0;
|
||||
|
||||
FSFAT_DBGLOG("%s:Write files\n", __func__);
|
||||
char filename[32];
|
||||
for (int i = 0; i < 10; i++) {
|
||||
sprintf(filename, "/sd/test_%d.txt", i);
|
||||
FSFAT_DBGLOG("Creating file: %s\n", filename);
|
||||
f = fopen(filename, "w");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fopen() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(f != NULL, fsfat_basic_msg_g);
|
||||
|
||||
ret = fprintf(f, str);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: writing file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == (int) strlen(str), fsfat_basic_msg_g);
|
||||
|
||||
ret = fclose(f);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fclose() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
}
|
||||
|
||||
FSFAT_DBGLOG("%s:List files:\n", __func__);
|
||||
DIR *d = opendir("/sd");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: opendir() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(d != NULL, fsfat_basic_msg_g);
|
||||
|
||||
struct dirent *p;
|
||||
while ((p = readdir(d)) != NULL)
|
||||
FSFAT_DBGLOG("%s\n", p->d_name);
|
||||
closedir(d);
|
||||
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
/** @brief basic test to write a file to sd card, and read it back again
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/file/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_06()
|
||||
{
|
||||
int ret = -1;
|
||||
char mac[16];
|
||||
mbed_mac_address(mac);
|
||||
FSFAT_DBGLOG("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
FILE *f;
|
||||
const char *str = FSFAT_BASIC_TEST_05_TEST_STRING;
|
||||
int str_len = strlen(FSFAT_BASIC_TEST_05_TEST_STRING);
|
||||
|
||||
f = fopen(sd_file_path, "w");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fopen() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(f != NULL, fsfat_basic_msg_g);
|
||||
|
||||
ret = fprintf(f, str);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: writing file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == (int) strlen(str), fsfat_basic_msg_g);
|
||||
|
||||
ret = fclose(f);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fclose() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
// Read
|
||||
f = fopen(sd_file_path, "r");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fopen() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(f != NULL, fsfat_basic_msg_g);
|
||||
|
||||
int n = fread(fsfat_basic_buffer, sizeof(unsigned char), str_len, f);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fread() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(n == str_len, fsfat_basic_msg_g);
|
||||
|
||||
ret = fclose(f);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: fclose() failed.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
/** @brief basic test to write a file to sd card.
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/sd/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_07()
|
||||
{
|
||||
uint8_t data_written[FSFAT_BASIC_DATA_SIZE] = { 0 };
|
||||
|
||||
// Fill data_written buffer with random data
|
||||
// Write these data into the file
|
||||
bool write_result = false;
|
||||
{
|
||||
FSFAT_DBGLOG("%s:SD: Writing ... ", __func__);
|
||||
FILE *f = fopen(sd_file_path, "w");
|
||||
if (f) {
|
||||
for (int i = 0; i < FSFAT_BASIC_DATA_SIZE; i++) {
|
||||
data_written[i] = rand() % 0XFF;
|
||||
fprintf(f, "%c", data_written[i]);
|
||||
}
|
||||
write_result = true;
|
||||
fclose(f);
|
||||
}
|
||||
FSFAT_DBGLOG("[%s]\n", write_result ? "OK" : "FAIL");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: unexpected write failure.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(write_result == true, fsfat_basic_msg_g);
|
||||
}
|
||||
|
||||
// Read back the data from the file and store them in data_read
|
||||
bool read_result = false;
|
||||
{
|
||||
FSFAT_DBGLOG("%s:SD: Reading data ... ", __func__);
|
||||
FILE *f = fopen(sd_file_path, "r");
|
||||
if (f) {
|
||||
read_result = true;
|
||||
for (int i = 0; i < FSFAT_BASIC_DATA_SIZE; i++) {
|
||||
uint8_t data = fgetc(f);
|
||||
if (data != data_written[i]) {
|
||||
read_result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
FSFAT_DBGLOG("[%s]\n", read_result ? "OK" : "FAIL");
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: unexpected read failure.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(read_result == true, fsfat_basic_msg_g);
|
||||
}
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
static bool fsfat_basic_test_file_write_fhandle(const char *filename, const int kib_rw)
|
||||
{
|
||||
int ret = -1;
|
||||
File file;
|
||||
|
||||
ret = file.open(&fs, filename, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
int byte_write = 0;
|
||||
fsfat_basic_timer.start();
|
||||
for (int i = 0; i < kib_rw; i++) {
|
||||
ret = file.write(fsfat_basic_buffer, sizeof(fsfat_basic_buffer));
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to write to file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == sizeof(fsfat_basic_buffer), fsfat_basic_msg_g);
|
||||
byte_write++;
|
||||
}
|
||||
fsfat_basic_timer.stop();
|
||||
file.close();
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB write in %.3f sec with speed of %.4f KiB/s\n", byte_write, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool fsfat_basic_test_file_read_fhandle(const char *filename, const int kib_rw)
|
||||
{
|
||||
int ret = -1;
|
||||
File file;
|
||||
ret = file.open(&fs, filename, O_RDONLY);
|
||||
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_basic_msg_g);
|
||||
|
||||
fsfat_basic_timer.start();
|
||||
int byte_read = 0;
|
||||
while (file.read(fsfat_basic_buffer, sizeof(fsfat_basic_buffer)) == sizeof(fsfat_basic_buffer)) {
|
||||
byte_read++;
|
||||
}
|
||||
fsfat_basic_timer.stop();
|
||||
file.close();
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB read in %.3f sec with speed of %.4f KiB/s\n", byte_read, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static char fsfat_basic_test_random_char()
|
||||
{
|
||||
return rand() % 100;
|
||||
}
|
||||
|
||||
|
||||
/** @brief basic sd card performance test
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/sd_perf_handle/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_08()
|
||||
{
|
||||
// Test header
|
||||
FSFAT_DBGLOG("\n%s:SD Card FileHandle Performance Test\n", __func__);
|
||||
FSFAT_DBGLOG("File name: %s\n", fsfat_basic_bin_filename);
|
||||
FSFAT_DBGLOG("Buffer size: %d KiB\n", (FSFAT_BASIC_KIB_RW * sizeof(fsfat_basic_buffer)) / 1024);
|
||||
|
||||
// Initialize buffer
|
||||
srand(0);
|
||||
char *buffer_end = fsfat_basic_buffer + sizeof(fsfat_basic_buffer);
|
||||
std::generate (fsfat_basic_buffer, buffer_end, fsfat_basic_test_random_char);
|
||||
|
||||
bool result = true;
|
||||
for (;;) {
|
||||
FSFAT_DBGLOG("%s:Write test...\n", __func__);
|
||||
if (fsfat_basic_test_file_write_fhandle(fsfat_basic_bin_filename_test_08, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
FSFAT_DBGLOG("%s:Read test...\n", __func__);
|
||||
if (fsfat_basic_test_file_read_fhandle(fsfat_basic_bin_filename_test_08, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(result == true, "something went wrong");
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
bool fsfat_basic_test_sf_file_write_stdio(const char *filename, const int kib_rw)
|
||||
{
|
||||
int ret = -1;
|
||||
FILE* file = fopen(filename, "w");
|
||||
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(file != NULL, fsfat_basic_msg_g);
|
||||
|
||||
int byte_write = 0;
|
||||
fsfat_basic_timer.start();
|
||||
for (int i = 0; i < kib_rw; i++) {
|
||||
ret = fwrite(fsfat_basic_buffer, sizeof(char), sizeof(fsfat_basic_buffer), file);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to write to file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(ret == sizeof(fsfat_basic_buffer), fsfat_basic_msg_g);
|
||||
byte_write++;
|
||||
}
|
||||
fsfat_basic_timer.stop();
|
||||
fclose(file);
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB write in %.3f sec with speed of %.4f KiB/s\n", byte_write, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool fsfat_basic_test_sf_file_read_stdio(const char *filename, const int kib_rw)
|
||||
{
|
||||
FILE* file = fopen(filename, "r");
|
||||
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(file != NULL, fsfat_basic_msg_g);
|
||||
fsfat_basic_timer.start();
|
||||
int byte_read = 0;
|
||||
while (fread(fsfat_basic_buffer, sizeof(char), sizeof(fsfat_basic_buffer), file) == sizeof(fsfat_basic_buffer)) {
|
||||
byte_read++;
|
||||
}
|
||||
fsfat_basic_timer.stop();
|
||||
fclose(file);
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB read in %.3f sec with speed of %.4f KiB/s\n", byte_read, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/** @brief basic test to write a file to sd card.
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/sd_perf_stdio/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_09()
|
||||
{
|
||||
// Test header
|
||||
FSFAT_DBGLOG("\n%s:SD Card Stdio Performance Test\n", __func__);
|
||||
FSFAT_DBGLOG("File name: %s\n", fsfat_basic_bin_filename);
|
||||
FSFAT_DBGLOG("Buffer size: %d KiB\n", (FSFAT_BASIC_KIB_RW * sizeof(fsfat_basic_buffer)) / 1024);
|
||||
|
||||
// Initialize buffer
|
||||
srand(0);
|
||||
char *buffer_end = fsfat_basic_buffer + sizeof(fsfat_basic_buffer);
|
||||
std::generate (fsfat_basic_buffer, buffer_end, fsfat_basic_test_random_char);
|
||||
|
||||
bool result = true;
|
||||
for (;;) {
|
||||
FSFAT_DBGLOG("%s:Write test...\n", __func__);
|
||||
if (fsfat_basic_test_sf_file_write_stdio(fsfat_basic_bin_filename, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
FSFAT_DBGLOG("%s:Read test...\n", __func__);
|
||||
if (fsfat_basic_test_sf_file_read_stdio(fsfat_basic_bin_filename, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(result == true, "Expected true result not found");
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
bool fsfat_basic_test_file_write_fatfs(const char *filename, const int kib_rw)
|
||||
{
|
||||
FIL file;
|
||||
FRESULT res = f_open(&file, filename, FA_WRITE | FA_CREATE_ALWAYS);
|
||||
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(res == FR_OK, fsfat_basic_msg_g);
|
||||
|
||||
int byte_write = 0;
|
||||
unsigned int bytes = 0;
|
||||
fsfat_basic_timer.start();
|
||||
for (int i = 0; i < kib_rw; i++) {
|
||||
res = f_write(&file, fsfat_basic_buffer, sizeof(fsfat_basic_buffer), &bytes);
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to write to file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(res == FR_OK, fsfat_basic_msg_g);
|
||||
byte_write++;
|
||||
}
|
||||
fsfat_basic_timer.stop();
|
||||
f_close(&file);
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB write in %.3f sec with speed of %.4f KiB/s\n", byte_write, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fsfat_basic_test_file_read_fatfs(const char *filename, const int kib_rw)
|
||||
{
|
||||
FIL file;
|
||||
FRESULT res = f_open(&file, filename, FA_READ | FA_OPEN_EXISTING);
|
||||
|
||||
FSFAT_BASIC_MSG(fsfat_basic_msg_g, FSFAT_BASIC_MSG_BUF_SIZE, "%s: Error: failed to open file.\n", __func__);
|
||||
TEST_ASSERT_MESSAGE(res == FR_OK, fsfat_basic_msg_g);
|
||||
|
||||
fsfat_basic_timer.start();
|
||||
int byte_read = 0;
|
||||
unsigned int bytes = 0;
|
||||
do {
|
||||
res = f_read(&file, fsfat_basic_buffer, sizeof(fsfat_basic_buffer), &bytes);
|
||||
byte_read++;
|
||||
} while (res == FR_OK && bytes == sizeof(fsfat_basic_buffer));
|
||||
fsfat_basic_timer.stop();
|
||||
f_close(&file);
|
||||
#ifdef FSFAT_DEBUG
|
||||
double test_time_sec = fsfat_basic_timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
FSFAT_DBGLOG("%d KiB read in %.3f sec with speed of %.4f KiB/s\n", byte_read, test_time_sec, speed);
|
||||
#endif
|
||||
fsfat_basic_timer.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @brief basic test to write a file to sd card.
|
||||
*
|
||||
* This test has been ported from armmbed/mbed-os/features/unsupported/tests/mbed/sd_perf_stdio/main.cpp.
|
||||
*
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
static control_t fsfat_basic_test_10()
|
||||
{
|
||||
// Test header
|
||||
FSFAT_DBGLOG("\n%sSD Card FatFS Performance Test\n", __func__);
|
||||
FSFAT_DBGLOG("File name: %s\n", fsfat_basic_bin_filename_test_10);
|
||||
FSFAT_DBGLOG("Buffer size: %d KiB\n", (FSFAT_BASIC_KIB_RW * sizeof(fsfat_basic_buffer)) / 1024);
|
||||
|
||||
// Initialize buffer
|
||||
srand(1);
|
||||
char *buffer_end = fsfat_basic_buffer + sizeof(fsfat_basic_buffer);
|
||||
std::generate (fsfat_basic_buffer, buffer_end, fsfat_basic_test_random_char);
|
||||
|
||||
bool result = true;
|
||||
for (;;) {
|
||||
FSFAT_DBGLOG("%s:Write test...\n", __func__);
|
||||
if (fsfat_basic_test_file_write_fatfs(fsfat_basic_bin_filename_test_10, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
FSFAT_DBGLOG("%s:Read test...\n", __func__);
|
||||
if (fsfat_basic_test_file_read_fatfs(fsfat_basic_bin_filename_test_10, FSFAT_BASIC_KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(result == true, "Expected true result not found");
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define FSFAT_BASIC_TEST_00 fsfat_basic_test_dummy
|
||||
#define FSFAT_BASIC_TEST_01 fsfat_basic_test_dummy
|
||||
#define FSFAT_BASIC_TEST_02 fsfat_basic_test_dummy
|
||||
#define FSFAT_BASIC_TEST_03 fsfat_basic_test_dummy
|
||||
#define FSFAT_BASIC_TEST_04 fsfat_basic_test_dummy
|
||||
#define FSFAT_BASIC_TEST_05 fsfat_basic_test_dummy
|
||||
#define FSFAT_BASIC_TEST_06 fsfat_basic_test_dummy
|
||||
#define FSFAT_BASIC_TEST_07 fsfat_basic_test_dummy
|
||||
#define FSFAT_BASIC_TEST_08 fsfat_basic_test_dummy
|
||||
#define FSFAT_BASIC_TEST_09 fsfat_basic_test_dummy
|
||||
#define FSFAT_BASIC_TEST_10 fsfat_basic_test_dummy
|
||||
|
||||
|
||||
/** @brief fsfat_basic_test_dummy Dummy test case for testing when platform doesnt have an SDCard installed.
|
||||
*
|
||||
* @return success always
|
||||
*/
|
||||
static control_t fsfat_basic_test_dummy()
|
||||
{
|
||||
printf("Null test\n");
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
utest::v1::status_t greentea_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(300, "default_auto");
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
|
||||
Case cases[] = {
|
||||
/* 1 2 3 4 5 6 7 */
|
||||
/* 1234567890123456789012345678901234567890123456789012345678901234567890 */
|
||||
Case("FSFAT_BASIC_TEST_00: fopen()/fgetc()/fprintf()/fclose() test.", FSFAT_BASIC_TEST_00),
|
||||
Case("FSFAT_BASIC_TEST_01: fopen()/fseek()/fclose() test.", FSFAT_BASIC_TEST_01),
|
||||
/* WARNING: Test case not working but currently not required for PAL support
|
||||
* Case("FSFAT_BASIC_TEST_02: fopen()/fgets()/fputs()/ftell()/rewind()/remove() test.", FSFAT_BASIC_TEST_02) */
|
||||
Case("FSFAT_BASIC_TEST_03: tmpnam() test.", FSFAT_BASIC_TEST_03),
|
||||
Case("FSFAT_BASIC_TEST_04: fileno() test.", FSFAT_BASIC_TEST_04),
|
||||
Case("FSFAT_BASIC_TEST_05: opendir() basic test.", FSFAT_BASIC_TEST_05),
|
||||
Case("FSFAT_BASIC_TEST_06: fread()/fwrite() file to sdcard.", FSFAT_BASIC_TEST_06),
|
||||
Case("FSFAT_BASIC_TEST_07: sdcard fwrite() file test.", FSFAT_BASIC_TEST_07),
|
||||
Case("FSFAT_BASIC_TEST_08: FATFileSystem::read()/write() test.", FSFAT_BASIC_TEST_08),
|
||||
Case("FSFAT_BASIC_TEST_09: POSIX FILE API fread()/fwrite() test.", FSFAT_BASIC_TEST_09),
|
||||
Case("FSFAT_BASIC_TEST_10: ChanFS read()/write()) test.", FSFAT_BASIC_TEST_10),
|
||||
};
|
||||
|
||||
|
||||
/* Declare your test specification with a custom setup handler */
|
||||
Specification specification(greentea_setup, cases);
|
||||
|
||||
int main()
|
||||
{
|
||||
return !Harness::run(specification);
|
||||
}
|
|
@ -1,3 +1,19 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2016 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
|
@ -67,7 +83,8 @@ uint8_t wbuffer[MBED_TEST_BUFFER];
|
|||
|
||||
// tests
|
||||
|
||||
void test_directory_tests() {
|
||||
void test_directory_tests()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -80,7 +97,8 @@ void test_directory_tests() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_root_directory() {
|
||||
void test_root_directory()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -99,7 +117,8 @@ void test_root_directory() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_directory_creation() {
|
||||
void test_directory_creation()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -116,7 +135,8 @@ void test_directory_creation() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_file_creation() {
|
||||
void test_file_creation()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -135,9 +155,10 @@ void test_file_creation() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void dir_file_check(char *list[], uint32_t elements) {
|
||||
void dir_file_check(char *list[], uint32_t elements)
|
||||
{
|
||||
int res;
|
||||
while(1) {
|
||||
while (1) {
|
||||
res = dir[0].read(&ent);
|
||||
if (0 == res) {
|
||||
break;
|
||||
|
@ -150,15 +171,15 @@ void dir_file_check(char *list[], uint32_t elements) {
|
|||
TEST_ASSERT(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if( i == elements) {
|
||||
} else if ( i == elements) {
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_directory_iteration() {
|
||||
void test_directory_iteration()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -168,7 +189,7 @@ void test_directory_iteration() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
char *dir_list[] = {"potato", "burito", ".", ".."};
|
||||
|
||||
dir_file_check(dir_list, (sizeof(dir_list)/sizeof(dir_list[0])));
|
||||
dir_file_check(dir_list, (sizeof(dir_list) / sizeof(dir_list[0])));
|
||||
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -178,7 +199,8 @@ void test_directory_iteration() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_directory_failures() {
|
||||
void test_directory_failures()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -203,7 +225,8 @@ void test_directory_failures() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_nested_directories() {
|
||||
void test_nested_directories()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -226,7 +249,7 @@ void test_nested_directories() {
|
|||
res = dir[0].open(&fs, "/");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
char *dir_list[] = {"potato", "baked", "sweet", "fried", ".", ".."};
|
||||
dir_file_check(dir_list, (sizeof(dir_list)/sizeof(dir_list[0])));
|
||||
dir_file_check(dir_list, (sizeof(dir_list) / sizeof(dir_list[0])));
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fs.unmount();
|
||||
|
@ -237,7 +260,8 @@ void test_nested_directories() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_multi_block_directory() {
|
||||
void test_multi_block_directory()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -247,8 +271,8 @@ void test_multi_block_directory() {
|
|||
res = fs.mkdir("cactus", 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
for (int i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "cactus/test%d", i);
|
||||
res = fs.mkdir((char*)buffer, 0777);
|
||||
sprintf((char *)buffer, "cactus/test%d", i);
|
||||
res = fs.mkdir((char *)buffer, 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
res = fs.unmount();
|
||||
|
@ -263,14 +287,14 @@ void test_multi_block_directory() {
|
|||
|
||||
#if (MBED_TEST_FILESYSTEM != FATFileSystem)
|
||||
char *dir_list[] = {".", ".."};
|
||||
dir_file_check(dir_list, (sizeof(dir_list)/sizeof(dir_list[0])));
|
||||
dir_file_check(dir_list, (sizeof(dir_list) / sizeof(dir_list[0])));
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "test%d", i);
|
||||
sprintf((char *)buffer, "test%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
res = dir[0].read(&ent);
|
||||
|
@ -285,7 +309,8 @@ void test_multi_block_directory() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_directory_remove() {
|
||||
void test_directory_remove()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -305,7 +330,7 @@ void test_directory_remove() {
|
|||
|
||||
#if (MBED_TEST_FILESYSTEM != FATFileSystem)
|
||||
char *dir_list[] = {".", ".."};
|
||||
dir_file_check(dir_list, (sizeof(dir_list)/sizeof(dir_list[0])));
|
||||
dir_file_check(dir_list, (sizeof(dir_list) / sizeof(dir_list[0])));
|
||||
#endif
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
|
@ -324,7 +349,7 @@ void test_directory_remove() {
|
|||
res = dir[0].open(&fs, "/");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
char *dir_list[] = {"burito", "cactus", ".", ".."};
|
||||
dir_file_check(dir_list, (sizeof(dir_list)/sizeof(dir_list[0])));
|
||||
dir_file_check(dir_list, (sizeof(dir_list) / sizeof(dir_list[0])));
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fs.unmount();
|
||||
|
@ -335,7 +360,8 @@ void test_directory_remove() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_directory_rename() {
|
||||
void test_directory_rename()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -369,7 +395,7 @@ void test_directory_rename() {
|
|||
res = dir[0].open(&fs, "hotpotato");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
char *dir_list[] = {"baked", "sweet", "fried", ".", ".."};
|
||||
dir_file_check(dir_list, (sizeof(dir_list)/sizeof(dir_list[0])));
|
||||
dir_file_check(dir_list, (sizeof(dir_list) / sizeof(dir_list[0])));
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fs.unmount();
|
||||
|
@ -401,7 +427,7 @@ void test_directory_rename() {
|
|||
res = dir[0].open(&fs, "warmpotato");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
char *dir_list[] = {"baked", "sweet", "fried", ".", ".."};
|
||||
dir_file_check(dir_list, (sizeof(dir_list)/sizeof(dir_list[0])));
|
||||
dir_file_check(dir_list, (sizeof(dir_list) / sizeof(dir_list[0])));
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fs.unmount();
|
||||
|
@ -433,7 +459,7 @@ void test_directory_rename() {
|
|||
res = dir[0].open(&fs, "coldpotato");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
char *dir_list[] = {"baked", "sweet", "fried", ".", ".."};
|
||||
dir_file_check(dir_list, (sizeof(dir_list)/sizeof(dir_list[0])));
|
||||
dir_file_check(dir_list, (sizeof(dir_list) / sizeof(dir_list[0])));
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fs.unmount();
|
||||
|
@ -447,7 +473,8 @@ void test_directory_rename() {
|
|||
|
||||
|
||||
// test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(MBED_TEST_TIMEOUT, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
@ -467,6 +494,7 @@ Case cases[] = {
|
|||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return !Harness::run(specification);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2016 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
|
@ -66,11 +82,13 @@ uint8_t wbuffer[MBED_TEST_BUFFER];
|
|||
|
||||
static char file_counter = 0;
|
||||
const char *filenames[] = {"smallavacado", "mediumavacado", "largeavacado",
|
||||
"blockfile", "bigblockfile", "hello", ".", ".."};
|
||||
"blockfile", "bigblockfile", "hello", ".", ".."
|
||||
};
|
||||
|
||||
// tests
|
||||
|
||||
void test_file_tests() {
|
||||
void test_file_tests()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -83,7 +101,8 @@ void test_file_tests() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_simple_file_test() {
|
||||
void test_simple_file_test()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -116,7 +135,8 @@ void test_simple_file_test() {
|
|||
}
|
||||
|
||||
template <int file_size, int write_size, int read_size>
|
||||
void test_write_file_test() {
|
||||
void test_write_file_test()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -154,7 +174,7 @@ void test_write_file_test() {
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -170,7 +190,8 @@ void test_write_file_test() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_non_overlap_check() {
|
||||
void test_non_overlap_check()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -186,7 +207,7 @@ void test_non_overlap_check() {
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -209,7 +230,7 @@ void test_non_overlap_check() {
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -232,7 +253,7 @@ void test_non_overlap_check() {
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -247,7 +268,8 @@ void test_non_overlap_check() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_dir_check() {
|
||||
void test_dir_check()
|
||||
{
|
||||
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -257,14 +279,14 @@ void test_dir_check() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].open(&fs, "/");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
int numFiles = sizeof(filenames)/sizeof(filenames[0]);
|
||||
int numFiles = sizeof(filenames) / sizeof(filenames[0]);
|
||||
// Check the filenames in directory
|
||||
while(1) {
|
||||
while (1) {
|
||||
res = dir[0].read(&ent);
|
||||
if (0 == res) {
|
||||
break;
|
||||
}
|
||||
for (int i=0; i < numFiles ; i++) {
|
||||
for (int i = 0; i < numFiles ; i++) {
|
||||
res = strcmp(ent.d_name, filenames[i]);
|
||||
if (0 == res) {
|
||||
res = ent.d_type;
|
||||
|
@ -272,8 +294,7 @@ void test_dir_check() {
|
|||
TEST_ASSERT(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if( i == numFiles) {
|
||||
} else if ( i == numFiles) {
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +311,8 @@ void test_dir_check() {
|
|||
|
||||
|
||||
// test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(MBED_TEST_TIMEOUT, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
@ -309,6 +331,7 @@ Case cases[] = {
|
|||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return !Harness::run(specification);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,19 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2016 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
|
@ -67,7 +83,8 @@ volatile bool count_done = 0;
|
|||
|
||||
// tests
|
||||
|
||||
void test_file_tests() {
|
||||
void test_file_tests()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -80,7 +97,8 @@ void test_file_tests() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void write_file_data (char count) {
|
||||
void write_file_data (char count)
|
||||
{
|
||||
|
||||
char filename[10];
|
||||
uint8_t wbuffer[MBED_TEST_BUFFER];
|
||||
|
@ -89,15 +107,15 @@ void write_file_data (char count) {
|
|||
sprintf(filename, "%s%d", "data", count);
|
||||
res = file[count].open(&fs, filename, O_WRONLY | O_CREAT);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
char letter = 'A'+ count;
|
||||
|
||||
char letter = 'A' + count;
|
||||
for (uint32_t i = 0; i < MBED_TEST_BUFFER; i++) {
|
||||
wbuffer[i] = letter++;
|
||||
if ('z' == letter) {
|
||||
letter = 'A' + count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (uint32_t i = 0; i < 5; i++) {
|
||||
res = file[count].write(wbuffer, MBED_TEST_BUFFER);
|
||||
TEST_ASSERT_EQUAL(MBED_TEST_BUFFER, res);
|
||||
|
@ -107,7 +125,8 @@ void write_file_data (char count) {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void read_file_data (char count) {
|
||||
void read_file_data (char count)
|
||||
{
|
||||
char filename[10];
|
||||
uint8_t rbuffer[MBED_TEST_BUFFER];
|
||||
int res;
|
||||
|
@ -133,28 +152,29 @@ void read_file_data (char count) {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_thread_access_test() {
|
||||
|
||||
Thread *data[MBED_THREAD_COUNT];
|
||||
void test_thread_access_test()
|
||||
{
|
||||
|
||||
Thread *data[MBED_THREAD_COUNT];
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fs.mount(&bd);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
// Write threads in parallel
|
||||
for (char thread_count = 0; thread_count < MBED_THREAD_COUNT; thread_count++) {
|
||||
data[thread_count] = new Thread(osPriorityNormal);
|
||||
data[thread_count]->start(callback((void(*)(void*))write_file_data, (void*)thread_count));
|
||||
data[thread_count]->start(callback((void(*)(void *))write_file_data, (void *)thread_count));
|
||||
}
|
||||
|
||||
|
||||
// Wait for write thread to join before creating read thread
|
||||
for (char thread_count = 0; thread_count < MBED_THREAD_COUNT; thread_count++) {
|
||||
data[thread_count]->join();
|
||||
delete data[thread_count];
|
||||
data[thread_count] = new Thread(osPriorityNormal);
|
||||
data[thread_count]->start(callback((void(*)(void*))read_file_data, (void*)thread_count));
|
||||
data[thread_count]->start(callback((void(*)(void *))read_file_data, (void *)thread_count));
|
||||
}
|
||||
|
||||
|
||||
// Wait for read threads to join
|
||||
for (char thread_count = 0; thread_count < MBED_THREAD_COUNT; thread_count++) {
|
||||
data[thread_count]->join();
|
||||
|
@ -167,7 +187,8 @@ void test_thread_access_test() {
|
|||
}
|
||||
|
||||
// test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(MBED_TEST_TIMEOUT, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
@ -179,6 +200,7 @@ Case cases[] = {
|
|||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return !Harness::run(specification);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2016 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
|
@ -67,7 +83,8 @@ uint8_t wbuffer[MBED_TEST_BUFFER];
|
|||
|
||||
// tests
|
||||
|
||||
void test_seek_tests() {
|
||||
void test_seek_tests()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -79,11 +96,11 @@ void test_seek_tests() {
|
|||
res = fs.mkdir("hello", 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
for (int i = 0; i < 132; i++) {
|
||||
sprintf((char*)buffer, "hello/kitty%d", i);
|
||||
res = file[0].open(&fs, (char*)buffer,
|
||||
O_WRONLY | O_CREAT | O_APPEND);
|
||||
sprintf((char *)buffer, "hello/kitty%d", i);
|
||||
res = file[0].open(&fs, (char *)buffer,
|
||||
O_WRONLY | O_CREAT | O_APPEND);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size = strlen("kittycatcat");
|
||||
memcpy(buffer, "kittycatcat", size);
|
||||
for (int j = 0; j < 132; j++) {
|
||||
|
@ -100,7 +117,8 @@ void test_seek_tests() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_simple_dir_seek() {
|
||||
void test_simple_dir_seek()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -123,25 +141,25 @@ void test_simple_dir_seek() {
|
|||
off_t pos;
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
pos = dir[0].tell();
|
||||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
dir[0].rewind();
|
||||
sprintf((char*)buffer, "kitty%d", 0);
|
||||
sprintf((char *)buffer, "kitty%d", 0);
|
||||
#if (MBED_TEST_FILESYSTEM != FATFileSystem)
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
@ -154,14 +172,14 @@ void test_simple_dir_seek() {
|
|||
#endif
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -173,7 +191,8 @@ void test_simple_dir_seek() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_large_dir_seek() {
|
||||
void test_large_dir_seek()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -196,25 +215,25 @@ void test_large_dir_seek() {
|
|||
off_t pos;
|
||||
int i;
|
||||
for (i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
pos = dir[0].tell();
|
||||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
dir[0].rewind();
|
||||
sprintf((char*)buffer, "kitty%d", 0);
|
||||
sprintf((char *)buffer, "kitty%d", 0);
|
||||
#if (MBED_TEST_FILESYSTEM != FATFileSystem)
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
@ -227,14 +246,14 @@ void test_large_dir_seek() {
|
|||
#endif
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -246,7 +265,8 @@ void test_large_dir_seek() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_simple_file_seek() {
|
||||
void test_simple_file_seek()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -255,7 +275,7 @@ void test_simple_file_seek() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDONLY);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -273,7 +293,7 @@ void test_simple_file_seek() {
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
file[0].rewind();
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -297,7 +317,7 @@ void test_simple_file_seek() {
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size_t size = file[0].size();
|
||||
res = file[0].seek(0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -311,7 +331,8 @@ void test_simple_file_seek() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_large_file_seek() {
|
||||
void test_large_file_seek()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -320,7 +341,7 @@ void test_large_file_seek() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDONLY);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 128; i++) {
|
||||
|
@ -338,7 +359,7 @@ void test_large_file_seek() {
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
file[0].rewind();
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -362,7 +383,7 @@ void test_large_file_seek() {
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size_t size = file[0].size();
|
||||
res = file[0].seek(0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -376,7 +397,8 @@ void test_large_file_seek() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_simple_file_seek_and_write() {
|
||||
void test_simple_file_seek_and_write()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -385,7 +407,7 @@ void test_simple_file_seek_and_write() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDWR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -397,7 +419,7 @@ void test_simple_file_seek_and_write() {
|
|||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
memcpy(buffer, "doggodogdog", size);
|
||||
res = file[0].seek(pos, SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(pos, res);
|
||||
|
@ -409,7 +431,7 @@ void test_simple_file_seek_and_write() {
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "doggodogdog", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
file[0].rewind();
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -427,7 +449,7 @@ void test_simple_file_seek_and_write() {
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size_t size = file[0].size();
|
||||
res = file[0].seek(0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -441,7 +463,8 @@ void test_simple_file_seek_and_write() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_large_file_seek_and_write() {
|
||||
void test_large_file_seek_and_write()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -450,7 +473,7 @@ void test_large_file_seek_and_write() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDWR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 128; i++) {
|
||||
|
@ -464,7 +487,7 @@ void test_large_file_seek_and_write() {
|
|||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
memcpy(buffer, "doggodogdog", size);
|
||||
res = file[0].seek(pos, SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(pos, res);
|
||||
|
@ -476,7 +499,7 @@ void test_large_file_seek_and_write() {
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "doggodogdog", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
file[0].rewind();
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -494,7 +517,7 @@ void test_large_file_seek_and_write() {
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size_t size = file[0].size();
|
||||
res = file[0].seek(0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -508,7 +531,8 @@ void test_large_file_seek_and_write() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_boundary_seek_and_write() {
|
||||
void test_boundary_seek_and_write()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -517,10 +541,10 @@ void test_boundary_seek_and_write() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDWR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size = strlen("hedgehoghog");
|
||||
const off_t offsets[] = {512, 1020, 513, 1021, 511, 1019};
|
||||
|
||||
|
||||
for (int i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
|
||||
off_t off = offsets[i];
|
||||
memcpy(buffer, "hedgehoghog", size);
|
||||
|
@ -553,7 +577,8 @@ void test_boundary_seek_and_write() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
||||
void test_out_of_bounds_seek() {
|
||||
void test_out_of_bounds_seek()
|
||||
{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
@ -562,29 +587,29 @@ void test_out_of_bounds_seek() {
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDWR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size = strlen("kittycatcat");
|
||||
res = file[0].size();
|
||||
TEST_ASSERT_EQUAL(132*size, res);
|
||||
res = file[0].seek((132+4)*size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL((132+4)*size, res);
|
||||
TEST_ASSERT_EQUAL(132 * size, res);
|
||||
res = file[0].seek((132 + 4) * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL((132 + 4)*size, res);
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
memcpy(buffer, "porcupineee", size);
|
||||
res = file[0].write(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = file[0].seek((132+4)*size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL((132+4)*size, res);
|
||||
res = file[0].seek((132 + 4) * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL((132 + 4)*size, res);
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "porcupineee", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].seek(132*size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(132*size, res);
|
||||
res = file[0].seek(132 * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(132 * size, res);
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
#if (MBED_TEST_FILESYSTEM != FATFileSystem)
|
||||
|
@ -605,7 +630,8 @@ void test_out_of_bounds_seek() {
|
|||
|
||||
|
||||
// test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(MBED_TEST_TIMEOUT, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
@ -624,6 +650,7 @@ Case cases[] = {
|
|||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
return !Harness::run(specification);
|
||||
}
|
||||
|
|
|
@ -209,6 +209,12 @@
|
|||
"SPI_MISO": "D12",
|
||||
"SPI_CLK": "D13",
|
||||
"SPI_CS": "D9"
|
||||
},
|
||||
"NUCLEO_F207ZG": {
|
||||
"SPI_MOSI": "PC_12",
|
||||
"SPI_MISO": "PC_11",
|
||||
"SPI_CLK": "PC_10",
|
||||
"SPI_CS": "PA_15"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 502 KiB |
|
@ -1,3 +1,19 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2016 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/** @file fsfat_debug.h
|
||||
*
|
||||
* component debug header file.
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
script:
|
||||
# Check that examples compile
|
||||
- sed -n '/``` cpp/,${/```$/q;/```/d;p}' README.md > main.cpp &&
|
||||
PYTHONPATH=mbed-os python mbed-os/tools/make.py -t GCC_ARM -m K82F
|
||||
--source=. --build=BUILD/K82F/GCC_ARM -j0 &&
|
||||
rm main.cpp
|
||||
- sed -n '/@code/,${/@endcode/q;/@/d;s/^ \*//;p}' SPIFBlockDevice.h > main.cpp &&
|
||||
PYTHONPATH=mbed-os python mbed-os/tools/make.py -t GCC_ARM -m K82F
|
||||
--source=. --build=BUILD/K82F/GCC_ARM -j0 &&
|
||||
rm main.cpp
|
||||
|
||||
# Check that tests compile
|
||||
- rm -r BUILD && PYTHONPATH=mbed-os python mbed-os/tools/test.py
|
||||
-t GCC_ARM -m K82F --source=. --build=BUILD/TESTS/K82F/GCC_ARM -j0
|
||||
-n tests*
|
||||
|
||||
python:
|
||||
- "2.7"
|
||||
|
||||
install:
|
||||
# Get arm-none-eabi-gcc
|
||||
- sudo add-apt-repository -y ppa:terry.guo/gcc-arm-embedded
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq gcc-arm-none-eabi --force-yes
|
||||
# Get dependencies
|
||||
- git clone https://github.com/armmbed/mbed-os.git
|
||||
# Install python dependencies
|
||||
- sudo pip install -r mbed-os/requirements.txt
|
|
@ -1,165 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and
|
||||
distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||
owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
||||
that control, are controlled by, or are under common control with that entity.
|
||||
For the purposes of this definition, "control" means (i) the power, direct or
|
||||
indirect, to cause the direction or management of such entity, whether by
|
||||
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
||||
permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including
|
||||
but not limited to software source code, documentation source, and configuration
|
||||
files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or
|
||||
translation of a Source form, including but not limited to compiled object code,
|
||||
generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
||||
available under the License, as indicated by a copyright notice that is included
|
||||
in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
||||
is based on (or derived from) the Work and for which the editorial revisions,
|
||||
annotations, elaborations, or other modifications represent, as a whole, an
|
||||
original work of authorship. For the purposes of this License, Derivative Works
|
||||
shall not include works that remain separable from, or merely link (or bind by
|
||||
name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version
|
||||
of the Work and any modifications or additions to that Work or Derivative Works
|
||||
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
||||
by the copyright owner or by an individual or Legal Entity authorized to submit
|
||||
on behalf of the copyright owner. For the purposes of this definition,
|
||||
"submitted" means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems, and
|
||||
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
||||
the purpose of discussing and improving the Work, but excluding communication
|
||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||
owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||
of whom a Contribution has been received by Licensor and subsequently
|
||||
incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the Work and such
|
||||
Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable (except as stated in this section) patent license to make, have
|
||||
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
||||
such license applies only to those patent claims licensable by such Contributor
|
||||
that are necessarily infringed by their Contribution(s) alone or by combination
|
||||
of their Contribution(s) with the Work to which such Contribution(s) was
|
||||
submitted. If You institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
||||
Contribution incorporated within the Work constitutes direct or contributory
|
||||
patent infringement, then any patent licenses granted to You under this License
|
||||
for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution.
|
||||
|
||||
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
||||
in any medium, with or without modifications, and in Source or Object form,
|
||||
provided that You meet the following conditions:
|
||||
|
||||
You must give any other recipients of the Work or Derivative Works a copy of
|
||||
this License; and
|
||||
You must cause any modified files to carry prominent notices stating that You
|
||||
changed the files; and
|
||||
You must retain, in the Source form of any Derivative Works that You distribute,
|
||||
all copyright, patent, trademark, and attribution notices from the Source form
|
||||
of the Work, excluding those notices that do not pertain to any part of the
|
||||
Derivative Works; and
|
||||
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
||||
Derivative Works that You distribute must include a readable copy of the
|
||||
attribution notices contained within such NOTICE file, excluding those notices
|
||||
that do not pertain to any part of the Derivative Works, in at least one of the
|
||||
following places: within a NOTICE text file distributed as part of the
|
||||
Derivative Works; within the Source form or documentation, if provided along
|
||||
with the Derivative Works; or, within a display generated by the Derivative
|
||||
Works, if and wherever such third-party notices normally appear. The contents of
|
||||
the NOTICE file are for informational purposes only and do not modify the
|
||||
License. You may add Your own attribution notices within Derivative Works that
|
||||
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
||||
provided that such additional attribution notices cannot be construed as
|
||||
modifying the License.
|
||||
You may add Your own copyright statement to Your modifications and may provide
|
||||
additional or different license terms and conditions for use, reproduction, or
|
||||
distribution of Your modifications, or for any such Derivative Works as a whole,
|
||||
provided Your use, reproduction, and distribution of the Work otherwise complies
|
||||
with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions.
|
||||
|
||||
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
||||
for inclusion in the Work by You to the Licensor shall be under the terms and
|
||||
conditions of this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
||||
any separate license agreement you may have executed with Licensor regarding
|
||||
such Contributions.
|
||||
|
||||
6. Trademarks.
|
||||
|
||||
This License does not grant permission to use the trade names, trademarks,
|
||||
service marks, or product names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, Licensor provides the
|
||||
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
||||
including, without limitation, any warranties or conditions of TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
||||
solely responsible for determining the appropriateness of using or
|
||||
redistributing the Work and assume any risks associated with Your exercise of
|
||||
permissions under this License.
|
||||
|
||||
8. Limitation of Liability.
|
||||
|
||||
In no event and under no legal theory, whether in tort (including negligence),
|
||||
contract, or otherwise, unless required by applicable law (such as deliberate
|
||||
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special, incidental,
|
||||
or consequential damages of any character arising as a result of this License or
|
||||
out of the use or inability to use the Work (including but not limited to
|
||||
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
||||
any and all other commercial damages or losses), even if such Contributor has
|
||||
been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability.
|
||||
|
||||
While redistributing the Work or Derivative Works thereof, You may choose to
|
||||
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
||||
other liability obligations and/or rights consistent with this License. However,
|
||||
in accepting such obligations, You may act only on Your own behalf and on Your
|
||||
sole responsibility, not on behalf of any other Contributor, and only if You
|
||||
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason of your
|
||||
accepting any such warranty or additional liability.
|
|
@ -1,42 +0,0 @@
|
|||
# SPI Flash Driver
|
||||
|
||||
Block device driver for NOR based SPI flash devices that support SFDP.
|
||||
|
||||
NOR based SPI flash supports byte-sized read and writes, with an erase size of around 4kbytes. An erase sets a block to all 1s, with successive writes clearing set bits.
|
||||
|
||||
More info on NOR flash can be found on wikipedia:
|
||||
https://en.wikipedia.org/wiki/Flash_memory#NOR_memories
|
||||
|
||||
``` cpp
|
||||
// Here's an example using the MX25R SPI flash device on the K82F
|
||||
#include "mbed.h"
|
||||
#include "SPIFBlockDevice.h"
|
||||
|
||||
// Create flash device on SPI bus with PTE5 as chip select
|
||||
SPIFBlockDevice spif(PTE2, PTE4, PTE1, PTE5);
|
||||
|
||||
int main() {
|
||||
printf("spif test\n");
|
||||
|
||||
// Initialize the SPI flash device and print the memory layout
|
||||
spif.init();
|
||||
printf("spif size: %llu\n", spif.size());
|
||||
printf("spif read size: %llu\n", spif.get_read_size());
|
||||
printf("spif program size: %llu\n", spif.get_program_size());
|
||||
printf("spif erase size: %llu\n", spif.get_erase_size());
|
||||
|
||||
// Write "Hello World!" to the first block
|
||||
char *buffer = (char*)malloc(spif.get_erase_size());
|
||||
sprintf(buffer, "Hello World!\n");
|
||||
spif.erase(0, spif.get_erase_size());
|
||||
spif.program(buffer, 0, spif.get_erase_size());
|
||||
|
||||
// Read back what was stored
|
||||
spif.read(buffer, 0, spif.get_erase_size());
|
||||
printf("%s", buffer);
|
||||
|
||||
// Deinitialize the device
|
||||
spif.deinit();
|
||||
}
|
||||
```
|
||||
|
|
@ -333,17 +333,18 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
|||
}
|
||||
|
||||
int type = 0;
|
||||
uint32_t offset = 0;
|
||||
uint32_t chunk = 4096;
|
||||
int cur_erase_inst = _erase_instruction;
|
||||
int size = (int)in_size;
|
||||
bool erase_failed = false;
|
||||
int status = SPIF_BD_ERROR_OK;
|
||||
// Find region of erased address
|
||||
// Find region of erased address
|
||||
int region = _utils_find_addr_region(addr);
|
||||
// Erase Types of selected region
|
||||
uint8_t bitfield = _region_erase_types_bitfield[region];
|
||||
|
||||
tr_debug("DEBUG: erase - addr: %llu, in_size: %llu", addr, in_size);
|
||||
tr_error("DEBUG: erase - addr: %llu, in_size: %llu", addr, in_size);
|
||||
|
||||
// For each iteration erase the largest section supported by current region
|
||||
while (size > 0) {
|
||||
|
@ -352,11 +353,13 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
|
|||
// find the matching instruction and erase size chunk for that type.
|
||||
type = _utils_iterate_next_largest_erase_type(bitfield, size, (unsigned int)addr, _region_high_boundary[region]);
|
||||
cur_erase_inst = _erase_type_inst_arr[type];
|
||||
chunk = _erase_type_size_arr[type];
|
||||
//chunk = _erase_type_size_arr[type];
|
||||
offset = addr % _erase_type_size_arr[type];
|
||||
chunk = ( (offset + size) < _erase_type_size_arr[type]) ? size : (_erase_type_size_arr[type] - offset);
|
||||
|
||||
tr_debug("DEBUG: erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %lu , ",
|
||||
tr_error("DEBUG: erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %lu , ",
|
||||
addr, size, cur_erase_inst, chunk);
|
||||
tr_debug("DEBUG: erase - Region: %d, Type:%d",
|
||||
tr_error("DEBUG: erase - Region: %d, Type:%d",
|
||||
region, type);
|
||||
|
||||
_mutex->lock();
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
/** Enum spif standard error codes
|
||||
*
|
||||
* @enum qpif_bd_error
|
||||
* @enum spif_bd_error
|
||||
*/
|
||||
enum spif_bd_error {
|
||||
SPIF_BD_ERROR_OK = 0, /*!< no error */
|
||||
|
|
|
@ -164,7 +164,7 @@ void test_spif_unaligned_program()
|
|||
}
|
||||
|
||||
{
|
||||
bd_addr_t block = (rand() * block_size) % blockD.size() + 15;
|
||||
bd_addr_t block = (rand() * block_size) % blockD.size() + 1;
|
||||
|
||||
// Use next random number as temporary seed to keep
|
||||
// the address progressing in the pseudorandom sequence
|
||||
|
@ -182,6 +182,9 @@ void test_spif_unaligned_program()
|
|||
err = blockD.erase(block, block_size);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
//err = blockD.erase(block+4096, block_size);
|
||||
//TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
err = blockD.program(write_block, block, block_size);
|
||||
TEST_ASSERT_EQUAL(0, err);
|
||||
|
||||
|
@ -191,6 +194,7 @@ void test_spif_unaligned_program()
|
|||
// Check that the data was unmodified
|
||||
srand(seed);
|
||||
for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) {
|
||||
//printf("index %d\n", i_ind);
|
||||
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i_ind]);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -43,6 +43,19 @@ typedef uint64_t bd_size_t;
|
|||
class BlockDevice
|
||||
{
|
||||
public:
|
||||
|
||||
/** Return the default block device
|
||||
*
|
||||
* Returns the default BlockDevice base on configuration json.
|
||||
* Use the components in target.json or application config to change
|
||||
* the default block device.
|
||||
*
|
||||
* An application can override all target settings by implementing
|
||||
* BlockDevice::get_default_instance() themselves - the default
|
||||
* definition is weak, and calls get_target_default_instance().
|
||||
*/
|
||||
static BlockDevice *get_default_instance();
|
||||
|
||||
/** Lifetime of a block device
|
||||
*/
|
||||
virtual ~BlockDevice() {};
|
|
@ -48,6 +48,7 @@ class File;
|
|||
*/
|
||||
class FileSystem : public FileSystemLike {
|
||||
public:
|
||||
|
||||
/** FileSystem lifetime
|
||||
*
|
||||
* @param name Name to add filesystem to tree as
|
||||
|
@ -55,6 +56,21 @@ public:
|
|||
FileSystem(const char *name = NULL);
|
||||
virtual ~FileSystem() {}
|
||||
|
||||
/** Return the default filesystem
|
||||
*
|
||||
* Returns the default FileSystem base on the default BlockDevice configuration.
|
||||
* Use the components in target.json or application config to change
|
||||
* the default block device and affect the default filesystem.
|
||||
* SD block device => FAT filesystem
|
||||
* SPIF block device => LITTLE filesystem
|
||||
* DATAFLASH block device => LITTLE filesystem
|
||||
*
|
||||
* An application can override all target settings by implementing
|
||||
* FileSystem::get_default_instance() themselves - the default
|
||||
* definition is weak, and calls get_target_default_instance().
|
||||
*/
|
||||
static FileSystem *get_default_instance();
|
||||
|
||||
/** Mounts a filesystem to a block device
|
||||
*
|
||||
* @param bd BlockDevice to mount to
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue