Microchip® Advanced Software Framework

unit_tests.c File Reference

Main functions for USB host unit tests.

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

#include <stdio.h>
#include <asf.h>
#include <unit_test/suite.h>
#include <stdio_serial.h>
#include <conf_test.h>
#include "delay.h"

Macros

#define CHECK_EVENT(event, msg)
 
#define CHECK_EVENT_CONNECTION()   CHECK_EVENT( MAIN_EVENT_CONNECTION ,"Event MAIN_EVENT_CONNECTION not received")
 
#define CHECK_EVENT_DEVICE_MODE()   CHECK_EVENT( MAIN_EVENT_DEVICE_MODE ,"Event MAIN_EVENT_DEVICE_MODE not received")
 
#define CHECK_EVENT_DISCONNECTION()   CHECK_EVENT( MAIN_EVENT_DISCONNECTION ,"Event MAIN_EVENT_DISCONNECTION not received")
 
#define CHECK_EVENT_ENUM_FAIL()   CHECK_EVENT( MAIN_EVENT_ENUM_FAIL ,"Event MAIN_EVENT_ENUM_FAIL not received")
 
#define CHECK_EVENT_ENUM_HARDWARE_LIMIT()   CHECK_EVENT( MAIN_EVENT_ENUM_HARDWARE_LIMIT ,"Event MAIN_EVENT_ENUM_HARDWARE_LIMIT not received")
 
#define CHECK_EVENT_ENUM_OVERCURRENT()   CHECK_EVENT( MAIN_EVENT_ENUM_OVERCURRENT ,"Event MAIN_EVENT_ENUM_OVERCURRENT not received")
 
#define CHECK_EVENT_ENUM_SUCCESS_FULL_SPEEP()   CHECK_EVENT( MAIN_EVENT_ENUM_SUCCESS_FULL_SPEEP,"Event MAIN_EVENT_ENUM_SUCCESS_FULL_SPEEP not received")
 
#define CHECK_EVENT_ENUM_SUCCESS_HIGH_SPEEP()   CHECK_EVENT( MAIN_EVENT_ENUM_SUCCESS_HIGH_SPEEP,"Event MAIN_EVENT_ENUM_SUCCESS_HIGH_SPEEP not received")
 
#define CHECK_EVENT_ENUM_SUCCESS_LOW_SPEEP()   CHECK_EVENT( MAIN_EVENT_ENUM_SUCCESS_LOW_SPEEP ,"Event MAIN_EVENT_ENUM_SUCCESS_LOW_SPEEP not received")
 
#define CHECK_EVENT_ENUM_UNKNOW()   CHECK_EVENT( MAIN_EVENT_ENUM_UNKNOW ,"Event MAIN_EVENT_ENUM_UNKNOW not received")
 
#define CHECK_EVENT_ENUM_UNSUPPORTED()   CHECK_EVENT( MAIN_EVENT_ENUM_UNSUPPORTED ,"Event MAIN_EVENT_ENUM_UNSUPPORTED not received")
 
#define CHECK_EVENT_HOST_MODE()   CHECK_EVENT( MAIN_EVENT_HOST_MODE ,"Event MAIN_EVENT_HOST_MODE not received")
 
#define CHECK_EVENT_VBUS_NOT_PRESENT()   CHECK_EVENT( MAIN_EVENT_VBUS_NOT_PRESENT ,"Event MAIN_EVENT_VBUS_NOT_PRESENT not received")
 
#define CHECK_EVENT_VBUS_PRESENT()   CHECK_EVENT( MAIN_EVENT_VBUS_PRESENT ,"Event MAIN_EVENT_VBUS_PRESENT not received")
 
#define CHECK_EVENT_WAKEUP()   CHECK_EVENT( MAIN_EVENT_WAKEUP ,"Event MAIN_EVENT_WAKEUP not received")
 
#define MAIN_EVENT_CONNECTION   (1u<<4)
 
#define MAIN_EVENT_DEVICE_MODE   (1u<<1)
 
#define MAIN_EVENT_DISCONNECTION   (1u<<5)
 
#define MAIN_EVENT_ENUM_FAIL   (1u<<11)
 
