Microchip® Advanced Software Framework

mega/drivers/twi/unit_tests/unit_tests.c File Reference

Unit tests for TWI driver.

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

#include <asf.h>
#include <conf_test.h>

Functions

int main (void)
 Run TWI unit tests. 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. Master is megaRF device and the slave is on board EEPROM.Configuring EEPROM as slave is not required. More...
 
static void run_twi_master_recv_test (const struct test_case *test)
 This test requests previously sent packet to be sent from the slave, and checks that the correct packet is received by the master. Master is megaRF device and the slave is on board EEPROM.Configuring EEPROM as slave is not required. More...
 

TWI unit test definitions

#define TWI_MASTER   &TWBR
 TWI master module. More...
 
#define TWI_SPEED   125000
 TWI data transfer rate. More...
 
#define TWI_SLAVE_ADDR   0xA0
 TWI slave address. More...
 
#define SLAVE_MEM_ADDR   0x10
 TWI slave memeroy address. More...
 
#define SLAVE_MEM_ADDR_LENGTH   TWI_SLAVE_ONE_BYTE_SIZE
 TWI slave memeory address length. More...
 
#define PATTERN_TEST_LENGTH   sizeof(test_pattern)
 Test Pattern size. More...
 
const uint8_t test_pattern []
 Test Pattern. More...
 

#define PATTERN_TEST_LENGTH   sizeof(test_pattern)

Test Pattern size.

Referenced by run_twi_master_recv_test(), and run_twi_master_send_test().

#define SLAVE_MEM_ADDR   0x10

TWI slave memeroy address.

Referenced by run_twi_master_recv_test(), and run_twi_master_send_test().

#define SLAVE_MEM_ADDR_LENGTH   TWI_SLAVE_ONE_BYTE_SIZE

TWI slave memeory address length.

Referenced by main(), run_twi_master_recv_test(), and run_twi_master_send_test().

#define TWI_MASTER   &TWBR

TWI master module.

Referenced by run_twi_master_recv_test(), and run_twi_master_send_test().

#define TWI_SLAVE_ADDR   0xA0

TWI slave address.

Referenced by run_twi_master_recv_test(), and run_twi_master_send_test().

#define TWI_SPEED   125000

TWI data transfer rate.

Referenced by run_twi_master_recv_test(), and run_twi_master_send_test().

int main ( void  )

Run TWI unit tests.

Main function.

Initializes the clock system, board and serial output, then sets up the TWI unit test suite and runs it.

The SAM3X_EK, SAM3X Arduino board and SAM4C_EK use two bytes length internal address EEPROM.

References usart_rs232_options::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, NULL, run_twi_master_recv_test(), run_twi_master_send_test(), stdio_serial_init(), sysclk_init(), test_suite_run(), and usart_serial_options.

static void run_twi_master_recv_test ( const struct test_case test)
static

This test requests previously sent packet to be sent from the slave, and checks that the correct packet is received by the master. Master is megaRF device and the slave is on board EEPROM.Configuring EEPROM as slave is not required.

Parameters
testCurrent test case.

References twi_package_t::addr, twi_master_options_t::baud_reg, PATTERN_TEST_LENGTH, SLAVE_MEM_ADDR, SLAVE_MEM_ADDR_LENGTH, twi_master_options_t::speed, sysclk_enable_peripheral_clock(), sysclk_get_cpu_hz(), test_assert_true, test_pattern, TWI_CLOCK_RATE, TWI_MASTER, twi_master_init(), twi_master_read(), TWI_SLAVE_ADDR, and TWI_SPEED.

Referenced by main().

static void run_twi_master_send_test ( const struct test_case test)
static

This test sends a packet from the master, and checks that the sending happens without errors. Master is megaRF device and the slave is on board EEPROM.Configuring EEPROM as slave is not required.

Parameters
testCurrent test case.

References twi_package_t::addr, twi_master_options_t::baud_reg, PATTERN_TEST_LENGTH, SLAVE_MEM_ADDR, SLAVE_MEM_ADDR_LENGTH, twi_master_options_t::speed, STATUS_OK, sysclk_enable_peripheral_clock(), sysclk_get_cpu_hz(), test_assert_true, test_pattern, TWI_CLOCK_RATE, TWI_MASTER, twi_master_init(), twi_master_write(), TWI_SLAVE_ADDR, and TWI_SPEED.

Referenced by main().

const uint8_t test_pattern[]
Initial value:
= {
0x55,
0xA5,
0x5A,
0x77,
0x99
}

Test Pattern.