Ejemplo n.º 1
0
/*-----------------------------------------------------------------------------
   function:    void TOOL_sleep(U8 timeToWait)
   description: waits for given time
   input:       U8 timeToWait
   output:      nothing
   return:      nothing
-----------------------------------------------------------------------------*/
void TOOL_sleep(U32 timeToWait)
{
   U32 t1, t2;

   t1 = GD_TIMER_ReadTimerStamp();
   do
   {
       t2 = GD_TIMER_ReadTimerStamp();
       if (t2<t1) /* in case of timer overflow */
       {
           t1 = GD_TIMER_ReadTimerStamp();
           t2 = GD_TIMER_ReadTimerStamp();
       }
   } while ((t2-t1) < (U32)timeToWait);
}
Ejemplo n.º 2
0
AVL63X1_ErrorCode AVL63X1_IBSP_Delay( AVL_uint32 uiDelay_ms )
{
	AVL_uint32 t1, t2;

	t1 = GD_TIMER_ReadTimerStamp();
	do
	{
		t2 = GD_TIMER_ReadTimerStamp();
		if (t2<t1) /* in case of timer overflow */
		{
			t1 = GD_TIMER_ReadTimerStamp();
			t2 = GD_TIMER_ReadTimerStamp();
		}
	} while ((t2-t1) < uiDelay_ms);

	return(AVL63X1_EC_OK);
}
Ejemplo n.º 3
0
/**************************************************
* Fe_User_SleepTime
* This function currently justs wastes the time in a loop.
* It is recommended that the user implements it in such a
* way that the processor uses the time for other functions,
* For example in an RTOS-environment the control can be given
* back to the scheduler to allow other tasks to execute within
* that time.
* The function is used in all files of the QST_Api only as a
* minimum wait time: That means implementations that "wait" longer
* than specified by ulTime are allowed. But please keep in mind
* that this may increase the locking time and reduce your zapping speed.
*
* Inputs:
*   ulTime: the min. time to sleep in ms.
*
* Returns:
*   GD_OK or GD_ERR_BAD_PARAMETER
***************************************************/
GERR FE_SleepTime(U32 ulTime)
{
    U32 t1, t2;

    t1 = GD_TIMER_ReadTimerStamp();
    do
    {
      t2 = GD_TIMER_ReadTimerStamp();
      if( t2 < t1 ) /* in case of timer overflow */
      {
          t1 = GD_TIMER_ReadTimerStamp();
          t2 = GD_TIMER_ReadTimerStamp();
      }
    } while( ( t2 - t1 ) < (U32)ulTime );

    return GD_OK;
}
Ejemplo n.º 4
0
/*!
*******************************************************************************
**
** \brief  delay in milliseconds.
**
** \param msecs to be delay in milliseconds
**
**
******************************************************************************/
GERR GD_TIMER_Delay(U32 msecs)
{
    U32     start_time = 0;
    U32     end_time = 0;
    int     time_difference  = 0;

    start_time = GD_TIMER_ReadTimerStamp();
    do
    {
        end_time = GD_TIMER_ReadTimerStamp();
        time_difference = (U32)(end_time - start_time);
        /* check overflow */
        if(start_time > end_time)
        {
            time_difference = ((time_difference < 0L) ? -time_difference : time_difference); /* C-LIB code for labs() */
        }
    }while(time_difference < msecs);

    return GD_OK;
}
Ejemplo n.º 5
0
/**************************************************
* MB86667_User_Sleep
* This function currently justs wastes the time in a loop.
* It is recommended that the user implements it in such a
* way that the processor uses the time for other functions,
* For example in an RTOS-environment the control can be given
* back to the scheduler to allow other tasks to execute within
* that time.
* The function is used in all files of the MB86667_Api only as a
* minimum wait time: That means implementations that "wait" longer
* than specified by ulTime are allowed. But please keep in mind
* that this may increase the locking time and reduce your zapping speed.
*
* Inputs:
*   ulTime: the min. time to sleep in ms.
*
* Returns:
*   GD_OK or GD_ERR_BAD_PARAMETER, defined in MB86667_API.h
***************************************************/
GERR MB86667_User_Sleep(U32 ulTime)
{
    /* enter your code here to realise a "wait" function */
    #ifdef USE_WITHIN_GOKESDK
      U32 t1, t2;

      t1 = GD_TIMER_ReadTimerStamp();
      do
      {
        t2 = GD_TIMER_ReadTimerStamp();
        if (t2<t1) /* in case of timer overflow */
        {
            t1 = GD_TIMER_ReadTimerStamp();
            t2 = GD_TIMER_ReadTimerStamp();
        }
      } while ((t2-t1) < (U32)ulTime);
    #else
      Sleep(ulTime);
    #endif

    return GD_OK;
}
Ejemplo n.º 6
0
/*!
********************************************************************************
**
** \brief Send a T=0 data block to the smartcard
**
** This function sends a T=0 data block by sending the data given in the 
** sendBuffer and reading the status bytes SW1 and SW2 into the receive buffer. 
**
** Depending on the finishCallback parameter this function either blocks
** (if NULL) or returns immediatly (if non-NULL).
**
** \note The finishCallback function must be handled with care as it is
**       called in interrupt context!!!
**
** \param handle         a handle specifying which ICC instance to be accessed
** \param sendBufferP    a pointer to a buffer containg the data to be send
** \param sendSize       the number of bytes in the send buffer to be transfered
** \param receiveBufferP a pointer to the receive buffer where to store the response
** \param receiveSize    the max. size of the receive buffer, at least 2 bytes
**                       holding the status word bytes SW1 and SW2
** \param receivedBytesP a pointer to a variable where to store the real number
**                       of received bytes
** \param finishCallback a function pointer to be called if transfer has finished
**                       passing NULL here forces function to block until transfer
**                       has finished
**
** \return
** - GD_ERR_INVALID_HANDLE in case of error if the given handle is invalid
** - GD_OK if successfull
** - GD_ERR_ICC_OVERFLOW if read buffer overflow occoured
** - GD_ERR_ICC_TIMEOUT if a timeout was detected during read
** - GD_ERR_ICC_NO_ANSWER if the card did not response at all
** - GD_ERR_ICC_SLOT_EMPTY if there is no card in the slot
** - GD_ERR_UNKNOWN for any other unknown error condition
**
********************************************************************************
*/
GERR GD_ICC_T0SendData( GD_HANDLE handle, 
                        U8* sendBufferP, U32 sendSize, 
                        U8* receiveBufferP, U32 receiveSize, 
                        U32* receivedBytesP,                         
                        GD_ICC_FINISH_T finishCallback )
{
   
    U8 slot_state;
    volatile GD_ICC_STATE_MACHINE_S* icc_sm;
    U32 oldtime;
     
    #ifdef GD_ICC_DEBUG
    #undef  __FUNCTION__
    #define __FUNCTION__ "GD_ICC_T0SendData"
    GD_ICC_Printf( "[%s] enter\n", __FUNCTION__ );
    #endif
    
    if( ICC_CheckHandle( handle ) != GTRUE )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_INVALID_HANDLE)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_INVALID_HANDLE );
    }

    GD_ICC_GetSlotStatus( handle, &slot_state );
    if( slot_state == GD_ICC_NO_CARD )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_SLOT_EMPTY)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_ICC_SLOT_EMPTY );
    }
    
    icc_sm = (volatile GD_ICC_STATE_MACHINE_S*)(void*)handle;
    oldtime = GD_TIMER_ReadTimerStamp();
    while( icc_sm->status == GD_ERR_ICC_RUNNING )
    {
      if((GD_TIMER_ReadTimerStamp()-oldtime)>ICC_MAX_WAIT_TIME)
        {
          icc_sm->status=GD_OK;
          return(GD_ERR_ICC_TIMEOUT);
        }
    }

    //icc_sm = (volatile GD_ICC_STATE_MACHINE_S*)(void*)handle;
    icc_sm->status = GD_ERR_ICC_RUNNING;
    icc_sm->nextState = ICC_STATE_T0_TRANSMIT_START;
    icc_sm->readBuffer = receiveBufferP;
    icc_sm->readSize = receiveSize;
    icc_sm->readBytes = 0;
    icc_sm->readBytesP = receivedBytesP;
    icc_sm->writeBuffer = sendBufferP;
    icc_sm->writeBytes = sendSize;
    icc_sm->writePos = 0;
    icc_sm->checkPos = 0;
    icc_sm->finishCallback = finishCallback;
    icc_sm->irqRxCallback = ICC_StateMachine;
    icc_sm->irqTxCallback = ICC_StateMachine;

    //if( icc_sm->CWT == 0 ) icc_sm->CWT = 12;
    //if( icc_sm->BWT == 0 ) icc_sm->BWT = 12;

    ICC_EnableRxIrq( icc_sm->fhIndex, 0 );
    ICC_EnableTxIrq( icc_sm->fhIndex, 0 );

    ICC_DebugTransfer( GFALSE );
    ICC_StartIdleTimer( icc_sm, 1, GFALSE, ICC_StateMachine );

    if( finishCallback != NULL )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (OK)\n", __FUNCTION__ );
        #endif
        return( GD_OK );
    }

    oldtime = GD_TIMER_ReadTimerStamp();
    while( icc_sm->status == GD_ERR_ICC_RUNNING )
    {
      if((GD_TIMER_ReadTimerStamp()-oldtime)>ICC_MAX_WAIT_TIME)
        {
          icc_sm->status=GD_OK;
          return(GD_ERR_ICC_TIMEOUT);
        }
    }
    ICC_DebugTransfer( GTRUE );

    #ifdef GD_ICC_ATR_DEBUG
        ICC_DebugHandle( icc_sm );
    #endif

    *receivedBytesP = icc_sm->readBytes;
    GD_ICC_GetSlotStatus( handle, &slot_state );
    if( slot_state == GD_ICC_NO_CARD )
     {       
       return( GD_ERR_ICC_SLOT_EMPTY );
     }    
    if( icc_sm->status == GD_OK )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (OK)\n", __FUNCTION__ );
        #endif
        return( GD_OK );
    }
    
    if( icc_sm->status == GD_ERR_ICC_TIMEOUT )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_TIMEOUT)\n", __FUNCTION__ );
        #endif
        return( GD_OK );
    }
    
    if( icc_sm->status == GD_ERR_ICC_NO_ANSWER )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_NO_ANSWER)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_ICC_NO_ANSWER );
    }
        
    #ifdef GD_ICC_DEBUG
        GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_UNKNOWN)\n", __FUNCTION__ );
    #endif
    return( GD_ERR_ICC_UNKNOWN );
}
Ejemplo n.º 7
0
/*!
********************************************************************************
**
** \brief Perform a cold reset
**
** This function does a cold-reset and waits for the ATR from the card.
**
** Depending on the finishCallback parameter this function either blocks
** (if NULL) or returns immediatly (if non-NULL).
**
** \note The finishCallback function must be handled with care as it is
**       called in interrupt context!!!
**
** \param handle         a handle specifying which ICC instance to be accessed
** \param paramsP        a #GD_ICC_COLD_RESET_PARAMS_S containing cold reset
**                       parameters
** \param finishCallback a function pointer to be called if transfer has 
**                       finished, passing NULL here forces function to block 
**                       until reset has finished
**
** \return
** - GD_ERR_INVALID_HANDLE in case of error if the given handle is invalid
** - GD_OK if successfull
** - GD_ERR_ICC_OVERFLOW if read buffer overflow occoured
** - GD_ERR_ICC_TIMEOUT if a timeout was detected during read
** - GD_ERR_ICC_NO_ANSWER if the card did not response at all
** - GD_ERR_ICC_SLOT_EMPTY if there is no card in the slot
** - GD_ERR_UNKNOWN for any other unknown error condition
**
********************************************************************************
*/
GERR GD_ICC_ColdReset( GD_HANDLE handle, 
                       GD_ICC_COLD_RESET_PARAMS_S* paramsP,
                       GD_ICC_FINISH_T finishCallback )
{

    U8 slot_state;
    volatile GD_ICC_STATE_MACHINE_S* icc_sm;
   U32 oldtime;
   
    #ifdef GD_ICC_DEBUG
    #undef  __FUNCTION__
    #define __FUNCTION__ "GD_ICC_ColdReset"
        GD_ICC_Printf( "[%s] enter\n", __FUNCTION__ );
    #endif

    if( ICC_CheckHandle( handle ) != GTRUE )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_INVALID_HANDLE)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_INVALID_HANDLE );
    }

    icc_sm = (volatile GD_ICC_STATE_MACHINE_S*)(void*)handle;
    
    GD_ICC_GetSlotStatus( handle, &slot_state );
    if( slot_state == GD_ICC_NO_CARD )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_SLOT_EMPTY)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_ICC_SLOT_EMPTY );
    }

    oldtime = GD_TIMER_ReadTimerStamp();
    while( icc_sm->status == GD_ERR_ICC_RUNNING )
    {
      if((GD_TIMER_ReadTimerStamp()-oldtime)>ICC_MAX_WAIT_TIME)
        {
          icc_sm->status=GD_OK;
          return(GD_ERR_ICC_TIMEOUT);
        }
    }
         
    GH_ICC_set_GlobalControl_RESND( icc_state_machine->fhIndex, 0 );

    if( ( paramsP->cardClock / 1000 ) < 1000 )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_BAD_PARAMETER)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_BAD_PARAMETER );
    }

    if( ( paramsP->convention != GD_ICC_INVERSE_CONVENTION )
    &&  ( paramsP->convention != GD_ICC_DIRECT_CONVENTION ) )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_BAD_PARAMETER)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_BAD_PARAMETER );
    }
        
    if( ( paramsP->parity != GD_ICC_ODD_PARITY )
    &&  ( paramsP->parity != GD_ICC_EVEN_PARITY )
    &&  ( paramsP->parity != GD_ICC_NO_PARITY ) )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_BAD_PARAMETER)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_BAD_PARAMETER );
    }
    
    if( ( paramsP->parityErrResend != GD_ICC_PAR_ERR_RESEND_EN )
    &&  ( paramsP->parityErrResend != GD_ICC_PAR_ERR_RESEND_DIS ) )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_BAD_PARAMETER)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_BAD_PARAMETER );
    }

    if( ( paramsP->dataBits != GD_ICC_8BIT_DATA )
    &&  ( paramsP->dataBits != GD_ICC_9BIT_DATA ) )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_BAD_PARAMETER)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_BAD_PARAMETER );
    }

    if( paramsP->dataBits == GD_ICC_8BIT_DATA)
    {
        if( paramsP->parity == GD_ICC_NO_PARITY )
        {
            GH_ICC_set_GlobalControl_MODE_8N1( icc_state_machine->fhIndex, 1 );
            GH_ICC_set_GlobalControl_FRM0( icc_state_machine->fhIndex, 1 );
        }
        if( paramsP->parity == GD_ICC_ODD_PARITY )
        {
            GH_ICC_set_GlobalControl_MODE_8N1( icc_state_machine->fhIndex, 0 );
            GH_ICC_set_GlobalControl_PARITY( icc_state_machine->fhIndex, 1 );
            GH_ICC_set_GlobalControl_FRM0( icc_state_machine->fhIndex, 0 );
        }
        else if( paramsP->parity == GD_ICC_EVEN_PARITY )
        {
            GH_ICC_set_GlobalControl_MODE_8N1( icc_state_machine->fhIndex, 0 );
            GH_ICC_set_GlobalControl_PARITY( icc_state_machine->fhIndex, 0 );
            GH_ICC_set_GlobalControl_FRM0( icc_state_machine->fhIndex, 0 );
        }
    }

    if( paramsP->dataBits == GD_ICC_9BIT_DATA)
    {
        GH_ICC_set_GlobalControl_FRM0( icc_state_machine->fhIndex, 1 );
    }
    
    if( paramsP->parityErrResend == GD_ICC_PAR_ERR_RESEND_EN )
    {
        GH_ICC_set_GlobalControl_RESND( icc_state_machine->fhIndex, 1 );
    }
    
    icc_sm->status = GD_ERR_ICC_RUNNING;
    icc_sm->nextState = ICC_STATE_COLD_RESET_START;
    icc_sm->cardClock = paramsP->cardClock / 1000;
    icc_sm->baudRate = paramsP->baudRate;
    icc_sm->convention = paramsP->convention;
    icc_sm->parity = paramsP->parity;
    icc_sm->parityErrResend = paramsP->parityErrResend;
    icc_sm->dataBits = paramsP->dataBits;
    icc_sm->atrBytes = 0;    
    icc_sm->readBuffer = icc_sm->atrBuffer;    
    icc_sm->readSize = icc_sm->atrSize;    
    icc_sm->readBytes = 0;    
    icc_sm->writeBuffer = 0;
    icc_sm->writeBytes = 0;
    icc_sm->writePos = 0;
    icc_sm->checkPos = 0;
    icc_sm->finishCallback = finishCallback;
    icc_sm->atrParity = 0;   
    icc_sm->irqRxCallback = ICC_StateMachine;   

    ICC_DebugTransfer( GFALSE );
    ICC_StartIdleTimer( icc_sm, 1, GFALSE, ICC_StateMachine );
    
