Microchip® Advanced Software Framework

xmega/drivers/dma/unit_tests/unit_tests.c File Reference

Unit tests for Direct Memory Access controller driver.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include <stdint.h>
#include <stdbool.h>
#include <board.h>
#include <sysclk.h>
#include <dma.h>
#include <pmic.h>
#include <tc.h>
#include <sleepmgr.h>
#include <string.h>
#include <unit_test/suite.h>
#include <stdio_serial.h>
#include <conf_test.h>
#include <conf_board.h>

Functions

int main (void)
 
Callback functions
static void dma_transfer_is_complete (enum dma_channel_status status)
 DMA transfer complete callback. More...
 
static void timer_overflow_callback (void)
 Timer overflow callback. More...
 
DMA module test functions
static void run_dma_memory_copy_burst_length_test (const struct test_case *test)
 Test the different burst lengths by copying on all channels. More...
 
static void run_dma_direction_test (const struct test_case *test)
 Test different directions on all channels. More...
 
static void run_dma_config_interface_test (const struct test_case *test)
 Set DMA configuration, and read it back. More...
 
static void run_dma_triggered_with_callback (const struct test_case *test)
 Test read from fixed location, trigger from timer and callback. More...
 
static void run_dma_error_handling_test (const struct test_case *test)
 Test the error handling of the module. More...
 
static void run_dma_double_buffering_test (const struct test_case *test)
 Test double buffering mode. More...
 

Variables

Variables
uint8_t memory_block_src [MEMORY_BLOCK_SIZE]
 Memory block to read from. More...
 
uint8_t memory_block_dest [MEMORY_BLOCK_SIZE]
 Memory block to write to. More...
 
uint8_t dest_block_tc [DEST_BLOCK_TC_SIZE]
 Memory block to write to, used by run_dma_triggered_with_callback. More...
 
uint8_t expected_result_tc [DEST_BLOCK_TC_SIZE]
 Expected result from trigger/interrupt copy. More...
 
volatile bool dma_has_completed = false
 Whether DMA has finished copying, used by run_dma_triggered_with_callback. More...
 
volatile uint8_t timer_overflow_counter = 0
 Counter incremented by timer overflow. More...
 

Helper functions

#define set_buffer(buffer, value)   memset(buffer, value, sizeof(buffer))
 Set all bytes in buffer to value. More...
 
static void block_fill (uint8_t *block, uint16_t size)
 Fill a block with a certain pattern. More...
 
static bool block_compare (const uint8_t *block_1, const uint8_t *block_2, uint16_t block_size)
 Compare two 8-bit data blocks of given size. More...
 
static bool block_compare_reverse (const uint8_t *block_1, const uint8_t *block_2, uint16_t block_size)
 Compare two 8-bit data blocks of given size in reverse. More...
 
static void dma_transfer_block (dma_channel_num_t channel_num)
 Trigger and wait for a successful transfer. More...
 

#define set_buffer (   buffer,
  value 
)    memset(buffer, value, sizeof(buffer))

static bool block_compare ( const uint8_t *  block_1,
const uint8_t *  block_2,
uint16_t  block_size 
)
static

Compare two 8-bit data blocks of given size.

Note
Compares two blocks of equal size to see if they are equal.
Parameters
block_1Pointer to first block.
block_2Pointer to second block.
block_sizeSize of blocks to compare.

Referenced by run_dma_direction_test(), run_dma_memory_copy_burst_length_test(), and run_dma_triggered_with_callback().

static bool block_compare_reverse ( const uint8_t *  block_1,
const uint8_t *  block_2,
uint16_t  block_size 
)
static

Compare two 8-bit data blocks of given size in reverse.

Note
Compares two blocks of equal size in reverse to see if they are equal.
Parameters
block_1Pointer to first block.
block_2Pointer to second block.
block_sizeSize of blocks to compare.

Referenced by run_dma_direction_test().

static void block_fill ( uint8_t *  block,
uint16_t  size 
)
static

Fill a block with a certain pattern.

Parameters
block_1Pointer to block.
block_sizeSize of block to fill.

Referenced by run_dma_direction_test(), run_dma_double_buffering_test(), and run_dma_memory_copy_burst_length_test().

static void dma_transfer_block ( dma_channel_num_t  channel_num)
static

Trigger and wait for a successful transfer.

Parameters
channel_numChannel number

References DMA_CH_TRANSFER_COMPLETED, dma_channel_trigger_block_transfer(), and dma_get_channel_status().

Referenced by run_dma_direction_test(), and run_dma_memory_copy_burst_length_test().

static void dma_transfer_is_complete ( enum dma_channel_status  status)
static

DMA transfer complete callback.

Parameters
statusStatus of transfer

References DMA_CH_TRANSFER_COMPLETED, dma_has_completed, and tc_disable().

Referenced by run_dma_triggered_with_callback().

static void run_dma_double_buffering_test ( const struct test_case test)
static
static void run_dma_error_handling_test ( const struct test_case test)
static
static void run_dma_memory_copy_burst_length_test ( const struct test_case test)
static

Test the different burst lengths by copying on all channels.

Note
This test copies a memory block using different burst lengths, and verifies that they have been copied correctly, thereby testing both burst lengths and memory transfer.
Parameters
testCurrent test

References block_compare(), block_fill(), dma_channel_disable(), dma_channel_enable(), dma_channel_reset(), dma_channel_set_burst_length(), dma_channel_set_dest_dir_mode(), dma_channel_set_dest_reload_mode(), dma_channel_set_destination_address(), dma_channel_set_source_address(), dma_channel_set_src_dir_mode(), dma_channel_set_src_reload_mode(), dma_channel_set_transfer_count(), dma_channel_write_config(), dma_disable(), dma_enable(), DMA_NUMBER_OF_CHANNELS, dma_transfer_block(), memory_block_dest, memory_block_src, set_buffer, success, and test_assert_true.

Referenced by main().

static void timer_overflow_callback ( void  )
static

Timer overflow callback.

Note
The callback increments the overflow counter

References timer_overflow_counter.

Referenced by run_dma_triggered_with_callback().

uint8_t dest_block_tc[DEST_BLOCK_TC_SIZE]

Memory block to write to, used by run_dma_triggered_with_callback.

Referenced by run_dma_triggered_with_callback().

volatile bool dma_has_completed = false

Whether DMA has finished copying, used by run_dma_triggered_with_callback.

Referenced by dma_transfer_is_complete(), and run_dma_triggered_with_callback().

uint8_t expected_result_tc[DEST_BLOCK_TC_SIZE]
Initial value:
= {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
}

Expected result from trigger/interrupt copy.

Referenced by run_dma_triggered_with_callback().

uint8_t memory_block_dest[MEMORY_BLOCK_SIZE]
uint8_t memory_block_src[MEMORY_BLOCK_SIZE]
volatile uint8_t timer_overflow_counter = 0

Counter incremented by timer overflow.

Referenced by run_dma_triggered_with_callback(), and timer_overflow_callback().