示例#1
0
// -----------------------------------------------------------------------------
// DIscQueue::Remove
// Removes first element from the queue
// ( other items were commented in a header ).
// -----------------------------------------------------------------------------
//
EXPORT_C TAny* DIscQueue::RemoveFirst()
    {
    E_TRACE( ( _T( "IQ:R %d %d" ), iCount, iSize ) );
    
    TAny* result = NULL;
    TInt irqLevel = DisableIrqs();

    if ( iCount == 0 || iSize == 0 )
        {
        RestoreIrqs( irqLevel );
        return NULL;
        }
    // Get an element from the queue.
    result = ( TAny* )iQueue[ iHead ];

    iQueue[ iHead ] = NULL;

    // Adjust the head of the queue.
    iHead = ++iHead % iSize;
    // Decrease counter.
    iCount--;

    RestoreIrqs( irqLevel );

    return result;

    }
示例#2
0
// -----------------------------------------------------------------------------
// DIscDevice::Flush
// Dfc to empty control channel and other send queues
// ( other items were commented in a header ).
// -----------------------------------------------------------------------------
//
void DIscDevice::Flush( TAny* aPtr )
    {
    C_TRACE( ( _T( "DIscDevice::Flush(0x%x)" ), aPtr ) );
    DIscDevice* device = ( DIscDevice* )aPtr;

    TDes8* frame = NULL;
    TIscSendFrameInfo* temp = NULL;

    TInt irqLevel(0);

    // If transmission is asynchronous and there can't be
    // several requests at the same time
    if ( !iIscDataTransmissionInterface->IsWritePending() )
        {
        irqLevel = DisableIrqs();
        if ( !iControlSendQueue->Empty() )
            {
            temp = iControlSendQueue->GetFirstFrameInfo();
            frame = ( TDes8* )iControlSendQueue->RemoveFirst();
            }
        else
            {
            temp = iSendQueue->GetFirstFrameInfo();
            frame = ( TDes8* )iSendQueue->RemoveFirst();
            }
        RestoreIrqs( irqLevel );
        C_TRACE( ( _T( "DIscDevice::Flush after RESTOREIRQS" ) ) );    
        if ( frame )    
            iIscDataTransmissionInterface->SendFrame( *frame, device->iSendDfc, temp->iFrameInfo );
        }
    C_TRACE( ( _T( "DIscDevice::Flush - return 0x0" ) ) );

    }
示例#3
0
// -----------------------------------------------------------------------------
// DIscQueue::Add
// Function to add element to queue
// ( other items were commented in a header ).
// -----------------------------------------------------------------------------
//
EXPORT_C TInt DIscQueue::Add( TAny* anEntry )
    {
    E_TRACE( ( _T( "IQ:A %d 0x%x" ), iCount, iQueue ) );
    
    TInt irqLevel = DisableIrqs();

    if ( iCount == iSize || iSize == 0 )
        {
        RestoreIrqs( irqLevel );
        return KErrNoMemory;//EFalse;
        }

    /* place the buffer into the queue */
    iQueue[ iTail ] = ( TUint32* )( anEntry );

    if ( iSize > 0 )
        {
        /* adjust tail pointer */
        iTail = ++iTail % iSize;

        /* remember the amount of the requests in the queue */
        iCount++;
        }
    else
        {
        ASSERT_RESET_ALWAYS( 0, "IscDriver", EIscBufferAllocationFailure )
        }

    RestoreIrqs( irqLevel );

    return KErrNone;
    }
