Unit tests for TWI driver.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <asf.h>
#include <conf_test.h>
Functions | |
int | main (void) |
Run TWI unit tests. More... | |
TWI unit test helper functions | |
static void | slave_process (void) |
Pointer to process data function for TWI slave. More... | |
ISR (TWIF_TWIS_vect) | |
Interrupt routine for TWI slave Calls TWI_SlaveInterruptHandler. More... | |
TWI unit test functions | |
static void | run_twi_master_send_test (const struct test_case *test) |
This test sends a packet from the master, and checks that the sending happens without errors. More... | |
static void | run_twi_slave_recv_test (const struct test_case *test) |
This test sends a packet from the master to the slave, and checks that the correct packet is received. More... | |
static void | run_twi_master_recv_test (const struct test_case *test) |
This test requests a packet to be sent from the slave, and checks that the correct packet is received by the master. More... | |
TWI unit test definitions | |
#define | TWI_MASTER TWIC |
TWI master module. More... | |
#define | TWI_MASTER_PORT PORTC |
TWI master module port. More... | |
#define | TWI_SLAVE TWIF |
TWI slave module. More... | |
#define | TWI_SPEED 50000 |
TWI data transfer rate. More... | |
#define | TWI_MASTER_ADDR 0x50 |
TWI master address. More... | |
#define | TWI_SLAVE_ADDR 0x60 |
TWI slave address. More... | |
#define | PATTERN_TEST_LENGTH sizeof(test_pattern) |
Test Pattern size. More... | |
const uint8_t | test_pattern [] |
Test Pattern. More... | |
TWI_Slave_t | slave |
TWI slave struct. More... | |
#define PATTERN_TEST_LENGTH sizeof(test_pattern) |
Test Pattern size.
Referenced by run_twi_master_recv_test(), run_twi_master_send_test(), and run_twi_slave_recv_test().
#define TWI_MASTER TWIC |
TWI master module.
Referenced by run_twi_master_recv_test(), run_twi_master_send_test(), and run_twi_slave_recv_test().
#define TWI_MASTER_ADDR 0x50 |
TWI master address.
Referenced by run_twi_master_recv_test(), run_twi_master_send_test(), and run_twi_slave_recv_test().
#define TWI_MASTER_PORT PORTC |
TWI master module port.
Referenced by main().
#define TWI_SLAVE TWIF |
TWI slave module.
Referenced by run_twi_master_recv_test(), run_twi_master_send_test(), and run_twi_slave_recv_test().
#define TWI_SLAVE_ADDR 0x60 |
TWI slave address.
Referenced by run_twi_master_recv_test(), run_twi_master_send_test(), and run_twi_slave_recv_test().
#define TWI_SPEED 50000 |
TWI data transfer rate.
Referenced by run_twi_master_recv_test(), run_twi_master_send_test(), and run_twi_slave_recv_test().
ISR | ( | TWIF_TWIS_vect | ) |
Interrupt routine for TWI slave Calls TWI_SlaveInterruptHandler.
References TWI_SlaveInterruptHandler().
int main | ( | void | ) |
Run TWI unit tests.
Initializes the clock system, board and serial output, then sets up the TWI unit test suite and runs it.
References usart_rs232_options::baudrate, board_init(), CONF_TEST_BAUDRATE, CONF_TEST_CHARLENGTH, CONF_TEST_PARITY, CONF_TEST_STOPBITS, CONF_TEST_USART, DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, run_twi_master_recv_test(), run_twi_master_send_test(), run_twi_slave_recv_test(), stdio_serial_init(), sysclk_init(), test_suite_run(), and TWI_MASTER_PORT.
|
static |
This test requests a packet to be sent from the slave, and checks that the correct packet is received by the master.
test | Current test case. |
References twi_package_t::addr_length, cpu_irq_enable, irq_initialize_vectors, PATTERN_TEST_LENGTH, TWI_Slave::receivedData, TWI_Slave::result, TWI_Slave::sendData, slave_process(), twi_options_t::speed, sysclk_enable_peripheral_clock(), sysclk_get_cpu_hz(), test_assert_true, test_pattern, TWI_BAUD, TWI_MASTER, TWI_MASTER_ADDR, twi_master_enable(), twi_master_init(), twi_master_read(), TWI_SLAVE, TWI_SLAVE_ADDR, TWI_SlaveInitializeDriver(), TWI_SlaveInitializeModule(), TWI_SPEED, TWIS_RESULT_OK, and TWIS_SEND_BUFFER_SIZE.
Referenced by main().
|
static |
This test sends a packet from the master, and checks that the sending happens without errors.
test | Current test case. |
References twi_package_t::addr_length, cpu_irq_enable, irq_initialize_vectors, PATTERN_TEST_LENGTH, slave_process(), twi_options_t::speed, STATUS_OK, sysclk_enable_peripheral_clock(), sysclk_get_cpu_hz(), test_assert_true, test_pattern, TWI_BAUD, TWI_MASTER, TWI_MASTER_ADDR, twi_master_enable(), twi_master_init(), twi_master_write(), TWI_SLAVE, TWI_SLAVE_ADDR, TWI_SlaveInitializeDriver(), TWI_SlaveInitializeModule(), and TWI_SPEED.
Referenced by main().
|
static |
This test sends a packet from the master to the slave, and checks that the correct packet is received.
test | Current test case. |
References twi_package_t::addr_length, cpu_irq_enable, irq_initialize_vectors, PATTERN_TEST_LENGTH, TWI_Slave::receivedData, TWI_Slave::result, slave_process(), twi_options_t::speed, sysclk_enable_peripheral_clock(), sysclk_get_cpu_hz(), test_assert_true, test_pattern, TWI_BAUD, TWI_MASTER, TWI_MASTER_ADDR, twi_master_enable(), twi_master_init(), twi_master_write(), TWI_SLAVE, TWI_SLAVE_ADDR, TWI_SlaveInitializeDriver(), TWI_SlaveInitializeModule(), TWI_SPEED, TWIS_RESULT_OK, and TWIS_SEND_BUFFER_SIZE.
Referenced by main().
|
static |
Pointer to process data function for TWI slave.
Referenced by run_twi_master_recv_test(), run_twi_master_send_test(), and run_twi_slave_recv_test().
TWI_Slave_t slave |
TWI slave struct.
const uint8_t test_pattern[] |
Test Pattern.
Referenced by run_twi_master_recv_test(), run_twi_master_send_test(), and run_twi_slave_recv_test().