From 61052dbed72f78f8e46a9f4ad274496254803c33 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Mon, 9 Nov 2020 16:44:29 +0100 Subject: [PATCH] msp430: Adapt to flashpage/flashpage_pagewise API --- cpu/msp430_common/Kconfig | 2 +- cpu/msp430_common/Makefile.features | 2 +- cpu/msp430_common/include/cpu_conf.h | 4 ++-- cpu/msp430_common/periph/flashpage.c | 35 ++++++++++++---------------- 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/cpu/msp430_common/Kconfig b/cpu/msp430_common/Kconfig index 9674ae4051..cbdf20e7d4 100644 --- a/cpu/msp430_common/Kconfig +++ b/cpu/msp430_common/Kconfig @@ -11,7 +11,7 @@ config CPU_ARCH_MSP430 select HAS_ARCH_16BIT select HAS_ARCH_MSP430 select HAS_PERIPH_FLASHPAGE - select HAS_PERIPH_FLASHPAGE_RAW + select HAS_PERIPH_FLASHPAGE_PAGEWISE select HAS_PERIPH_PM config CPU_CORE_MSP430 diff --git a/cpu/msp430_common/Makefile.features b/cpu/msp430_common/Makefile.features index 0b543b37f1..96151a8936 100644 --- a/cpu/msp430_common/Makefile.features +++ b/cpu/msp430_common/Makefile.features @@ -4,5 +4,5 @@ CPU_CORE = msp430 FEATURES_PROVIDED += arch_16bit FEATURES_PROVIDED += arch_msp430 FEATURES_PROVIDED += periph_flashpage -FEATURES_PROVIDED += periph_flashpage_raw +FEATURES_PROVIDED += periph_flashpage_pagewise FEATURES_PROVIDED += periph_pm diff --git a/cpu/msp430_common/include/cpu_conf.h b/cpu/msp430_common/include/cpu_conf.h index b58fa5af74..dd1926df9c 100644 --- a/cpu/msp430_common/include/cpu_conf.h +++ b/cpu/msp430_common/include/cpu_conf.h @@ -50,9 +50,9 @@ extern "C" { /* The minimum block size which can be written is 1B. However, the erase * block is always FLASHPAGE_SIZE. */ -#define FLASHPAGE_RAW_BLOCKSIZE (1U) +#define FLASHPAGE_WRITE_BLOCK_SIZE (1U) /* Writing should be always 2 byte aligned */ -#define FLASHPAGE_RAW_ALIGNMENT (2U) +#define FLASHPAGE_WRITE_BLOCK_ALIGNMENT (2U) /** @} */ /** diff --git a/cpu/msp430_common/periph/flashpage.c b/cpu/msp430_common/periph/flashpage.c index 4eaffe13bf..b54b83ab85 100644 --- a/cpu/msp430_common/periph/flashpage.c +++ b/cpu/msp430_common/periph/flashpage.c @@ -55,15 +55,25 @@ static inline void _erase(uint16_t *page_addr) _lock(state); } -void flashpage_write_raw(void *target_addr, const void *data, size_t len) +void flashpage_erase(unsigned page) { - /* assert multiples of FLASHPAGE_RAW_BLOCKSIZE are written and no less of + assert((unsigned) page < FLASHPAGE_NUMOF); + + uint16_t *page_addr = (uint16_t *)flashpage_addr(page); + + /* erase page */ + _erase(page_addr); +} + +void flashpage_write(void *target_addr, const void *data, size_t len) +{ + /* assert multiples of FLASHPAGE_WRITE_BLOCK_SIZE are written and no less of that length. */ - assert(!(len % FLASHPAGE_RAW_BLOCKSIZE)); + assert(!(len % FLASHPAGE_WRITE_BLOCK_SIZE)); /* ensure writes are aligned */ - assert(!(((unsigned)target_addr % FLASHPAGE_RAW_ALIGNMENT) || - ((unsigned)data % FLASHPAGE_RAW_ALIGNMENT))); + assert(!(((unsigned)target_addr % FLASHPAGE_WRITE_BLOCK_ALIGNMENT) || + ((unsigned)data % FLASHPAGE_WRITE_BLOCK_ALIGNMENT))); /* ensure the length doesn't exceed the actual flash size */ assert(((unsigned)target_addr + len) < @@ -87,18 +97,3 @@ void flashpage_write_raw(void *target_addr, const void *data, size_t len) /* lock flash and re-enable interrupts */ _lock(state); } - -void flashpage_write(int page, const void *data) -{ - assert((unsigned) page < FLASHPAGE_NUMOF); - - uint16_t *page_addr = (uint16_t *)flashpage_addr(page); - - /* erase page */ - _erase(page_addr); - - /* write page */ - if (data != NULL) { - flashpage_write_raw(page_addr, data, FLASHPAGE_SIZE); - } -}