blob: d26bee070730a8e0bf55599cdf7dc37994dd7286 [file] [log] [blame]
/*
** Copyright (c) 2013-2017 by Silicon Laboratories, Inc.
**
** $Id: api_demo.c 6594 2017-06-30 22:51:35Z mjmourni $
**
** This file contains proprietary information.
** No dissemination allowed without prior written permission from
** Silicon Laboratories, Inc.
**
** File Description:
**
** This file contains example implementation and use of ProSLIC API
**
*/
////#include "stdio.h"
#include "api_demo.h"
#include "user_intf.h"
#include "spi_main.h"
#include "SLICApp.h"
#ifdef MLT_ENABLED
#include "proslic_mlt.h"
#endif
/*
** Device Specific Includes
*/
#ifdef SI3217X
#include "si3217x.h"
#include "vdaa.h"
extern Si3217x_General_Cfg Si3217x_General_Configuration;
#endif
#ifdef SI_ENABLE_LOGGING
#include <stdio.h>
FILE *SILABS_LOG_FP;
FILE *std_out;
int is_stdout = 1;
#endif
#ifdef LUA
#include <lua_util.h>
#endif
/*****************************************************************************************************/
void change_channel(demo_state_t *pState)
{
int i,m;
demo_port_t *cPort;
if(pState->totalChannelCount == 1)
{
printf("Only 1 channel supported, aborting request.\n");
return;
}
do
{
printf("\nPlease Enter Channel: (0->%d) %s", (pState->totalChannelCount-1),
PROSLIC_PROMPT);
fflush(stdin);
m = get_int(0, (pState->totalChannelCount-1));
}
while( m >= pState->totalChannelCount);
pState->currentChannel = m;
for(i = 0; i < DEMO_PORT_COUNT; i++)
{
cPort = &(pState->ports[i]);
if(m < ((cPort->numberOfChan) + (cPort->channelBaseIndex) ) )
{
pState->currentPort = cPort;
pState->currentChanPtr = cPort->channelPtrs[(m - (cPort->channelBaseIndex) ) ];
return;
}
}
}
demo_state_t demo_state; /* declare channel state structures */
si_hctrl_t demo_spiGciObj; /* Link to host spi obj (os specific) */
systemTimer_S demo_timerObj; /* Link to host timer obj (os specific)*/
controlInterfaceType demo_ProHWIntf; /* proslic hardware interface object */
demo_port_t *demo_ports; /* declare channel state structures */
/*****************************************************************************************************/
int API_Demo(void)
{
int i = 0;
int rc = 0;
//Link with the global pointer
SLICAPP_pState = &demo_state;
SETUP_STDOUT_FLUSH;
#ifdef SI_ENABLE_LOGGING
std_out = stdout;
#ifdef ENABLE_INITIAL_LOGGING
SILABS_LOG_FP = fopen("api_demo.log", "w");
if(SILABS_LOG_FP == NULL)
{
perror("Failed to open log file - aborting");
rc = -2;
return rc;
}
is_stdout = 0;
#else
SILABS_LOG_FP = stdout;
#endif
#endif
demo_ports = SIVOICE_CALLOC(sizeof(demo_port_t), DEMO_PORT_COUNT);
if(demo_ports == NULL)
{
printf("%s Failed to allocate memory\n", LOGPRINT_PREFIX);
rc = -1;
return rc;
}
demo_state.currentChannel = 0;
demo_state.totalChannelCount = 0;
demo_state.ports = demo_ports;
demo_state.currentPort = demo_ports;
////PROSLIC_CLS;
printf("ProSLIC API Implementation Demo");
printf("\nCopyright 2013-2017, Silicon Labs\n");
printf("API Version %s\n", ProSLIC_Version());
#ifdef MLT_ENABLED
printf("MLT Version: %s\n", ProSLIC_mlt_version());
#endif
/*
** --------------------------------------------------------------------
** Initialize host SPI interface object (optional - platform dependent)
** --------------------------------------------------------------------
*/
printf("\n%sConnecting to Host -> %s ...\n", LOGPRINT_PREFIX, VMB_INFO);
if(SPI_Init(&demo_spiGciObj))
{
printf("%sCannot connect to %s\n",LOGPRINT_PREFIX, VMB_INFO);
rc = -1;
goto API_DEMO_EXIT_SIVOICE_FREE;
}
/*
** ----------------------------------------------------------------------
** Initialize host TIMER interface object (optional - platform dependent)
** ----------------------------------------------------------------------
*/
printf("%sInitializing system timer...\n", LOGPRINT_PREFIX);
TimerInit(&demo_timerObj);
LOGPRINT("%sLinking function pointers...\n", LOGPRINT_PREFIX);
initControlInterfaces(&demo_ProHWIntf, &demo_spiGciObj, &demo_timerObj);
/*
** In theory, you could have multiple DEMO_PORTs aka evb boards/chipset combos.
** This feature has not been tested well enough at this point...
*/
for(i = 0; i < DEMO_PORT_COUNT; i++)
{
demo_init_port_info(&demo_ports[i], i);
/* We assume in our sivoice_init_port_info that we have a 178/179 - which
is a SLIC + VDAA device, 2 ports, if the VDAA support is disabled,
stop here and not allocate/init the 2nd port.
*/
#if defined(SI3217X) && !defined(VDAA_SUPPORT)
/* Subtract from #chan the device count since we doubled it */
demo_ports[i].numberOfChan -= demo_ports[i].numberOfDevice;
demo_ports[i].chanPerDevice--;
#endif
if(demo_alloc(&demo_ports[i], &(demo_state.totalChannelCount),
&demo_ProHWIntf) != RC_NONE)
{
LOGPRINT("%sFailed to allocate for port %d - exiting program.\n",
LOGPRINT_PREFIX, i);
rc = -2;
goto API_DEMO_EXIT_SIVOICE_FREE;
}
#if defined(SI3217X) && defined(VDAA_SUPPORT)
/* Check if we do have a 178/179 - we assume the 1st device is just like the rest... */
if(Si3217x_General_Configuration.daa_cntl!= 0)
{
uInt8 reg_data;
reg_data = SiVoice_ReadReg(*(demo_ports->channelPtrs), PROSLIC_REG_ID);
if( (( (reg_data>>3) & 7) != 6)
&& ( (reg_data & 0xF) == 1 ) )
{
demo_ports->numberOfChan -= SI3217XB_NUMBER_OF_DEVICE;
demo_ports->chanPerDevice--;
demo_state.totalChannelCount -= SI3217XB_NUMBER_OF_DEVICE;
}
}
else
{
demo_ports->numberOfChan -= SI3217XB_NUMBER_OF_DEVICE;
demo_ports->chanPerDevice--;
demo_state.totalChannelCount -= SI3217XB_NUMBER_OF_DEVICE;
}
#endif
printf("\tNumber of devices: %d Number of channels: %d\n",
demo_ports[i].numberOfDevice,
demo_ports[i].numberOfChan);
if( (demo_init_devices(&demo_ports[i]) != 0)
|| ( demo_load_presets(&demo_ports[i]) != 0)
|| (demo_set_chan_state(&demo_ports[i]) ) )
{
rc = -3;
goto API_DEMO_EXIT_demo_free;
}
}
demo_state.currentChanPtr = demo_ports->channels;
printf("%s Initialization Complete\n", LOGPRINT_PREFIX);
#ifdef LUA
init_lua(&demo_state);
#endif
if( demo_state.currentChanPtr->channelType != DAA)
{
#ifdef NOFXS_SUPPORT
printf("Detected a FXS in a FXO only build!\n");
rc = -4;
goto API_DEMO_EXIT_demo_shutdown;
#else
/*
** Main Demo Menu
*/
#ifdef PROSLIC_API_TEST
proslic_main_menu(&demo_state);
#else
extern void SLICAPP_Main(void);
SLICAPP_Main();
#endif
#endif
}
#ifdef VDAA_SUPPORT
else
{
daa_main_menu(&demo_state);
}
#endif
API_DEMO_EXIT_demo_shutdown:
for(i = 0; i < DEMO_PORT_COUNT; i++)
{
demo_shutdown(&demo_ports[i]);
}
SiVoice_Reset(demo_state.currentChanPtr);
API_DEMO_EXIT_demo_free:
for(i = 0; i < DEMO_PORT_COUNT; i++)
{
demo_free(&demo_ports[i]);
}
API_DEMO_EXIT_SIVOICE_FREE:
SIVOICE_FREE(demo_ports);
demo_ports = (demo_port_t *)NULL;
return rc;
}