Пример #1
0
/**
 * \function 	SendSemCycle
 * \brief    	周期性发送信号量
 **/
void SendSemCycle()
{
	Uint8   RTC_time[8];
	static  Uint8 temp_min = 0;
	static  Uint8 temp_hour = 0;
	
	Roseek_RTC_ReadTime(RTC_time);//当前系统时间
	if(RTC_time[5]>temp_min)
	{
		if(RTC_time[5]-temp_min > CONNECT_CYCLE)
		{	
			temp_min = RTC_time[5];
			temp_hour = RTC_time[4];
			SEM_post( &sem_SendRoadInfReconnect );//通知连接服务器信号量
			
		}							
	}
	else
	{
		if( temp_min < (60 - CONNECT_CYCLE) || temp_hour != RTC_time[4])
		{	
			temp_min = RTC_time[5] ;
			temp_hour = RTC_time[4] ;
			SEM_post( &sem_SendRoadInfReconnect );//通知连接服务器信号量
			
		}
	}
}
Пример #2
0
/******************************************************************************
 * Fifo_flush
 ******************************************************************************/
Int Fifo_flush(Fifo_Handle hFifo)
{
    assert(hFifo);

    SEM_pend(&hFifo->mutex, SYS_FOREVER);
    hFifo->flush = TRUE;
    SEM_post(&hFifo->mutex);

    /* Make sure any Fifo_get() calls are unblocked */
    SEM_post(&hFifo->sem);

    return Dmai_EOK;
}
Пример #3
0
/*
 *  ======== DPI_close ========
 */
Static Int DPI_close(DEV_Handle dev)
{
    PipeObj         *pipe = (PipeObj *)dev->object;
    SPipeObj        *sPipe = pipe->sPipe;

    MEM_free(0, pipe, sizeof(PipeObj));
    
    SEM_pend(mutex, SYS_FOREVER);

    sPipe->device[dev->mode] = NULL;
    sPipe->readySem[dev->mode] = NULL;
             
    if (sPipe->device[DEV_INPUT] == NULL &&
                sPipe->device[DEV_OUTPUT] == NULL) {
        /* delete all shared pipe sub-objects */
        SEM_delete(sPipe->dataSem);
        SEM_delete(sPipe->freeSem);

        /* remove sPipe obj from sPipeList */
        QUE_remove(&sPipe->link);
        
        /* delete sPipe object itself */
        MEM_free(0, sPipe, sizeof (SPipeObj));
    }

    SEM_post(mutex);

    return (SYS_OK);
}
Пример #4
0
/*
 *  ======== DIO_tskIssue ========
 */
Int DIO_tskIssue(DEV_Handle device)
{
    DIO_Handle dio = (DIO_Handle)device->object;
    DEV_Frame   *frame;
    Int         status;

    frame = QUE_get(device->todevice);

    frame->cmd = (device->mode == DEV_INPUT) ? IOM_READ : IOM_WRITE;
    frame->status = IOM_PENDING;

    status = dio->fxns->mdSubmitChan(dio->chanp, frame);

    if (status < 0) {
        return (SYS_EBADIO);
    }
    else {
        if (status == IOM_COMPLETED) {
            QUE_put(device->fromdevice, frame);
            SEM_post(dio->context.sems.complete);
        }
        
        return (SYS_OK);
    }
}
Пример #5
0
void CClassification::SignalTrigger()
{
#ifndef _WINDOWS // ------- Don't compile on windows -----

	SEM_post( &m_semTrigger );

#endif // ------------------------------------------------
}
Пример #6
0
/******************************************************************************
 * Fifo_get
 ******************************************************************************/
Int Fifo_get(Fifo_Handle hFifo, Ptr ptrPtr)
{
    Int flush;
    Fifo_Elem * elem;
    Ptr * p = (Ptr *)ptrPtr;

    assert(hFifo);
    assert(ptrPtr);

    SEM_pend(&hFifo->mutex, SYS_FOREVER);
    flush = hFifo->flush;
    SEM_post(&hFifo->mutex);

    /* If pipe is already flushed, do not block */
    if (flush) {
        return Dmai_EFLUSH;
    }

    /* Wait for element from other thread */
    SEM_pend(&hFifo->sem, SYS_FOREVER);
   
    /* Handle flushed fifo */
    SEM_pend(&hFifo->mutex, SYS_FOREVER);
    flush = hFifo->flush;
    if (flush) {
        hFifo->flush = FALSE;
    }
    SEM_post(&hFifo->mutex);
    if (flush) {
        return Dmai_EFLUSH;
    }
    
    /* Get an element from the Fifo queue */
    elem = (Fifo_Elem *)QUE_get(&hFifo->queue);
    *p = elem->ptr;
    if (BUF_free(hFifo->hBufPool, elem) != TRUE) {
        return Dmai_EFAIL;
    }    

    SEM_pend(&hFifo->mutex, SYS_FOREVER);
    hFifo->numBufs--;
    SEM_post(&hFifo->mutex);

    return Dmai_EOK;
}
Пример #7
0
/******************************************************************************
 * Fifo_getNumEntries
 ******************************************************************************/
Int Fifo_getNumEntries(Fifo_Handle hFifo)
{
    Int numEntries;

    assert(hFifo);

    SEM_pend(&hFifo->mutex, SYS_FOREVER);
    numEntries = hFifo->numBufs;
    SEM_post(&hFifo->mutex);

    return numEntries;
}
Пример #8
0
/**
 *  \brief  USB Msc task
 *
 *  \param  None
 *
 *  \return None
 */
static void MSCTask(void)
{
    CSL_UsbMscMsg        wMSCMsg;
    pUsbContext     pContext = &gUsbContext;
    volatile WORD     Msg;
    pUsbEpStatus         peps;

    //TSK_settime(TSK_self()); // statistic collection
    while(TRUE)
    {
        /* wait for mailbox to be posted */
        MBX_pend(&MBX_msc, &wMSCMsg, SYS_FOREVER);
        Msg = wMSCMsg;
        if(Msg == CSL_USB_MSG_MSC_TASK_EXIT)
            break;

        switch(Msg)
        {
            case CSL_USB_MSG_MSC_CTL:
                peps = &pContext->pEpStatus[CSL_USB_EP0];
                if(peps->hEventHandler)
                    (*peps->hEventHandler)();
                break;

            case CSL_USB_MSG_ISO_IN:
                peps = &pContext->pEpStatus[CSL_USB_EP1];
                if(peps->hEventHandler)
                    (*peps->hEventHandler)();
                break;

            case CSL_USB_MSG_ISO_OUT:
                peps = &pContext->pEpStatus[CSL_USB_EP2];
                if(peps->hEventHandler)
                    (*peps->hEventHandler)();
                break;

            case CSL_USB_MSG_HID_INT_IN:
                peps = &pContext->pEpStatus[CSL_USB_EP3];
                if(peps->hEventHandler)
                    (*peps->hEventHandler)();
                break;

            default:
                break;
        }

        //TSK_deltatime(TSK_self()); // statistic collection
    }
    /* Ack for exit this task */
    SEM_post(&SEM_MUSBMSCTaskExited);

}
Пример #9
0
/*
 *  ======== DIO_tskIdle ========
 *  DIO_tskIdle() puts the device back to the state it was in just after
 *  DIO_open() was called.
 */