示例#4
0
文件: kl_usb.cpp 项目: Kreyl/nute
void Usb_t::ITask() {
    while(1) {
        chSysLock();
        if(!Ep[0].IsTxPending) {
            chSchGoSleepS(THD_STATE_SUSPENDED);     // Will wake up by IRQ
        }
        chSysUnlock();

        // Handle RX
//        while(OTG_FS->GINTSTS & GINTSTS_RXFLVL) RxHandler();

        // Handle TX
        for(uint8_t i=0; i<USB_EP_CNT; i++) {
            if(Ep[i].IsTxPending) {
                // Block IRQ for not to interfere in FIFO filling operation
                chSysLock();
                DisableIrqs();
                Ep[i].IsTxPending = false;
                //chSysUnlock();
                bool Done = Ep[i].TxFifoHandler();
                //Uart.Printf("Done: %u\r\n", Done);
                // Unblock IRQs back
                //chSysLock();
                EnableIrqs();
                if(!Done) Ep[i].EnableInFifoEmptyIRQ();
                chSysUnlock();
            } // if pending
        } // for
    } // while 1
}
// -----------------------------------------------------------------------------
// DIscSendQueue::Add
// Function to add element to queue
// ( other items were commented in a header ).
// -----------------------------------------------------------------------------
//
EXPORT_C TInt DIscSendQueue::Add( TAny* anEntry, TUint16 aId, DIscChannel* aChannelPtr, TAny* aFrameInfo )
    {
    E_TRACE( ( _T( "ISQ:A %d, 0x%x" ), iCount, iQueue ) );

    TInt irqLevel = DisableIrqs();

    if ( iCount == iSize || iSize == 0 )
        {
        RestoreIrqs( irqLevel );
        return KErrNoMemory;//EFalse;
        }

    /* place the buffer into the queue */
    iQueue[ iTail ] = ( TUint32* )( anEntry );

    TIscSendFrameInfo* tmp = iParameterQueue[ iTail ];
    // Set additional info for send frame
    tmp->iChannelId = aId;
    
    tmp->iChannelPtr = aChannelPtr;

    tmp->iFrameInfo = aFrameInfo;

    /* adjust tail pointer */
    iTail = ++iTail % iSize;

    /* remember the amount of the requests in the queue */
    iCount++;

    RestoreIrqs( irqLevel );

    return KErrNone;
    }
示例#6
0
// -----------------------------------------------------------------------------
// DIscQueue::Empty
// Checks if queue is empty
// ( other items were commented in a header ).
// -----------------------------------------------------------------------------
//
EXPORT_C TBool DIscQueue::Empty()
    {
    TInt result;
    TInt irqLevel = DisableIrqs();
    result = iCount == 0 ? ETrue : EFalse;
    RestoreIrqs( irqLevel );

    return result;
    }
示例#7
0
// -----------------------------------------------------------------------------
// DIscQueue::NextBufferLenth
// Gets length of next frame in queue
// ( other items were commented in a header ).
// -----------------------------------------------------------------------------
//
EXPORT_C TUint16 DIscQueue::NextBufferLength()
    {
    TUint16 length;

    TInt irqLevel = DisableIrqs();

    if ( iCount == 0 )
        {
        RestoreIrqs( irqLevel );
        return 0;
        }    

    length = ( TUint16 )( ( ( TDes8* )iQueue[ iHead ] )->Length() );    


    RestoreIrqs( irqLevel );

    return length;
    }
示例#8
0
// -----------------------------------------------------------------------------
// DIscQueue::GetFirst
// Fetches first element from the queue
// ( other items were commented in a header ).
// -----------------------------------------------------------------------------
//
EXPORT_C TAny* DIscQueue::GetFirst()
    {
    E_TRACE( ( _T( "IQ:G %d %d" ), iCount, iSize ) );
    
    TAny* result;
    TInt irqLevel = DisableIrqs();

    if ( iCount == 0 || iSize == 0 )
        {
        RestoreIrqs( irqLevel );
        return NULL;
        }
    // Get an element from the queue.
    result = ( TAny* )iQueue[ iHead ];
    
    RestoreIrqs( irqLevel );
    
    return result;

    }
// -----------------------------------------------------------------------------
// DIscSendQueue::GetFirstFrameInfo
// Returns a frist frame info from list.
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
EXPORT_C TIscSendFrameInfo* DIscSendQueue::GetFirstFrameInfo()
    {
    E_TRACE( ( _T( "ISQ:G(%d, 0x%x)" ), iCount, iQueue ) );

    TIscSendFrameInfo* result;

    TInt irqLevel = DisableIrqs();

    if ( iCount == 0 || iSize == 0 )
        {
        RestoreIrqs( irqLevel );
        return NULL;
        }

    result = iParameterQueue[ iHead ];
    
    RestoreIrqs( irqLevel );

    return result;
    }
示例#10
0
// -----------------------------------------------------------------------------
// DIscQueue::DeleteFirst
// Deletes first element from the queue
// ( other items were commented in a header ).
// -----------------------------------------------------------------------------
//
EXPORT_C void DIscQueue::DeleteFirst()
    {
    E_TRACE( ( _T( "IQ:D %d %d" ), iCount, iSize ) );
    
    TInt irqLevel = DisableIrqs();

    iQueue[ iHead ] = NULL;

    if ( iSize > 0 )
        {
        // Adjust the head of the queue.
        iHead = ++iHead % iSize;
        // decrease counter.
        iCount--;
        }
    else
        {
        ASSERT_RESET_ALWAYS( 0, "IscDriver", EIscBufferAllocationFailure )
        }

    RestoreIrqs( irqLevel );

    }
