Microchip® Advanced Software Framework

common/components/crypto/sha204/unit_tests/unit_tests.c File Reference

unit tests for ATSHA204 components mounted on a Security Xplained extension board

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

#include <asf.h>
#include <compiler.h>
#include <stdint.h>
#include <stdbool.h>
#include <board.h>
#include <sysclk.h>
#include <string.h>
#include <unit_test/suite.h>
#include <stdio_serial.h>
#include <wdt.h>
#include <conf_test.h>
#include <conf_atsha204.h>
#include <sha204_comm.h>

Functions

int main (void)
 This function runs ATSHA204 component unit tests. More...
 
static void test_all_devices (const struct test_case *test)
 This function runs a SHA204 Read test on all four devices. More...
 
static void test_sha204_wakeup (const struct test_case *test)
 This function runs a SHA204 Wakeup / Sleep test. More...
 

Variables

static bool success = false
 Variable to keep track of test results. More...
 

static void test_all_devices ( const struct test_case test)
static

This function runs a SHA204 Read test on all four devices.

This test wakes up the devices, reads their TWI addresses from their Config zone, and sends them back to sleep. The test fails if there are communication failures or the TWI addresses do not match.

Parameters
testcurrent test case

References READ_4_RSP_SIZE, READ_COUNT, sha204_read_parameters::rx_buffer, SHA204_BUFFER_POS_DATA, SHA204_DEVICE_COUNT, sha204_i2c_address(), SHA204_SUCCESS, SHA204_ZONE_CONFIG, sha204m_read(), sha204p_set_device_id(), sha204p_sleep(), sha204p_wakeup(), success, test_assert_true, and sha204_read_parameters::tx_buffer.

Referenced by main().

static void test_sha204_wakeup ( const struct test_case test)
static

This function runs a SHA204 Wakeup / Sleep test.

This test wakes up the device, reads its Wakeup response, and sends a Sleep command. It then sends a command and expects a response timeout to verify that the device has gone to sleep.

Parameters
testcurrent test case

References CHIP_RESET_CAUSE_BOD_CPU, CHIP_RESET_CAUSE_EXTRST, CHIP_RESET_CAUSE_OCD, CHIP_RESET_CAUSE_POR, CHIP_RESET_CAUSE_SOFT, CHIP_RESET_CAUSE_SPIKE, CHIP_RESET_CAUSE_WDT, DEVREV_COUNT, DEVREV_RSP_SIZE, reset_cause_clear_causes(), reset_cause_get_causes(), SHA204_DEVREV, SHA204_SUCCESS, sha204c_wakeup(), sha204p_send_command(), sha204p_sleep(), success, test_assert_false, test_assert_true, wdt_disable(), wdt_enable(), wdt_set_timeout_period(), and WDT_TIMEOUT_PERIOD_250CLK.

Referenced by main().

bool success = false
static

Variable to keep track of test results.