mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
periph/flashpage: extend API
This commit is contained in:
parent
1ba0bdfa9c
commit
72d47013dd
@ -211,6 +211,16 @@ unsigned flashpage_page(const void *addr);
|
||||
*/
|
||||
void flashpage_erase(unsigned page);
|
||||
|
||||
/**
|
||||
* @brief Get number of first free flashpage
|
||||
*/
|
||||
unsigned flashpage_first_free(void);
|
||||
|
||||
/**
|
||||
* @brief Get number of last free flashpage
|
||||
*/
|
||||
unsigned flashpage_last_free(void);
|
||||
|
||||
/**
|
||||
* @brief Write the given page with the given data
|
||||
*
|
||||
|
@ -30,14 +30,6 @@
|
||||
|
||||
#define LINE_LEN (16)
|
||||
|
||||
/* For MSP430 cpu's the last page holds the interrupt vector, although the api
|
||||
should not limit erasing that page, we don't want to break when testing */
|
||||
#if defined(CPU_CC430) || defined(CPU_MSP430FXYZ)
|
||||
#define TEST_LAST_AVAILABLE_PAGE (FLASHPAGE_NUMOF - 2)
|
||||
#else
|
||||
#define TEST_LAST_AVAILABLE_PAGE (FLASHPAGE_NUMOF - 1)
|
||||
#endif
|
||||
|
||||
/* When writing raw bytes on flash, data must be correctly aligned. */
|
||||
#define ALIGNMENT_ATTR __attribute__((aligned(FLASHPAGE_WRITE_BLOCK_ALIGNMENT)))
|
||||
|
||||
@ -115,24 +107,27 @@ static int cmd_info(int argc, char **argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
printf("Flash start addr:\t0x%08x\n", (int)CPU_FLASH_BASE);
|
||||
printf("Flash start addr:\t\t0x%08x\n", (int)CPU_FLASH_BASE);
|
||||
#ifdef FLASHPAGE_SIZE
|
||||
printf("Page size:\t\t%i\n", (int)FLASHPAGE_SIZE);
|
||||
printf("Page size:\t\t\t%i\n", (int)FLASHPAGE_SIZE);
|
||||
#else
|
||||
puts("Page size:\t\tvariable");
|
||||
puts("Page size:\t\t\tvariable");
|
||||
#endif
|
||||
printf("Number of pages:\t%i\n", (int)FLASHPAGE_NUMOF);
|
||||
printf("Number of pages:\t\t%i\n", (int)FLASHPAGE_NUMOF);
|
||||
|
||||
#ifdef FLASHPAGE_RWWEE_NUMOF
|
||||
printf("RWWEE Flash start addr:\t0x%08x\n", (int)CPU_FLASH_RWWEE_BASE);
|
||||
printf("RWWEE Number of pages:\t%i\n", (int)FLASHPAGE_RWWEE_NUMOF);
|
||||
printf("RWWEE Flash start addr:\t\t0x%08x\n", (int)CPU_FLASH_RWWEE_BASE);
|
||||
printf("RWWEE Number of pages:\t\t%i\n", (int)FLASHPAGE_RWWEE_NUMOF);
|
||||
#endif
|
||||
|
||||
#ifdef NVMCTRL_USER
|
||||
printf("AUX page size:\t%i\n", FLASH_USER_PAGE_AUX_SIZE + sizeof(nvm_user_page_t));
|
||||
printf(" user area:\t%i\n", FLASH_USER_PAGE_AUX_SIZE);
|
||||
printf("AUX page size:\t\t%i\n", FLASH_USER_PAGE_AUX_SIZE + sizeof(nvm_user_page_t));
|
||||
printf(" user area:\t\t%i\n", FLASH_USER_PAGE_AUX_SIZE);
|
||||
#endif
|
||||
|
||||
printf("Number of first free page: \t%u \n", flashpage_first_free());
|
||||
printf("Number of last free page: \t%u \n", flashpage_last_free());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -349,6 +344,7 @@ static int cmd_test_last(int argc, char **argv)
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
char fill = 'a';
|
||||
unsigned last_free = flashpage_last_free();
|
||||
|
||||
for (unsigned i = 0; i < sizeof(page_mem); i++) {
|
||||
page_mem[i] = (uint8_t)fill++;
|
||||
@ -357,9 +353,9 @@ static int cmd_test_last(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
#if defined(CPU_CC430) || defined(CPU_MSP430FXYZ)
|
||||
printf("The last page holds the ISR vector, so test page %d\n", TEST_LAST_AVAILABLE_PAGE);
|
||||
printf("The last page holds the ISR vector, so test page %u\n", last_free);
|
||||
#endif
|
||||
if (flashpage_write_and_verify(TEST_LAST_AVAILABLE_PAGE, page_mem) != FLASHPAGE_OK) {
|
||||
if (flashpage_write_and_verify(last_free, page_mem) != FLASHPAGE_OK) {
|
||||
puts("error verifying the content of last page");
|
||||
return 1;
|
||||
}
|
||||
@ -380,22 +376,23 @@ static int cmd_test_last_raw(int argc, char **argv)
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
unsigned last_free = flashpage_last_free();
|
||||
|
||||
memset(raw_buf, 0, sizeof(raw_buf));
|
||||
|
||||
/* try to align */
|
||||
memcpy(raw_buf, "test12344321tset", 16);
|
||||
#if defined(CPU_CC430) || defined(CPU_MSP430FXYZ)
|
||||
printf("The last page holds the ISR vector, so test page %d\n", TEST_LAST_AVAILABLE_PAGE);
|
||||
printf("The last page holds the ISR vector, so test page %u\n", last_free);
|
||||
#endif
|
||||
|
||||
/* erase the page first */
|
||||
flashpage_erase(TEST_LAST_AVAILABLE_PAGE);
|
||||
flashpage_erase(last_free);
|
||||
|
||||
flashpage_write(flashpage_addr(TEST_LAST_AVAILABLE_PAGE), raw_buf, sizeof(raw_buf));
|
||||
flashpage_write(flashpage_addr(last_free), raw_buf, sizeof(raw_buf));
|
||||
|
||||
/* verify that previous write_raw effectively wrote the desired data */
|
||||
if (memcmp(flashpage_addr(TEST_LAST_AVAILABLE_PAGE), raw_buf, strlen(raw_buf)) != 0) {
|
||||
if (memcmp(flashpage_addr(last_free), raw_buf, strlen(raw_buf)) != 0) {
|
||||
puts("error verifying the content of last page");
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user