Microchip® Advanced Software Framework

drivers/ac/unit_test/unit_test.c File Reference

SAM Analog Comparator (AC) Unit test.

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

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

Macros

#define AC_SCALER_0_25_VOLT   4
 
#define AC_SCALER_0_50_VOLT   9
 
#define AC_SCALER_0_75_VOLT   14
 
#define DAC_VAL_HALF_VOLT   512
 
#define DAC_VAL_ONE_VOLT   1023
 
#define DAC_VAL_ZERO_VOLT   0
 

Functions

static void ac_user_callback (struct ac_module *const module_inst)
 AC callback function. More...
 
static void cdc_uart_init (void)
 Initialize the USART for unit test. More...
 
static void cleanup_ac_callback_mode_test (const struct test_case *test)
 Cleanup Function: AC callback mode test. More...
 
int main (void)
 Run AC unit tests. More...
 
static void run_ac_callback_mode_test (const struct test_case *test)
 AC callback mode test function. More...
 
static void run_ac_init_test (const struct test_case *test)
 Test for AC initialization. More...
 
static void run_ac_single_shot_test (const struct test_case *test)
 Test for AC comparison in single shot mode. More...
 
static void run_ac_window_mode_test (const struct test_case *test)
 AC window mode test function. More...
 
static void setup_ac_callback_mode_test (const struct test_case *test)
 Setup Function: AC callback mode test. More...
 
static void setup_ac_window_mode_test (const struct test_case *test)
 Setup Function: AC window mode test. More...
 
static void test_dac_init (void)
 Initialize the DAC for unit test. More...
 

Variables

volatile bool ac_init_success = false
 
struct ac_module ac_inst
 
struct usart_module cdc_uart_module
 
struct dac_module dac_inst
 
volatile bool interrupt_flag = false
 

#define AC_SCALER_0_25_VOLT   4
#define AC_SCALER_0_50_VOLT   9
#define AC_SCALER_0_75_VOLT   14
#define DAC_VAL_HALF_VOLT   512

Referenced by run_ac_window_mode_test().

#define DAC_VAL_ONE_VOLT   1023
#define DAC_VAL_ZERO_VOLT   0

static void ac_user_callback ( struct ac_module *const  module_inst)
static

AC callback function.

Called by AC driver on interrupt detection.

Parameters
modulePointer to the AC module (not used)

References interrupt_flag.

Referenced by setup_ac_callback_mode_test().

static void cdc_uart_init ( void  )
static
static void cleanup_ac_callback_mode_test ( const struct test_case test)
static

Cleanup Function: AC callback mode test.

This function unregisters & disables callback for edge detection.

Parameters
testCurrent test case.

References AC_CALLBACK_COMPARATOR_0, ac_disable_callback(), ac_inst, and ac_unregister_callback().

Referenced by main().

static void run_ac_callback_mode_test ( const struct test_case test)
static

AC callback mode test function.

This test changes the positive input from 0V to 1V to detect the rising edge and again from 1V to 0V to detect the falling edge.

Parameters
testCurrent test case.

References ac_init_success, dac_chan_write(), DAC_CHANNEL_0, dac_inst, DAC_VAL_ONE_VOLT, DAC_VAL_ZERO_VOLT, delay_ms, interrupt_flag, and test_assert_true.

Referenced by main().

static void run_ac_single_shot_test ( const struct test_case test)
static

Test for AC comparison in single shot mode.

This test checks the single shot comparison of the AC. 0.5V is applied to the negative input of AC from internal voltage scaler. 0V and 1V from DAC is applied to the positive input and the results are verified.

Parameters
testCurrent test case.

References AC_CHAN_CHANNEL_0, ac_chan_clear_status(), ac_chan_get_status(), ac_chan_is_ready(), AC_CHAN_STATUS_NEG_ABOVE_POS, AC_CHAN_STATUS_POS_ABOVE_NEG, AC_CHAN_STATUS_UNKNOWN, ac_chan_trigger_single_shot(), ac_init_success, ac_inst, dac_chan_write(), DAC_CHANNEL_0, dac_inst, DAC_VAL_ONE_VOLT, DAC_VAL_ZERO_VOLT, delay_ms, state, and test_assert_true.

Referenced by main().

static void run_ac_window_mode_test ( const struct test_case test)
static

AC window mode test function.

This test checks the window functionality of the AC module. Inputs are given in each region of the window (below, inside & above) and corresponding window output states are verified.

Parameters
testCurrent test case.

References AC_CHAN_CHANNEL_0, AC_CHAN_CHANNEL_1, ac_chan_clear_status(), ac_chan_trigger_single_shot(), ac_init_success, ac_inst, AC_WIN_CHANNEL_0, ac_win_clear_status(), ac_win_get_status(), ac_win_is_ready(), AC_WIN_STATUS_ABOVE, AC_WIN_STATUS_BELOW, AC_WIN_STATUS_INSIDE, AC_WIN_STATUS_UNKNOWN, dac_chan_write(), DAC_CHANNEL_0, dac_inst, DAC_VAL_HALF_VOLT, DAC_VAL_ONE_VOLT, DAC_VAL_ZERO_VOLT, delay_ms, state, and test_assert_true.

Referenced by main().

static void test_dac_init ( void  )
static

Initialize the DAC for unit test.

Initializes the DAC module used for sending the analog values to the AC during test.

References dac_chan_enable(), dac_chan_get_config_defaults(), dac_chan_set_config(), DAC_CHANNEL_0, dac_enable(), dac_get_config_defaults(), dac_init(), and dac_inst.

Referenced by main().

struct usart_module cdc_uart_module
volatile bool interrupt_flag = false