Int DIO_tskIdle(DEV_Handle device, Bool flush)
{
    DIO_Handle dio = (DIO_Handle)device->object;
    Uns         pendCount = 0;
    DEV_Frame   localFrame;
    Int         status;

    localFrame.status = IOM_PENDING;

    if (device->mode == DEV_INPUT || flush) {
        localFrame.cmd = IOM_ABORT;
    }
    else {
        localFrame.cmd = IOM_FLUSH;
    }

    status = dio->fxns->mdSubmitChan(dio->chanp, &localFrame);

    if (status == IOM_PENDING) {
        for (;;) {
            if (SEM_pend(dio->context.sems.complete, device->timeout)) {
                /*
                 * Break out of the for loop when the local abort/flush
                 * frame status shows that it is complete.
                 */
                if (localFrame.status == IOM_COMPLETED) {
                    break;
                }
                else {
                    /* keep track of data frame completions */
                    pendCount++;
                }
            }
            else {
                return (SYS_ETIMEOUT);
            }
        }

        /* 
         * Update complete semaphore so it corresponds to number of frames
         * on the 'todevice' queue.  'for' loop above may have made the 
         * complete sem count inconsistent.
         */
        while (pendCount--) {
            SEM_post(dio->context.sems.complete);
        }
    }

    return (SYS_OK);
}
Пример #10
0
/*
 *  ======== DIO_tskCallback ========
 */
Void DIO_tskCallback(Ptr devp, DEV_Frame *frame)
{
    DEV_Handle  device = (DEV_Handle)devp;
    DIO_Handle  dio = (DIO_Handle)device->object;

    if (frame->cmd == IOM_READ || frame->cmd == IOM_WRITE) {
        QUE_put(device->fromdevice, frame); 

        SEM_post(dio->context.sems.complete);

        /*
         * If semaphore was registered with DIO_ready(), dio->ready will
         * be non-NULL.  In this case, SIO_select() is probably waiting for
         * this semaphore to be posted by the first ready device.
         */
        if (dio->context.sems.ready) {
            SEM_post(dio->context.sems.ready);
        }
    }
    else {
        SEM_post(dio->context.sems.complete);
    }
}
Пример #11
0
/**
 *   \brief Call back function for DMA left channel receive complete
 *
 *  This function will be called when DMA receive completes
 *  This function changes the destination address of the DMA channel and
 *  restarts the DMA transfer.
 *
 *   \param dmaStatus    [IN]    Status of the DMA transfer
 *   \param dataCallback [IN]    I2S handle
 *
 *   \return             void
 *
 */
void I2S_DmaRxLChCallBack(
    PSP_DMATransferStatus    dmaStatus,
    void    *dataCallback
)
{
	Uint16 *ptrRxLeft;
	Uint16 i;


#ifdef ENABLE_RECORD
    if ((dataCallback != NULL) && (dmaStatus == PSP_DMA_TRANSFER_COMPLETE))
    {
    	/* Get pointer to ping/pong buffer */
    	ptrRxLeft = &my_i2sRxLeftBuf[0];
    	if (left_rx_buf_sel == 0x1) /* check ping or pong buffer */
    	{
    	  	/* this buffer has data to be processed */
            ptrRxLeft += DMA_TARNSFER_SZ;
        }
        left_rx_buf_sel ^= 0x1; /* update ping/pong */
    	// copy data to the
        /*if(SEM_count(&SEM_BufferFull) > PROCESS_BUFFER_SIZE/DMA_TARNSFER_SZ){
        	return;
        }*/
       	for (i = 0; i < DMA_BUFFER_SZ; i++)
       	{
            // NOTE: since we need datapack to be disabled on I2S tx, we need it disabled on I2S rx therefore
            // we get 2 words per DMA transfer so the offset into DMA buffers has to be twice as big

       		recInLeftBuf = *ptrRxLeft;
    	    ptrRxLeft += 2;
    	    circular_buffer_put(recInLeftBuf);
    	    /*bufferIn[bufferInIdx] =  (recInLeftBuf & 0xFF);
    	    bufferInIdx = (bufferInIdx+1) % PROCESS_BUFFER_SIZE;
    	    bufferIn[bufferInIdx] =  ((recInLeftBuf >> 8) & 0xFF);
    	    bufferInIdx = (bufferInIdx+1) % PROCESS_BUFFER_SIZE; */
    	}
    	SEM_post(&SEM_BufferFull);
    	//LOG_printf(&trace, "IN log %ld\n",bufferInIdx);
    }
    else
    {
#ifdef DEBUG_LOG_PRINT
        LOG_printf(&trace, "Left RX DMA Failed");
#endif
    }

#endif // ENABLE_RECORD
}
Пример #12
0
/******************************************************************************
 * Fifo_put
 ******************************************************************************/
Int Fifo_put(Fifo_Handle hFifo, Ptr ptr)
{
    Fifo_Elem * elem;
    
    assert(hFifo);
    assert(ptr);

    SEM_pend(&hFifo->mutex, SYS_FOREVER);
    hFifo->numBufs++;
    SEM_post(&hFifo->mutex);

    elem = BUF_alloc(hFifo->hBufPool);
    if (elem == NULL) {
        Dmai_err0("Failed to allocate space for Fifo Object\n");
        return Dmai_EFAIL;
    }
    elem->ptr = ptr;
    
    /* Putting an element on the queue with ptr as payload */
    QUE_put(&hFifo->queue, (QUE_Elem *)elem);
    SEM_post(&hFifo->sem);
    
    return Dmai_EOK;
}
Пример #13
0
/**
 *   \brief Call back function for DMA transmit complete
 *
 *  This function will be called when DMA transmit completes.
 *  This function changes the source address of the DMA channel and
 *  restarts the DMA transfer.
 *
 *   \param dmaStatus    [IN]    Status of the DMA transfer
 *   \param dataCallback [IN]    I2S handle
 *
 *   \return   void
 *
 */
