Microchip® Advanced Software Framework

main.c File Reference

Main functions for USB host vendor example.

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

#include <asf.h>
#include "conf_usb_host.h"
#include "ui.h"
#include "main.h"
#include <string.h>

Macros

#define MAIN_VENDOR_ISO_SIZE_1   (MAIN_VENDOR_LOOPBACK_SIZE/2)
 
#define MAIN_VENDOR_ISO_SIZE_2   ((MAIN_VENDOR_LOOPBACK_SIZE-MAIN_VENDOR_ISO_SIZE_1)/4)
 
#define MAIN_VENDOR_LOOPBACK_SIZE   (1024)
 
#define NB_TESTS   (sizeof(loop_back_tests) / sizeof(loop_back_tests[0]))
 Number of tests available. More...
 

Functions

int main (void)
 Main function. Execution starts here. More...
 
static int main_cmp_buffers (void)
 Compare output buffer with input buffer. More...
 
static bool main_control_is_available (void)
 Check if control test is available (control EP exist) More...
 
static void main_control_transfer_done (usb_add_t add, uhd_trans_status_t status, uint16_t payload_trans)
 End of setup callback. More...
 
static void main_init_buffers (void)
 Initialize test buffers. More...
 
static void main_iso_in_done (usb_add_t add, usb_ep_t ep, uhd_trans_status_t status, iram_size_t nb_transfered)
 End of ISO IN transfer callback. More...
 
static void main_iso_out_done (usb_add_t add, usb_ep_t ep, uhd_trans_status_t status, iram_size_t nb_transfered)
 End of ISO OUT transfer callback. More...
 
static bool main_loop_back_bulk (void)
 Perform loop back test on control endpoint. More...
 
static bool main_loop_back_control (void)
 Perform loop back test on control endpoint. More...
 
static bool main_loop_back_int (void)
 Perform loop back test on interrupt endpoint. More...
 
static bool main_loop_back_iso (void)
 Perform loop back test on ISO endpoint. More...
 
static void main_transfer_done (usb_add_t add, usb_ep_t ep, uhd_trans_status_t status, iram_size_t nb_transfered)
 End of transfer callback. More...
 
void main_usb_sof_event (void)
 Notify that a SOF has been sent (each 1 ms) More...
 
void main_usb_vendor_change (uhc_device_t *dev, bool b_present)
 Notify that a USB device vendor has been connected or disconnected. More...
 

Variables

static bool(* loop_back_tests [])(void)
 The test function entries. More...
 
static bool(* loop_back_tests_is_available [])(void)
 If the test is available (the endpoint is found on attached device) More...
 
static volatile bool main_b_control_busy
 The control transfer is in progress. More...
 
static volatile bool main_b_in_busy
 The (bulk/interrupt/iso) IN transfer is in progress. More...
 
static volatile bool main_b_out_busy
 The (bulk/interrupt/iso) OUT transfer is in progress. More...
 
static volatile bool main_b_usb_start_test = false
 Indicate that the test can be started. More...
 
static volatile uhd_trans_status_t main_transfer_status
 The transfer status. More...
 
static COMPILER_WORD_ALIGNED
uint8_t 
main_vendor_buf_in [MAIN_VENDOR_LOOPBACK_SIZE]
 Input buffer for vendor class test. More...
 
static COMPILER_WORD_ALIGNED
uint8_t 
main_vendor_buf_out [MAIN_VENDOR_LOOPBACK_SIZE]
 Output buffer for vendor class test. More...
 
static volatile uint32_t main_vendor_iso_in_index
 Index for ISO IN data transfer. More...
 
static volatile uint32_t main_vendor_iso_out_index
 Index for ISO OUT data transfer. More...
 

#define MAIN_VENDOR_ISO_SIZE_1   (MAIN_VENDOR_LOOPBACK_SIZE/2)

Referenced by main_loop_back_iso().

#define MAIN_VENDOR_ISO_SIZE_2   ((MAIN_VENDOR_LOOPBACK_SIZE-MAIN_VENDOR_ISO_SIZE_1)/4)

Referenced by main_iso_out_done().

#define NB_TESTS   (sizeof(loop_back_tests) / sizeof(loop_back_tests[0]))

Number of tests available.

Referenced by main().

static int main_cmp_buffers ( void  )
static

Compare output buffer with input buffer.

Returns
0 if buffer is equal, else -1

References main_vendor_buf_in, main_vendor_buf_out, and MAIN_VENDOR_LOOPBACK_SIZE.

Referenced by main().

static bool main_control_is_available ( void  )
static

Check if control test is available (control EP exist)

Returns
always true
static void main_control_transfer_done ( usb_add_t  add,
uhd_trans_status_t  status,
uint16_t  payload_trans 
)
static

End of setup callback.

