Microchip® Advanced Software Framework

drivers/sercom/i2c/unit_test/unit_test.c File Reference

SAM SERCOM I2C Unit test.

Copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries.

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

Macros

#define DATA_LENGTH   10
 
#define SLAVE_ADDRESS   0x12
 

Functions

static void cdc_uart_init (void)
 Initialize the USART for unit test. More...
 
void configure_i2c_slave_callbacks (void)
 
void i2c_slave_read_request_callback (struct i2c_slave_module *const module)
 
void i2c_slave_write_request_callback (struct i2c_slave_module *const module)
 
int main (void)
 Run I2C master unit tests. More...
 
static void run_i2c_full_speed_test (const struct test_case *test)
 Test full speed mode master transfer. More...
 
static void run_i2c_init_test (const struct test_case *test)
 Test for I2C master and slave initialization. More...
 
static void run_i2c_master_transfer_test (const struct test_case *test)
 Test for I2C master transfer. More...
 

Variables

struct usart_module cdc_uart_module
 
static struct i2c_master_module i2c_master_instance
 
static struct i2c_slave_module i2c_slave_instance
 
static uint8_t master_read_buffer [DATA_LENGTH] = {0}
 
static uint8_t master_write_buffer [DATA_LENGTH]
 
static uint8_t slave_buffer [DATA_LENGTH] = {0}
 
static struct i2c_slave_packet slave_packet
 

#define SLAVE_ADDRESS   0x12

static void cdc_uart_init ( void  )
static
void configure_i2c_slave_callbacks ( void  )
void i2c_slave_read_request_callback ( struct i2c_slave_module *const  module)
void i2c_slave_write_request_callback ( struct i2c_slave_module *const  module)
int main ( void  )

Run I2C master unit tests.

Initializes the system and serial output, then sets up the I2C master unit test suite and runs it.

References cdc_uart_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, NULL, run_i2c_full_speed_test(), run_i2c_init_test(), run_i2c_master_transfer_test(), system_init(), and test_suite_run().

static void run_i2c_master_transfer_test ( const struct test_case test)
static

Test for I2C master transfer.

First test transfer function with stop. write to slave, read from slave and then compare the data. the slave send out the data it received, so master write and read data should be the same.

Then test transfer function without stop. write to slave, then use i2c_master_send_stop to complete writing, read from slave, compare the data. finally, use function with stop to complete the transfer.

Parameters
testCurrent test case.

References i2c_master_packet::address, i2c_master_packet::data, DATA_LENGTH, i, i2c_master_instance, i2c_master_read_packet_wait(), i2c_master_read_packet_wait_no_stop(), i2c_master_write_packet_wait(), i2c_master_write_packet_wait_no_stop(), master_read_buffer, master_write_buffer, SLAVE_ADDRESS, STATUS_OK, and test_assert_true.

Referenced by main().

struct usart_module cdc_uart_module
struct i2c_master_module i2c_master_instance
static
struct i2c_slave_module i2c_slave_instance
static
uint8_t master_read_buffer[DATA_LENGTH] = {0}
static
uint8_t master_write_buffer[DATA_LENGTH]
static
Initial value:
= {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
}

Referenced by run_i2c_full_speed_test(), and run_i2c_master_transfer_test().

uint8_t slave_buffer[DATA_LENGTH] = {0}
static