Ejemplo n.º 1
0
/*
** Function: powerAlarm (transition)
**
** Description:
** called when power alarm detected
**
** Input Parameters:
** pState: pointer to channel state data structure
**
** Return:
**
*/
static void powerAlarm (chanState *pState) {
    //implement recovery from alarm
#if (PRINTF_IS_OK)
    printf ("Power Alarm!\n");
#endif
    pState->powerAlarmCount++;
    pState->currentState=OnHook;
    if (pState->powerAlarmCount < 6)
        ProSLIC_SetLinefeedStatus(pState->ProObj,LF_FWD_ACTIVE); //Go Forward active
    else {
        ProSLIC_SetLinefeedStatus(pState->ProObj,LF_OPEN);
#if(DEBUG)
        LOGPRINT ("Too many power alarms!\n");
#endif
    }
}
Ejemplo n.º 2
0
/* *********************************** */
int ProSLIC_testInRinging(proslicChanType *pProslic, proslicTestInObjType *pTstin)
{
uInt8 ringcon_save,enhance_save;
int32 vtr[MAX_RINGING_SAMPLES];
int i;
uInt8 lf;
uInt32 rtper_save, ringfr_save,ringamp_save,ringof_save,rtacth_save,rtdcth_save;
ProSLIC_DCfeed_Cfg dcfeedCfg;

	/* Valid device check */
	if(TSTIN_INVALID_PART_NUM)
	{
		return RC_UNSUPPORTED_FEATURE;
	}

	/* Check if enabled */
	if(!pTstin->ringingTest.testEnable)
	{
		return RC_TEST_DISABLED;
	}

	/* Verify line not in use */
	if(ProSLIC_ReadReg(pProslic,34) & 0x02)  /* LCR */
	{
#ifdef ENABLE_DEBUG
		if(pProslic->debugMode)
		{
			LOGPRINT("\nProSLIC : TestIn : Ringing : Line in Use\n");
		}
#endif
		if(pTstin->ringingTest.abortIfLineInUse)
		{
			return RC_LINE_IN_USE;
		}
	}

	/* Invalidate last test results */
	pTstin->ringingTest.testDataValid = TSTIN_RESULTS_INVALID;

	/* Check sample size/rate */
	if(pTstin->ringingTest.numSamples > MAX_RINGING_SAMPLES)
		pTstin->ringingTest.numSamples = MAX_RINGING_SAMPLES;

	if(pTstin->ringingTest.sampleInterval > MAX_RINGING_SAMPLE_INTERVAL)
		pTstin->ringingTest.sampleInterval = MAX_RINGING_SAMPLE_INTERVAL;

	if(pTstin->ringingTest.sampleInterval < MIN_RINGING_SAMPLE_INTERVAL)
		pTstin->ringingTest.sampleInterval = MIN_RINGING_SAMPLE_INTERVAL;

	/* Disable Powersave */
	enhance_save = ProSLIC_ReadReg(pProslic,47);
	ProSLIC_WriteReg(pProslic,47,0x20);
	Delay(pProTimer,10);

	/* Disable ring cadencing */
	ringcon_save = ProSLIC_ReadReg(pProslic,38); /* RINGCON */
	ProSLIC_WriteReg(pProslic,38,ringcon_save&0xE7); /* RINGCON */

	/* Must enter ringing through active state */
	lf = ProSLIC_ReadReg(pProslic,30);  /* LINEFEED */
	ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
	Delay(pProTimer,20); /* settle */

	/* Start ringing */
	ProSLIC_SetLinefeedStatus(pProslic,LF_RINGING);
	Delay(pProTimer,500);

	/* Verify Ring Started */
	if(ProSLIC_ReadReg(pProslic,30) != 0x44)
	{
		ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
		ProSLIC_SetLinefeedStatus(pProslic,LF_OPEN);
        ProSLIC_WriteReg(pProslic,38,ringcon_save);
		ProSLIC_WriteReg(pProslic,47,enhance_save);
		ProSLIC_SetLinefeedStatus(pProslic,lf);
#ifdef ENABLE_DEBUG
		if(pProslic->debugMode)
		{
			LOGPRINT("ProSLIC : TestIn : Ringing : Ring Start Fail\n");
		}
#endif
		pTstin->ringingTest.testResult = RC_TEST_FAILED;
		return RC_RING_START_FAIL;
	}

	/* Capture samples */
	pTstin->ringingTest.ringingVdc.value = 0;
	for(i=0;i<pTstin->ringingTest.numSamples;i++)
	{
		vtr[i] = ProSLIC_ReadMADCScaled(pProslic,69,0); /* VDIFF_FILT */
		pTstin->ringingTest.ringingVdc.value += vtr[i];
#ifdef ENABLE_DEBUG
		if(pProslic->debugMode)
		{
			LOGPRINT("ProSLIC : TestIn : Ringing : Vtr[%d] = %d\n",i,vtr[i]);
		}
#endif
		Delay(pProTimer,pTstin->ringingTest.sampleInterval);
	}
	
	/* Restore linefeed */
	ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
	Delay(pProTimer,20);

    /* Process Results */
	pTstin->ringingTest.ringingVdc.value /= pTstin->ringingTest.numSamples;
	for(i=0;i<pTstin->ringingTest.numSamples;i++)
	{
		vtr[i] -= pTstin->ringingTest.ringingVdc.value;
		pTstin->ringingTest.ringingVac.value += ((vtr[i]/100L) * (vtr[i]/100L));
	}


	pTstin->ringingTest.ringingVac.value /= pTstin->ringingTest.numSamples;
	pTstin->ringingTest.ringingVac.value = Isqrt32(pTstin->ringingTest.ringingVac.value);
	pTstin->ringingTest.ringingVac.value *= 100L;

	pTstin->ringingTest.testResult = RC_TEST_PASSED;
	pTstin->ringingTest.testResult |= logTest(pProslic,&(pTstin->ringingTest.ringingVdc),"Ringing : VDC");
	pTstin->ringingTest.testResult |= logTest(pProslic,&(pTstin->ringingTest.ringingVac),"Ringing : VAC");
	/*
	** Optional Ringtrip Test 
	*/

	if(pTstin->ringingTest.ringtripTestEnable == RTP_CHECK_ENABLED)
	{
		/* Setup low voltage linefeed so low level ringing may be used */
		ProSLIC_SetLinefeedStatus(pProslic,LF_OPEN);
		storeDCFeedPreset(pProslic,&dcfeedCfg);
		ProSLIC_DCFeedSetupCfg(pProslic,ringtripTestDCFeedPreset,0);

		/* Optional Ringtrip Test (modified ringer settings to use test load to trip) */
		rtper_save = ProSLIC_ReadRAM(pProslic,755);
		ringfr_save = ProSLIC_ReadRAM(pProslic,844);
		ringamp_save = ProSLIC_ReadRAM(pProslic,845);
		ringof_save = ProSLIC_ReadRAM(pProslic,843);
		rtacth_save = ProSLIC_ReadRAM(pProslic,848);
		rtdcth_save = ProSLIC_ReadRAM(pProslic,847);

		ProSLIC_WriteRAM(pProslic,755,0x50000L);  /* RTPER */
		ProSLIC_WriteRAM(pProslic,844,0x7EFE000L);/* RINGFR */
		ProSLIC_WriteRAM(pProslic,845,0xD6307L);  /* RINGAMP */
		ProSLIC_WriteRAM(pProslic,843,0x0L);      /* RINGOF */
		ProSLIC_WriteRAM(pProslic,848,0x7827FL);  /* RTACTH */
		ProSLIC_WriteRAM(pProslic,847,0xFFFFFFFL);/* RTDCTH */

		/* Start ringing from active state */
		ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
		Delay(pProTimer,20);
		ProSLIC_SetLinefeedStatus(pProslic,LF_RINGING);
		Delay(pProTimer,200);

			/* Verify Ring Started */
		if(ProSLIC_ReadReg(pProslic,30) != 0x44)
		{
			ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
			ProSLIC_SetLinefeedStatus(pProslic,LF_OPEN);
			ProSLIC_WriteReg(pProslic,38,ringcon_save);
			ProSLIC_WriteReg(pProslic,47,enhance_save);
			ProSLIC_SetLinefeedStatus(pProslic,lf);
#ifdef ENABLE_DEBUG
			if(pProslic->debugMode)
			{
				LOGPRINT("ProSLIC : TestIn : Ringtrip : Ring Start Fail\n");
			}
#endif
			pTstin->ringingTest.testResult=RC_TEST_FAILED;
			return RC_RING_START_FAIL;
		}

		/* Connect Test Load to cause ringtrip */
	    setInternalTestLoad(pProslic,1);
		Delay(pProTimer,200);

		/* Check for RTP */
		if(ProSLIC_ReadReg(pProslic,34) & 0x01)  /* LCRRTP */
		{
			pTstin->ringingTest.rtpStatus = 1;
		    pTstin->ringingTest.testResult |= RC_TEST_PASSED;
		}
		else
		{
			pTstin->ringingTest.rtpStatus = 0;
			pTstin->ringingTest.testResult |= RC_TEST_FAILED;
			ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
		}		
	    setInternalTestLoad(pProslic,0);
		Delay(pProTimer,20);

		logStatus(pProslic,pTstin->ringingTest.rtpStatus,"Ringing : RTP");

		/* Restore DC Feed */
		ProSLIC_DCFeedSetupCfg(pProslic,&dcfeedCfg,0);

		/* Restore Ring Settings */
		ProSLIC_WriteRAM(pProslic,755,rtper_save);/* RTPER */
		ProSLIC_WriteRAM(pProslic,844,ringfr_save);/*RINGFR */
		ProSLIC_WriteRAM(pProslic,845,ringamp_save); /* RINGAMP */
		ProSLIC_WriteRAM(pProslic,843,ringof_save); /* RINGOF */
		ProSLIC_WriteRAM(pProslic,848,rtacth_save);/* RTACTH */
		ProSLIC_WriteRAM(pProslic,847,rtdcth_save);/* RTDCTH */

	}/* end of ringtrip test 

	/* Restore Linefeed */
	ProSLIC_SetLinefeedStatus(pProslic,lf);

	/* Restore RINGCON and ENHANCE */
	ProSLIC_WriteReg(pProslic,38,ringcon_save); 
    ProSLIC_WriteReg(pProslic,47,enhance_save);  

	pTstin->ringingTest.testDataValid = TSTIN_RESULTS_VALID;

	return (pTstin->ringingTest.testResult);
}
Ejemplo n.º 3
0
/* *********************************** */
int ProSLIC_testInAudio(proslicChanType *pProslic, proslicTestInObjType *pTstin)
{
uInt8 enhanceRegSave;
uInt8 lf;
int32 data;
int32 gainMeas1,gainMeas2;
int32 gainMeas3 = 0;
ProSLIC_audioGain_Cfg gainCfg;
int32 Pin = -3980;   /* -10dBm + 6.02dB (since OHT w/ no AC load) */

	/* Valid device check */
	if(TSTIN_INVALID_PART_NUM)
	{
		return RC_UNSUPPORTED_FEATURE;
	}

	/* Check if enabled */
	if(!pTstin->audioTest.testEnable)
	{
		return RC_TEST_DISABLED;
	}

	/* Invalidate last test results */
	pTstin->audioTest.testDataValid = TSTIN_RESULTS_INVALID;

	/* Verify line not in use */
	if(ProSLIC_ReadReg(pProslic,34) & 0x02)  /* LCR */
	{
#ifdef ENABLE_DEBUG
		if(pProslic->debugMode)
		{
			LOGPRINT("\nProSLIC : TestIn : Audio : Line in Use\n");
		}
#endif
		if(pTstin->audioTest.abortIfLineInUse == ABORT_LIU_ENABLED)
		{
			return RC_LINE_IN_USE;
		}
	}

	/* Disable Powersave */
	enhanceRegSave = ProSLIC_ReadReg(pProslic,47);
	ProSLIC_WriteReg(pProslic,47,0x20);
	Delay(pProTimer,10);


	/* Setup Audio Filter, enable audio in OHT */
	lf = ProSLIC_ReadReg(pProslic,30);  /* LINEFEED */
	ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
	Delay(pProTimer,20); /* settle */
	setup1kHzBandpass(pProslic);
	ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_OHT);

	/* Setup osc1 for 1kHz -10dBm tone, disable hybrid, enable filters */
	ProSLIC_WriteRAM(pProslic,26,0x5A80000L); /* OSC1FREQ */
	ProSLIC_WriteRAM(pProslic,27,0x5D8000L);  /* OSC1AMP */
	ProSLIC_WriteReg(pProslic,48,0x02);       /* OMODE */
	ProSLIC_WriteReg(pProslic,49,0x01);       /* OCON */
	ProSLIC_WriteReg(pProslic,44,0x10);       /* DIGCON */
	ProSLIC_WriteReg(pProslic,71,0x10);       /* DIAG1 */

	/* Settle */
	Delay(pProTimer,800);

	/* Read first gain measurement (Gtx + Grx + Gzadj) */
	gainMeas1 = readAudioDiagLevel(pProslic,pTstin->audioTest.zerodBm_mVpk);

	/* Bypass TXACHPF and set TXACEQ to unity */
	gainCfg.acgain = ProSLIC_ReadRAM(pProslic,544);  /* TXACGAIN */
	gainCfg.aceq_c0 = ProSLIC_ReadRAM(pProslic,540); /* TXACEQ_C0 */
	gainCfg.aceq_c1 = ProSLIC_ReadRAM(pProslic,541); /* TXACEQ_C1 */
	gainCfg.aceq_c2 = ProSLIC_ReadRAM(pProslic,542); /* TXACEQ_C2 */
	gainCfg.aceq_c3 = ProSLIC_ReadRAM(pProslic,543); /* TXACEQ_C3 */
	ProSLIC_WriteRAM(pProslic,544,0x8000000L); 
	ProSLIC_WriteRAM(pProslic,543,0x0L);
	ProSLIC_WriteRAM(pProslic,542,0x0L);
	ProSLIC_WriteRAM(pProslic,541,0x0L);
	ProSLIC_WriteRAM(pProslic,540,0x8000000L);
	ProSLIC_WriteReg(pProslic,44,0x18);

	/* Settle */
	Delay(pProTimer,800);

	/* Read second level measurement (RX level only) */
	gainMeas2 = readAudioDiagLevel(pProslic,pTstin->audioTest.zerodBm_mVpk);

	/* Adjust txgain if TXACGAIN wasn't unity during gainMeas1 */
	if(gainCfg.acgain != 0x8000000L)
	{
		data = (gainCfg.acgain*10)/134217;
		gainMeas3 = dBLookup(data);
	}

	/* Computations */
	pTstin->audioTest.rxGain.value = gainMeas2 - Pin;
	pTstin->audioTest.txGain.value = gainMeas1 - gainMeas2 + gainMeas3;
	
