Пример #1
0
uint8_t UartUsbGetChar( Uart_t *obj, uint8_t *data )
{
    if( IsFifoEmpty( &obj->FifoRx ) == false )
    {
        BoardDisableIrq( );
        *data = FifoPop( &obj->FifoRx );
        BoardEnableIrq( );
        return 0;
    }
    return 1;
}
Пример #2
0
uint8_t UartMcuGetChar( Uart_t *obj, uint8_t *data )
{
    if( IsFifoEmpty( &obj->FifoRx ) == false )
    {
        __disable_irq( );
        *data = FifoPop( &obj->FifoRx );
        __enable_irq( );
        return 0;
    }
    return 1;
}
/**
  * @brief  VCP_DataRx
  *         Data received over USB OUT endpoint are sent over CDC interface 
  *         through this function.
  *           
  *         @note
  *         This function will block any OUT packet reception on USB endpoint 
  *         untill exiting this function. If you exit this function before transfer
  *         is complete on CDC interface (ie. using DMA controller) it will result 
  *         in receiving more data while previous ones are still not sent.
  *                 
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL
  */
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
{
    uint32_t i;
  
	if( IsFifoEmpty( &FifoRx ) == true )
	{
		for( i = 0; i < Len; i++ )
		{
			FifoPush( &FifoRx, Buf[i] );
		}
	}
 
  return USBD_OK;
}
uint8_t UartUsbGetChar( Uart_t *obj, uint8_t *data )
{
    if( UsbMcuIsDeviceConfigured( ) == false )
    {
        return 2;
    }
    SetEPRxValid( ENDP3 );
    if( IsFifoEmpty( &obj->FifoRx ) == false )
    {
        __disable_irq( );
        *data = FifoPop( &obj->FifoRx );
        __enable_irq( );
        return 0;
    }
    return 1;
}
Пример #5
0
void USART1_IRQHandler( void )
{
    uint8_t data;

    if( USART_GetITStatus( USART1, USART_IT_TXE ) != RESET )
    {
		//GpioWrite( &LedRed, 0 );
        if( IsFifoEmpty( &Uart1.FifoTx ) == false )
        {
            data = FifoPop( &Uart1.FifoTx );
            //  Write one byte to the transmit data register
            USART_SendData( USART1, data );
        }
        else
        {
            // Disable the USART Transmit interrupt
            USART_ITConfig( USART1, USART_IT_TXE, DISABLE );
        }
        if( Uart1.IrqNotify != NULL )
        {
            Uart1.IrqNotify( UART_NOTIFY_TX );
        }
		//GpioWrite( &LedRed, 1 );
    }

    if( USART_GetITStatus( USART1, USART_IT_ORE_RX ) != RESET )
    {
        USART_ReceiveData( USART1 );
    }

    if( USART_GetITStatus( USART1, USART_IT_RXNE ) != RESET )
    {
		//UartPrintf( &Uart1, "USART_GetITStatus( USART1, USART_IT_RXNE )\n" );
		//GpioWrite( &LedGreen, 0 );
        data = USART_ReceiveData( USART1 );
        if( IsFifoFull( &Uart1.FifoRx ) == false )
        {
            // Read one byte from the receive data register
            FifoPush( &Uart1.FifoRx, data );
        }
        if( Uart1.IrqNotify != NULL )
        {
            Uart1.IrqNotify( UART_NOTIFY_RX );
        }
		//GpioWrite( &LedGreen, 1 );
    }
}
void EP1_IN_Callback (void)
{
    UsbPacketTx = 1;
    
    UsbTxLength = 0;
    
    while( IsFifoEmpty( &UartUsb.FifoTx ) == false )
    {
        UsbTxBuffer[UsbTxLength] = FifoPop( &UartUsb.FifoTx );
        UsbTxLength++;
    }

    if( UsbTxLength > 0 )
    {
        UsbPacketTx = 0;
        UserToPMABufferCopy( ( unsigned char* )UsbTxBuffer, ENDP1_TXADDR, UsbTxLength );
        SetEPTxCount( ENDP1, UsbTxLength );
        SetEPTxValid( ENDP1 );

    }
}