mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/mtd_flashpage: add 16bit compatibility
This commit is contained in:
parent
b9b01ac57e
commit
f0bbcef987
@ -27,7 +27,7 @@
|
||||
#include "mtd_flashpage.h"
|
||||
#include "periph/flashpage.h"
|
||||
|
||||
#define MTD_FLASHPAGE_END_ADDR CPU_FLASH_BASE + (FLASHPAGE_NUMOF * FLASHPAGE_SIZE)
|
||||
#define MTD_FLASHPAGE_END_ADDR ((uint32_t) CPU_FLASH_BASE + (FLASHPAGE_NUMOF * FLASHPAGE_SIZE))
|
||||
|
||||
static int _init(mtd_dev_t *dev)
|
||||
{
|
||||
@ -39,13 +39,20 @@ static int _init(mtd_dev_t *dev)
|
||||
static int _read(mtd_dev_t *dev, void *buf, uint32_t addr, uint32_t size)
|
||||
{
|
||||
assert(addr < MTD_FLASHPAGE_END_ADDR);
|
||||
|
||||
(void)dev;
|
||||
|
||||
if (addr % FLASHPAGE_RAW_ALIGNMENT) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
memcpy(buf, (void*)addr, size);
|
||||
#if (__SIZEOF_POINTER__ == 2)
|
||||
uint16_t dst_addr = addr;
|
||||
#else
|
||||
uint32_t dst_addr = addr;
|
||||
#endif
|
||||
|
||||
memcpy(buf, (void *)dst_addr, size);
|
||||
|
||||
return size;
|
||||
}
|
||||
@ -53,6 +60,7 @@ static int _read(mtd_dev_t *dev, void *buf, uint32_t addr, uint32_t size)
|
||||
static int _write(mtd_dev_t *dev, const void *buf, uint32_t addr, uint32_t size)
|
||||
{
|
||||
(void)dev;
|
||||
|
||||
if (addr % FLASHPAGE_RAW_ALIGNMENT) {
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -65,7 +73,14 @@ static int _write(mtd_dev_t *dev, const void *buf, uint32_t addr, uint32_t size)
|
||||
if (addr + size > MTD_FLASHPAGE_END_ADDR) {
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
flashpage_write_raw((void *)addr, buf, size);
|
||||
|
||||
#if (__SIZEOF_POINTER__ == 2)
|
||||
uint16_t dst_addr = addr;
|
||||
#else
|
||||
uint32_t dst_addr = addr;
|
||||
#endif
|
||||
|
||||
flashpage_write_raw((void *)dst_addr, buf, size);
|
||||
|
||||
return size;
|
||||
}
|
||||
@ -78,13 +93,20 @@ int _erase(mtd_dev_t *dev, uint32_t addr, uint32_t size)
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
if (addr + size > MTD_FLASHPAGE_END_ADDR) {
|
||||
return - EOVERFLOW;
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
if (addr % sector_size) {
|
||||
return - EOVERFLOW;
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
#if (__SIZEOF_POINTER__ == 2)
|
||||
uint16_t dst_addr = addr;
|
||||
#else
|
||||
uint32_t dst_addr = addr;
|
||||
#endif
|
||||
|
||||
for (size_t i = 0; i < size; i += sector_size) {
|
||||
flashpage_write(flashpage_page((void *)addr), NULL);
|
||||
flashpage_write(flashpage_page((void *)dst_addr), NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -19,8 +19,13 @@
|
||||
#include "mtd.h"
|
||||
#include "mtd_flashpage.h"
|
||||
|
||||
#define TEST_ADDRESS1 (uint32_t)flashpage_addr(FLASHPAGE_NUMOF - 1)
|
||||
#define TEST_ADDRESS2 (uint32_t)flashpage_addr(FLASHPAGE_NUMOF - 2)
|
||||
#if (__SIZEOF_POINTER__ == 2)
|
||||
#define TEST_ADDRESS1 (uint16_t)flashpage_addr(FLASHPAGE_NUMOF - 1)
|
||||
#define TEST_ADDRESS2 (uint16_t)flashpage_addr(FLASHPAGE_NUMOF - 2)
|
||||
#else
|
||||
#define TEST_ADDRESS1 (uint32_t)flashpage_addr(FLASHPAGE_NUMOF - 1)
|
||||
#define TEST_ADDRESS2 (uint32_t)flashpage_addr(FLASHPAGE_NUMOF - 2)
|
||||
#endif
|
||||
|
||||
static mtd_dev_t _dev = MTD_FLASHPAGE_INIT_VAL(8);
|
||||
static mtd_dev_t *dev = &_dev;
|
||||
|
Loading…
Reference in New Issue
Block a user