void I2S_DmaTxRChCallBack(
    PSP_DMATransferStatus dmaStatus,
    void *dataCallback
)
{
    if ((dataCallback != NULL) && (dmaStatus == PSP_DMA_TRANSFER_COMPLETE))
    {
        SEM_post(&SEM_PingPongTxRightComplete);
    }
    else
    {
#ifdef DEBUG_LOG_PRINT
        LOG_printf(&trace, "Right TX DMA Failed");
#endif
    }
}
Пример #14
0
void		bfqPutBuffer		( BufferQueue_Handle queue, Ptr buffer )
{
	BufferQueue_Frame * frame;
	
	// get a free frame (don't have to check if queue is empty).
	frame = QUE_get( (Ptr) &(queue->queEmptyFrames) );
	
	// Put the buffer to the frame.
	frame->Buffer = buffer;
	
	// Put the frame on the _back queue.
	QUE_put( &(queue->queFullBuffers), frame);	
	
	// ... and post the corresponding sem
	SEM_post( &(queue->semFullBuffers) );
}
Пример #15
0
static Void Task_notify (Uint32 eventNo, Ptr arg, Ptr info)
{
    static int count = 0;
    Task_TransferInfo * mpcsInfo = (Task_TransferInfo *) arg ;

    (Void) eventNo ; /* To avoid compiler warning. */

    count++;
    if (count==1) {
        buf =(unsigned char*)info ;
    }
    if (count==2) {
        length = (int)info;
    }

    SEM_post(&(mpcsInfo->notifySemObj));
}
Пример #16
0
/*
 * interrupt routine to test input from I2S on a SampleBySample basis
 ***********************************************************************/
void i2s_rxIsr(void) /* dispatcher used */
//interrupt void i2s_rxIsr(void) /* no dispatcher used */
{ /* SampleBySample */
#ifdef SAMPLE_BY_SAMPLE_REC
    static Uint16 sample_cnt = 0;

    //if (set_record_interface >= START_REC_WAIT_NUM_FRAMES)
    //if (h_usb_int_tcount > 1) /* wait for IN tokens from Host */
    {
        /* Get sample from I2S input, place in input circular buffer */
        codec_input_buffer[codec_input_buffer_input_index] = *(ioport volatile unsigned *)I2S2_I2SRXLT1;

        // instead of changing codec sample rate to 16KHz, get same input sample 3 times (when codec is set to 48KHz)
        if (sample_cnt >= 2)
        {
            codec_input_buffer_input_index++;
            if (codec_input_buffer_input_index >= CODEC_INPUT_BUFFER_SIZE)
            {
                codec_input_buffer_input_index = 0;
                SEM_post(&SEM_DmaRxLeftComplete);
            }

            codec_input_sample_count++;

            // check for overflow
            if (codec_input_sample_count > CODEC_INPUT_BUFFER_SIZE)
            {
                codec_input_buffer_overflow++;
                //LOG_printf(&trace, "ERROR: codec_input_buffer_overflow: %d", codec_input_buffer_overflow);
                LOG_printf(&trace, "ERROR: codec input buffer OVERFLOW: %d", codec_input_sample_count);
            }
        }
    }

    if ((set_record_interface >= 2) && (++sample_cnt >= 3))
    {
#ifdef COUNT_REC_SAMPS_IN_USB_FRAME_REC
        i2sRxSampCnt++;
#endif
        sample_cnt = 0;
    }

#endif /* SAMPLE_BY_SAMPLE_REC */

}
/**
* \brief   EDMA3 OS Semaphore Give
*
*      This function gives or relinquishes an already
*      acquired semaphore token
* \param   hSem [IN] is the handle of the specified semaphore
* \return  EDMA3_DRV_Result if successful else a suitable error code
*/
EDMA3_DRV_Result edma3OsSemGive(EDMA3_OS_Sem_Handle hSem)
{
#if 0  
  EDMA3_DRV_Result semGiveResult = EDMA3_DRV_SOK;
  
  if(NULL == hSem)
  {
    semGiveResult = EDMA3_DRV_E_INVALID_PARAM;
  }
  else
  {
    if (TSK_self() != (TSK_Handle)&KNL_dummy)
    {
      SEM_post(hSem);
    }
  }
  
  return semGiveResult;
#else
  return 0;
#endif
}
void FollowUpMonitorWakeup()
{
	globals.statistics.system.ticksPassed++;
	if(SEM_count(&FollowUpMonitorSem) == 0)
		SEM_post(&FollowUpMonitorSem);
}
Пример #19
0
/**
 *  \brief  Function to play the audio
 *
 *  \param  dataLength    - Length of the data to be sent to audio device (In words)
 *  \param  leftDataBuf   - Left data buffer pointer
 *  \param  rightDataBuf  - Right data buffer pointer
 *  \param  ptr           - Pointer to hold the palyback status
 *
 *  \return Media status
 */
