コード例 #1
0
ファイル: ZL880_line_test.c プロジェクト: 12019/bcm63xx-phone
/**
 * Function:  main()
 *
 * Description: This function initializes the API and Devices/Lines.
 * It also starts the "alarmHandle" function to be called at a periodic rate.
 */
int main(void)
{
    VpStatusType status;
    struct itimerval timeStruct, timeOldVal;
    uint8 lineNum = 0;

    /* ZTAP board initialization (platform specific) */
    BoardInit(); /* See "../common/board.c" */
    VpSysInit();

    /*
     * The following structure is specific to Linux.  It sets up a timed call
     * to a user specified function.  For the purpose of this demo, the timing
     * is 20mS and the function that will be called is "alarmHandle".  The timer
     * and function call does not start until "setitimer()" and "signal()" are
     * called (below).
     */
    timeStruct.it_interval.tv_sec = 0L;
    timeStruct.it_interval.tv_usec = 19990L;
    timeStruct.it_value.tv_sec = 0L;
    timeStruct.it_value.tv_usec = 19990L;

    timeOldVal.it_interval.tv_sec = 0L;
    timeOldVal.it_interval.tv_usec = 0L;
    timeOldVal.it_value.tv_sec = 0L;
    timeOldVal.it_value.tv_usec = 0L;

    /* Make the objects (1 device, 2 lines) */
#if (SUPPLY_CONFIGURATION == ABS_SUPPLY)
    status = VpMakeDeviceObject(VP_DEV_886_SERIES, deviceId, &devCtx, &devObj);
#else
    status = VpMakeDeviceObject(VP_DEV_887_SERIES, deviceId, &devCtx, &devObj);
#endif
    if (status != VP_STATUS_SUCCESS) {
        QS_DEBUG("Error making the device object: %s\n", MapStatus(status));
        exit(-1);
    }

    for (; lineNum < NB_LINE; lineNum++) {
        status = VpMakeLineObject(VP_TERM_FXS_LOW_PWR, lineNum, &lineCtx[lineNum], &lineObj[lineNum], &devCtx);
        if (status != VP_STATUS_SUCCESS) {
            QS_DEBUG("Error calling VpMakeLineObject on lineNum %i: %s\n", lineNum, MapStatus(status));
            exit(-1);
        }
        QS_DEBUG("--- Created lineNum %i---\n", lineNum);
    }

    /* Start VpInitDevice and wait for the event VP_DEV_EVID_DEV_INIT_CMP */
#if (SUPPLY_CONFIGURATION == FLY_BACK_SUPPLY)
    status = VpInitDevice(&devCtx, FB_DEV_PROFILE, FB_AC_600_FXS, FB_DC_25MA_CC, FB_RING_25HZ_SINE, VP_PTABLE_NULL, VP_PTABLE_NULL);
#elif (SUPPLY_CONFIGURATION == INVERTING_BOOST_SUPPLY)
    status = VpInitDevice(&devCtx, IB_DEV_PROFILE, IB_AC_600_FXS, IB_DC_25MA_CC, IB_RING_25HZ_SINE, VP_PTABLE_NULL, VP_PTABLE_NULL);
#elif (SUPPLY_CONFIGURATION == ABS_SUPPLY)
    status = VpInitDevice(&devCtx, ABS_DEV_PROFILE, ABS_AC_600_FXS, ABS_DC_23MA_CC, ABS_RING_25HZ_SINE, VP_PTABLE_NULL, VP_PTABLE_NULL);
#else
    #error "SUPPLY_CONFIGURATION is incorrectly set"
#endif

    if (status != VP_STATUS_SUCCESS) {
        QS_DEBUG("Device not properly initialized: %s\n", MapStatus(status));
        exit(-1);
    } else {
        QS_DEBUG("\nDevice Initialization started\n");
    }

    /*
     * The following two function calls were described above as Linux specific.
     * They are used to call a user defined function at set increments.  The
     * user may have several other methods to perform the same.
     */
    signal(SIGVTALRM, alarmHandle);
    setitimer(ITIMER_VIRTUAL, &timeStruct, &timeOldVal);

    /*
     * Once the "tick" is setup, the main program can enter a "while(1)" loop
     * and the user specified function will take over the application (with the
     * help of the Linux OS)
     */


    while(1);

    return 0;
}
コード例 #2
0
/* 
** API	  : zarlinkInitDevice()
** Desp	  :	Init Zarlink device
** input  : Realtek device obj pointer
** return : SUCCESS/FAILED
*/
BOOL zarlinkInitDevice( RTKDevObj *pDev )
{
   	int ch;
	BOOL rtn;
	VpProfilePtrType dev_profile;
	VpStatusType status;
	VpTermType term_type;

   	PRINT_MSG("Initializing device 0x%x\n", pDev->dev_id);

	/* Create the API-2 device */
	status = VpMakeDeviceObject( pDev->VpDevType, 
								 (VpDeviceIdType) pDev->dev_id, 
								 pDev->pDevCtx,	
								 pDev->pDevObj	
							  );

	if ( status != VP_STATUS_SUCCESS ) {
	  	PRINT_R("Error: VpMakeDeviceObject (status %d) \n", status);
	  	return FAILED;
	}

	for (ch=0; ch < pDev->max_line; ch++) {

		if (pDev->pLine[ch]->line_type == LINE_FXS ) 
			 term_type = VP_TERM_FXS_GENERIC;
		else term_type = VP_TERM_FXO_GENERIC;

		/* Create line objects */
		status = VpMakeLineObject( term_type, 
							   pDev->pLine[ch]->channelId,	
							   pDev->pLine[ch]->pLineCtx,
							   pDev->pLine[ch]->pLineObj,
							   pDev->pDevCtx		
							);
		if ( status != VP_STATUS_SUCCESS ) {
	  		PRINT_R("Error: VpMakeLineObject ch %d term=%d(status %d) \n", 
				ch, term_type, status);
	  		return FAILED;
		}
	}

	dev_profile = pDev->pDev_profile;

	PRINT_MSG("tick rate %d ms\n", dev_profile[DEVICE_PROFILE_TICK_RATE_IDX]);

	/* Avoid taking to long to init device */
#ifdef CONFIG_RTL865X_WTDOG
	plat_disable_watchdog();
	PRINT_MSG("Disable watchdog\n" );
#elif defined( CONFIG_RTL_WTDOG )
	bsp_disable_watchdog();
	PRINT_MSG("Disable watchdog\n" );
#endif	

	/* Initialize the device */
	status = VpInitDevice(  pDev->pDevCtx,		
						   	pDev->pDev_profile,
						   	pDev->pAC_profile,
						   	pDev->pDC_profile,
						   	pDev->pRing_profile,
						   	pDev->pACFxoLC_profile,
						   	pDev->pFxoDial_profile
						);

	if ( status != VP_STATUS_SUCCESS ) {
		PRINT_R("Error: VpInitDevice (status %d)\n", status );
		goto DONE;
	}

	/* Check if VP_DEV_EVID_DEV_INIT_CMP occurred */
	if( TRUE != zarlinkWaitForEvent( pDev->pDevCtx, 
		VP_EVCAT_RESPONSE, VP_DEV_EVID_DEV_INIT_CMP ) ) {
		PRINT_R("Error: Device %d initialization was not complete\n",pDev->dev_id);
		status = VP_STATUS_FAILURE;
		goto DONE;
	}

	PRINT_MSG("DEV%x initialized OK\n",pDev->dev_id);
	pDev->dev_st = DEV_S_READY;

	/* Initialize API-2 line settings */
	for (ch=0; ch < pDev->max_line; ch++) {
		if (pDev->pLine[ch]->line_type == LINE_FXS)	{
			rtn = RtkInitFxsLine(pDev->pLine[ch]);

		} else if (pDev->pLine[ch]->line_type == LINE_FXO) {
			rtn = RtkInitFxoLine(pDev->pLine[ch]);

		} else {
			PRINT_R("Error: unknow line_type %d\n",pDev->pLine[ch]->line_type);
			goto DONE;
		}
	}

DONE:
#ifdef CONFIG_RTL865X_WTDOG
	plat_enable_watchdog();
	PRINT_MSG("Enable watchdog\n");
#elif defined( CONFIG_RTL_WTDOG )
	bsp_enable_watchdog();
	PRINT_MSG("Enable watchdog\n");
#endif
	if ( status != VP_STATUS_SUCCESS )	return FAILED;

	return SUCCESS;
}
コード例 #3
0
ファイル: vpapi_dev.c プロジェクト: HuxyUK/xpenology-3.x
static int vpapi_init_device(unsigned long arg)
{
	VpApiModInitDeviceType data;
	VpDeviceIdType deviceId;
	VpProfileDataType devProfile[MAX_PROFILE_SIZE];
	VpProfileDataType acProfile[MAX_PROFILE_SIZE];
	VpProfileDataType dcProfile[MAX_PROFILE_SIZE];
	VpProfileDataType ringProfile[MAX_PROFILE_SIZE];
	VpProfileDataType fxoAcProfile[MAX_PROFILE_SIZE];
	VpProfileDataType fxoCfgProfile[MAX_PROFILE_SIZE];
	VpProfilePtrType pDevProfile = NULL, pAcProfile = NULL;
	VpProfilePtrType pDcProfile = NULL, pRingProfile = NULL;
	VpProfilePtrType pFxoAcProfile = NULL, pFxoCfgProfile = NULL;
	u16 devProfileSize, acProfileSize, dcProfileSize;
	u16 ringProfileSize, fxoAcProfileSize, fxoCfgProfileSize;

	/* Get user data */
	if(copy_from_user(&data, (void*)arg, sizeof(VpApiModInitDeviceType))) {
			printk("%s: copy_from_user failed\n", __func__);
			return -EFAULT;
	}

	deviceId = data.deviceId;
	devProfileSize = data.devProfileSize;
	acProfileSize = data.acProfileSize;
	dcProfileSize = data.dcProfileSize;
	ringProfileSize = data.ringProfileSize;
	fxoAcProfileSize = data.fxoAcProfileSize;
	fxoCfgProfileSize = data.fxoCfgProfileSize;

	if(devProfileSize) {
		/* Get device profile */
		if(copy_from_user(devProfile, (void*)data.pDevProfile, (sizeof(VpProfileDataType)*devProfileSize))) {
			printk("%s: copy_from_user failed\n", __func__);
			return -EFAULT;
		}
		pDevProfile = devProfile;
	}

	if(acProfileSize) {
		/* Get AC profile */
		if(copy_from_user(acProfile, (void*)data.pAcProfile, (sizeof(VpProfileDataType)*acProfileSize))) {
			printk("%s: copy_from_user failed\n", __func__);
			return -EFAULT;
		}
		pAcProfile = acProfile;
	}

	if(dcProfileSize) {
		/* Get DC profile */
		if(copy_from_user(dcProfile, (void*)data.pDcProfile, (sizeof(VpProfileDataType)*dcProfileSize))) {
			printk("%s: copy_from_user failed\n", __func__);
			return -EFAULT;
		}
		pDcProfile = dcProfile;
	}

	if(ringProfileSize) {
		/* Get ring profile */
		if(copy_from_user(ringProfile, (void*)data.pRingProfile, (sizeof(VpProfileDataType)*ringProfileSize))) {
			printk("%s: copy_from_user failed\n", __func__);
			return -EFAULT;
		}
		pRingProfile = ringProfile;
	}

	if(fxoAcProfileSize) {
		/* Get FXO AC profile */
		if(copy_from_user(fxoAcProfile, (void*)data.pFxoAcProfile, (sizeof(VpProfileDataType)*fxoAcProfileSize))) {
			printk("%s: copy_from_user failed\n", __func__);
			return -EFAULT;
		}
		pFxoAcProfile = fxoAcProfile;
	}

	if(fxoCfgProfileSize) {
		/* Get FXO configuration profile */
		if(copy_from_user(fxoCfgProfile, (void*)data.pFxoCfgProfile,
					 (sizeof(VpProfileDataType)*fxoCfgProfileSize))) {
			printk("%s: copy_from_user failed\n", __func__);
			return -EFAULT;
		}
		pFxoCfgProfile = fxoCfgProfile;
	}

	data.status = VpInitDevice(&pDevCtx[deviceId], pDevProfile, pAcProfile, pDcProfile, pRingProfile,
					 pFxoAcProfile, pFxoCfgProfile);

	if(data.status == VP_STATUS_SUCCESS) {
		total_devs++;
		REGISTER_DEVICE(deviceId);

		if(!atomic_read(&vpapi_init)) {
#if defined(SLIC_TIMER_EVENT_SUPPORT)
			memset(&vpapi_timer, 0, sizeof(struct timer_list));
			init_timer(&vpapi_timer);
			vpapi_timer.function = vpapi_tick_handler;
			vpapi_timer.data = -1;
			vpapi_timer.expires = jiffies + VPAPI_TICK_TIMER_PERIOD;
			add_timer(&vpapi_timer);
#endif
			atomic_set(&vpapi_init, 1);
		}
	}

	/* Copy status back to user */
	if(copy_to_user((void*)arg, &data, sizeof(VpApiModInitDeviceType))) {
		printk("%s: copy_to_user failed\n", __func__);
		return  -EFAULT;
	}

	return 0;
}