Microchip® Advanced Software Framework

drivers/i2s/unit_test/unit_test.c File Reference

SAM I2S Unit test.

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

#include <asf.h>
#include <stdio_serial.h>
#include <string.h>
#include "conf_test.h"

Macros

#define TEST_SIZE   4
 

Functions

static void cdc_uart_init (void)
 Initialize the USART for unit test. More...
 
static void cleanup_i2s_callback_mode_test (const struct test_case *test)
 Cleanup function for callback mode test. More...
 
static void cleanup_i2s_polled_mode_test (const struct test_case *test)
 Cleanup function for polled mode test. More...
 
static void i2s_callback_rx (struct i2s_module *const module_inst)
 I2S data RX callback. More...
 
static void i2s_callback_tx (struct i2s_module *const module_inst)
 I2S data TX callback. More...
 
int main (void)
 Run I2S unit tests. More...
 
static void run_i2s_callback_mode_test (const struct test_case *test)
 Test for I2S TX/RX using callback. More...
 
static void run_i2s_polled_mode_test (const struct test_case *test)
 Test for I2S TX/RX by polling. More...
 
static void setup_i2s (void)
 Initialize the I2S module Clock Unit and Serializer. More...
 
static void setup_i2s_callback_mode_test (const struct test_case *test)
 Setup function for callback mode test. More...
 
static void setup_i2s_polled_mode_test (const struct test_case *test)
 Setup function for polled mode test. More...
 

Variables

struct usart_module cdc_uart_module
 
struct i2s_module i2s_instance
 
uint16_t test_rx_data [TEST_SIZE] = {0, 0, 0, 0}
 
volatile uint32_t test_rx_done = false
 
uint16_t test_tx_data [TEST_SIZE] = {11, 60, 0xF860, 0x9001}
 
volatile uint32_t test_tx_done = false
 

#define TEST_SIZE   4

static void cdc_uart_init ( void  )
static
static void cleanup_i2s_callback_mode_test ( const struct test_case test)
static

Cleanup function for callback mode test.

This function disables the callback & I2S module.

Parameters
testCurrent test case.

References i2s_disable(), i2s_instance, I2S_SERIALIZER_0, I2S_SERIALIZER_1, I2S_SERIALIZER_CALLBACK_BUFFER_DONE, i2s_serializer_disable_callback(), and i2s_serializer_unregister_callback().

Referenced by main().

static void cleanup_i2s_polled_mode_test ( const struct test_case test)
static

Cleanup function for polled mode test.

This function disables the I2S module.

Parameters
testCurrent test case.

References i2s_disable(), and i2s_instance.

Referenced by main().

static void i2s_callback_rx ( struct i2s_module *const  module_inst)
static

I2S data RX callback.

References test_rx_done.

Referenced by setup_i2s_callback_mode_test().

static void i2s_callback_tx ( struct i2s_module *const  module_inst)
static

I2S data TX callback.

References test_tx_done.

Referenced by setup_i2s_callback_mode_test().

static void run_i2s_callback_mode_test ( const struct test_case test)
static
static void run_i2s_polled_mode_test ( const struct test_case test)
static

Test for I2S TX/RX by polling.

Send several words by polling and receive them.

Note
In polling mode, the first received word may not be the first one sent due to timing delay, so test words list are sent twice, to confirm that all words are received.
Parameters
testCurrent test case.

References i, i2s_instance, I2S_SERIALIZER_0, I2S_SERIALIZER_1, i2s_serializer_read_wait(), i2s_serializer_write_wait(), j, test_assert_true, test_rx_data, TEST_SIZE, and test_tx_data.

Referenced by main().

static void setup_i2s ( void  )
static
static void setup_i2s_callback_mode_test ( const struct test_case test)
static

Setup function for callback mode test.

This function sets up the I2S & the callback function.

Parameters
testCurrent test case.

References i2s_callback_rx(), i2s_callback_tx(), i2s_instance, I2S_SERIALIZER_0, I2S_SERIALIZER_1, I2S_SERIALIZER_CALLBACK_BUFFER_DONE, i2s_serializer_enable_callback(), i2s_serializer_register_callback(), and setup_i2s().

Referenced by main().

static void setup_i2s_polled_mode_test ( const struct test_case test)
static

Setup function for polled mode test.

This function sets up the I2S module.

Parameters
testCurrent test case.

References setup_i2s().

Referenced by main().

struct usart_module cdc_uart_module
uint16_t test_rx_data[TEST_SIZE] = {0, 0, 0, 0}
volatile uint32_t test_rx_done = false
uint16_t test_tx_data[TEST_SIZE] = {11, 60, 0xF860, 0x9001}
volatile uint32_t test_tx_done = false