CSL_AcMediaStatus appPlayAudio(
    Uint16    dataLength,
    Uint16    *leftDataBuf,
    Uint16    *rightDataBuf,
    void      *ptr
)
{
    Uint16    *playBackActive;
    Int16     asrcOutputFifoNumBlk;
#ifdef ENABLE_ASRC
    Uint16    numOutSamps;
    Int16     status;
#else
    Uint16    looper;
    Uint16    tmpIdx;
#endif

#ifdef C5535_EZDSP_DEMO
	int i, numSample;
	int *samplePtr;
	extern int bufferIn[1024];
	extern int bufferInIdx;
	// get the number of samples
	numSample = dataLength/2;
	samplePtr = (int*)leftDataBuf;
#endif

    // NOTE: leftDataBuf and rightDataBuf point to the same buffer

    playBackActive = (Uint16*)ptr;
    *playBackActive = TRUE;

    // the first byte is the number of bytes in the buffer followed by the first left audio sample
    leftDataBuf++;

#ifdef C5535_EZDSP_DEMO
	samplePtr++;
	for (i=0; i<numSample; i++)
	{
		if (bufferInIdx<256)
		{
			/* Take average of left and right channels. */
			//temp = (signed long)samplePtr[i*2] + (signed long)samplePtr[i*2+1];
			//temp >>= 1;    /* Divide by 2 to prevent overload at output */
			//bufferIn[bufferInIdx] = (int)temp;
			// copy the audio sample from the USB buffer into bufferIn (left channel only)
			bufferIn[bufferInIdx] = (int)samplePtr[i*2]*2;
			bufferInIdx++;
			// if the bufferIn is filled, then send a semaphore to the SpectrumDisplayTask
			if (bufferInIdx==256)
			{
				// send semaphore
				SEM_post(&SEM_BufferInReady);
			}
		}
	}
#endif

#ifdef ENABLE_STEREO_PLAYBACK
    // stereo USB audio - the audio data is L R L R ........

#ifdef ENABLE_ASRC
    //STS_add(&mySts2, hAsrc->numOutSamps); // debug

    /* Update ASRC phase increment */
    status = ASRC_updatePhaseIncr(hAsrc);
    //STS_add(&mySts2, hAsrc->deltaPhaseIncr);
    if (status != ASRC_SOK)
    {
        usb_error++;
        LOG_printf(&trace, "ERROR: ASRC_updatePhaseIncr() failed: %d\n", status);
    }

    /* Update ASRC input FIFO */
    status = ASRC_updateInFifo(hAsrc, (Int16 *)leftDataBuf, dataLength/2);
    if (status != ASRC_SOK)
    {
        usb_error++;
        LOG_printf(&trace, "ERROR: ASRC_updateInFifo() failed: %d\n", status);
    }

    /* Get ASRC number of output samples to generate */
    status = ASRC_getNumOutSamps(hAsrc, &numOutSamps);
    if (status != ASRC_SOK)
    {
        usb_error++;
        LOG_printf(&trace, "ERROR: ASRC_getNumOutSamps() failed.");
    }

    //HWI_disable();
    /* Check output FIFO overflow -- require at least one free buffer in output FIFO */
    asrcOutputFifoNumBlk = asrcOutputFifoInBlk - asrcOutputFifoOutBlk + 1;
    //HWI_enable();
    if (asrcOutputFifoNumBlk < 0)
    {
        asrcOutputFifoNumBlk += ASRC_OUTPUT_FIFO_NUM_BLK;
    }
    //STS_add(&mySts2, asrcOutputFifoNumBlk); // debug
    //LOG_printf(&trace, "%d", asrcOutputFifoNumBlk); // debug
    if (asrcOutputFifoNumBlk > (ASRC_OUTPUT_FIFO_NUM_BLK - 2))
    {
        asrcOutputFifoInError++;
        LOG_printf(&trace, "ERROR: ASRC output FIFO OVERFLOW");
        //LOG_printf(&trace, "%04x %d", (asrcOutputFifoInBlk<<8)|asrcOutputFifoOutBlk, asrcOutputFifoNumBlk);
    }

    /* Generate ASRC output samples */
    status = ASRC_genOutInterpCoefs16b(hAsrc, &asrcOutputFifo[asrcOutputFifoInBlk][0], numOutSamps);
    if (status != ASRC_SOK)
    {
        usb_error++;
        LOG_printf(&trace, "ERROR: ASRC_genOutInterpCoefs16b() failed.");
    }

    /* Update ASRC output FIFO */
    if (rdy_to_consume_asrc_output == TRUE)
    {
        //HWI_disable();
        asrcOutputFifoBlkNumSamps[asrcOutputFifoInBlk] = 2 * numOutSamps; // outFifoNumCh * numOutSamps;
        //HWI_enable();
        asrcOutputFifoInBlk = (asrcOutputFifoInBlk + 1) & (ASRC_OUTPUT_FIFO_NUM_BLK - 1);
    }

    if (usb_play_mode == FALSE)
    {
        usb_play_mode = TRUE;
    }

#else /* ENABLE_ASRC */

    /* Copy audio samples to circular buffer */
    for (looper = 0; looper < (dataLength/2); looper++)
    {
        /* Check for overflow */
        tmpIdx = no_asrc_buffer_input_index + 1;
        if (tmpIdx >= CODEC_OUTPUT_BUFFER_SIZE)
        {
            tmpIdx = 0;
        }
        if(tmpIdx == no_asrc_buffer_output_index)
        {
            no_asrc_buffer_in_error++;
            LOG_printf(&trace, "ERROR: no_asrc_buffer OVERFLOW");
        }

        /* Copy left */
        no_asrc_buffer[no_asrc_buffer_input_index++] = *leftDataBuf++;
        /* Copy right */
        no_asrc_buffer[no_asrc_buffer_input_index++] = *leftDataBuf++;

        if (no_asrc_buffer_input_index >= CODEC_OUTPUT_BUFFER_SIZE)
        {
            no_asrc_buffer_inwrap++;
            no_asrc_buffer_input_index = 0;
        }
    }

    //HWI_disable();
    /* Check output FIFO overflow -- require at least one free buffer in output FIFO */
    asrcOutputFifoNumBlk = asrcOutputFifoInBlk - asrcOutputFifoOutBlk + 1;
    //HWI_enable();
    if (asrcOutputFifoNumBlk < 0)
    {
        asrcOutputFifoNumBlk += ASRC_OUTPUT_FIFO_NUM_BLK;
    }
    if (asrcOutputFifoNumBlk > (ASRC_OUTPUT_FIFO_NUM_BLK - 2))
    {
        asrcOutputFifoInError++;
        LOG_printf(&trace, "ERROR: ASRC output FIFO OVERFLOW");
    }

    /* Copy audio samples to codec output FIFO */
    for (looper = 0; looper < (dataLength/2); looper++)
    {
        /* Check for underflow */
        if (no_asrc_buffer_output_index == no_asrc_buffer_input_index)
        {
            no_asrc_buffer_out_error++;
            LOG_printf(&trace, "ERROR: no_asrc_buffer UNDERFLOW");
        }

        asrcOutputFifo[asrcOutputFifoInBlk][2*looper] = no_asrc_buffer[no_asrc_buffer_output_index++];
        asrcOutputFifo[asrcOutputFifoInBlk][2*looper+1] = no_asrc_buffer[no_asrc_buffer_output_index++];
        if(no_asrc_buffer_output_index >= CODEC_OUTPUT_BUFFER_SIZE)
        {
            no_asrc_buffer_outwrap++;
            no_asrc_buffer_output_index = 0;
        }
    }

    if (rdy_to_consume_asrc_output == TRUE)
    {
        /* Update codec output FIFO */
        //HWI_disable();
        asrcOutputFifoBlkNumSamps[asrcOutputFifoInBlk] = dataLength;
        //HWI_enable();
        asrcOutputFifoInBlk = (asrcOutputFifoInBlk + 1) & (ASRC_OUTPUT_FIFO_NUM_BLK - 1);
    }

    if (usb_play_mode == FALSE)
    {
        usb_play_mode = TRUE;
    }
#endif /* ENABLE_ASRC */

#else //ENABLE_STEREO_PLAYBACK
    LOG_printf(&trace, "ERROR: assumed stereo playback, but ENABLE_STEREO_PLAYBACK is not defined");
#endif // ENABLE_STEREO_PLAYBACK

    return(CSL_AC_MEDIACCESS_SUCCESS);
}
Пример #20
0
/*
 *  ======== DPI_open ========
 */