#define MAIN_EVENT_ENUM_HARDWARE_LIMIT   (1u<<12)
 
#define MAIN_EVENT_ENUM_OVERCURRENT   (1u<<10)
 
#define MAIN_EVENT_ENUM_SUCCESS_FULL_SPEEP   (1u<<7)
 
#define MAIN_EVENT_ENUM_SUCCESS_HIGH_SPEEP   (1u<<8)
 
#define MAIN_EVENT_ENUM_SUCCESS_LOW_SPEEP   (1u<<6)
 
#define MAIN_EVENT_ENUM_UNKNOW   (1u<<13)
 
#define MAIN_EVENT_ENUM_UNSUPPORTED   (1u<<9)
 
#define MAIN_EVENT_HOST_MODE   (1u<<0)
 
#define MAIN_EVENT_VBUS_NOT_PRESENT   (1u<<3)
 
#define MAIN_EVENT_VBUS_PRESENT   (1u<<2)
 
#define MAIN_EVENT_WAKEUP   (1u<<14)
 
#define record_events()
 

Functions

static void cdc_uart_init (void)
 Initialize the USART for unit test. More...
 
int main (void)
 Run usb host core unit tests. More...
 
static void main_display_event (void)
 
void main_usb_connection_event (uhc_device_t *dev, bool b_present)
 Notify that a USB device has been connected or disconnected. More...
 
void main_usb_enum_event (uhc_device_t *dev, uhc_enum_status_t status)
 Notify the end of a USB device enumeration. More...
 
void main_usb_mode_change (bool b_host_mode)
 Notify that the USB mode was automatically switched. This is possible only when ID pin is available. More...
 
void main_usb_sof_event (void)
 Notify that a SOF has been sent (each 1 ms) More...
 
void main_usb_vbus_change (bool b_vbus_present)
 Notify that a Vbus transition has occurred Available only in USB hardware with Vbus monitoring. More...
 
void main_usb_vbus_error (void)
 Notify that a Vbus error has occurred Available only in USB hardware with Vbus monitoring. More...
 
void main_usb_wakeup_event (void)
 Notify that a USB device or the host has wake up the USB line. More...
 
static void run_test_disconnection (const struct test_case *test)
 
static void run_test_disconnection_in_suspend (const struct test_case *test)
 
static void run_test_downstream (const struct test_case *test)
 
static void run_test_downstream_disconnection (const struct test_case *test)
 
static void run_test_enum_fail (const struct test_case *test)
 
static void run_test_enum_hardwarelimit (const struct test_case *test)
 
static void run_test_enum_overcurrent (const struct test_case *test)
 
static void run_test_enum_success_fs (const struct test_case *test)
 
static void run_test_enum_success_hs (const struct test_case *test)
 
static void run_test_enum_success_ls (const struct test_case *test)
 
static void run_test_enum_unsupported (const struct test_case *test)
 
static void run_test_start_uhc (const struct test_case *test)
 
static void run_test_stop_uhc (const struct test_case *test)
 
static void run_test_upstream_fs (const struct test_case *test)
 
static void run_test_upstream_hs (const struct test_case *test)
 
static void run_test_upstream_ls (const struct test_case *test)
 

Variables

volatile uint32_t main_events = 0
 

