mtd: Redefine MTD_0 as a mtd_dev_t *

This commit is contained in:
Joakim Nohlgård 2017-03-28 16:46:56 +02:00
parent 796eb64c0b
commit d1ea50a600
4 changed files with 10 additions and 14 deletions

View File

@ -47,7 +47,7 @@ void board_init(void)
#define MTD_NATIVE_FILENAME "MEMORY.bin" #define MTD_NATIVE_FILENAME "MEMORY.bin"
#endif #endif
mtd_native_dev_t mtd0 = { static mtd_native_dev_t mtd0_dev = {
.dev = { .dev = {
.driver = &native_flash_driver, .driver = &native_flash_driver,
.sector_count = MTD_NATIVE_SECTOR_NUM, .sector_count = MTD_NATIVE_SECTOR_NUM,
@ -56,4 +56,6 @@ mtd_native_dev_t mtd0 = {
}, },
.fname = MTD_NATIVE_FILENAME, .fname = MTD_NATIVE_FILENAME,
}; };
mtd_dev_t *mtd0 = (mtd_dev_t *)&mtd0_dev;
#endif #endif

View File

@ -57,7 +57,7 @@ void _native_LED_RED_TOGGLE(void);
#define MTD_0 mtd0 #define MTD_0 mtd0
/** mtd flash emulation device */ /** mtd flash emulation device */
extern mtd_native_dev_t mtd0; extern mtd_dev_t *mtd0;
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -304,7 +304,7 @@ __attribute__((constructor)) static void startup(int argc, char **argv)
break; break;
#ifdef MODULE_MTD_NATIVE #ifdef MODULE_MTD_NATIVE
case 'm': case 'm':
mtd0.fname = strndup(optarg, PATH_MAX - 1); ((mtd_native_dev_t *)mtd0)->fname = strndup(optarg, PATH_MAX - 1);
break; break;
#endif #endif
default: default:

View File

@ -27,7 +27,7 @@
/* Define MTD_0 in board.h to use the board mtd if any */ /* Define MTD_0 in board.h to use the board mtd if any */
#ifdef MTD_0 #ifdef MTD_0
#define _dev MTD_0 #define dev (MTD_0)
#else #else
/* Test mock object implementing a simple RAM-based mtd */ /* Test mock object implementing a simple RAM-based mtd */
#ifndef SECTOR_COUNT #ifndef SECTOR_COUNT
@ -116,27 +116,24 @@ static mtd_dev_t _dev = {
.pages_per_sector = PAGE_PER_SECTOR, .pages_per_sector = PAGE_PER_SECTOR,
.page_size = PAGE_SIZE, .page_size = PAGE_SIZE,
}; };
static mtd_dev_t *dev = (mtd_dev_t*) &_dev;
#endif /* MTD_0 */ #endif /* MTD_0 */
static void setup_teardown(void) static void setup_teardown(void)
{ {
mtd_dev_t *dev = (mtd_dev_t*) &_dev;
mtd_erase(dev, 0, dev->pages_per_sector * dev->page_size); mtd_erase(dev, 0, dev->pages_per_sector * dev->page_size);
} }
static void test_mtd_init(void) static void test_mtd_init(void)
{ {
mtd_dev_t *dev = (mtd_dev_t*) &_dev;
int ret = mtd_init(dev); int ret = mtd_init(dev);
TEST_ASSERT_EQUAL_INT(0, ret); TEST_ASSERT_EQUAL_INT(0, ret);
} }
static void test_mtd_erase(void) static void test_mtd_erase(void)
{ {
mtd_dev_t *dev = (mtd_dev_t*) &_dev;
/* Erase first sector */ /* Erase first sector */
int ret = mtd_erase(dev, 0, dev->pages_per_sector * dev->page_size); int ret = mtd_erase(dev, 0, dev->pages_per_sector * dev->page_size);
TEST_ASSERT_EQUAL_INT(0, ret); TEST_ASSERT_EQUAL_INT(0, ret);
@ -162,7 +159,6 @@ static void test_mtd_erase(void)
static void test_mtd_write_erase(void) static void test_mtd_write_erase(void)
{ {
mtd_dev_t *dev = (mtd_dev_t*) &_dev;
const char buf[] = "ABCDEFGHIJK"; const char buf[] = "ABCDEFGHIJK";
uint8_t buf_empty[] = {0xff, 0xff, 0xff}; uint8_t buf_empty[] = {0xff, 0xff, 0xff};
char buf_read[sizeof(buf) + sizeof(buf_empty)]; char buf_read[sizeof(buf) + sizeof(buf_empty)];
@ -184,7 +180,6 @@ static void test_mtd_write_erase(void)
static void test_mtd_write_read(void) static void test_mtd_write_read(void)
{ {
mtd_dev_t *dev = (mtd_dev_t*) &_dev;
const char buf[] = "ABCDEFGH"; const char buf[] = "ABCDEFGH";
uint8_t buf_empty[] = {0xff, 0xff, 0xff}; uint8_t buf_empty[] = {0xff, 0xff, 0xff};
char buf_read[sizeof(buf) + sizeof(buf_empty)]; char buf_read[sizeof(buf) + sizeof(buf_empty)];
@ -221,7 +216,6 @@ static void test_mtd_write_read(void)
static void test_mtd_write_read_flash(void) static void test_mtd_write_read_flash(void)
{ {
mtd_dev_t *dev = (mtd_dev_t*) &_dev;
const uint8_t buf1[] = {0xee, 0xdd, 0xcc}; const uint8_t buf1[] = {0xee, 0xdd, 0xcc};
const uint8_t buf2[] = {0x33, 0x33, 0x33}; const uint8_t buf2[] = {0x33, 0x33, 0x33};
const uint8_t buf_expected[] = {0x22, 0x11, 0x0}; const uint8_t buf_expected[] = {0x22, 0x11, 0x0};
@ -247,7 +241,7 @@ static void test_mtd_write_read_flash(void)
static void test_mtd_vfs(void) static void test_mtd_vfs(void)
{ {
int fd; int fd;
fd = vfs_bind(VFS_ANY_FD, O_RDWR, &mtd_vfs_ops, &_dev); fd = vfs_bind(VFS_ANY_FD, O_RDWR, &mtd_vfs_ops, dev);
const char buf[] = "mnopqrst"; const char buf[] = "mnopqrst";
uint8_t buf_empty[] = {0xff, 0xff, 0xff}; uint8_t buf_empty[] = {0xff, 0xff, 0xff};
char buf_read[sizeof(buf) + sizeof(buf_empty)]; char buf_read[sizeof(buf) + sizeof(buf_empty)];