Static Int DPI_open(DEV_Handle dev, String name)
{
    PipeObj         *pipe;
    SPipeObj        *sPipe, *tmpPipe;

    /* decode and validate devid */
    if (dev->devid < 0) {
        dev->devid = atoi(name);
    }

    SEM_pend(mutex, SYS_FOREVER);

    /* search pipe list for previously opened pipe with same id */
    sPipe = MEM_ILLEGAL;
    if (!QUE_empty(sPipeList)) {
        tmpPipe = (SPipeObj *)QUE_head(sPipeList);
        do {
            if (tmpPipe->id == dev->devid) {
                sPipe = tmpPipe;
                break;
            }
            tmpPipe = (SPipeObj *)QUE_next((&tmpPipe->link));
        } while (tmpPipe != (SPipeObj *)sPipeList);
    }

    if (sPipe == MEM_ILLEGAL) {
        /*
         * Allocate and initialize SPipeObj on first open.
         */
        sPipe = mkSPipe(dev);
        if (sPipe == MEM_ILLEGAL) {
            SEM_post(mutex);
            return SYS_EALLOC;
        }
        QUE_put(sPipeList, &sPipe->link);
    }
    else {      /* sPipe found on list */
        if (sPipe->device[dev->mode] != NULL) {
            /*
             * Only one input and one output allowed
             */
            SEM_post(mutex);
            return SYS_EBUSY;
        }
    }
    sPipe->device[dev->mode] = dev;
    SEM_post(mutex);

    pipe = MEM_alloc(0, sizeof (PipeObj), 0);
    if (pipe == MEM_ILLEGAL) {
        /*
         * We need to undo work done by mkSPipe() if first open.
         * Also need to undo changes to sPipeList queue.
         */
        QUE_remove(&sPipe->link);
        rmSPipe(sPipe);
        return SYS_EALLOC;
    }

    /*
     * Criss-cross SEM handles so both sides are referencing
     * the same physical objects.
     */
    if (dev->mode == DEV_INPUT) {
        pipe->fromSem = sPipe->dataSem;
        pipe->toSem = sPipe->freeSem;
    }
    else {
        pipe->toSem = sPipe->dataSem;
        pipe->fromSem = sPipe->freeSem;
    }

    /*
     * Point things around.
     */
    pipe->sPipe = sPipe;
    dev->object = (Ptr)pipe;

    return (SYS_OK);
}
Пример #21
0
/*
 * interrupt routine to test output to I2S on a SampleBySample basis
 ***********************************************************************/
void i2s_txIsr(void) /* dispatcher used */
//interrupt void i2s_txIsr(void) /* no dispatcher used */
{ /* SampleBySample */
#ifdef SAMPLE_BY_SAMPLE_PB
    Int16     status;
#if defined(SAMPLE_RATE_TX_48kHz) && defined(SAMPLE_RATE_RX_16kHz)  /* 48 kHz playback, but 16 kHz record => count every 3rd sample for record */
    static Uint16 sample_cnt = 0;
#endif

    /* Get sample from output FIFO, place in I2S output */
    *(ioport volatile unsigned *)I2S_I2STXLT1 = codec_output_buffer[codec_output_buf_samp_cnt];
    *(ioport volatile unsigned *)I2S_I2STXRT1 = codec_output_buffer[codec_output_buf_samp_cnt+1];

    if (usb_play_mode == TRUE)
    {
        /* Accumulate phase */
        status = ASRC_accPhase(hAsrc);
        if (status != ASRC_SOK)
        {
            dma_error++;
            LOG_printf(&trace, "ERROR: ASRC_accPhase() failed: %d\n", status);
            //while(1);
        }
    }

    codec_output_buf_samp_cnt += 2;

    /* Check if swapping ping/pong buffers */
    if (codec_output_buf_samp_cnt >= i2sTxBuffSz)
    {
        if (codec_output_buffer_avail == FALSE) /* check output FIFO underflow */
        {
            codec_output_buffer_out_error++;
            LOG_printf(&trace, "ERROR: codec output FIFO UNDERFLOW");
            //while(1);
        }

        tx_buf_sel ^= 0x1;
        codec_output_buffer = ping_pong_i2sTxBuf + tx_buf_sel*i2sTxBuffSz;
        codec_output_buf_samp_cnt = 0;
        codec_output_buffer_avail = FALSE;

        SEM_post(&SEM_PbAudioAlg);
        //SEM_post(&SEM_DmaRxLeftComplete);
    }

#ifdef COUNT_REC_SAMPS_IN_USB_FRAME_PB
#if defined(SAMPLE_RATE_TX_48kHz) && defined(SAMPLE_RATE_RX_16kHz)  /* 48 kHz playback, but 16 kHz record => count every 3rd sample for record */
    if ((set_record_interface >= 2) && (sample_cnt >= 2))
    {
        i2sRxSampCnt++;
    }

    if (++sample_cnt >= 3)
    {
        sample_cnt = 0;
    }
#else
    if (set_record_interface >= 2) /* (48 kHz playback and 48 kHz record) or (16 kHz playback and 16 kHz record) */
    {
        i2sRxSampCnt++;
    }
#endif
#endif

#endif /* SAMPLE_BY_SAMPLE_PB */
}
Пример #22
0
/*
 * interrupt routine to test output to I2S on a SampleBySample basis
 ***********************************************************************/