/*    if( finishCallback != NULL )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (OK)\n", __FUNCTION__ );
        #endif
        return( GD_OK );
    }*/
    
    oldtime = GD_TIMER_ReadTimerStamp();
    while( icc_sm->status == GD_ERR_ICC_RUNNING )
    {
      if((GD_TIMER_ReadTimerStamp()-oldtime)>ICC_MAX_WAIT_TIME)
        {
          icc_sm->status=GD_OK;
          return(GD_ERR_ICC_TIMEOUT);
        }
    }


    if( ICC_CheckATRData( icc_sm ) )
    {
        GH_ICC_set_GlobalControl_MASKRXFUL( icc_sm->fhIndex, 0 );
        icc_sm->status = GD_OK;
        icc_sm->nextState = ICC_STATE_COLD_RESET_FINISH;
        ICC_StartIdleTimer( icc_sm, 1, GFALSE, ICC_StateMachine );            
    }
    else
    {
         if( icc_sm->readBytes == 0 )
            icc_sm->status = GD_ERR_ICC_NO_ANSWER;
        else
            icc_sm->status = GD_ERR_ICC_TIMEOUT;
         icc_sm->nextState = ICC_STATE_COLD_RESET_FINISH;
         ICC_StartIdleTimer( icc_sm, 1, GFALSE, ICC_StateMachine );
    }
    ICC_DebugTransfer( GTRUE );
    
    #ifdef GD_ICC_DEBUG
        GD_ICC_Printf( "[%s] leave (OK)\n", __FUNCTION__ );
    #endif

    //GD_ICC_SetBaudRate( (GD_HANDLE)(void*)icc_sm, icc_sm->baudRate );

    GD_ICC_GetSlotStatus( handle, &slot_state );
    if( slot_state == GD_ICC_NO_CARD )
     {         
       return( GD_ERR_ICC_SLOT_EMPTY );
     }
    if( icc_sm->status == GD_OK )
    {
        if( icc_sm->readBytes > icc_sm->atrSize )
        {
            #ifdef GD_ICC_DEBUG
                GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_OVERFLOW)\n", __FUNCTION__ );
            #endif
            return( GD_ERR_ICC_OVERFLOW );
        }

        #ifdef GD_ICC_ATR_DEBUG
            ICC_DebugHandle( icc_sm );
        #endif
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (OK)\n", __FUNCTION__ );
        #endif
        if( paramsP->parityErrResend == GD_ICC_PAR_ERR_RESEND_EN )
        {
            GH_ICC_set_GlobalControl_RESND( icc_state_machine->fhIndex, 1 );
        }
    
        return( GD_OK );
    }
    
    if( icc_sm->status == GD_ERR_ICC_TIMEOUT )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_TIMEOUT)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_ICC_TIMEOUT );
    }
    
    if( icc_sm->status == GD_ERR_ICC_OVERFLOW )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_OVERFLOW)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_ICC_OVERFLOW );
    }
    
    if( icc_sm->status == GD_ERR_ICC_NO_ANSWER )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_NO_ANSWER)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_ICC_NO_ANSWER );
    }
        
    if( icc_sm->status == GD_ERR_ICC_SLOT_EMPTY )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_SLOT_EMPTY)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_ICC_SLOT_EMPTY );
    }
        
    #ifdef GD_ICC_DEBUG
        GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_UNKNOWN)\n", __FUNCTION__ );
    #endif
    return( GD_ERR_ICC_UNKNOWN );
}
Ejemplo n.º 8
0
/*!
********************************************************************************
**
** \brief Perform a warm reset
**
** This function does a warm-reset and waits until the card is ready again.
**
** Depending on the finishCallback parameter this function either blocks
** (if NULL) or returns immediatly (if non-NULL).
**
** \note The finishCallback function must be handled with care as it is
**       called in interrupt context!!!
**
** \param handle         a handle specifying which ICC instance to be accessed
** \param paramsP        a #GD_ICC_WARM_RESET_PARAMS_S containing warm reset
**                       parameters
** \param finishCallback a function pointer to be called if transfer has 
**                       finished, passing NULL here forces function to block 
**                       until reset has finished
**
** \return
** - GD_ERR_INVALID_HANDLE in case of error if the given handle is invalid
** - GD_OK if successfull
** - GD_ERR_ICC_OVERFLOW if read buffer overflow occoured
** - GD_ERR_ICC_TIMEOUT if a timeout was detected during read
** - GD_ERR_ICC_NO_ANSWER if the card did not response at all
** - GD_ERR_ICC_SLOT_EMPTY if there is no card in the slot
** - GD_ERR_UNKNOWN for any other unknown error condition
**
********************************************************************************
*/
GERR GD_ICC_WarmReset( GD_HANDLE handle, 
                       GD_ICC_WARM_RESET_PARAMS_S* paramsP,
                       GD_ICC_FINISH_T finishCallback )
{

    volatile GD_ICC_STATE_MACHINE_S* icc_sm;
    U8 slot_state;
    U32 oldtime;
    
    #ifdef GD_ICC_DEBUG
    #undef  __FUNCTION__
    #define __FUNCTION__ "GD_ICC_WarmReset"
        GD_ICC_Printf( "[%s] enter\n", __FUNCTION__ );
    #endif
    
    if( ICC_CheckHandle( handle ) != GTRUE )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_INVALID_HANDLE)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_INVALID_HANDLE );
    }
    GD_ICC_GetSlotStatus( handle, &slot_state );
    if( slot_state == GD_ICC_NO_CARD )
    {
      #ifdef GD_ICC_DEBUG
              GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_SLOT_EMPTY)\n", __FUNCTION__ );
      #endif
          return( GD_ERR_ICC_SLOT_EMPTY );
    }
    
    icc_sm = (volatile GD_ICC_STATE_MACHINE_S*)(void*)handle;
    oldtime = GD_TIMER_ReadTimerStamp();
    while( icc_sm->status == GD_ERR_ICC_RUNNING )
    {
      if((GD_TIMER_ReadTimerStamp()-oldtime)>ICC_MAX_WAIT_TIME)
        {
          icc_sm->status=GD_OK;
          return(GD_ERR_ICC_TIMEOUT);
        }
    }

    //icc_sm = (volatile GD_ICC_STATE_MACHINE_S*)(void*)handle;
    icc_sm->cardClock = paramsP->cardClock / 1000;
    icc_sm->baudRate = paramsP->baudRate;
    icc_sm->status = GD_ERR_ICC_RUNNING;
    icc_sm->nextState = ICC_STATE_WARM_RESET_START;
    icc_sm->atrBytes = 0;    
    icc_sm->readBuffer = icc_sm->atrBuffer;    
    icc_sm->readSize = icc_sm->atrSize;    
    icc_sm->readBytes = 0;    
    icc_sm->writeBuffer = 0;
    icc_sm->writeBytes = 0;
    icc_sm->writePos = 0;
    icc_sm->checkPos = 0;
    icc_sm->finishCallback = finishCallback;
    icc_sm->atrParity = 0;   
    icc_sm->irqRxCallback = ICC_StateMachine;    

    ICC_DebugTransfer( GFALSE );
    ICC_StartIdleTimer( icc_sm, 1, GFALSE, ICC_StateMachine );