#ifdef ENABLE_DEBUG
	if(pProslic->debugMode)
	{
		LOGPRINT("ProSLIC : TestIn : Audio : gainMeas1 = %d\n", gainMeas1);
		LOGPRINT("ProSLIC : TestIn : Audio : gainMeas2 = %d\n", gainMeas2);
		LOGPRINT("ProSLIC : TestIn : Audio : gainMeas3 = %d\n", gainMeas3);
	}
#endif
	pTstin->audioTest.testResult = RC_TEST_PASSED;
	pTstin->audioTest.testResult |= logTest(pProslic,&(pTstin->audioTest.rxGain),"RX Path Gain");
	pTstin->audioTest.testResult |= logTest(pProslic,&(pTstin->audioTest.txGain),"TX Path Gain");



	/*
	** Restore 
	*/

	/* Need to store/restore all modified reg/RAM */
	ProSLIC_WriteRAM(pProslic,544,gainCfg.acgain); 
	ProSLIC_WriteRAM(pProslic,540,gainCfg.aceq_c0);
	ProSLIC_WriteRAM(pProslic,541,gainCfg.aceq_c1);
	ProSLIC_WriteRAM(pProslic,542,gainCfg.aceq_c2);
	ProSLIC_WriteRAM(pProslic,543,gainCfg.aceq_c3);

	ProSLIC_WriteReg(pProslic,71,0x0);  /* DIAG1 */
	ProSLIC_WriteReg(pProslic,44,0x0);  /* DIGCON */
	ProSLIC_WriteReg(pProslic,48,0x0);  /* OMODE */
	ProSLIC_WriteReg(pProslic,49,0x0);  /* OCON */
	ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
	ProSLIC_WriteReg(pProslic,47,enhanceRegSave);
	ProSLIC_SetLinefeedStatus(pProslic,lf);

	/* Validate last test results */
	pTstin->audioTest.testDataValid = TSTIN_RESULTS_VALID;

	return pTstin->audioTest.testResult;
}
Ejemplo n.º 4
0
int CustomerVoice_HWInit() 
{
	int i; 
ctrl_S  spiGciObj;              /* User¡¦s control interface object */ 
systemTimer_S timerObj;         /* User¡¦s timer object */ 

 
/* Define Voice control interface object */ 
SiVoiceControlInterfaceType *VoiceHWIntf; 
 
/* Define array of Voice device objects */ 
SiVoiceDeviceType *VoiceDevices[NUMBER_OF_DEVICES]; 
 
/* Define array of ProSLIC channel object pointers */ 
SiVoiceChanType_ptr arrayOfVoiceChans[NUMBER_OF_CHAN]; 

    ProSLIC_dbgRingCfg ringCfg; 
    uInt8 hsState;  
    /* 
    ** 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 Voice Control Interface Object 
    */  
    SiVoice_createControlInterface(&VoiceHWIntf); 
 
    /* 
    ** Step 3: (required) 
    ** Create Voice Device Objects 
    */ 
    for(i=0;i<NUMBER_OF_DEVICES;i++) 
    { 
        SiVoice_createDevice(&(VoiceDevices[i])); 
    } 
 
    /* 
    ** Step 4: (required) 
    ** Create and initialize Voice 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++) 
    { 
        SiVoice_createChannel(&(ports[i].VoiceObj)); 
        SiVoice_SWInitChan(ports[i].VoiceObj,i,VOICE_DEVICE_TYPE, 
                           VoiceDevices[i/CHAN_PER_DEVICE],VoiceHWIntf); 
        arrayOfVoiceChans[i] = ports[i].VoiceObj; 
        SiVoice_setSWDebugMode(ports[i].VoiceObj,TRUE);  /* optional */ 
        //ProSLIC_setSWDebugMode(ports[i].ProObj,TRUE); /* optional */
    } 
 
    /* 
    ** Step 5: (required) 
    ** Establish linkage between host objects/functions and 
    ** API  
    */ 
    SiVoice_setControlInterfaceCtrlObj (VoiceHWIntf, &spiGciObj); 
    SiVoice_setControlInterfaceReset (VoiceHWIntf, ctrl_ResetWrapper); 
    SiVoice_setControlInterfaceWriteRegister (VoiceHWIntf, ctrl_WriteRegisterWrapper); 
    SiVoice_setControlInterfaceReadRegister (VoiceHWIntf, ctrl_ReadRegisterWrapper);   
    SiVoice_setControlInterfaceWriteRAM (VoiceHWIntf, ctrl_WriteRAMWrapper); 
    SiVoice_setControlInterfaceReadRAM (VoiceHWIntf, ctrl_ReadRAMWrapper); 
    SiVoice_setControlInterfaceTimerObj (VoiceHWIntf, &timerObj); 
    SiVoice_setControlInterfaceDelay (VoiceHWIntf, time_DelayWrapper); 
    SiVoice_setControlInterfaceTimeElapsed (VoiceHWIntf, time_TimeElapsedWrapper); 
    SiVoice_setControlInterfaceGetTime (VoiceHWIntf, time_GetTimeWrapper); 
    SiVoice_setControlInterfaceSemaphore (VoiceHWIntf, NULL); 