void i2s_txIsr(void) /* dispatcher used */
//interrupt void i2s_txIsr(void) /* no dispatcher used */
{ /* SampleBySample */
#ifdef SAMPLE_BY_SAMPLE_PB
    Int16     status;
    static Uint16 sample_cnt = 0;

    /* Get sample from output FIFO, place in I2S output */
    *(ioport volatile unsigned *)I2S_I2STXLT1 = codec_output_buffer[codec_output_buf_samp_cnt];
    *(ioport volatile unsigned *)I2S_I2STXRT1 = codec_output_buffer[codec_output_buf_samp_cnt+1];

    /* Instead of changing codec sample rate to 16KHz, output same sample 3 times (when codec is set to 48KHz) */
    if ((active_sample_rate == ACTIVE_SAMPLE_RATE_48KHZ) || (sample_cnt >= 2))
    {
        if (usb_play_mode == TRUE)
        {
            /* Accumulate phase */
            status = ASRC_accPhase(hAsrc);
            if (status != ASRC_SOK)
            {
                dma_error++;
                LOG_printf(&trace, "ERROR: ASRC_accPhase() failed: %d\n", status);
                //while(1);
            }
        }

        codec_output_buf_samp_cnt += 2;

        /* Check if moving to next output block in FIFO */
        if (codec_output_buf_samp_cnt >= i2sTxBuffSz)
        {
            if (codec_output_buffer_avail == FALSE) /* check output FIFO underflow */
            {
                codec_output_buffer_out_error++;
                LOG_printf(&trace, "ERROR: codec output FIFO UNDERFLOW");
                //while(1);
            }

            tx_buf_sel ^= 0x1;
            codec_output_buffer = ping_pong_i2sTxBuf + tx_buf_sel*i2sTxBuffSz;
            codec_output_buf_samp_cnt = 0;
            codec_output_buffer_avail = FALSE;

            SEM_post(&SEM_PbAudioAlg);
        }
    }

#ifdef COUNT_REC_SAMPS_IN_USB_FRAME_PB
#ifdef SAMPLE_RATE_RX_16kHz /* 48 kHz playback, but 16 kHz record => count every 3rd sample */
    if ((set_record_interface >= 2) && (sample_cnt >= 2))
    {
        i2sRxSampCnt++;
    }
#else
    if (set_record_interface >= 2) /* 48 kHz record, so count every sample */
    {
        i2sRxSampCnt++;
    }
#endif
#endif

    if (++sample_cnt >= 3)
    {
        sample_cnt = 0;
    }

#endif /* SAMPLE_BY_SAMPLE_PB */
}
Пример #23
0
/*
 *  ======== Sem_post ========
 */
Void Sem_post(Sem_Handle sem)
{
    SEM_post((SEM_Handle)sem);
}
Пример #24
0
/*
 *  ======== DPI_issue ========
 */