/*
    if( finishCallback != NULL )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (OK)\n", __FUNCTION__ );
        #endif
        return( GD_OK );
    }
*/
    oldtime = GD_TIMER_ReadTimerStamp();
    while( icc_sm->status == GD_ERR_ICC_RUNNING )
    {
      if((GD_TIMER_ReadTimerStamp()-oldtime)>ICC_MAX_WAIT_TIME)
        {
          icc_sm->status=GD_OK;
          return(GD_ERR_ICC_TIMEOUT);
        }
    }
    if( ICC_CheckATRData( icc_sm ) )
    {
        GH_ICC_set_GlobalControl_MASKRXFUL( icc_sm->fhIndex, 0 );
        icc_sm->status = GD_OK;
        icc_sm->nextState = ICC_STATE_COLD_RESET_FINISH;
        ICC_StartIdleTimer( icc_sm, 1, GFALSE, ICC_StateMachine );            
    }
    else
    {
         if( icc_sm->readBytes == 0 )
            icc_sm->status = GD_ERR_ICC_NO_ANSWER;
        else
            icc_sm->status = GD_ERR_ICC_TIMEOUT;
         icc_sm->nextState = ICC_STATE_COLD_RESET_FINISH;
         ICC_StartIdleTimer( icc_sm, 1, GFALSE, ICC_StateMachine );
    }
    ICC_DebugTransfer( GTRUE );

    //GD_ICC_SetBaudRate( (GD_HANDLE)(void*)icc_sm, icc_sm->baudRate );
    GD_ICC_GetSlotStatus( handle, &slot_state );
    if( slot_state == GD_ICC_NO_CARD )
     {         
       return( GD_ERR_ICC_SLOT_EMPTY );
     }
    if( icc_sm->status == GD_OK )
    {
        if( icc_sm->readBytes > icc_sm->atrSize )
        {
            #ifdef GD_ICC_DEBUG
                GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_OVERFLOW)\n", __FUNCTION__ );
            #endif
            return( GD_ERR_ICC_OVERFLOW );
        }

        #ifdef GD_ICC_ATR_DEBUG
            ICC_DebugHandle( icc_sm );
        #endif
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (OK)\n", __FUNCTION__ );
        #endif
        return( GD_OK );
    }
    
    if( icc_sm->status == GD_ERR_ICC_TIMEOUT )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_TIMEOUT)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_ICC_TIMEOUT );
    }
    
    if( icc_sm->status == GD_ERR_ICC_OVERFLOW )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_OVERFLOW)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_ICC_OVERFLOW );
    }
           
    if( icc_sm->status == GD_ERR_ICC_NO_ANSWER )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_NO_ANSWER)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_ICC_NO_ANSWER );
    }

    if( icc_sm->status == GD_ERR_ICC_SLOT_EMPTY )
    {
        #ifdef GD_ICC_DEBUG
            GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_SLOT_EMPTY)\n", __FUNCTION__ );
        #endif
        return( GD_ERR_ICC_SLOT_EMPTY );
    }
        
    #ifdef GD_ICC_DEBUG
        GD_ICC_Printf( "[%s] leave (GD_ERR_ICC_UNKNOWN)\n", __FUNCTION__ );
    #endif
    return( GD_ERR_ICC_UNKNOWN );
}
Ejemplo n.º 9
0
GERR GND_I2C_Read(GD_HANDLE *handleP, U8 msSlaveAddr, U8* writeDataP,U32 wrDataLen, U8* readDataP, U32 rdDataLen)
{
    GBOOL           wrFlag = GFALSE;
    GD_I2C_SPEED_E  speed;
    U32             stTime, endTime, timeOut;
    S32             diff;

    speed = (GD_I2C_SPEED_E)LOWBYTE(*handleP);

    if( State == GD_ERR_I2C_BUSY )
        return GD_ERR_I2C_BUSY;

    if ((speed != GD_I2C_100KBPS &&
         speed != GD_I2C_400KBPS )       ||
         wrDataLen > MAX_DATA_LENGTH ||
         rdDataLen > MAX_DATA_LENGTH ||
        readDataP == NULL                ||
        rdDataLen == 0
       )
        return GD_ERR_BAD_PARAMETER;

    if (speed == GD_I2C_100KBPS)
        timeOut = (rdDataLen<<4)/100 + I2C_MIN_TIMEOUT;
    else
        timeOut = (rdDataLen<<4)/400 + I2C_MIN_TIMEOUT;

    /* check the OCCUP */
    /*
    GH_I2C_get_StatusReg1();
    if ( GH_I2C_getm_StatusReg1_OCCUP() != GFALSE )
        return GD_ERR_I2C_BUS_OCCUP;
    */
    stTime = GNH_EXT_GetRegister(REG_I2C_STATUSREG1);
    if ((stTime&BIT2) == BIT2)
        return GD_ERR_I2C_BUS_OCCUP;

    /* set pointer buffer for ISR */
    WriteBufferP =  writeDataP;
    ReadBufferP  =  readDataP;

    //GD_INT_SetInterruptMask( I2CHandle, GD_INT_DISABLED);
    GD_INT_SetInterruptMask( GD_INT_IIC_IRQ, GD_INT_DISABLED);
    /* check if speed for channel already set */
    if (speed == GD_I2C_400KBPS)
        //GH_I2C_set_ControlReg1_I2C_SPEED(1);
        //GNH_EXT_SetRegister(REG_I2C_CONTROLREG1,CtrlReg1Shadow|BIT0);
        CtrlReg1Shadow |= BIT0;
    else
        //GH_I2C_set_ControlReg1_I2C_SPEED(0);
        //GNH_EXT_SetRegister(REG_I2C_CONTROLREG1,CtrlReg1Shadow&(~BIT0));
        CtrlReg1Shadow &= ~BIT0;
    GNH_EXT_SetRegister(REG_I2C_CONTROLREG1,CtrlReg1Shadow);

    /* reset Generic mode*/
    /*
    GH_I2C_set_ControlReg0(CtrlReg0Shadow);
    GH_I2C_set_ControlReg0_RESET(1);
    GH_I2C_set_ControlReg0_RESET(0);
    */

    GNH_EXT_SetRegister(REG_I2C_CONTROLREG0,CtrlReg0Shadow|BIT3);
    GNH_EXT_SetRegister(REG_I2C_CONTROLREG0,CtrlReg0Shadow);
    if( wrDataLen > 0)
    {
        wrFlag = GTRUE;
        /* enable IRQ mask */
        //GH_I2C_set_IRQMask1_AM_END(1);
        //GH_I2C_set_IRQMask1_AM_ERR(1);
        //GH_I2C_set_IRQMask1_AM_MRX_REQ(1);
        //GH_I2C_set_IRQMask1_AM_MTX_REQ(1);
        GNH_EXT_SetRegister(REG_I2C_IRQMASK1,BIT6|BIT5|BIT4|BIT3);

        //GH_I2C_set_IRQMask0(0L);
        GNH_EXT_SetRegister(REG_I2C_IRQMASK0,0);

        //GH_I2C_set_ControlReg1_MS_SLA_ADD(msSlaveAddr>>1);
        GNH_EXT_SetRegister(REG_I2C_CONTROLREG1,CtrlReg1Shadow|(((msSlaveAddr>>1)&0x7F)<<8));
        /* set length in transmit register */
        //GH_I2C_set_ControlReg2(wrDataLen+1);
        GNH_EXT_SetRegister(REG_I2C_CONTROLREG2,wrDataLen+1);
        /* set length in receive register */
        //GH_I2C_set_ControlReg3(MIN_DATA_LENGTH);
        GNH_EXT_SetRegister(REG_I2C_CONTROLREG3,MIN_DATA_LENGTH);

        State = GD_ERR_I2C_BUSY;

        /* reset Auto mode and DMA mode */
        //GH_I2C_set_GoReg(0L);
        GNH_EXT_SetRegister(REG_I2C_GOREG,0);
        //GH_I2C_set_GoReg_AM_RESET(1);
        GNH_EXT_SetRegister(REG_I2C_GOREG,BIT1);
        /* start data request */
        //GH_I2C_set_GoReg(0L);
        GNH_EXT_SetRegister(REG_I2C_GOREG,0);
        //GH_I2C_set_GoReg_AM_START(1);
        GNH_EXT_SetRegister(REG_I2C_GOREG,BIT2);

        //GD_INT_SetInterruptMask( I2CHandle, GD_INT_ENABLED);
        GD_INT_SetInterruptMask(  GD_INT_IIC_IRQ, GD_INT_ENABLED);

        stTime = GD_TIMER_ReadTimerStamp();
        do
        {
            endTime= GD_TIMER_ReadTimerStamp();
            diff = endTime - stTime;
            if(stTime > endTime) /* check overflow */
                diff = ((diff < 0L) ? -diff : diff); /* C-LIB code for labs() */
        }while(State == GD_ERR_I2C_BUSY && (diff < timeOut) );

        if (State == GD_ERR_I2C_BUSY)
            State = GD_ERR_TIMEOUT;

        if (State != GD_OK)
            return State;

        //GD_INT_SetInterruptMask( I2CHandle, GD_INT_DISABLED);
        GD_INT_SetInterruptMask(  GD_INT_IIC_IRQ, GD_INT_DISABLED);
    }
Ejemplo n.º 10
0
/**************************************************
*
*
* Inputs:
*   ucFlag :
*               TIM_SYN_TIM
*                 This flag causes the routine to wait for a transition of the system tick.
*                 If you use TIM_RES_TIM and TIM_GET_TIM and the routine was not
*                 synchronised before then you have to add one tick time
*                 to your timeout in order to guarantee at least the timeout length.
*                 ucIndex is ignored if only this flag is set.
*               TIM_RES_TIM Resets the timer counter with Index ucIndex.
*                 The reset is done immediately without synchronisation to the system
*                 timer. If your timer tick is long (like the 40ms in our example) then it is
*                 recommended to call User_Timers with TIM_SYN_TIM before.
*                 This gives the maximum accuracy but requires in worst case 40 ms for
*                 synchronisation.
*               TIM_GET_TIM requests the elapsed time of Index ucIndex since its last reset
*   ucIndex:    Timer index (currently from 0 to MAX_INDEX)
*   ulDiffTime: holds the elapsed time of a request in ms.
*               The precision is depending on the system clock.
*               Here we have a resolution of 40 resp. 33 ms
*               This gives in total a max time of more than 1000 hours.
*
* Returns:
*   GD_OK or GD_ERR_BAD_PARAMETER, defined in MB86667_API.h
***************************************************/
GERR MB86667_User_Timers(U8 ucFlag, U8 ucIndex, U32 *pulDiffTime)
{
    U32 ulTempTime;

    *pulDiffTime = 0;

    if (ucFlag > TIM_GET_TIM) return(GD_ERR_BAD_PARAMETER);
    if (ucIndex > MB86667_MAX_USER_TIMERS) return(GD_ERR_BAD_PARAMETER);

    /* sync */
    if ((ucFlag & TIM_SYN_TIM) == TIM_SYN_TIM)
    {
        /* wait here until timer changes */
        #ifdef USE_WITHIN_GOKESDK
        ulTempTime = GD_TIMER_ReadTimerStamp();
        while (GD_TIMER_ReadTimerStamp() == ulTempTime); /* wait */
        #else
        {
           LARGE_INTEGER ft_start,ft;
           GetSystemTimeAsFileTime((FILETIME *)&ft_start);
           ft_start.QuadPart /= 10000;
           do
           {
              GetSystemTimeAsFileTime((FILETIME *)&ft);
              ft.QuadPart /= 10000;
           }
           while (ft.QuadPart==ft_start.QuadPart);
        }
        #endif
    }

    /* reset */
    if ((ucFlag & TIM_RES_TIM) == TIM_RES_TIM)
    {
        /* set start time to current time */
        #ifdef USE_WITHIN_GOKESDK
        StartTimes[ucIndex] = GD_TIMER_ReadTimerStamp();
        #else
        {
           LARGE_INTEGER ft;
           GetSystemTimeAsFileTime((FILETIME *)&ft);
           ft.QuadPart /= 10000;
           StartTimes[ucIndex] = (U32) ft.QuadPart;
        }
        #endif
        *pulDiffTime = 0;
    }

    /* get */
    if ((ucFlag & TIM_GET_TIM) == TIM_GET_TIM)
    {
        /* return current time */
        #ifdef USE_WITHIN_GOKESDK
        ulTempTime = GD_TIMER_ReadTimerStamp();
        #else
        {
           LARGE_INTEGER ft;
           GetSystemTimeAsFileTime((FILETIME *)&ft);
           ft.QuadPart /= 10000;
           ulTempTime = (U32) ft.QuadPart;
        }
        #endif
        if (ulTempTime >= StartTimes[ucIndex])
        {
           *pulDiffTime = (U32)(ulTempTime - StartTimes[ucIndex]);
        }
        else
        {
           /* in case of timer overflow reset start time */
            #ifdef USE_WITHIN_GOKESDK
            StartTimes[ucIndex] = GD_TIMER_ReadTimerStamp();
            #else
            {
               LARGE_INTEGER ft;
               GetSystemTimeAsFileTime((FILETIME *)&ft);
               ft.QuadPart /= 10000;
               StartTimes[ucIndex] = (U32) ft.QuadPart;
            }
            #endif
            *pulDiffTime = 0;
        }
    }

    /* Mp_VoIntTimeClock increments every 1/25 sec (1/30 for NTSC) */
    /* Other systems may have better reference and need to correct the pulDiffTime in a different way */
    *pulDiffTime *= TIM_RESOLUTION; /* with this multiplication we get an overflow if time is longer than 1000 hours => shouldn't be a problem */

    return GD_OK;
}
Ejemplo n.º 11
0
/*!
*******************************************************************************
**
** \brief  Feeds data into VBV buffer.
**
**         \c GD_VID_OpenMemory() has to be called before.
**
** \param  dataP     Pointer to video data.
** \param  size      Number of 32 bit words to copy.
**
** \return Number of copied bytes.
**
** \sa     GD_VID_OpenMemory()    <br>
**         GD_VID_FlushData()     <br>
**         GD_VID_CloseMemory()   <br>
**
******************************************************************************/
U32 GD_VID_FeedData(U32 *dataP, U32 size)
{
#if defined(GK6105S)
    U16 i,k;
    U32 tt;
    U32 *p;
    U32 count;
    U32 indx = 0;
    U8  tsd;
    S16 pid;
    U32 time = 0;
    U32 vbvBufferSize = 0;
    U32 TsPacket = 0;
    U32 leftByte = 0;
    U8 MuxCfg = 0,writestep=0;
#else
    volatile U32* adt;
    U32 i;
    U8  tsd;
#endif

#if defined(GD_VID_GKFEEDDATA_DEBUG)
    U32 time_old = GD_TIMER_ReadTimerStamp();
    
    GM_Printf("GD_VID_FeedData started on %d\n", time_old);
#endif
    
    /* copy the Iframe header to IFrameHeader, it is used in GD_VID_FlushData*/
    IFrameHeader[0] = dataP[0];
    IFrameHeader[1] = dataP[1];
    
    if(VideoFromMemFlag == GFALSE)
        return 0;
    
#if defined(GK6105S)
    TsPacket = (size*4)/184;
        
    leftByte = (size*4)%184;        
    if(leftByte != 0)
    {
        TsPacket++;
    }
    /*add more ts packets to vbv*/
    TsPacket = TsPacket*4;
    
    // to be customized here
    pid = 0x123;
#ifdef AV_SEPRATE_FLAG
    tsd = GD_TSD_GetHardwareControlledBuffer(GD_TSD_VIDEO_PES);
#else
    tsd = GD_TSD_GetHardwareControlledBuffer();
#endif
        
    vbvBufferSize = GH_BM_get_BufferSize(tsd, GD_TSD_VIDEO_PES);
    GH_TSD_set_SyncDistance(0xFF);
    GH_TSD_set_SyncDistance(187);
    //GH_TSD_set_InputMode_TS1_AM_SYNC(1); 
    GH_VD_set_VideoControl_DEC( 0);    /* reset VD */
    GH_BM_set_BufferReadPointer(tsd, GD_TSD_VIDEO_PES,GH_BM_get_BufferWritePointer(tsd,GD_TSD_VIDEO_PES));
    //GH_BM_set_BufferWritePointer(tsd, GD_TSD_VIDEO_PES, vbvBufferSize-184);
    //GH_BM_set_BufferReadPointer(tsd, GD_TSD_VIDEO_PES, vbvBufferSize-184);
    GD_TSD_SetChannelPid(GD_TSD_VIDEO_PES, tsd, pid);

    if(tsd == GD_TSD_1)
    {
        MuxCfg = GH_TSD_getm_MuxConfig_TSD1_MUX_CFG();
        GH_TSD_set_InputMode_TS1_AM_SYNC(1); 
        GH_TSD_set_MuxConfig_TSD1_MUX_CFG(3);
    }
    else if(tsd == GD_TSD_2)
    {
        MuxCfg = GH_TSD_getm_MuxConfig_TSD2_MUX_CFG();
        GH_TSD_set_InputMode_TS2_AM_SYNC(1); 
        GH_TSD_set_MuxConfig_TSD2_MUX_CFG(3);
    }
//  #if defined (GK6106)
//      else if(tsd == GD_TSD_3)
//      {
//          MuxCfg = GH_TSD_getm_MuxConfig_TSD2_MUX_CFG();
//          GH_TSD34_set_InputMode_TS1_AM_SYNC(1); 
//          GH_TSD34_set_MuxConfig_TSD3_MUX_CFG(3);
//      }
//      else if(tsd == GD_TSD_4)
//      {
//          MuxCfg = GH_TSD_getm_MuxConfig_TSD2_MUX_CFG();
//          GH_TSD34_set_InputMode_TS2_AM_SYNC(1); 
//          GH_TSD34_set_MuxConfig_TSD4_MUX_CFG(3);
//      }
//  #endif
    GD_TSD_ControlChannel(GD_TSD_VIDEO_PES, tsd, GD_TSD_ENABLE);
        
    for(indx = 0; indx<1; indx++)
    {
        count = 0;
        p = (U32 *)dataP;
        for (k = 0; k < TsPacket;k++)
        {
            tt = 20000;
            while((GH_TSD_get_PacketControl(tsd) != 0) && ((--tt) > 0) );
            if(tt == 0)
                return 0;

            tt = 20000;
            while((GH_TSD_get_PacketStatus(tsd) != 0) && ((--tt) > 0) );
            if(tt == 0)
                return 0;           
            
            /* write the first ts packet at the end of the vbv buffer. */
            if(writestep == 0)
            {
                GH_TSD_set_Packet0(tsd, 0, (0x47<<24) | (k & 0xF)|(pid<<8)|(0x1<<4)|(0x0<<6));
                for(i=1;i<47;i++)
                {
                    GH_TSD_set_Packet0(tsd, i,*p++);
                    count++;
                    if (count%size==0 )
                    {
                        p = (U32 *)dataP;
                    }
                }
                GH_TSD_set_PacketControl(tsd, 4);
            }
            
            if(writestep == 1)
            {
                GH_TSD_set_Packet1(tsd, 0, (0x47<<24) | (k & 0xF)|(pid<<8)|(0x1<<4)|(0x0<<6));
                for(i=1;i<47;i++)
                {
                    GH_TSD_set_Packet1(tsd, i,*p++);
                    count++;
                    if (count%size==0 )
                    {
                        p = (U32 *)dataP;
                    }
                }
                GH_TSD_set_PacketControl(tsd, 0x50);
            }
            
            if(writestep == 2)
            {
                GH_TSD_set_Packet2(tsd, 0, (0x47<<24) | (k & 0xF)|(pid<<8)|(0x1<<4)|(0x0<<6));
                for(i=1;i<47;i++)
                {
                    GH_TSD_set_Packet2(tsd, i,*p++);
                    count++;
                    if (count%size==0 )
                    {
                        p = (U32 *)dataP;
                    }
                }
                GH_TSD_set_PacketControl(tsd, 0x600);
            }
            
            if(writestep == 3)
            {
                GH_TSD_set_Packet3(tsd, 0, (0x47<<24) | (k & 0xF)|(pid<<8)|(0x1<<4)|(0x0<<6));
                for(i=1;i<47;i++)
                {
                    GH_TSD_set_Packet3(tsd, i,*p++);
                    count++;
                    if (count%size==0 )
                    {
                        p = (U32 *)dataP;
                    }
                }
                GH_TSD_set_PacketControl(tsd, 0x7000);
            }
            
            writestep++;
            if(writestep > 3)
            {
                writestep = 0;
            }
        }
    }
    GD_TSD_ControlChannel(GD_TSD_VIDEO_PES, tsd, GD_TSD_DISABLE);
    if(tsd == GD_TSD_1)
    {
        GH_TSD_set_MuxConfig_TSD1_MUX_CFG(MuxCfg);
    }
    else if(tsd == GD_TSD_2)
    {
        GH_TSD_set_MuxConfig_TSD2_MUX_CFG(MuxCfg);
    }
//  #if defined (GK6106)
//      else if(tsd == GD_TSD_3)
//      {
//          GH_TSD34_set_MuxConfig_TSD3_MUX_CFG(MuxCfg);
//      }
//      else if(tsd == GD_TSD_4)
//      {
//          GH_TSD34_set_MuxConfig_TSD4_MUX_CFG(MuxCfg);
//      }
//  #endif
    NumStillDataBytes = count<<2;

#if defined(GD_VID_GKFEEDDATA_DEBUG)    
    time_old = GD_TIMER_ReadTimerStamp();
    GM_Printf("GD_VID_FeedData end on %d\n", time_old);
#endif
    
#else
    /* reset buffer pointer and stop decoder */
    GH_VD_set_VideoControl_DEC( 0);    /* reset VD */
#ifdef AV_SEPRATE_FLAG
    tsd = GD_TSD_GetHardwareControlledBuffer(GD_TSD_VIDEO_PES);
#else
    tsd = GD_TSD_GetHardwareControlledBuffer();
#endif
    GH_BM_set_BufferReadPointer( tsd, GD_TSD_VIDEO_PES, 0);
    GH_BM_set_BufferWritePointer(tsd, GD_TSD_VIDEO_PES, 0);

    /* copy data into VBV buffer */
    adt = GD_VID_GetBuffer();
    for (i=0; i < size; i++)
        adt[i]=dataP[i];
    /* A still image is only shown after a new image is going to be decoded. */
    /* Therefore we add a few bytes from the same image at the end. */
    for (i=0; i < 64; i++)
        adt[i+size]=adt[i];

    NumStillDataBytes = (size+64)<<2;
#endif

    return(NumStillDataBytes);
}