#define CHECK_EVENT (   event,
  msg 
)
Value:
while (!main_events) { \
} \
if (!(main_events & event)) { \
test_assert_true(test, main_events & event, msg); \
main_events &= (unsigned)~event;
#define test_assert_true(test, condition,...)
Verify that condition is true.
Definition: suite.h:386
volatile uint32_t main_events
Definition: unit_tests.c:119
static void sleepmgr_enter_sleep(void)
Go to sleep in the deepest allowed mode.
Definition: sleepmgr.h:235
static void main_display_event(void)
Definition: unit_tests.c:197
#define CHECK_EVENT_DEVICE_MODE ( )    CHECK_EVENT( MAIN_EVENT_DEVICE_MODE ,"Event MAIN_EVENT_DEVICE_MODE not received")
#define CHECK_EVENT_ENUM_FAIL ( )    CHECK_EVENT( MAIN_EVENT_ENUM_FAIL ,"Event MAIN_EVENT_ENUM_FAIL not received")

Referenced by run_test_enum_fail().

#define CHECK_EVENT_ENUM_HARDWARE_LIMIT ( )    CHECK_EVENT( MAIN_EVENT_ENUM_HARDWARE_LIMIT ,"Event MAIN_EVENT_ENUM_HARDWARE_LIMIT not received")
#define CHECK_EVENT_ENUM_OVERCURRENT ( )    CHECK_EVENT( MAIN_EVENT_ENUM_OVERCURRENT ,"Event MAIN_EVENT_ENUM_OVERCURRENT not received")
#define CHECK_EVENT_ENUM_SUCCESS_FULL_SPEEP ( )    CHECK_EVENT( MAIN_EVENT_ENUM_SUCCESS_FULL_SPEEP,"Event MAIN_EVENT_ENUM_SUCCESS_FULL_SPEEP not received")
#define CHECK_EVENT_ENUM_SUCCESS_HIGH_SPEEP ( )    CHECK_EVENT( MAIN_EVENT_ENUM_SUCCESS_HIGH_SPEEP,"Event MAIN_EVENT_ENUM_SUCCESS_HIGH_SPEEP not received")
#define CHECK_EVENT_ENUM_SUCCESS_LOW_SPEEP ( )    CHECK_EVENT( MAIN_EVENT_ENUM_SUCCESS_LOW_SPEEP ,"Event MAIN_EVENT_ENUM_SUCCESS_LOW_SPEEP not received")
#define CHECK_EVENT_ENUM_UNKNOW ( )    CHECK_EVENT( MAIN_EVENT_ENUM_UNKNOW ,"Event MAIN_EVENT_ENUM_UNKNOW not received")
#define CHECK_EVENT_ENUM_UNSUPPORTED ( )    CHECK_EVENT( MAIN_EVENT_ENUM_UNSUPPORTED ,"Event MAIN_EVENT_ENUM_UNSUPPORTED not received")
#define CHECK_EVENT_HOST_MODE ( )    CHECK_EVENT( MAIN_EVENT_HOST_MODE ,"Event MAIN_EVENT_HOST_MODE not received")

Referenced by run_test_start_uhc().

#define CHECK_EVENT_VBUS_NOT_PRESENT ( )    CHECK_EVENT( MAIN_EVENT_VBUS_NOT_PRESENT ,"Event MAIN_EVENT_VBUS_NOT_PRESENT not received")
#define CHECK_EVENT_VBUS_PRESENT ( )    CHECK_EVENT( MAIN_EVENT_VBUS_PRESENT ,"Event MAIN_EVENT_VBUS_PRESENT not received")

Referenced by run_test_start_uhc().

#define CHECK_EVENT_WAKEUP ( )    CHECK_EVENT( MAIN_EVENT_WAKEUP ,"Event MAIN_EVENT_WAKEUP not received")
#define MAIN_EVENT_CONNECTION   (1u<<4)
#define MAIN_EVENT_DEVICE_MODE   (1u<<1)
#define MAIN_EVENT_DISCONNECTION   (1u<<5)
#define MAIN_EVENT_ENUM_FAIL   (1u<<11)
#define MAIN_EVENT_ENUM_HARDWARE_LIMIT   (1u<<12)
#define MAIN_EVENT_ENUM_OVERCURRENT   (1u<<10)
#define MAIN_EVENT_ENUM_SUCCESS_FULL_SPEEP   (1u<<7)
#define MAIN_EVENT_ENUM_SUCCESS_HIGH_SPEEP   (1u<<8)
#define MAIN_EVENT_ENUM_SUCCESS_LOW_SPEEP   (1u<<6)
#define MAIN_EVENT_ENUM_UNKNOW   (1u<<13)
#define MAIN_EVENT_ENUM_UNSUPPORTED   (1u<<9)
#define MAIN_EVENT_HOST_MODE   (1u<<0)
#define MAIN_EVENT_VBUS_NOT_PRESENT   (1u<<3)
#define MAIN_EVENT_VBUS_PRESENT   (1u<<2)
#define MAIN_EVENT_WAKEUP   (1u<<14)
#define record_events ( )

Referenced by run_test_start_uhc().

static void cdc_uart_init ( void  )
static
void main_usb_connection_event ( uhc_device_t dev,
bool  b_present 
)

Notify that a USB device has been connected or disconnected.

Parameters
devPointer on USB device information
b_presenttrue, if the device has been connected

References MAIN_EVENT_CONNECTION, MAIN_EVENT_DISCONNECTION, main_events, and UNUSED.

void main_usb_enum_event ( uhc_device_t dev,
uhc_enum_status_t  status 
)

Notify the end of a USB device enumeration.

Parameters
devPointer on USB device information
statusStatus of the USB enumeration

Device is bus enumerated with at least one supported interface

All interfaces are not supported by UHIs

Device power can not be supported

A problem has been occurred during USB enumeration

USB hardware can not support it. Not enough free pipes.

References MAIN_EVENT_ENUM_FAIL, MAIN_EVENT_ENUM_HARDWARE_LIMIT, MAIN_EVENT_ENUM_OVERCURRENT, MAIN_EVENT_ENUM_SUCCESS_FULL_SPEEP, MAIN_EVENT_ENUM_SUCCESS_HIGH_SPEEP, MAIN_EVENT_ENUM_SUCCESS_LOW_SPEEP, MAIN_EVENT_ENUM_UNKNOW, MAIN_EVENT_ENUM_UNSUPPORTED, main_events, uhc_device_t::speed, UHC_ENUM_FAIL, UHC_ENUM_HARDWARE_LIMIT, UHC_ENUM_OVERCURRENT, UHC_ENUM_SUCCESS, UHC_ENUM_UNSUPPORTED, UHD_SPEED_FULL, UHD_SPEED_HIGH, and UHD_SPEED_LOW.

void main_usb_mode_change ( bool  b_host_mode)

Notify that the USB mode was automatically switched. This is possible only when ID pin is available.

Parameters
b_host_modetrue, if the host mode has been selected

References MAIN_EVENT_DEVICE_MODE, MAIN_EVENT_HOST_MODE, and main_events.

void main_usb_sof_event ( void  )

Notify that a SOF has been sent (each 1 ms)

void main_usb_vbus_change ( bool  b_vbus_present)

Notify that a Vbus transition has occurred Available only in USB hardware with Vbus monitoring.

Parameters
b_vbus_presenttrue, if Vbus is high.

References MAIN_EVENT_VBUS_NOT_PRESENT, MAIN_EVENT_VBUS_PRESENT, and main_events.

void main_usb_vbus_error ( void  )

Notify that a Vbus error has occurred Available only in USB hardware with Vbus monitoring.

void main_usb_wakeup_event ( void  )

Notify that a USB device or the host has wake up the USB line.

References MAIN_EVENT_WAKEUP, and main_events.

static void run_test_disconnection ( const struct test_case test)
static

References CHECK_EVENT_CONNECTION, and CHECK_EVENT_DISCONNECTION.

Referenced by main().

static void run_test_disconnection_in_suspend ( const struct test_case test)
static

References CHECK_EVENT_DISCONNECTION, and uhc_suspend().

Referenced by main().

static void run_test_downstream ( const struct test_case test)
static

References CHECK_EVENT_WAKEUP, delay_ms, uhc_resume(), and uhc_suspend().

Referenced by main().

static void run_test_downstream_disconnection ( const struct test_case test)
static
static void run_test_enum_fail ( const struct test_case test)
static
static void run_test_enum_hardwarelimit ( const struct test_case test)
static
static void run_test_enum_overcurrent ( const struct test_case test)
static
static void run_test_enum_success_fs ( const struct test_case test)
static
static void run_test_enum_success_hs ( const struct test_case test)
static
static void run_test_enum_success_ls ( const struct test_case test)
static
static void run_test_enum_unsupported ( const struct test_case test)
static
static void run_test_start_uhc ( const struct test_case test)
static
static void run_test_stop_uhc ( const struct test_case test)
static

References main_events, test_assert_true, and uhc_stop().

Referenced by main().

static void run_test_upstream_fs ( const struct test_case test)
static
static void run_test_upstream_hs ( const struct test_case test)
static
static void run_test_upstream_ls ( const struct test_case test)
static