mirror of https://github.com/ARMmbed/mbed-os.git
Fixed PR review remarks
parent
b71db496ba
commit
df36f0e757
|
@ -28,7 +28,7 @@ enum spif_bd_error {
|
||||||
SPIF_BD_ERROR_OK = 0, /*!< no error */
|
SPIF_BD_ERROR_OK = 0, /*!< no error */
|
||||||
SPIF_BD_ERROR_DEVICE_ERROR = BD_ERROR_DEVICE_ERROR, /*!< device specific error -4001 */
|
SPIF_BD_ERROR_DEVICE_ERROR = BD_ERROR_DEVICE_ERROR, /*!< device specific error -4001 */
|
||||||
SPIF_BD_ERROR_PARSING_FAILED = -4002, /* SFDP Parsing failed */
|
SPIF_BD_ERROR_PARSING_FAILED = -4002, /* SFDP Parsing failed */
|
||||||
SPIF_BD_ERROR_READY_FAILED = -4003, /* Wait for Mem Ready failed */
|
SPIF_BD_ERROR_READY_FAILED = -4003, /* Wait for Mem Ready failed */
|
||||||
SPIF_BD_ERROR_WREN_FAILED = -4004, /* Write Enable Failed */
|
SPIF_BD_ERROR_WREN_FAILED = -4004, /* Write Enable Failed */
|
||||||
SPIF_BD_ERROR_INVALID_ERASE_PARAMS = -4005, /* Erase command not on sector aligned addresses or exceeds device size */
|
SPIF_BD_ERROR_INVALID_ERASE_PARAMS = -4005, /* Erase command not on sector aligned addresses or exceeds device size */
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,13 +41,13 @@ static SingletonPtr<PlatformMutex> _mutex;
|
||||||
// Mutex is protecting rand() per srand for buffer writing and verification.
|
// Mutex is protecting rand() per srand for buffer writing and verification.
|
||||||
// Mutex is also protecting printouts for clear logs.
|
// Mutex is also protecting printouts for clear logs.
|
||||||
// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test!
|
// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test!
|
||||||
void basic_erase_program_read_test(SPIFBlockDevice& blockD, bd_size_t block_size, uint8_t *write_block,
|
void basic_erase_program_read_test(SPIFBlockDevice& block_device, bd_size_t block_size, uint8_t *write_block,
|
||||||
uint8_t *read_block, unsigned addrwidth)
|
uint8_t *read_block, unsigned addrwidth)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
_mutex->lock();
|
_mutex->lock();
|
||||||
// Find a random block
|
// Find a random block
|
||||||
bd_addr_t block = (rand() * block_size) % blockD.size();
|
bd_addr_t block = (rand() * block_size) % block_device.size();
|
||||||
|
|
||||||
// Use next random number as temporary seed to keep
|
// Use next random number as temporary seed to keep
|
||||||
// the address progressing in the pseudorandom sequence
|
// the address progressing in the pseudorandom sequence
|
||||||
|
@ -62,13 +62,13 @@ void basic_erase_program_read_test(SPIFBlockDevice& blockD, bd_size_t block_size
|
||||||
utest_printf("\ntest %0*llx:%llu...", addrwidth, block, block_size);
|
utest_printf("\ntest %0*llx:%llu...", addrwidth, block, block_size);
|
||||||
_mutex->unlock();
|
_mutex->unlock();
|
||||||
|
|
||||||
err = blockD.erase(block, block_size);
|
err = block_device.erase(block, block_size);
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
err = blockD.program(write_block, block, block_size);
|
err = block_device.program(write_block, block, block_size);
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
err = blockD.read(read_block, block, block_size);
|
err = block_device.read(read_block, block, block_size);
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
_mutex->lock();
|
_mutex->lock();
|
||||||
|
@ -91,16 +91,17 @@ void test_spif_random_program_read_erase()
|
||||||
{
|
{
|
||||||
utest_printf("\nTest Random Program Read Erase Starts..\n");
|
utest_printf("\nTest Random Program Read Erase Starts..\n");
|
||||||
|
|
||||||
SPIFBlockDevice blockD(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO, MBED_CONF_SPIF_DRIVER_SPI_CLK,
|
SPIFBlockDevice block_device(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO,
|
||||||
MBED_CONF_SPIF_DRIVER_SPI_CS);
|
MBED_CONF_SPIF_DRIVER_SPI_CLK,
|
||||||
|
MBED_CONF_SPIF_DRIVER_SPI_CS);
|
||||||
|
|
||||||
int err = blockD.init();
|
int err = block_device.init();
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) {
|
for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) {
|
||||||
static const char *prefixes[] = {"", "k", "M", "G"};
|
static const char *prefixes[] = {"", "k", "M", "G"};
|
||||||
for (int i_ind = 3; i_ind >= 0; i_ind--) {
|
for (int i_ind = 3; i_ind >= 0; i_ind--) {
|
||||||
bd_size_t size = (blockD.*ATTRS[atr].method)();
|
bd_size_t size = (block_device.*ATTRS[atr].method)();
|
||||||
if (size >= (1ULL << 10 * i_ind)) {
|
if (size >= (1ULL << 10 * i_ind)) {
|
||||||
utest_printf("%s: %llu%sbytes (%llubytes)\n",
|
utest_printf("%s: %llu%sbytes (%llubytes)\n",
|
||||||
ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size);
|
ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size);
|
||||||
|
@ -109,8 +110,8 @@ void test_spif_random_program_read_erase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bd_size_t block_size = blockD.get_erase_size();
|
bd_size_t block_size = block_device.get_erase_size();
|
||||||
unsigned addrwidth = ceil(log(float(blockD.size() - 1)) / log(float(16))) + 1;
|
unsigned addrwidth = ceil(log(float(block_device.size() - 1)) / log(float(16))) + 1;
|
||||||
|
|
||||||
uint8_t *write_block = new (std::nothrow) uint8_t[block_size];
|
uint8_t *write_block = new (std::nothrow) uint8_t[block_size];
|
||||||
uint8_t *read_block = new (std::nothrow) uint8_t[block_size];
|
uint8_t *read_block = new (std::nothrow) uint8_t[block_size];
|
||||||
|
@ -120,10 +121,10 @@ void test_spif_random_program_read_erase()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
|
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
|
||||||
basic_erase_program_read_test(blockD, block_size, write_block, read_block, addrwidth);
|
basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = blockD.deinit();
|
err = block_device.deinit();
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
@ -135,16 +136,17 @@ void test_spif_unaligned_erase()
|
||||||
{
|
{
|
||||||
utest_printf("\nTest Unaligned Erase Starts..\n");
|
utest_printf("\nTest Unaligned Erase Starts..\n");
|
||||||
|
|
||||||
SPIFBlockDevice blockD(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO, MBED_CONF_SPIF_DRIVER_SPI_CLK,
|
SPIFBlockDevice block_device(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO,
|
||||||
MBED_CONF_SPIF_DRIVER_SPI_CS);
|
MBED_CONF_SPIF_DRIVER_SPI_CLK,
|
||||||
|
MBED_CONF_SPIF_DRIVER_SPI_CS);
|
||||||
|
|
||||||
int err = blockD.init();
|
int err = block_device.init();
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) {
|
for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) {
|
||||||
static const char *prefixes[] = {"", "k", "M", "G"};
|
static const char *prefixes[] = {"", "k", "M", "G"};
|
||||||
for (int i_ind = 3; i_ind >= 0; i_ind--) {
|
for (int i_ind = 3; i_ind >= 0; i_ind--) {
|
||||||
bd_size_t size = (blockD.*ATTRS[atr].method)();
|
bd_size_t size = (block_device.*ATTRS[atr].method)();
|
||||||
if (size >= (1ULL << 10 * i_ind)) {
|
if (size >= (1ULL << 10 * i_ind)) {
|
||||||
utest_printf("%s: %llu%sbytes (%llubytes)\n",
|
utest_printf("%s: %llu%sbytes (%llubytes)\n",
|
||||||
ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size);
|
ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size);
|
||||||
|
@ -154,52 +156,52 @@ void test_spif_unaligned_erase()
|
||||||
}
|
}
|
||||||
|
|
||||||
bd_addr_t addr = 0;
|
bd_addr_t addr = 0;
|
||||||
bd_size_t sector_erase_size = blockD.get_erase_size(addr);
|
bd_size_t sector_erase_size = block_device.get_erase_size(addr);
|
||||||
unsigned addrwidth = ceil(log(float(blockD.size() - 1)) / log(float(16))) + 1;
|
unsigned addrwidth = ceil(log(float(block_device.size() - 1)) / log(float(16))) + 1;
|
||||||
|
|
||||||
utest_printf("\ntest %0*llx:%llu...", addrwidth, addr, sector_erase_size);
|
utest_printf("\ntest %0*llx:%llu...", addrwidth, addr, sector_erase_size);
|
||||||
|
|
||||||
//unaligned start address
|
//unaligned start address
|
||||||
addr += 1;
|
addr += 1;
|
||||||
err = blockD.erase(addr, sector_erase_size - 1);
|
err = block_device.erase(addr, sector_erase_size - 1);
|
||||||
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
||||||
|
|
||||||
err = blockD.erase(addr, sector_erase_size);
|
err = block_device.erase(addr, sector_erase_size);
|
||||||
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
||||||
|
|
||||||
err = blockD.erase(addr, 1);
|
err = block_device.erase(addr, 1);
|
||||||
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
||||||
|
|
||||||
//unaligned end address
|
//unaligned end address
|
||||||
addr = 0;
|
addr = 0;
|
||||||
|
|
||||||
err = blockD.erase(addr, 1);
|
err = block_device.erase(addr, 1);
|
||||||
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
||||||
|
|
||||||
err = blockD.erase(addr, sector_erase_size + 1);
|
err = block_device.erase(addr, sector_erase_size + 1);
|
||||||
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
||||||
|
|
||||||
//erase size exceeds flash device size
|
//erase size exceeds flash device size
|
||||||
err = blockD.erase(addr, blockD.size() + 1);
|
err = block_device.erase(addr, block_device.size() + 1);
|
||||||
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_INVALID_ERASE_PARAMS, err);
|
||||||
|
|
||||||
// Valid erase
|
// Valid erase
|
||||||
err = blockD.erase(addr, sector_erase_size);
|
err = block_device.erase(addr, sector_erase_size);
|
||||||
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_OK, err);
|
TEST_ASSERT_EQUAL(SPIF_BD_ERROR_OK, err);
|
||||||
|
|
||||||
err = blockD.deinit();
|
err = block_device.deinit();
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_spif_thread_job(void *vBlockD/*, int thread_num*/)
|
static void test_spif_thread_job(void *block_device_ptr/*, int thread_num*/)
|
||||||
{
|
{
|
||||||
static int thread_num = 0;
|
static int thread_num = 0;
|
||||||
thread_num++;
|
thread_num++;
|
||||||
SPIFBlockDevice *blockD = (SPIFBlockDevice *)vBlockD;
|
SPIFBlockDevice *block_device = (SPIFBlockDevice *)block_device_ptr;
|
||||||
utest_printf("\n Thread %d Started \n", thread_num);
|
utest_printf("\n Thread %d Started \n", thread_num);
|
||||||
|
|
||||||
bd_size_t block_size = blockD->get_erase_size();
|
bd_size_t block_size = block_device->get_erase_size();
|
||||||
unsigned addrwidth = ceil(log(float(blockD->size() - 1)) / log(float(16))) + 1;
|
unsigned addrwidth = ceil(log(float(block_device->size() - 1)) / log(float(16))) + 1;
|
||||||
|
|
||||||
uint8_t *write_block = new (std::nothrow) uint8_t[block_size];
|
uint8_t *write_block = new (std::nothrow) uint8_t[block_size];
|
||||||
uint8_t *read_block = new (std::nothrow) uint8_t[block_size];
|
uint8_t *read_block = new (std::nothrow) uint8_t[block_size];
|
||||||
|
@ -209,7 +211,7 @@ static void test_spif_thread_job(void *vBlockD/*, int thread_num*/)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
|
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
|
||||||
basic_erase_program_read_test((*blockD), block_size, write_block, read_block, addrwidth);
|
basic_erase_program_read_test((*block_device), block_size, write_block, read_block, addrwidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
@ -221,16 +223,17 @@ void test_spif_multi_threads()
|
||||||
{
|
{
|
||||||
utest_printf("\nTest Multi Threaded Erase/Program/Read Starts..\n");
|
utest_printf("\nTest Multi Threaded Erase/Program/Read Starts..\n");
|
||||||
|
|
||||||
SPIFBlockDevice blockD(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO, MBED_CONF_SPIF_DRIVER_SPI_CLK,
|
SPIFBlockDevice block_device(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_SPI_MISO,
|
||||||
MBED_CONF_SPIF_DRIVER_SPI_CS);
|
MBED_CONF_SPIF_DRIVER_SPI_CLK,
|
||||||
|
MBED_CONF_SPIF_DRIVER_SPI_CS);
|
||||||
|
|
||||||
int err = blockD.init();
|
int err = block_device.init();
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) {
|
for (unsigned atr = 0; atr < sizeof(ATTRS) / sizeof(ATTRS[0]); atr++) {
|
||||||
static const char *prefixes[] = {"", "k", "M", "G"};
|
static const char *prefixes[] = {"", "k", "M", "G"};
|
||||||
for (int i_ind = 3; i_ind >= 0; i_ind--) {
|
for (int i_ind = 3; i_ind >= 0; i_ind--) {
|
||||||
bd_size_t size = (blockD.*ATTRS[atr].method)();
|
bd_size_t size = (block_device.*ATTRS[atr].method)();
|
||||||
if (size >= (1ULL << 10 * i_ind)) {
|
if (size >= (1ULL << 10 * i_ind)) {
|
||||||
utest_printf("%s: %llu%sbytes (%llubytes)\n",
|
utest_printf("%s: %llu%sbytes (%llubytes)\n",
|
||||||
ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size);
|
ATTRS[atr].name, size >> 10 * i_ind, prefixes[i_ind], size);
|
||||||
|
@ -245,7 +248,7 @@ void test_spif_multi_threads()
|
||||||
int i_ind;
|
int i_ind;
|
||||||
|
|
||||||
for (i_ind = 0; i_ind < SPIF_TEST_NUM_OF_THREADS; i_ind++) {
|
for (i_ind = 0; i_ind < SPIF_TEST_NUM_OF_THREADS; i_ind++) {
|
||||||
threadStatus = spif_bd_thread[i_ind].start(test_spif_thread_job, (void *)&blockD);
|
threadStatus = spif_bd_thread[i_ind].start(test_spif_thread_job, (void *)&block_device);
|
||||||
if (threadStatus != 0) {
|
if (threadStatus != 0) {
|
||||||
utest_printf("\n Thread %d Start Failed!", i_ind + 1);
|
utest_printf("\n Thread %d Start Failed!", i_ind + 1);
|
||||||
}
|
}
|
||||||
|
@ -255,7 +258,7 @@ void test_spif_multi_threads()
|
||||||
spif_bd_thread[i_ind].join();
|
spif_bd_thread[i_ind].join();
|
||||||
}
|
}
|
||||||
|
|
||||||
err = blockD.deinit();
|
err = block_device.deinit();
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue