示例#1
0
/******************************************************************************
 * Fifo_create
 ******************************************************************************/
Fifo_Handle Fifo_create(Fifo_Attrs *attrs)
{
    Fifo_Handle hFifo;
    BUF_Attrs bAttrs = BUF_ATTRS;

    if (attrs == NULL) {
        return NULL;
    }
    
    hFifo = MEM_calloc(Dmai_Bios_segid, sizeof(Fifo_Object), 0);

    if (hFifo == NULL) {
        Dmai_err0("Failed to allocate space for Fifo Object\n");
        return NULL;
    }
    
    /* Allocate a buffer pool for messages */
    bAttrs.segid = Dmai_Bios_segid;
    hFifo->hBufPool = BUF_create(attrs->maxElems, sizeof(Fifo_Elem), 0, &bAttrs);
    if (hFifo->hBufPool == NULL) {
        Dmai_err0("Failed to allocate space for buffer pool\n");
        MEM_free(Dmai_Bios_segid, hFifo, sizeof(Fifo_Object));
        return NULL;
    }
    
    /* initialize the object */
    QUE_new(&hFifo->queue);
    SEM_new(&hFifo->sem, 0);
    SEM_new(&hFifo->mutex, 1);

    return hFifo;
}
示例#2
0
Bool		bfqCreate			( BufferQueue_Handle queue, BufferQueue_Frame * frames, Int BufCount, Int BufSize, Int SegID)
{
	Int i;
	Ptr p;
	
	// Acquire the frames
	queue->Frames = frames;
	queue->bDynamicFrames = FALSE;
	
	// Init the QUE and SEM objects.
	SEM_new(&(queue->semFullBuffers), 0);
	SEM_new(&(queue->semEmptyBuffers), BufCount);
	
	QUE_new( &(queue->queFullBuffers) );
	QUE_new( &(queue->queEmptyBuffers) );
	QUE_new( &(queue->queEmptyFrames) );
	
	for (i=0; i<BufCount; i++)
	{
		// TODO: handle errors.
		
		// If the _BFQ_INIT_BUFFERS is defined, fill the buffers with 0xFF,
		// leave them uninitialized, otherwise.
#ifdef _BFQ_INIT_BUFFERS
		p = MEM_valloc( SegID, BufSize, 0, 0xFF );
		queue->Frames[i].Buffer = p;
		assertLog( p != MEM_ILLEGAL);
#else
		p = MEM_alloc( SegID, BufSize, 0 );
		queue->Frames[i].Buffer = p;
		assertLog( p != MEM_ILLEGAL);
#endif
		QUE_put(&(queue->queEmptyBuffers), &(queue->Frames[i]));
	}
		
	queue->BufSize = BufSize;
	queue->BufCount = BufCount;
	queue->SegId   = SegID;
	
	return TRUE;
}
示例#3
0
文件: task.c 项目: Imara90/ESLab
Int Task_create (Task_TransferInfo ** infoPtr)
{
    Int status    = SYS_OK ;
    Task_TransferInfo * info = NULL ;

    /* Allocate Task_TransferInfo structure that will be initialized
     * and passed to other phases of the application */
    if (status == SYS_OK) 
	{
        *infoPtr = MEM_calloc (DSPLINK_SEGID,
                               sizeof (Task_TransferInfo),
                               0) ; /* No alignment restriction */
        if (*infoPtr == NULL) 
		{
            status = SYS_EALLOC ;
        }
        else 
		{
            info = *infoPtr ;
        }
    }

    /* Fill up the transfer info structure */
    if (status == SYS_OK) 
	{
        info->dataBuf       = NULL ; /* Set through notification callback. */
        info->bufferSize    = MPCSXFER_BufferSize ;
        SEM_new (&(info->notifySemObj), 0) ;
    }

    /*
     *  Register notification for the event callback to get control and data
     *  buffer pointers from the GPP-side.
     */
    if (status == SYS_OK) 
	{
        status = NOTIFY_register (ID_GPP,
                                  MPCSXFER_IPS_ID,
                                  MPCSXFER_IPS_EVENTNO,
                                  (FnNotifyCbck) Task_notify,
                                  info) ;
        if (status != SYS_OK) 
		{
            return status;
        }
    }

    /*
     *  Send notification to the GPP-side that the application has completed its
     *  setup and is ready for further execution.
     */
    if (status == SYS_OK) 
	{
        status = NOTIFY_notify (ID_GPP,
                                MPCSXFER_IPS_ID,
                                MPCSXFER_IPS_EVENTNO,
                                (Uint32) 0) ; /* No payload to be sent. */
        if (status != SYS_OK) 
		{
            return status;
        }
    }

    /*
     *  Wait for the event callback from the GPP-side to post the semaphore
     *  indicating receipt of the data buffer pointer and image width and height.
     */
    SEM_pend (&(info->notifySemObj), SYS_FOREVER) ;
    SEM_pend (&(info->notifySemObj), SYS_FOREVER) ;

    return status ;
}
示例#4
0
void CClassification::EnterTask()
{
#ifndef _WINDOWS // ------- Don't compile on windows -----

	Uint32 unIntervalTicks;
	
	Bool bLed2 = FALSE;
	ledLight( 2, FALSE );
	
	// Initialize the conveyor device driver and register the trigger semaphore.
	convInit( );
	SEM_new( &m_semTrigger, 0 );
	
	convRegisterSemTrigger( &m_semTrigger, &m_bTrigger );	
	
	// Reset statstics
	GetStats( NULL, TRUE );

	// Initialize the high res timer
	timeInit();
	
	// Pre-calculate the maximum wait time for the semaphore.
	unIntervalTicks = hlpMsToTicks( 1000 * MAXWAIT_SECONDS );
	
	// Open the interlink UART channel and configure it.
	m_hPPUSerial = serOpen( INTERLINK_UART_CHAN, sizeof( ClassificationTable ) *4 );
	assertLog( m_hPPUSerial != NULL );
	serConfigChannel( m_hPPUSerial, 115000, FALSE, FALSE, FALSE );	
	
	// Initialize the jet controller
	TSK_sleep( 2000 );
	CJetControl::Instance()->Init();
	
	// Start watchdog and set it to twice the time of our maximum interval.
	m_unWatchId = CWatchdog::Instance()->AddToWatch( "Classification", MAXWAIT_SECONDS * 2 );
	CWatchdog::Instance()->EnableWatch( m_unWatchId, TRUE );
	
	while( 1 )
	{
			
		// Wait for a trigger signal, timeout at some time to reset watchdog
		if ( SEM_pend( &m_semTrigger, unIntervalTicks ) )
		{
			// Succesfully received a trigger
			ledLight( 2, bLed2 );
			bLed2 = !bLed2;			
						
			// Get the trigger time as exact as possible.
			Uint32 unCurTime = convGetLastTriggerTime();
						
			// Increment our trigger counter.
			m_unCurrentTriggerPulse++;
			// dbgLog( "Entering Trigger %d", m_unCurrentTriggerPulse );
			
			// Store that trigger in the stats. This increments the number of possible potatoes by the number
			// of lanes.
			m_sClassificationStats.unNumPossible += m_nNumLanes;
			
			// See if we're in service mode and handle it.
			if ( m_csmServiceMode != CSM_NORMAL )
			{
				if (   (m_csmServiceMode == CSM_ADJUST_SMALL_EJECTION_PARAMS )
					|| (m_csmServiceMode == CSM_ADJUST_MEDIUM_EJECTION_PARAMS )
					|| (m_csmServiceMode == CSM_ADJUST_LARGE_EJECTION_PARAMS ) )
					ServiceGenParamAdjustCommands( unCurTime );
			}
			else
			{		
				// If not in service mode, see if we've got any due ejections to make and generate
				// the commands for it.
				EjectionTable * pTable;
				
				// See if any ejections are due and generate the jetcontrol commands, which are then
				// sent to the jet control.
				pTable = GetDueEjectionTable();
				if ( pTable != NULL )
				{
					// Generate ejection commands, but only if we're in classification mode.
					if ( m_eOperationMode == OP_CLASSIFICATION )
					{
						GenerateEjectionCommands( pTable, unCurTime );
					}
					ReleaseEjectionTable( pTable );
				}
							
				// Now we have to classify the potatoes and create the ejection table for the current
				// line. Only build the table if we've got a reference to the global potato table
				if ( m_pPotatoTable != NULL )
				{												
					// Build the local classification table (i.e. the per-frame classification)
					BuildTable( &m_LocalClassificationTable,  m_pPotatoTable );
					
					// Only exchange tables if we're in classification mode.
					if ( m_eOperationMode == OP_CLASSIFICATION )
					{					
						// Exchange the table with the other DSP
						if ( ExchangeTables( &m_LocalClassificationTable, &m_ForeignClassificationTable ) == TRUE )
						{
							MergeTables( &m_LocalClassificationTable, &m_ForeignClassificationTable );
						}
					}
						
					// Classify the potatoes using a new ejection table. This, we'll
					// have to do even in calibration mode, because of the statistics
					// for the GUI.
					pTable = GetNewEjectionTable( m_nNumTriggerPulsesDelay );
					if ( pTable != NULL )
					{
						ClassifyPotatoes( & m_LocalClassificationTable, &m_ForeignClassificationTable, pTable );
					}	
					
				} // if potatoobject table accessible
				
			} // if not in servicemode
			
		} // if trigger occured
		
		else
		{
			// Clean the objects list from time to time, if we don't receive trigger signals for
			// a long time. This prevents the number of objects from growing to big.
			CleanObjects( m_pPotatoTable );	
			
			// Check for service operation
			if ( m_csmServiceMode == CSM_CHECK_JETS )
				ServiceGenJetCheckCommands();	
						
		}
		
		// See if any of the strictness values changed and apply it to the properties
		if (   m_propSplitStrictness.HasChanged()
			|| m_propShapeStrictness.HasChanged()
			|| m_propGreenStrictness.HasChanged()
			|| m_propColorStrictness.HasChanged() )
		{
			ApplyStrictness();		
		}
		
		// Signal the watchdog.
		CWatchdog::Instance()->SignalAlive( m_unWatchId );	
		
	} // while(1)

#endif // ------------------------------------------------

}