示例#11
0
// -----------------------------------------------------------------------------
// DIscDevice::CancelSending
// Cancels sending of frames to Domestic OS
// ( other items were commented in a header ).
// -----------------------------------------------------------------------------
//
EXPORT_C TInt DIscDevice::CancelSending( const TUint16 aChannelId, const TAny* aChannelPtr )
    {
    C_TRACE( ( _T( "DIscDevice::CancelSending - Caller is channel: %d (0x%x)" ), aChannelId, aChannelPtr ) );
    
    TInt error( KErrNotFound );
    TInt irqLevel( 0 );

    TInt counterA( 0 );
    TInt counterB( 0 );

    TIscSendFrameInfo* temp = NULL;
    TDes8* frame = NULL;

    irqLevel = DisableIrqs();

    if ( KIscControlChannel == aChannelId )
        {
        // empty control send queue
        while ( !iControlSendQueue->Empty() )
            {
            temp = iControlSendQueue->GetFirstFrameInfo();
            frame = ( TDes8* )iControlSendQueue->RemoveFirst();
            if ( temp && frame )
                {
                if ( temp->iChannelId == aChannelId && 
                     temp->iChannelPtr == ( DIscChannel* )aChannelPtr )
                    {
                    // sender found, no need to store the frame
                    counterB++;
                    }
                else
                    {
                    iTempQueue->Add( frame, temp->iChannelId, temp->iChannelPtr, temp->iFrameInfo );
                    }
                }
            else
                {
                // should never came here
                TRACE_ASSERT_ALWAYS;
                }
            counterA++;
            temp = NULL;
            frame = NULL;
            }  
        
        while ( !iTempQueue->Empty() )
            {
            temp = iTempQueue->GetFirstFrameInfo();
            frame = ( TDes8* )iTempQueue->RemoveFirst();
            if ( temp && frame )
                {
                iControlSendQueue->Add( frame, temp->iChannelId, temp->iChannelPtr, temp->iFrameInfo );
                }
            else
                {
                // should never came here
                TRACE_ASSERT_ALWAYS;
                }
            temp = NULL;
            frame = NULL;
            }
        }
    else
        {
        // empty normal send queue
        while ( !iSendQueue->Empty() )
            {
            temp = iSendQueue->GetFirstFrameInfo();
            frame = ( TDes8* )iSendQueue->RemoveFirst();
            if ( temp && frame )
                {
                if ( temp->iChannelId == aChannelId  && 
                     temp->iChannelPtr == ( DIscChannel* )aChannelPtr )            
                    {
                    // sender found, no need to store frame
                    counterB++;                
                    }
                else
                    {
                    iTempQueue->Add( frame, temp->iChannelId, temp->iChannelPtr, temp->iFrameInfo );
                    }
                }
            else
                {
                // should never came here
                TRACE_ASSERT_ALWAYS;
                }
            counterA++;
            temp = NULL;
            frame = NULL;
            }  

        while ( !iTempQueue->Empty() )
            {
            temp = iTempQueue->GetFirstFrameInfo();
            frame = ( TDes8* )iTempQueue->RemoveFirst();
            if ( temp && frame )
                {
                iSendQueue->Add( frame, temp->iChannelId, temp->iChannelPtr, temp->iFrameInfo );
                }
            else
                {
                // should never came here
                TRACE_ASSERT_ALWAYS;
                }

            temp = NULL;
            frame = NULL;
            }
        }
        
    RestoreIrqs( irqLevel );

    C_TRACE( ( _T( "DIscDevice::CancelSending() - Frames in queue: Before: %d, After: %d" ), counterA, ( counterA-counterB ) ) );
    C_TRACE( ( _T( "DIscDevice::CancelSending() - So channel 0x%x 0x%x had %d pending messages!" ), aChannelId, aChannelPtr, counterB ) );

    // if there weren't any frames that were cancelled return KErrNotFound, otherwise return KErrNone
    if ( counterB > 0 )
        {        
        error = KErrNone;
        }
    
    return error;

    }