SPI flash refactoring.

Extract common spiflash.c into core.
Use spiflash.c in sysparam.
Use memcpy in spiflash.c insted of hand-written version.
Tests for spiflash.c
This commit is contained in:
sheinz 2016-11-28 17:17:59 +02:00
parent 2105d5a5cd
commit e84f47f944
9 changed files with 140 additions and 247 deletions

View file

@ -252,7 +252,7 @@ static void clear_test_values(test_data_t *data)
}
static void test_task(void *pvParameters)
static void a_07_sysparam_load_test(void)
{
test_data_t test_data;
init_sysparam();
@ -276,11 +276,6 @@ static void test_task(void *pvParameters)
TEST_PASS();
}
static void a_07_sysparam_load_test(void)
{
xTaskCreate(test_task, "test_task", 256, NULL, 2, NULL);
}
static void a_07_sysparam_basic_test(void)
{
sysparam_status_t status;

51
tests/cases/08_spiflash.c Normal file
View file

@ -0,0 +1,51 @@
#include <string.h>
#include <espressif/esp_common.h>
#include <esp/uart.h>
#include <esp/timer.h>
#include <FreeRTOS.h>
#include <task.h>
#include <esp8266.h>
#include <stdio.h>
#include <testcase.h>
#include <spiflash.h>
DEFINE_SOLO_TESTCASE(08_spiflash_unaligned)
/**
* Test unaligned access to spi flash.
*/
static void a_08_spiflash_unaligned(void)
{
const int test_addr = 0x100000 - (4096 * 8);
const char test_str[] = "test_string";
const int buf_size = 256;
uint8_t buf[buf_size];
TEST_ASSERT_TRUE(spiflash_erase_sector(test_addr));
TEST_ASSERT_TRUE(spiflash_erase_sector(test_addr + 4096));
TEST_ASSERT_TRUE(
spiflash_write(test_addr, (uint8_t*)test_str, sizeof(test_str)));
TEST_ASSERT_TRUE(spiflash_read(test_addr, buf, buf_size));
TEST_ASSERT_EQUAL_STRING(test_str, buf);
TEST_ASSERT_TRUE(
spiflash_write(test_addr + 31, (uint8_t*)test_str, sizeof(test_str)));
TEST_ASSERT_TRUE(spiflash_read(test_addr + 31, buf, buf_size));
TEST_ASSERT_EQUAL_STRING(test_str, buf);
TEST_ASSERT_TRUE(
spiflash_write(test_addr + 101, (uint8_t*)test_str, sizeof(test_str)));
TEST_ASSERT_TRUE(spiflash_read(test_addr + 101, buf + 1, buf_size - 1));
TEST_ASSERT_EQUAL_STRING(test_str, buf + 1);
TEST_ASSERT_TRUE(
spiflash_write(test_addr + 201, (uint8_t*)test_str + 1, sizeof(test_str) - 1));
TEST_ASSERT_TRUE(spiflash_read(test_addr + 201, buf + 1, buf_size - 1));
TEST_ASSERT_EQUAL_STRING(test_str + 1, buf + 1);
TEST_PASS();
}