Ejemplo n.º 1
0
/*
** Function: PBX_Demo
**
** Description:
** PBX State Machine
**
** Input Parameters:
**
** Return:
** none
*/
uInt16 si3210_init (void) {
    ctrl_S spiGciObj; //spi interface object
    systemTimer_S timerObj;    //timer object
    controlInterfaceType *ProHWIntf; //hw interface
    ProslicDeviceType *ProSLICDevices[NUMBER_OF_PROSLIC]; //proslic device object
    proslicChanType_ptr arrayOfProslicChans[NUMBER_OF_CHAN]; //used for initialization only
    chanState ports[NUMBER_OF_CHAN];  //declare channel state structures
    uInt8 i=0;
    BOOLEAN keepRunning = TRUE;
    proslicChanType *pSlic;

#if (PRINTF_IS_OK)
    printf("Hang up phone!\n");
#endif
    //initialize timer
    TimerInit(&timerObj);
    ProSLIC_createControlInterface(&ProHWIntf);
    for (i=0; i<NUMBER_OF_PROSLIC; i++)
        ProSLIC_createDevice (&(ProSLICDevices[i]));
    for (i=0; i<NUMBER_OF_CHAN; i++) {
        widebandEn[i]=0;
        ProSLIC_createChannel(&(ports[i].ProObj));
        ProSLIC_SWInitChan (ports[i].ProObj,i,SI321X_TYPE, ProSLICDevices[i], ProHWIntf);
    }
    ProSLIC_setControlInterfaceCtrlObj (ProHWIntf, &spiGciObj);
    ProSLIC_setControlInterfaceReset (ProHWIntf, ctrl_ResetWrapper);
    ProSLIC_setControlInterfaceWriteRegister (ProHWIntf, ctrl_WriteRegisterWrapper);
    ProSLIC_setControlInterfaceReadRegister (ProHWIntf, ctrl_ReadRegisterWrapper);
    ProSLIC_setControlInterfaceWriteRAM (ProHWIntf, ctrl_WriteRAMWrapper);
    ProSLIC_setControlInterfaceReadRAM (ProHWIntf, ctrl_ReadRAMWrapper);
    ProSLIC_setControlInterfaceTimerObj (ProHWIntf, &timerObj);
    ProSLIC_setControlInterfaceDelay (ProHWIntf, time_DelayWrapper);
    ProSLIC_setControlInterfaceTimeElapsed (ProHWIntf, time_TimeElapsedWrapper);
    ProSLIC_setControlInterfaceGetTime (ProHWIntf, time_GetTimeWrapper);


#if (PRINTF_IS_OK)
    printf ("-------Si321x Rev ");
    printf (VERSIONSTR);
    printf (" PBX Demo Program------\n\n");
#endif


    ProSLIC_Reset((ports[0].ProObj));	//Reset the ProSLIC(s) before we begin

    //initialize SPI interface
    if (SPI_Init (&spiGciObj) ==  FALSE) {
#if (PRINTF_IS_OK)
        printf ("Cannot connect\n");
#endif
        return 0;
    }

    //Initialize the channel state for each channel
    for (i=0; i<NUMBER_OF_CHAN; i++) {
        arrayOfProslicChans[i] = (ports[i].ProObj); //create array of channel pointers (for broadcast init)
        ProSLIC_setSWDebugMode (ports[i].ProObj, 1);
    }
    ProSLIC_Init(arrayOfProslicChans,NUMBER_OF_CHAN);
    ProSLIC_RingSetup(ports[0].ProObj,USA_DEFAULT_RING);
    ProSLIC_SetLinefeedStatus(ports[0].ProObj,LF_FWD_ACTIVE);
    ProSLIC_EnableInterrupts(ports[0].ProObj);
    pSlic = (ports[0].ProObj);
    printChipDetails(pSlic);

    for (i=0; i<NUMBER_OF_CHAN; i++) {
        pSlic = (ports[i].ProObj);
        InitStateMachine(&(ports[i])); //initialize the call state machine
        ProSLIC_InitializeDialPulseDetect(&(ports[i].pulseDialData),&(ports[i].offHookTime),&(ports[i].onHookTime));
        if(pSlic->error==SPIFAIL)
            return 0;
        pSlic->deviceId->ctrlInterface->getTime_fptr(pSlic->deviceId->ctrlInterface->hTimer,&(ports[i].offHookTime));
        pSlic->deviceId->ctrlInterface->getTime_fptr(pSlic->deviceId->ctrlInterface->hTimer,&(ports[i].onHookTime));
    }


    //printMenu();
    callDoRinging (&(ports[0]));
    {
        int nTry = 20;
        uInt8 hkStat;
        do {
            ProSLIC_ReadHookStatus(ports[0].ProObj,&hkStat);
            if (hkStat != ONHOOK) {
                ProSLIC_ToneGenStop(ports[0].ProObj);
                break;
            }
            else {
                printf ("Waiting OnHOOK Event..%d\n", nTry);
            }
            nTry--;
            mdelay(300);
        } while(nTry>0);
    }


    ProSLIC_PCMTimeSlotSetup(ports[0].ProObj,ppcm_config->ts_start[0],ppcm_config->ts_start[0]);

#if	defined(PCM_LINEAR)
    callDoWideband(&(ports[0]));
#else
    callDoNarrowband(&(ports[0]));
#endif
    ProSLIC_PCMStart(ports[0].ProObj);
    ProSLIC_SetLinefeedStatus(ports[0].ProObj,LF_FWD_ACTIVE);
    //start the demo
    /*
    	while (keepRunning){
    		for (i=0;i<NUMBER_OF_CHAN;i++){
    			if (ports[i].ProObj->channelEnable){
    				channelDemo(&(ports[i]),&timerObj,&keepRunning);
    				if (ports[i].connectionWith != NOCONNECT)
    					connectionManager(&(ports[i]),&(ports[ports[i].connectionWith]));
    			}
    		}
    	}
    */
    return 1;
}
Ejemplo n.º 2
0
int ProSLIC_HWInit(void)
{
	int32 i, result = 0;
	ctrl_S spiGciObj; /* User¡¦s control interface object */
	systemTimer_S timerObj; /* User¡¦s timer object */
	chanState ports[NUMBER_OF_CHAN]; /* User¡¦s channel object, which has
									** a member defined as
									** proslicChanType_ptr ProObj;
									*/
	/* Define ProSLIC control interface object */
	controlInterfaceType *ProHWIntf;
	/* Define array of ProSLIC device objects */
	ProslicDeviceType *ProSLICDevices[NUMBER_OF_PROSLIC];
	/* Define array of ProSLIC channel object pointers */
	proslicChanType_ptr arrayOfProslicChans[NUMBER_OF_CHAN];
	/*
	** Step 1: (optional)
	** Initialize user¡¦s control interface and timer objects ¡V this
	** may already be done, if not, do it here
	*/
	/*
	** Step 2: (required)
	** Create ProSLIC Control Interface Object
	*/
	ProSLIC_createControlInterface(&ProHWIntf);
	/*
	** Step 3: (required)
	** Create ProSLIC Device Objects
	*/
	for(i=0;i<NUMBER_OF_PROSLIC;i++)
	{
		ProSLIC_createDevice(&(ProSLICDevices[i]));
	}
	/*
	** Step 4: (required)
	** Create and initialize ProSLIC channel objects
	** Also initialize array pointers to user¡¦s proslic channel object
	** members to simplify initialization process.
	*/
	for(i=0;i<NUMBER_OF_CHAN;i++)
	{
		ProSLIC_createChannel(&(ports[i].ProObj));
		ProSLIC_SWInitChan(ports[i].ProObj,i,PROSLIC_DEVICE_TYPE,
		ProSLICDevices[i/CHAN_PER_DEVICE],ProHWIntf);
		arrayOfProslicChans[i] = ports[i].ProObj;
		ProSLIC_setSWDebugMode(ports[i].ProObj,TRUE); /* optional */
	}
	/*
	** Step 5: (required)
	** Establish linkage between host objects/functions and
	** ProSLIC API
	*/
	ProSLIC_setControlInterfaceCtrlObj (ProHWIntf, &spiGciObj);
	ProSLIC_setControlInterfaceReset (ProHWIntf, ctrl_ResetWrapper);
	ProSLIC_setControlInterfaceWriteRegister (ProHWIntf, ctrl_WriteRegisterWrapper);
	ProSLIC_setControlInterfaceReadRegister (ProHWIntf, ctrl_ReadRegisterWrapper);
	ProSLIC_setControlInterfaceWriteRAM (ProHWIntf, ctrl_WriteRAMWrapper);
	ProSLIC_setControlInterfaceReadRAM (ProHWIntf, ctrl_ReadRAMWrapper);
	ProSLIC_setControlInterfaceTimerObj (ProHWIntf, &timerObj);
	ProSLIC_setControlInterfaceDelay (ProHWIntf, time_DelayWrapper);
	ProSLIC_setControlInterfaceTimeElapsed (ProHWIntf, time_TimeElapsedWrapper);
	ProSLIC_setControlInterfaceGetTime (ProHWIntf, time_GetTimeWrapper);
	ProSLIC_setControlInterfaceSemaphore (ProHWIntf, NULL);
	/*
	** Step 6: (system dependent)
	** Assert hardware Reset ¡V ensure VDD, PCLK, and FSYNC are present and stable
	** before releasing reset
	*/
	ProSLIC_Reset(ports[0].ProObj);
	
	//initialize SPI interface
    if (SPI_Init (NULL) ==  FALSE){

        printk ("Cannot connect\n");

        return 0;
    }

	/*
	** Step 7: (required)
	** Initialize device (loading of general parameters, calibrations,
	** dc-dc powerup, etc.)
	*/
	ProSLIC_Init(arrayOfProslicChans,NUMBER_OF_CHAN);
	printk("ProSLIC_Init done\n");
	for(i=0;i<NUMBER_OF_CHAN;i++)
	{
		if(arrayOfProslicChans[i]->error!=0)
		{
			printk("ProSLIC_Init[%d] ERR=%d\n",i,arrayOfProslicChans[i]->error);
			return 0;
		}
	}
	
	/*
	** Step 8: (design dependent)
	** Execute longitudinal balance calibration
	** or reload coefficients from factory LB cal
	**
	** Note: all batteries should be up and stable prior to
	** executing the lb cal
	*/
	ProSLIC_LBCal(arrayOfProslicChans,NUMBER_OF_CHAN);
	for(i=0;i<NUMBER_OF_CHAN;i++)
	{
		ProSLIC_GetLBCalResultPacked(arrayOfProslicChans[i], &result);
		printk("LBCal=0x%08X\n",result);
	}
	/*
	** Step 9: (design dependent)
	** Load custom configuration presets(generated using
	** ProSLIC API Config Tool)


	*/
	for(i=0;i<NUMBER_OF_CHAN;i++)
	{
		ProSLIC_PCMTimeSlotSetup(ports[i].ProObj,ppcm_config->ts_start[i],ppcm_config->ts_start[i]);
		
		ProSLIC_DCFeedSetup(ports[i].ProObj,DCFEED_48V_20MA);
		ProSLIC_RingSetup(ports[i].ProObj,RING_F20_45VRMS_0VDC_LPR);
#if defined(PCM_LINEAR)||defined(PCM_A2L2A)||defined(PCM_U2L2U)			
		ProSLIC_PCMSetup(ports[i].ProObj,PCM_16LIN);
#endif
#if defined(PCM_ULAW)||defined(PCM_L2U2L)		
		ProSLIC_PCMSetup(ports[i].ProObj,PCM_8ULAW);
#endif
#if defined(PCM_ALAW)			
		ProSLIC_PCMSetup(ports[i].ProObj,PCM_8ALAW);
#endif
#if defined(PCM_L2A2L)			
		ProSLIC_PCMSetup(ports[i].ProObj,PCM_8ALAW);
#endif
		ProSLIC_ZsynthSetup(ports[i].ProObj,ZSYN_600_0_0_30_0);
		ProSLIC_ToneGenSetup(ports[i].ProObj,TONEGEN_FCC_DIAL);
		
	}
	for(i=0;i<NUMBER_OF_CHAN;i++)
	{
		ProSLIC_PCMStart(ports[i].ProObj);
	}	
	for(i=0;i<NUMBER_OF_CHAN;i++)
	{
		ProSLIC_SetLinefeedStatus(ports[i].ProObj,LF_FWD_ACTIVE);
	}	
	return 1;
}