Atmel Software Framework

common/components/memory/data_flash/at45dbx/unit_tests/unit_tests.c File Reference

AT45dbx DataFlash Component Unit Test.

Copyright (c) 2011-2012 Atmel Corporation. All rights reserved.

#include <stdint.h>
#include <stdbool.h>
#include <asf.h>
#include <string.h>
#include "at45dbx.h"
#include "conf_test.h"

Macros

Byte pattern generator
#define BYTE_PATTERN1(x)   ((uint8_t) (((x) * 5 + 1) & 0xff))
 Generates byte pattern 1 for a given address. More...
 
#define BYTE_PATTERN2(x)   ((uint8_t) (((x) * 3) & 0xff))
 Generates byte pattern 2 for a given address. More...
 
#define BYTE_PATTERN3(x)   ((uint8_t) (((x) * 7 + 3) & 0xff))
 Generates byte pattern 3 for a given address. More...
 

Functions

int main (void)
 Run DataFlash component unit tests. More...
 
static void run_byte_access_test (const struct test_case *test)
 Test the read and write byte operations on the DataFlash. More...
 
static void run_memory_check_test (const struct test_case *test)
 Performs a memory check on all DataFlash memories. More...
 
static void run_memory_range_check_test (const struct test_case *test)
 Performs out of range memory test on DataFlash memory. More...
 
static void run_multiple_sector_access_test (const struct test_case *test)
 Test the read and write multiple sector operations on the DataFlash. More...
 
static void run_sector_access_test (const struct test_case *test)
 Test the read and write sector operations on the DataFlash. More...
 

Variables

static uint8_t sector_buf [AT45DBX_SECTOR_SIZE]
 A DataFlash sector-sized buffer for processing data in ram memory. More...
 

#define BYTE_PATTERN1 (   x)    ((uint8_t) (((x) * 5 + 1) & 0xff))

Generates byte pattern 1 for a given address.

Referenced by run_byte_access_test().

#define BYTE_PATTERN2 (   x)    ((uint8_t) (((x) * 3) & 0xff))

Generates byte pattern 2 for a given address.

Referenced by run_sector_access_test().

#define BYTE_PATTERN3 (   x)    ((uint8_t) (((x) * 7 + 3) & 0xff))

Generates byte pattern 3 for a given address.

Referenced by run_multiple_sector_access_test().

int main ( void  )

Run DataFlash component unit tests.

Initializes the clock system, board, serial output and DataFlash, then sets up the DataFlash unit test suite and runs it.

References at45dbx_init(), usart_options_t::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, NULL, run_byte_access_test(), run_memory_check_test(), run_memory_range_check_test(), run_multiple_sector_access_test(), run_sector_access_test(), stdio_serial_init(), sysclk_init(), test_suite_run(), and usart_serial_options.

static void run_byte_access_test ( const struct test_case test)
static

Test the read and write byte operations on the DataFlash.

This function will test the read and write functionalities of the DataFlash using byte access. It will first write a known pattern on the 2 first consecutive sectors and read it back by testing each value read.
In addition to test the data integrity and the byte read / write functions, this will also test the continuity of the sectors as well as the auto-incrementation of the DataFlash address.

Parameters
testCurrent test case.

References at45dbx_read_byte(), at45dbx_read_byte_open(), at45dbx_read_close(), AT45DBX_SECTOR_SIZE, at45dbx_write_byte(), at45dbx_write_byte_open(), at45dbx_write_close(), BYTE_PATTERN1, i, status, and test_assert_true.

Referenced by main().

static void run_memory_check_test ( const struct test_case test)
static

Performs a memory check on all DataFlash memories.

This function will simply test the output of the function at45dbx_mem_check and returns an error in case of failure.

Parameters
testCurrent test case.

References at45dbx_mem_check(), status, and test_assert_true.

Referenced by main().

static void run_memory_range_check_test ( const struct test_case test)
static

Performs out of range memory test on DataFlash memory.

This function will simply test the output of the function at45dbx_mem_check and returns an error in case of failure.

Parameters
testCurrent test case.

References AT45DBX_MEM_CNT, AT45DBX_MEM_SIZE, at45dbx_read_byte_open(), status, and test_assert_true.

Referenced by main().

static void run_multiple_sector_access_test ( const struct test_case test)
static

Test the read and write multiple sector operations on the DataFlash.

This function will test the read and write functionalities of the DataFlash using multiple sector access. It will first fill the 10 first DataFlash sectors with a known pattern and read it back to test each value.

Parameters
testCurrent test case.

References at45dbx_read_close(), at45dbx_read_sector_open(), at45dbx_read_sector_to_ram(), AT45DBX_SECTOR_SIZE, at45dbx_write_close(), at45dbx_write_sector_from_ram(), at45dbx_write_sector_open(), BYTE_PATTERN3, cur_sector, i, sector_buf, status, and test_assert_true.

Referenced by main().

static void run_sector_access_test ( const struct test_case test)
static

Test the read and write sector operations on the DataFlash.

This function will test the read and write functionalities of the DataFlash using sector access. It will first fill a sector with a known pattern and read it back by testing each value read.

Parameters
testCurrent test case.

References at45dbx_read_close(), at45dbx_read_sector_open(), at45dbx_read_sector_to_ram(), AT45DBX_SECTOR_SIZE, at45dbx_write_close(), at45dbx_write_sector_from_ram(), at45dbx_write_sector_open(), BYTE_PATTERN2, i, sector_buf, status, and test_assert_true.

Referenced by main().

uint8_t sector_buf[AT45DBX_SECTOR_SIZE]
static

A DataFlash sector-sized buffer for processing data in ram memory.

Referenced by run_multiple_sector_access_test(), and run_sector_access_test().