/* 
    ** Step 6: (system dependent) 
    ** Assert hardware Reset ¡V ensure VDD, PCLK, and FSYNC are present and stable 
    ** before releasing reset 
    */ 
    SiVoice_Reset(ports[0].VoiceObj);    
 
    /* 
    ** Step 7: (required) 
    ** Initialize channels (loading of general parameters, calibrations,  
    **   dc-dc powerup, etc.) 
    ** Note that VDAA channels are ignored by ProSLIC_Init and ProSLIC  
    ** channels are ignored by Vdaa_Init. 
    */ 
    ProSLIC_Init(arrayOfVoiceChans,NUMBER_OF_CHAN);
    for(i=0;i<NUMBER_OF_CHAN;i++)
	{
		if(arrayOfVoiceChans[i]->error!=0)
		{
			printk("ProSLIC_Init[%d] ERR=%d\n",i,arrayOfVoiceChans[i]->error);
			return 0;
		}
	}
#if 0
    Vdaa_Init(arrayOfVoiceChans,NUMBER_OF_CHAN); 
#endif	
 
    /* 
    ** 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(arrayOfVoiceChans,NUMBER_OF_CHAN); 
 
     
    /* 
    ** Step 9: (design dependent) 
    ** Load custom configuration presets(generated using 
    ** ProSLIC API Config Tool) 
    */ 
    for(i=0;i<NUMBER_OF_CHAN;i++) 
    { 
        ProSLIC_DCFeedSetup(ports[i].VoiceObj,DCFEED_48V_20MA); 
        ProSLIC_RingSetup(ports[i].VoiceObj,RING_F20_45VRMS_0VDC_LPR); 
        ProSLIC_PCMSetup(ports[i].VoiceObj,PCM_DEFAULT_CONFIG); 
        ProSLIC_ZsynthSetup(ports[i].VoiceObj,ZSYN_600_0_0); 
        ProSLIC_ToneGenSetup(ports[i].VoiceObj,TONEGEN_FCC_DIAL); 
        ProSLIC_PCMTimeSlotSetup(ports[i].VoiceObj,CONFIG_PCM_TS_START+i*16,CONFIG_PCM_TS_START+i*16);
    #if 0    
        Vdaa_CountrySetup(ports[i].VoiceObj,COU_USA); 
        Vdaa_HybridSetup(ports[i].VoiceObj,HYB_600_0_0_500FT_24AWG); 
        Vdaa_PCMSetup(ports[i].VoiceObj,PCM_LINEAR16); 
 	Vdaa_PCMTimeSlotSetup(ports[i].VoiceObj,CONFIG_PCM_TS_START+i*16,CONFIG_PCM_TS_START+i*16);
    #endif
    } 
     
    /* 
    ** END OF TYPICAL INITIALIZATION  
    */ 
	for(i=0;i<NUMBER_OF_CHAN;i++)
	{
		ProSLIC_PCMStart(ports[i].VoiceObj);
	}	
	
    
     /*  
    ** EXAMPLE: Change ALL ProSLIC ports to FWD_ACTIVE linefeed state 
    */ 
	for(i=0;i<NUMBER_OF_CHAN;i++) 
	{ 
		ProSLIC_SetLinefeedStatus(ports[i].VoiceObj,LF_FWD_ACTIVE); 
	} 
	#if 0
	
	ProSLIC_SetDAAEnable(ports[1].VoiceObj, 1);
	for(i=0;i<NUMBER_OF_CHAN;i++)
	{
		Vdaa_PCMStart(ports[i].VoiceObj);
	}
	
	
	hsState = Vdaa_GetHookStatus(ports[1].VoiceObj);
	if(hsState == VDAA_ONHOOK) {
		Vdaa_SetHookStatus(ports[1].VoiceObj, VDAA_OFFHOOK); 
	}      
	
	hsState = Vdaa_PowerupLineside(ports[1].VoiceObj);     
	#endif
	
	//ProSLIC_PrintDebugData(ports[0].VoiceObj);
	//Vdaa_PrintDebugData(ports[1].VoiceObj);
	
	
	return 1;
} 
Ejemplo n.º 5
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.º 6
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;
}	
Ejemplo n.º 7
0
int32 ProSLIC_GR909_REN(ProSLICGR909Type *pProSLIC909,SI321x_REN_STATE *pState){

	unsigned char vring; 
	int32 renValue; 
	int32 diff;
	int i;
	int32 ac;
	switch (pState->State.stage){
		case 0:
			si321x_preserve_state(pProSLIC909,&(pState->State)); /* Save off current register settings */
			pState->sumIq2 = 0;
			// Assummed that all calibrations have been completed and we are OPEN
			pProSLIC909->WriteReg(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, LINE_STATE, 0x1);// Enter active-MODE and charge
			pProSLIC909->WriteReg(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, COMMON_V, 0);//vtip = 0
			pProSLIC909->WriteReg(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, ON_HOOK_V, SI321X_LT_REN_VCHARGE);//vring=46.12v
			pState->State.stage++; 
			//pState->State.stage=5;
			pState->State.sampleIterations=0;
			pState->State.waitIterations=0;
			pState->pollCount=0;
			return 0;
		case 1:
			delay_poll(&(pState->State),(500/POLL_RATE)-2);
			return 0;
		case 2:
			pState->v1 = pProSLIC909->ReadReg(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, RING_V_SENSE);
			pProSLIC909->WriteReg(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, LINE_STATE, 0);
			pState->State.stage++; 
			return 0;
		case 3:
			vring = pProSLIC909->ReadReg(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, RING_V_SENSE);
			pState->pollCount++;
			if (vring < (pState->v1-SI321X_LT_REN_VSTOP) || (pState->pollCount>(2000/POLL_RATE))) //timeout 3 seconds
				pState->State.stage++; 
			return 0;
		case 4:
			//straight line curve fit (saves math)
			pProSLIC909->renValue = (((pState->pollCount*POLL_RATE)*SI321X_LT_REN_SLOPE) / 10 - SI321X_LT_REN_OFF)/10;
			if(pProSLIC909->renValue < 0)
				pProSLIC909->renValue = 0;	
		   
		   if (pState->pollCount>(2000/POLL_RATE)) //timeout
			   pProSLIC909->renValue = 0;
		   si321x_restore_state(pProSLIC909,&(pState->State));
#if (DEBUG)   
		   LOGPRINT(/*0,*/"SI321X_LT: RENLD for channel %u is milren= %ld\n",pState->State.channelNumber, pProSLIC909->renValue);
#endif
		   pState->State.stage++;
		   return 0;
		break;
		case 5:
			// Setup Ringer
		pProSLIC909->WriteRAM(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, RING_OSC_COEF, SI321X_LT_REN_RINGOSC);	// Ring 17vrms, 24vpk, 20Hz, 0vdc
		pProSLIC909->WriteRAM(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, RING_X, SI321X_LT_REN_RINGX);
		pProSLIC909->WriteRAM(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, RING_V_OFF, SI321X_LT_REN_RINGOF); //laj: 20Vdc needed to see beyond phone diodes

		pProSLIC909->WriteReg(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, RING_OSC_CTL, 0x2); // Disable timers
		pProSLIC909->WriteReg(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, COMMON_V, 0);//vtip = 0
		pProSLIC909->WriteReg(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, 72, SI321x_LT_REN_VOC);// Set VOC to 18v (Ring amp must be > Voc always)
		ProSLIC_SetLinefeedStatus(pProSLIC909->pProslic, 1); // Forward active
		pState->State.stage++;
		return 0;
		break;
		case 6:
		delay_poll(&(pState->State),(600/POLL_RATE)-2);
		return 0;
		break;
		case 7:
		// Bleed line again and switch to ringing
		ProSLIC_SetLinefeedStatus(pProSLIC909->pProslic, 0);
		pState->State.stage++;
		return 0;
		break;
		case 8:
		delay_poll(&(pState->State),(200/POLL_RATE)-2);
		return 0;
		break;
		case 9:
		ProSLIC_SetLinefeedStatus(pProSLIC909->pProslic, 1);
		ProSLIC_SetLinefeedStatus(pProSLIC909->pProslic, 4); // Start Ringing
		pState->pollCount = 0;
		pState->State.stage++;
		return 0;
		case 10:
		delay_poll(&(pState->State),(2500/POLL_RATE)-2);
		return 0;
		break;
		case 11:
		//if ((10/POLL_RATE) > 2){
		//	delay_poll(&(pState->State),(10/POLL_RATE)-2);
		//	return 0;
		//}
		//else
			pState->State.stage=12;
		case 12:
		if (pProSLIC909->ReadReg(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, 64) == 0){//check for power alarm
#if (DEBUG)
			pProSLIC909->renValue=0;
			LOGPRINT ("Power Alarm!\n");
			return 1;
#endif
		}
		// Capture 500ms of samples - must be recalibrated if this changes or POLL_RATE changes
		pState->iValues[pState->pollCount]= 
			pProSLIC909->ReadRAM(pProSLIC909->pProHW, pProSLIC909->pProslic->channel, 89);
		
		if ((++pState->pollCount) == (N_REN_SAMPLES))
			pState->State.stage=13;
		else 
			pState->State.stage=11;
		return 0;
		break;
		case 13:
#if (DEBUG)

		/*for (i=0;i<N_REN_SAMPLES;i++){
			
			LOGPRINT ("Ivalue = %d\n",pState->iValues[i]);
		}*/
#endif
		pState->sumIq2=0;
		for (i=0;i<N_REN_SAMPLES;i++){
			pState->sumIq2 += pState->iValues[i];
		}
		pState->sumIq2/=N_REN_SAMPLES;
		// Restore Ringer and DC Feed Settings
		ProSLIC_SetLinefeedStatus(pProSLIC909->pProslic, 1); // Forward active
		pState->State.stage++;
		return 0;
		break;
		case 14:
		delay_poll(&(pState->State),(100/POLL_RATE)-2); 
		return 0;
		case 15:
		ProSLIC_SetLinefeedStatus(pProSLIC909->pProslic, 0); // Open state
		si321x_restore_state(pProSLIC909,&(pState->State));
		
		if(pProSLIC909->CalFlag == 1){
			pProSLIC909->renValue = pState->sumIq2;
			return 1;
		}

		else{
			
			if(pState->sumIq2 > pState->renCal->renTrans)
				renValue = ((pState->sumIq2 - pState->renCal->highRenOffs)*1000)/pState->renCal->highRenSlope;
			else{
				renValue = ((pState->sumIq2 - pState->renCal->lowRenOffs)*1000)/pState->renCal->lowRenSlope;
			}
			if (renValue < 900)
				renValue = ((pState->sumIq2 - pState->renCal->extraLowRenOffset)*1000)/pState->renCal->extraLowRenSlope;
#if (DEBUG)
			if (pProSLIC909->pProslic->debugMode){
				LOGPRINT("IQ2(sum) = %d\n",pState->sumIq2);
				LOGPRINT("I method REN = %d mREN\n",renValue);
			}
#endif		
			if (renValue > 600)
				pProSLIC909->renValue = renValue;
			
		}
		if(pProSLIC909->renValue < 0) 
			pProSLIC909->renValue=0;
		break;

	}
   	return 1;
}