Static Int DPI_issue(DEV_Handle dev)
{
    PipeObj         *pipe = (PipeObj *)dev->object;
    SPipeObj        *sPipe = pipe->sPipe;
    DEV_Handle      otherdev = sPipe->device[dev->mode ^ 0x1];
    SEM_Handle      otherReady = sPipe->readySem[dev->mode ^ 0x1];
    DEV_Frame       *otherframe;
    DEV_Frame       *frame;
#ifdef COPYBUFS
    DEV_Frame       *srcframe;
    DEV_Frame       *dstframe;
#endif
    
    /*
     * Atomically check that each side has a frame so we can do an
     * exchange.  We can't be sure that a frame is on the
     * dev->todevice queue (just put there by SIO) since a task
     * switch to the task on the other side might intervene and
     * take the frame from this side.
     */
    TSK_disable();
    if (otherdev != NULL &&
        !QUE_empty(dev->todevice) && !QUE_empty(otherdev->todevice)) {

        otherframe = QUE_get(otherdev->todevice);
        frame = QUE_get(dev->todevice);

        /* done with atomic stuff */
        TSK_enable();

/*
 * #define COPYBUFS to cause buffers to be copied through the pipe
 * instead of being exchanged.  Doing so retains the semantics of
 * the ISSUERECLAIM model, but is slow.  If COPYBUFS is *not* defined,
 * then one side reclaims buffers issued by the other side, thereby
 * not strictly retaining buffer ordering.
 */
#ifdef COPYBUFS
        if (dev->mode == DEV_INPUT) {
            dstframe = frame;
            srcframe = otherframe;
        }
        else {
            dstframe = otherframe;
            srcframe = frame;
        }
        memcpy(dstframe->addr, srcframe->addr, srcframe->size);
        dstframe->size = srcframe->size;
        dstframe->arg = srcframe->arg;

        QUE_put(dev->fromdevice, frame);
        QUE_put(otherdev->fromdevice, otherframe);

        /*
         * frames reclaimed from an output device must have size 0.
         */
        if (dev->mode != DEV_INPUT) {
            frame->size = 0;
        }
        else {
            otherframe->size = 0;
        }
#else
        QUE_put(dev->fromdevice, otherframe);
        QUE_put(otherdev->fromdevice, frame);

        /*
         * frames reclaimed from an output device must have size 0.
         */
        if (dev->mode != DEV_INPUT) {
            otherframe->size = 0;
        }
        else {
            frame->size = 0;
        }
#endif
    }
    else {
        /* done with atomic stuff */
        TSK_enable();
    }

    SEM_post(pipe->toSem);

    if (otherReady != NULL) {
        SEM_post(otherReady);
    }

    return SYS_OK;
}
Пример #25
0
Int rmanTask(Arg scratchId, Arg resourceId,  Arg priority, Arg taskId, 
        Arg yieldFlag)
{

    Int i;
    IALG_Fxns * algFxns = &DUMALG_TI_IALG;
    IRES_Fxns * resFxns = &DUMALG_TI_IRES;
    IDUMALG_Handle dumHandle = NULL; 
    IDUMALG_Params params;

    GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_ENTER, "_rmanTask> Enter \n");

    params.size = sizeof(IDUMALG_Params);

    GT_4trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS, "_rmanTask> "
            "Task #%d: ScratchId %d, Priority %d Yield %d\n",taskId, scratchId,
            priority, yieldFlag);

    params.yieldFlag  = yieldFlag;
    params.taskId = taskId; 

    for (i = 0; i < NUM_RESOURCES; i++) {
        params.hdvicp[i] = *((IRES_HDVICP_RequestType *)resourceId + i);
        GT_1trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS, "_rmanTask> "
        "Requesting resource %d (2 => ANY)\n",(Int)params.hdvicp[i]);
    }
    /*
     * Create an instance of the algorithm using "algFxns" 
     */
    SEM_pend(mutex, SYS_FOREVER);
    dumHandle = (IDUMALG_Handle)DSKT2_createAlg((Int)scratchId, 
            (IALG_Fxns *)algFxns, NULL,(IALG_Params *)&params);
    if (dumHandle == NULL) {
        GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> "
                "Alg creation failed\n");
        return -1;
    } 
    SEM_post(mutex);
    /* Assign resources to the algorithm */
    if (IRES_OK != RMAN_assignResources((IALG_Handle)dumHandle,
                resFxns, scratchId)) {
        GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> "
                "Assign resource failed\n");
        return -1;
    }


    /*
     * Activate the Algorithm
     */
    DSKT2_activateAlg(scratchId, (IALG_Handle)dumHandle);

    /*
     * Activate All Resources
     */
    RMAN_activateAllResources((IALG_Handle)dumHandle, resFxns, scratchId);

    /*
     * Use IALG interfaces to do something 
     */
        dumHandle->fxns->useHDVICP(dumHandle, taskId);
    
    /*
     * Deactivate All Resources
     */
    RMAN_deactivateAllResources((IALG_Handle)dumHandle, resFxns, scratchId);

    /*
     * Deactivate algorithm 
     */
    DSKT2_deactivateAlg(scratchId, (IALG_Handle)dumHandle);

    /*
     * Free resources assigned to this algorihtm
     */
    if (IRES_OK != RMAN_freeResources((IALG_Handle)(dumHandle),
                resFxns, scratchId)) {
        GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> "
                "Free resource failed\n");
        return -1;
    }

    /*
     * Free instance of the algorithm created
     */
    SEM_pend(mutex, SYS_FOREVER);
    DSKT2_freeAlg(scratchId, (IALG_Handle)dumHandle);
    SEM_post(mutex);

    SEM_post(done);

    GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_ENTER, "_rmanTask> Exit \n");

    return 0;
}
void InitializeSystem(void* parameter, Uint16 followUpItemIndex)
{

	Uns interruptStatus;
	Uint16 i, j;
	double executionTime = 0;
	double genAvgTime = 0;
	double genMinTime = DBL_MAX;
	double genMaxTime = DBL_MIN;
	double avgTime[9] = {0,0,0,0,0,0,0,0,0};
	double minTime[9] = {DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX,DBL_MAX};
	double maxTime[9] = {DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN,DBL_MIN};
	Uint32 startTime = 0;
	Uint32 numSamples;
	struct Packet newPacket;

	// Allow the system to write to the system registers
	EALLOW;

	// Set up the heartbeat
	gpioCtrlRegisters.GPBDIR.bit.HEARTBEAT = 1;
	gpioDataRegisters.GPBDAT.bit.HEARTBEAT = 1;

	// Set up the seven segment display
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_A = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_A = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_B = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_B = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_C = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_C = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_D = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_D = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_E = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_E = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_F = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_F = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_G = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_G = 0;
	gpioCtrlRegisters.GPADIR.bit.SEVENSEG_DIGIT = 1;
	gpioDataRegisters.GPADAT.bit.SEVENSEG_DIGIT = 1;
	
	// Set up timer 0 for use with SPI related timings
	sysCtrlRegisters.HISPCP.all = 0;				// Set the HSPCLK to run at SYSCLK
	sysCtrlRegisters.LOSPCP.bit.LSPCLK = 0; 		// Set the LSPCLK to run at SYSCLK
	timer0Registers.TCR.bit.TSS = 1;				// Stop the timer
	timer0Registers.TPR.bit.TDDR = 0;				// Do not prescale the timer
	timer0Registers.PRD.all = 0xFFFFFFFF;			// Set the period register to it's largest possible value
	timer0Registers.TCR.bit.TIE = false;			// Disable timer interrupts
	timer0Registers.TCR.bit.FREE = 0;				// Set the timer to stop when a breakpoint occrs
	timer0Registers.TCR.bit.SOFT = 0;
	timer0Registers.TCR.bit.TRB = 1;				// Load the period register
	timer0Registers.TCR.bit.TSS = 0;				// Start the timer
	
	// Set up the global SPI-related settings
	IER |= 0x20;									// Enable CPU INT6
	
	// Disallow the system to write to the system registers
	EDIS;

	interruptStatus = HWI_disable();
	numSamples = 0;
	for(j = 0; j < 1000; j++)
	{
		
		InitializeGlobalVariables();

		globals.root.availableAddresses[0].address = 1;
		globals.root.availableAddresses[0].addressTaken = true;
		globals.root.availableAddresses[1].address = 2;
		globals.root.availableAddresses[1].addressTaken = true;
		globals.root.availableAddresses[2].address = 3;
		globals.root.availableAddresses[2].addressTaken = true;
		globals.root.availableAddresses[3].address = 4;
		globals.root.availableAddresses[3].addressTaken = true;
		globals.root.availableAddresses[4].address = 5;
		globals.root.availableAddresses[4].addressTaken = true;
		globals.root.availableAddresses[5].address = 6;
		globals.root.availableAddresses[5].addressTaken = true;
		globals.root.availableAddresses[6].address = 7;
		globals.root.availableAddresses[6].addressTaken = true;
		globals.root.availableAddresses[7].address = 8;
		globals.root.availableAddresses[7].addressTaken = true;	

		globals.protocol.globalNeighborInfo[1][PORTA].nodeAddress = 2;
		globals.protocol.globalNeighborInfo[1][PORTB].nodeAddress = 3;

		globals.protocol.globalNeighborInfo[2][PORTA].nodeAddress = 1;
		globals.protocol.globalNeighborInfo[2][PORTB].nodeAddress = 4;

		globals.protocol.globalNeighborInfo[3][PORTA].nodeAddress = 1;
		globals.protocol.globalNeighborInfo[3][PORTB].nodeAddress = 4;
		globals.protocol.globalNeighborInfo[3][PORTC].nodeAddress = 5;

		globals.protocol.globalNeighborInfo[4][PORTA].nodeAddress = 2;
		globals.protocol.globalNeighborInfo[4][PORTB].nodeAddress = 3;
		globals.protocol.globalNeighborInfo[4][PORTC].nodeAddress = 6;

		globals.protocol.globalNeighborInfo[5][PORTA].nodeAddress = 3;
		globals.protocol.globalNeighborInfo[5][PORTB].nodeAddress = 6;
		globals.protocol.globalNeighborInfo[5][PORTC].nodeAddress = 7;

		globals.protocol.globalNeighborInfo[6][PORTA].nodeAddress = 4;
		globals.protocol.globalNeighborInfo[6][PORTB].nodeAddress = 5;
		globals.protocol.globalNeighborInfo[6][PORTC].nodeAddress = 8;

		globals.protocol.globalNeighborInfo[7][PORTA].nodeAddress = 5;
		globals.protocol.globalNeighborInfo[7][PORTB].nodeAddress = 8;

		globals.protocol.globalNeighborInfo[8][PORTA].nodeAddress = 6;
		globals.protocol.globalNeighborInfo[8][PORTB].nodeAddress = 7;

		startTime = timer0Registers.TIM.all;
		GenerateRoutingTree();
		executionTime = TimeDifference(startTime, timer0Registers.TIM.all);
		genAvgTime = (genAvgTime * numSamples) + executionTime;
		numSamples++;
		genAvgTime /= numSamples;
		if(executionTime < genMinTime)
			genMinTime = executionTime;
		else if(executionTime > genMaxTime)
			genMaxTime = executionTime;
	}

	for(i = 2; i <= 8; i++)
	{
		numSamples = 0;
		for(j = 0; j < 1000; j++)
		{
			startTime = timer0Registers.TIM.all;
			GenerateRoutingPath(1, i, &newPacket);
			executionTime = TimeDifference(startTime, timer0Registers.TIM.all);
			avgTime[i] = (avgTime[i] * numSamples) + executionTime;
			numSamples++;
			avgTime[i] /= numSamples;
			if(executionTime < minTime[i])
				minTime[i] = executionTime;
			else if(executionTime > maxTime[i])
				maxTime[i] = executionTime;
		}
	}
	HWI_restore(interruptStatus);
	asm(" NOP");

	// Set the seed for the random number generator
	SetRandomSeed(0x175E);

	// Set up each individual port
	SetupPort(PORTA);
	SetupPort(PORTB);
	SetupPort(PORTC);
	SetupPort(PORTD);

	// Create the direct data cleanup follow-up item
	AddFollowUpItem(&CleanupDirectData,NULL,DIRECT_DATA_CLEANUP_RATE,true);

	// Create the neighbor check follow-up item
#if defined(IS_ROOT)

#if TEST != TEST_SPI
	globals.followUpMonitor.neighborFollowUpIndex = AddFollowUpItem(&NeighborFollowUp,NULL,NEIGHBOR_FOLLOW_UP_RATE,true);
#endif
	SetSevenSegmentDisplay(SEVENSEG_BLANK);
	globals.processing.sevenSegmentLowerDigit = globals.protocol.address;

#elif defined (IS_ROUTER)

#if TEST != TEST_SPI
	globals.followUpMonitor.neighborFollowUpIndex = AddFollowUpItem(&NeighborFollowUp,NULL,NEIGHBOR_FOLLOW_UP_RATE_WITHOUT_ADDRESS,true);
#endif
	SetSevenSegmentDisplay(SEVENSEG_BLANK);

	// Register the test service
	RegisterServiceProvider(TEST_SERVICE_TAG,TEST_SERVICE_TASK_PRIORITY,&TestServiceTask,&TestServiceSem);

#endif

	

	// Let the other threads know that initialization is finished
	SEM_post(&ProcessInboundFlitsSem);
	SEM_post(&TestServiceSem);
}
void CleanupDirectData(void* parameter, Uint16 followUpItemIndex)
{
	Uint16 i, j, port, virtualChannel;
	struct Mail message;

	// Check if there are any virtual channels that need to be cleared
	for(i = 0; i < NUM_PORTS; i++)
	{
		for(j = 0; j < NUM_VIRTUAL_DATA_CHANNELS; j++)
		{
			// Check if this virtual channel is active
			if(globals.processing.virtualChannels[i][j].virtualChannelBlockedCount > 0)
				globals.processing.virtualChannels[i][j].virtualChannelBlockedCount--;
		}
	}

	// Check if there are any data transfers that need to be tagged or removed
	for(i = 0; i < NUM_DATA_PACKET_LOOKUPS; i++)
	{
		// Check if this data transfer is active
		if(globals.processing.dataTransferPackets[i].transferInfo.packetID != 0)
		{
			// Decrement the time to live for the transfer
			globals.processing.dataTransferPackets[i].dataBufferInfo.timeToLive--;
			
			// Check if this transfer has expired
			if(globals.processing.dataTransferPackets[i].dataBufferInfo.timeToLive <= 0)
			{
#if TEST == TEST_PROTOCOL
				
				if(globals.processing.dataTransferPackets[i].transferInfo.packetID == protocolTestPacketIDs[0])
					receivedResponse[0] = true;
				if(globals.processing.dataTransferPackets[i].transferInfo.packetID == protocolTestPacketIDs[1])
					receivedResponse[1] = true;
				if(globals.processing.dataTransferPackets[i].transferInfo.packetID == protocolTestPacketIDs[2])
					receivedResponse[2] = true;
				if(SEM_count(&TestServiceSem) == 0)
					SEM_post(&TestServiceSem);

#elif TEST == TEST_MPI
				
				// Send a message to the MPI send service
				CreateMessage(&message, 
					NULL,
					0,
					MAIL_DATA_TRANSFER_FAILED,
					globals.processing.dataTransferPackets[i].transferInfo.packetID,
					MPI_ANY_REQUEST->requestType,
					MPI_ANY_REQUEST->requestID,
					ADDRESS_UNDEFINED,
					ADDRESS_UNDEFINED,
					TEST_SERVICE_TAG,
					TEST_SERVICE_TAG);
				SendMail(TEST_SERVICE_TAG, &message);

#endif
				port = globals.processing.dataTransferPackets[i].transferInfo.port;
				virtualChannel = globals.processing.dataTransferPackets[i].transferInfo.virtualChannel;
				ClearDataTransferLookup(globals.processing.dataTransferPackets[i].transferInfo.packetID);
				globals.processing.virtualChannels[port][virtualChannel].virtualChannelBlockedCount = VIRTUAL_CHANNEL_INITIAL_BLOCKED_COUNT;
				globals.statistics.packet.numDataTransfersExpired++;
			}
		}
	}

	// Check if there are any direct transfers that need to be tagged or removed
	for(i = 0; i < NUM_PORTS; i++)
	{
		for(j = 0; j < NUM_VIRTUAL_DATA_CHANNELS; j++)
		{
			// Check if this direct transfer is active
			if(globals.processing.directTransfers[i][j].destinationPort != PORT_UNDEFINED)
			{
				// Decrement the time to live for the transfer
				globals.processing.directTransfers[i][j].timeToLive--;
					
				// Check if this transfer has expired
				if(globals.processing.directTransfers[i][j].timeToLive <= 0)
				{
					ReleaseVirtualChannel(globals.processing.directTransfers[i][j].destinationPort,
						globals.processing.directTransfers[i][j].destinationVirtualChannel);
					globals.processing.directTransfers[i][j].destinationPort = PORT_UNDEFINED;
					globals.statistics.packet.numDirectTransfersExpired++;
				}
			}
		}
	}

	// Check if there are any direct buffers that need to be tagged or removed
	for(i = 0; i < NUM_PORTS; i++)
	{
		for(j = 0; j < NUM_VIRTUAL_DATA_CHANNELS; j++)
		{
			// Check if this direct buffer is active
			if(globals.processing.directBuffer[i][j].packet.dataBuffer != NULL)
			{
				// Decrement the time to live for the buffer
				globals.processing.directBuffer[i][j].bufferStatus.timeToLive--;
				
				// Check if this buffer has expired
				if(globals.processing.directBuffer[i][j].bufferStatus.timeToLive <= 0)
				{
					MemFree(globals.processing.directBuffer[i][j].packet.dataBuffer);
					globals.processing.directBuffer[i][j].packet.dataBuffer = NULL;
					globals.statistics.packet.numDirectBuffersExpired++;
				}
			}
		}
	}
}