SAM SERCOM I2C Unit test.
Copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries.
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 DATA_LENGTH 10 |
#define SLAVE_ADDRESS 0x12 |
Referenced by run_i2c_full_speed_test(), run_i2c_init_test(), and run_i2c_master_transfer_test().
|
static |
Initialize the USART for unit test.
Initializes the SERCOM USART (SERCOM4) used for sending the unit test status to the computer via the EDBG CDC gateway.
References usart_config::baudrate, cdc_uart_module, CONF_STDIO_BAUDRATE, CONF_STDIO_MUX_SETTING, CONF_STDIO_PINMUX_PAD0, CONF_STDIO_PINMUX_PAD1, CONF_STDIO_PINMUX_PAD2, CONF_STDIO_PINMUX_PAD3, CONF_STDIO_USART, usart_config::mux_setting, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, usart_enable(), and usart_get_config_defaults().
Referenced by main().
void configure_i2c_slave_callbacks | ( | void | ) |
void i2c_slave_read_request_callback | ( | struct i2c_slave_module *const | module | ) |
References i2c_slave_packet::data, i2c_slave_packet::data_length, DATA_LENGTH, i2c_slave_write_packet_job(), slave_buffer, and slave_packet.
Referenced by configure_i2c_slave_callbacks().
void i2c_slave_write_request_callback | ( | struct i2c_slave_module *const | module | ) |
References i2c_slave_packet::data, i2c_slave_packet::data_length, DATA_LENGTH, i2c_slave_read_packet_job(), slave_buffer, and slave_packet.
Referenced by configure_i2c_slave_callbacks().
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, run_i2c_full_speed_test(), run_i2c_init_test(), run_i2c_master_transfer_test(), system_init(), and test_suite_run().
|
static |
Test full speed mode master transfer.
test function with stop in full speed mode.
test | Current test case. |
References i2c_master_packet::address, i2c_master_config::baud_rate, i2c_master_config::buffer_timeout, CONF_I2C_MASTER_MODULE, CONF_MASTER_SCK_PINMUX, CONF_MASTER_SDA_PINMUX, i2c_master_packet::data, DATA_LENGTH, I2C_MASTER_BAUD_RATE_400KHZ, i2c_master_disable(), i2c_master_enable(), i2c_master_get_config_defaults(), i2c_master_init(), i2c_master_instance, i2c_master_read_packet_wait(), i2c_master_write_packet_wait(), master_read_buffer, master_write_buffer, i2c_master_config::pinmux_pad0, i2c_master_config::pinmux_pad1, SLAVE_ADDRESS, STATUS_OK, and test_assert_true.
Referenced by main().
|
static |
Test for I2C master and slave initialization.
This test initializes the i2c master and slave and checks whether the initialization is successful or not.
test | Current test case. |
References i2c_slave_config::address, i2c_slave_config::address_mode, i2c_master_config::buffer_timeout, i2c_slave_config::buffer_timeout, CONF_I2C_MASTER_MODULE, CONF_I2C_SLAVE_MODULE, CONF_MASTER_SCK_PINMUX, CONF_MASTER_SDA_PINMUX, CONF_SLAVE_SCK_PINMUX, CONF_SLAVE_SDA_PINMUX, configure_i2c_slave_callbacks(), i2c_master_enable(), i2c_master_get_config_defaults(), i2c_master_init(), i2c_master_instance, I2C_SLAVE_ADDRESS_MODE_MASK, i2c_slave_enable(), i2c_slave_get_config_defaults(), i2c_slave_init(), i2c_slave_instance, i2c_master_config::pinmux_pad0, i2c_slave_config::pinmux_pad0, i2c_master_config::pinmux_pad1, i2c_slave_config::pinmux_pad1, SLAVE_ADDRESS, STATUS_OK, and test_assert_true.
Referenced by main().
|
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.
test | Current test case. |
References i2c_master_packet::address, i2c_master_packet::data, DATA_LENGTH, 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 |
Referenced by cdc_uart_init().
|
static |
Referenced by run_i2c_full_speed_test(), run_i2c_init_test(), and run_i2c_master_transfer_test().
|
static |
Referenced by configure_i2c_slave_callbacks(), and run_i2c_init_test().
|
static |
Referenced by run_i2c_full_speed_test(), and run_i2c_master_transfer_test().
|
static |
Referenced by run_i2c_full_speed_test(), and run_i2c_master_transfer_test().
|
static |
Referenced by i2c_slave_read_request_callback(), and i2c_slave_write_request_callback().
|
static |
Referenced by i2c_slave_read_request_callback(), and i2c_slave_write_request_callback().