Parameters
addUSB address of the setup request
statusTransfer status
payload_transNumber of data transfered during DATA phase

References main_b_control_busy, main_transfer_status, and UNUSED.

Referenced by main_loop_back_control().

static void main_init_buffers ( void  )
static

Initialize test buffers.

References main_vendor_buf_in, main_vendor_buf_out, and MAIN_VENDOR_LOOPBACK_SIZE.

Referenced by main().

static void main_iso_in_done ( usb_add_t  add,
usb_ep_t  ep,
uhd_trans_status_t  status,
iram_size_t  nb_transfered 
)
static

End of ISO IN transfer callback.

Parameters
addUSB address used by the transfer
epEndpoint address used by the transfer
statusTransfer status
nb_transferedNumber of data transfered

References main_b_in_busy, main_transfer_status, main_vendor_buf_in, main_vendor_iso_in_index, MAIN_VENDOR_LOOPBACK_SIZE, uhi_vendor_iso_in_run(), and UNUSED.

Referenced by main_loop_back_iso().

static void main_iso_out_done ( usb_add_t  add,
usb_ep_t  ep,
uhd_trans_status_t  status,
iram_size_t  nb_transfered 
)
static

End of ISO OUT transfer callback.

Parameters
addUSB address used by the transfer
epEndpoint address used by the transfer
statusTransfer status
nb_transferedNumber of data transfered

References main_b_out_busy, main_transfer_status, main_vendor_buf_out, main_vendor_iso_out_index, MAIN_VENDOR_ISO_SIZE_2, MAIN_VENDOR_LOOPBACK_SIZE, uhi_vendor_iso_out_run(), and UNUSED.

Referenced by main_loop_back_iso().

static bool main_loop_back_control ( void  )
static
static bool main_loop_back_int ( void  )
static
static void main_transfer_done ( usb_add_t  add,
usb_ep_t  ep,
uhd_trans_status_t  status,
iram_size_t  nb_transfered 
)
static

End of transfer callback.

Parameters
addUSB address used by the transfer
epEndpoint address used by the transfer
statusTransfer status
nb_transferedNumber of data transfered

References main_b_in_busy, main_b_out_busy, main_transfer_status, UNUSED, and USB_EP_DIR_IN.

Referenced by main_loop_back_bulk(), and main_loop_back_int().

void main_usb_sof_event ( void  )

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

References ui_usb_sof_event().

void main_usb_vendor_change ( uhc_device_t *  dev,
bool  b_present 
)

Notify that a USB device vendor has been connected or disconnected.

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

References main_b_usb_start_test, and UNUSED.

bool(* loop_back_tests[])(void)
static
Initial value:
= {
}
static bool main_loop_back_control(void)
Perform loop back test on control endpoint.
Definition: main.c:233
static bool main_loop_back_iso(void)
Perform loop back test on ISO endpoint.
Definition: main.c:397
static bool main_loop_back_bulk(void)
Perform loop back test on control endpoint.
Definition: main.c:285
static bool main_loop_back_int(void)
Perform loop back test on interrupt endpoint.
Definition: main.c:314

The test function entries.

Referenced by main().

bool(* loop_back_tests_is_available[])(void)
static
Initial value:
= {
}
bool uhi_vendor_bulk_is_available(void)
Check if a transfer on BULK is possible.
Definition: uhi_vendor.c:278
bool uhi_vendor_int_is_available(void)
Check if a transfer on INTERRUPT is possible.
Definition: uhi_vendor.c:306
static bool main_control_is_available(void)
Check if control test is available (control EP exist)
Definition: main.c:207
bool uhi_vendor_iso_is_available(void)
Check if a transfer on ISO is possible.
Definition: uhi_vendor.c:334

If the test is available (the endpoint is found on attached device)

Referenced by main().

volatile bool main_b_control_busy
static

The control transfer is in progress.

Referenced by main_control_transfer_done(), and main_loop_back_control().

volatile bool main_b_in_busy
static

The (bulk/interrupt/iso) IN transfer is in progress.

Referenced by main_iso_in_done(), main_loop_back_bulk(), main_loop_back_int(), main_loop_back_iso(), and main_transfer_done().

volatile bool main_b_out_busy
static

The (bulk/interrupt/iso) OUT transfer is in progress.

Referenced by main_iso_out_done(), main_loop_back_bulk(), main_loop_back_int(), main_loop_back_iso(), and main_transfer_done().

volatile bool main_b_usb_start_test = false
static

Indicate that the test can be started.

Referenced by main(), and main_usb_vendor_change().

volatile uint32_t main_vendor_iso_in_index
static

Index for ISO IN data transfer.

Referenced by main_iso_in_done(), and main_loop_back_iso().

volatile uint32_t main_vendor_iso_out_index
static

Index for ISO OUT data transfer.

Referenced by main_iso_out_done(), and main_loop_back_iso().