/** * Function: alarmHandle() * * Description: This function is called at a periodic rate to perform all * required API operations. It implements the functional requirements of the * application mentioned in the header. */ void alarmHandle(int val) { VpStatusType status; VpEventType event; static bool deviceInitialized = FALSE; static uint8 cmpCounter = 0; /* * This loop will query the FXS device for events, and when an event is * found, it will parse the event and perform further operations. */ while(VpGetEvent(&devCtx, &event)) { /* Print the incoming event */ UtilPrintEvent(&event); /* See "../common/utils.c" */ /* * A channel under test should process all line events without * passing the events over to the main event handling loop */ if ((plineCtxUnderTest != NULL) && (plineCtxUnderTest == event.pLineCtx)) { ProcessLineTestEvent(&event); continue; } /* Parse the RESPONSE category */ if (event.eventCategory == VP_EVCAT_RESPONSE) { if(event.eventId == VP_DEV_EVID_DEV_INIT_CMP) { uint8 lineNum = 0; InitSetMasks(); QS_DEBUG("Device Initialization completed\n"); for (; lineNum < NB_LINE; lineNum++) { status = VpSetLineState(&lineCtx[lineNum], VP_LINE_STANDBY); if (status != VP_STATUS_SUCCESS) { QS_DEBUG("Error setting lineNum %i to VP_LINE_STANDBY: %s\n", lineNum, MapStatus(status)); exit(-1); } status = VpCalLine(&lineCtx[lineNum]); QS_DEBUG("Starting Calibration on lineNum %i\n", lineNum); if (status != VP_STATUS_SUCCESS) { QS_DEBUG("Error calling VpCalLine on lineNum %i:: %s\n", lineNum, MapStatus(status)); exit(-1); } } } else if (event.eventId == VP_EVID_CAL_CMP) { if (++cmpCounter == NB_LINE) { deviceInitialized = TRUE; QS_DEBUG("Calibration completed on both lines ... starting Line Test\n\n"); StartLineTest(0, LT_TID_LINE_V); } } } } /* end while(VpGetEvent(&devCtx, &event)) */ return; }
/** * Function: zarlinkAlarmHandle() * * Description: This function is called at a periodic rate to perform all * required API operations. It implements the functional requirements of the * application mentioned in the header. */ static void zarlinkAlarmHandle(unsigned long args) { int deviceNum; bool deviceEventStatus = FALSE; VpEventType pEvent; /* * This loop will query the FXS device for events, and when an event is * found (deviceEventStatus = TRUE), it will parse the event and perform * further operations. */ for (deviceNum = 0; deviceNum < gDevNum; deviceNum++) { VpApiTick(RTKDevList[deviceNum]->pDevCtx, &deviceEventStatus); RTKDevList[deviceNum]->UpdIOState(RTKDevList[deviceNum]->pLine[0]); if(deviceEventStatus == TRUE) { while(VpGetEvent(RTKDevList[deviceNum]->pDevObj, &pEvent)) { /* * If the event was a Response:Device Init Complete event, * we need to initialize the device and associated lines, so * send the event structure (pointer) to the Init function for * handling. */ if (pEvent.eventCategory == VP_EVCAT_RESPONSE) { if(pEvent.eventId == VP_DEV_EVID_DEV_INIT_CMP) { //InitQuickStartSettings(&pEvent); } else if (pEvent.eventId == VP_LINE_EVID_RD_OPTION) { //InitReadOptions(&pEvent); } else { /* Do nothing */ } /* We're initializing if a response event occurred. */ return; } //ProcessFXSEvent(&pEvent); } } } return; }
static void sys_service_tick_handler() { unsigned char deviceId; unsigned long flags; vpapi_event *pEvent; #if !defined(ZARLINK_SLIC_VE792) bool eventStatus; #endif sigset_t mask; pthread_mutex_lock(&vp_lock); for(deviceId = 0; deviceId < MAX_DEVICES; deviceId++) { if(GET_DEV_STATUS(deviceId) == 0) continue; /* Check for free resources */ if(event_count >= MAX_EVENT_QUEUE_SIZE) goto timer_exit; #if !defined(ZARLINK_SLIC_VE792) if(VP_STATUS_SUCCESS == VpApiTick(&pDevCtx[deviceId], &eventStatus)) { if(eventStatus == TRUE) { #endif pEvent = &event_queue[next_event]; while(VpGetEvent(&pDevCtx[deviceId], &pEvent->vp_event) == TRUE) { if(pEvent->vp_event.status != VP_STATUS_SUCCESS) { printf("%s: bad status(%d)\n", __func__, pEvent->vp_event.status); break; } if(pEvent->vp_event.eventId == 0) { printf("%s: warning, empty event\n", __func__); break; } next_event++; if(next_event == MAX_EVENT_QUEUE_SIZE) { next_event = 0; } event_count++; if(pEvent->valid == 0) { pEvent->valid = 1; } else { printf("%s: error, event(%u) was overrided\n", __func__, next_event); break; } pEvent = &event_queue[next_event]; } #if !defined(ZARLINK_SLIC_VE792) } } #endif } pthread_mutex_unlock(&vp_lock); return; timer_exit: return; }
/* ***************************************************************************** ** FUNCTION: zarlinkWaitForEvent ** ** PURPOSE: Waiting for specific event category and event Id on device. ** ** PARAMETERS: deviceNum - Device number of SLIC ** category - Event Category to wait for ** event - Event Id to wait for ** ** RETURNS: TRUE - Event occurred. ** FALSE - Event did not occur. ** ***************************************************************************** */ static BOOL zarlinkWaitForEvent( VpDevCtxType* pDevCtx, VpEventCategoryType category, uint16 event) { int i; VpStatusType status; bool vpApiEventPending = FALSE; for (i = 0; i<SLIC_INIT_TIMEOUT; i++) { status = VpApiTick( pDevCtx, &vpApiEventPending ); if ( (status == VP_STATUS_SUCCESS) && (TRUE == vpApiEventPending) ) { VpEventType pEvent; while(VpGetEvent(pDevCtx, &pEvent)) { switch (pEvent.eventCategory) { /* Add more categories as needed */ case VP_EVCAT_RESPONSE: switch(pEvent.eventId) { /* Add more events as needed */ case VP_DEV_EVID_DEV_INIT_CMP: PRINT_MSG("SLIC: Received VP_DEV_EVID_DEV_INIT_CMP event (i = %d)\n", i); //InitQuickStartSettings(&pEvent); break; case VP_LINE_EVID_LINE_INIT_CMP: PRINT_MSG("SLIC: Received VP_LINE_EVID_LINE_INIT_CMP event (i = %d)\n", i); break; case VP_EVID_CAL_CMP: PRINT_MSG("SLIC: Received VP_EVID_CAL_CMP event (i= %d)\n", i); break; case VP_LINE_EVID_RD_OPTION: PRINT_MSG("SLIC: Received VP_LINE_EVID_RD_OPTION event (i= %d)\n", i); //InitReadOptions(&pEvent); //EventMaskReady = 1; break; default: /* Do nothing */ #ifdef DEBUG_API PRINT_MSG("SLIC: ERROR Unexpected Event %d came from the SLIC.\n", pEvent.eventId); #endif break; } break; default: break; } /* As soon as it finds the event we are looking for, return */ if ( (pEvent.eventCategory == category) && (pEvent.eventId == event) ) { #ifdef DEBUG_API PRINT_MSG("SLIC: Found event: pEvent.eventCategory = %d pEvent.eventId = %d \n", pEvent.eventCategory, pEvent.eventId); #endif return TRUE; } else { #ifdef DEBUG_API PRINT_MSG("SLIC: Unexpected event: pEvent.eventCategory = %d pEvent.eventId = %d \n", pEvent.eventCategory, pEvent.eventId); #endif } } } mdelay(10); } /* Could not find any events if we reach here */ return FALSE; }
static void vpapi_tick_handler(unsigned long data) { u8 deviceId; unsigned long flags; vpapi_event *pEvent; #if !defined(CONFIG_ZARLINK_SLIC_VE792) bool eventStatus; #endif /* Check if events are already active and not processing IOCTL */ if((atomic_read(&vpapi_init) == 0) || (atomic_read(&vpapi_in_ioctl) == 1)) goto timer_exit; spin_lock_irqsave(&vpapi_lock, flags); for(deviceId = 0; deviceId < MAX_DEVICES; deviceId++) { if(GET_DEV_STATUS(deviceId) == 0) continue; /* Check for free resources */ if(atomic_read(&event_count) >= MAX_EVENT_QUEUE_SIZE) goto timer_exit; #if !defined(CONFIG_ZARLINK_SLIC_VE792) if(VP_STATUS_SUCCESS == VpApiTick(&pDevCtx[deviceId], &eventStatus)) { if(eventStatus == TRUE) { #endif pEvent = &event_queue[next_event]; while(VpGetEvent(&pDevCtx[deviceId], &pEvent->vp_event) == TRUE) { if(pEvent->vp_event.status != VP_STATUS_SUCCESS) { printk("%s: bad status(%d)\n", __func__, pEvent->vp_event.status); break; } if(pEvent->vp_event.eventId == 0) { printk("%s: warning, empty event\n", __func__); break; } next_event++; if(next_event == MAX_EVENT_QUEUE_SIZE) { next_event = 0; } atomic_inc(&event_count); if(pEvent->valid == 0) { pEvent->valid = 1; } else { printk("%s: error, event(%u) was overrided\n", __func__, next_event); break; } pEvent = &event_queue[next_event]; } #if !defined(CONFIG_ZARLINK_SLIC_VE792) } } #endif } spin_unlock_irqrestore(&vpapi_lock, flags); timer_exit: /* Checks if user application should be signaled */ if(atomic_read(&event_count) > 0) { wake_up_interruptible(&vpapi_wait); } /* Schedule next timer tick */ vpapi_timer.expires = jiffies + VPAPI_TICK_TIMER_PERIOD; add_timer(&vpapi_timer); }