/*
* COPYRIGHT (C) 2005-2010 BY
* GE Intelligent Platforms Embedded Systems, Inc., GOLETA, CALIFORNIA
* ALL RIGHTS RESERVED.
*
* THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND
* COPIED ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH
* THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY
* OTHER COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE
* AVAILABLE TO ANY OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE
* SOFTWARE IS HEREBY TRANSFERRED.
*
* THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT
* NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY GE
* EMBEDDED SYSTEMS.
*/
/*
* DESCRIPTION:
*
* -- SINGLE BOARD - ANY - VERSION INFO - ATLEAST 1 Port/dir
*
* This test retrieves and prints the version number for each of:
* - the FPGA
* - the driver
* - cnic.dll
* - cpcap.dll
* - afdx.dll
*
* Demonstrated functions:
* - afdx_open_board
* - afdx_close_board
* - afdx_get_version
* - afdx_get_last_error
*
* Author: Loris Degioanni, May 2006
*
*/
#include <stdio.h>
#include "AFDX-A.h"
#include "test_include.h"
char* LoadConfigFile(char *config_file_name, unsigned int *config_buff_size);
//
// Error callback.
// This function is called by the library to asynchronously notify the user
// that something went wrong inside one of its threads
//
void error_callback(char* ebuf, void* user_param)
{
//
// Print the error on the screen
//
printf("\nafdx critical error on board %d: %s\n", *(u_int32*)user_param, ebuf);
//
// This function is called in the context of the API, so now we have to notify
// the main program about the problem so that it can release its resources and
// exit cleanly.
// Since this is only a test, we strive to keep the code simple, and therefore
// we just exit brutally.
//
exit(0);
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
main(int argc, char **argv)
{
afdx_if_t *list;
int32 status = AFDX_SUCCESS;
char ebuf[AFDX_ERRBUF_SIZE];
afdx_t *handle;
char *configuration_buffer;
u_int32 config_buff_size;
char config_file_name[256];
u_int32 n_boards;
u_int32 board_number;
char **version_strings;
//
// Get the list of available boards
//
if((n_boards = afdx_get_board_list(&list, ebuf)) == 0)
{
printf("No CNIC boards found on this system");
return -1;
}
printf("Specify board number[0-%d]:", n_boards - 1);
if(scanf("%d", &board_number) != 1 || board_number > n_boards)
{
printf("Wrong value\n");
return -1;
}
//
// Free the boards list
//
afdx_free_board_list(list);
//
// Get the configuration from the file
//
configuration_buffer = LoadConfigFile("AFDX_config.xml", &config_buff_size);
if(!configuration_buffer)
{
fprintf(stderr, "unable to open configuration file %s", config_file_name);
return -1;
}
//
// Open Board
//
handle = afdx_open_board(configuration_buffer, // Configuration Buffer
config_buff_size, // Size of config buffer
0, // Group in the configuration file that we'll impersonate
board_number, // Physical board number
AFDX_OPEN_OPTIMIZE_CPU, // Flags. We don't have responsiveness requirements, so we ask for best CPU usage
error_callback, // Error callback function
&board_number, // Parameter for the error callback function. We give the board number, so that the error handler will be able to print it.
ebuf); // Error buffer
if(!handle)
{
printf("Error opening board 0 (%s)!\n", ebuf);
return -1;
}
if((version_strings = afdx_get_version(handle)) != NULL)
{
printf("\nFPGA version: %s\n", version_strings[AFDX_VERSION_FPGA]);
printf("driver version: %s\n", version_strings[AFDX_VERSION_DRIVER]);
printf("cnic library version: %s\n", version_strings[AFDX_VERSION_CNIC_API]);
printf("cpcap library version: %s\n", version_strings[AFDX_VERSION_CPCAP_API]);
printf("afdx library version: %s\n", version_strings[AFDX_VERSION_AFDX_API]);
}
else
{
printf("Error getting version information (%s)\n", afdx_get_last_error(handle));
}
// Close the board
afdx_close_board(handle);
return -1;
}
////////////////////////////////////////////////////////////////////////
// Get a configuration file name and move it to a memory buffer
////////////////////////////////////////////////////////////////////////
char* LoadConfigFile(char *config_file_name, unsigned int *config_buff_size)
{
unsigned int ReadBytes = 0;
char *configuration_buffer;
char ebuf[AFDX_ERRBUF_SIZE];
//
// Get the configuration from file
//
*config_buff_size = 0;
if(afdx_confg_load_buffer_from_file(config_file_name,
NULL,
config_buff_size,
ebuf) == AFDX_FAILURE)
{
fprintf(stderr, "unable to open configuration file %s", ebuf);
return NULL;
}
configuration_buffer = (char*)malloc(*config_buff_size);
if(!configuration_buffer)
{
fprintf(stderr, "unable to allocate configuration buffer");
return NULL;
}
if(afdx_confg_load_buffer_from_file(config_file_name,
configuration_buffer,
config_buff_size,
ebuf) == AFDX_FAILURE)
{
fprintf(stderr, "unable to open configuration file %s", ebuf);
return NULL;
}
return configuration_buffer;
}
评论0