uint8_t UartMcuPutChar( Uart_t *obj, uint8_t data ) { if( IsFifoFull( &obj->FifoTx ) == false ) { __disable_irq( ); FifoPush( &obj->FifoTx, data ); __enable_irq( ); // Enable the USART Transmit interrupt USART_ITConfig( USART1, USART_IT_TXE, ENABLE ); return 0; // OK } return 1; // Busy }
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 ); } }
uint8_t UartUsbPutChar( Uart_t *obj, uint8_t data ) { if( UsbMcuIsDeviceConfigured( ) == false ) { return 2; } if( IsFifoFull( &obj->FifoTx ) == false ) { __disable_irq( ); FifoPush( &obj->FifoTx, data ); __enable_irq( ); if( UsbPacketTx == 1 ) { /*Sent flag*/ UsbPacketTx = 0; SetEPTxCount( ENDP1, 0 ); SetEPTxValid( ENDP1 ); } return 0; // OK } return 1; // Busy // if( UsbPacketTx == 1 ) // { // /*Sent flag*/ // UsbPacketTx = 0; // /* send packet to PMA*/ // UserToPMABufferCopy( ( unsigned char* )&data, ENDP1_TXADDR, 1 ); // SetEPTxCount( ENDP1, 1 ); // SetEPTxValid( ENDP1 ); // return 0; // OK // } // else // { // if( IsFifoFull( &obj->FifoTx ) == false ) // { // __disable_irq( ); // FifoPush( &obj->FifoTx, data ); // __enable_irq( ); // return 0; // OK // } // } // return 1; // Busy }
/** * @brief CDC_Receive_FS * 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 operation: USBD_OK if all operations are OK else USBD_FAIL */ int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len) { uint8_t i; for( i = 0; i < *Len; i++ ) { if( IsFifoFull( &UartObj->FifoRx ) == false ) { // Read one byte from the receive data register FifoPush( &UartObj->FifoRx, Buf[i] ); } } if( UartObj->IrqNotify != NULL ) { UartObj->IrqNotify( UART_NOTIFY_RX ); } USBD_CDC_SetRxBuffer(hUsbDevice_0, Buf); USBD_CDC_ReceivePacket(hUsbDevice_0); return (USBD_OK); }
void EP3_OUT_Callback(void) { uint8_t i; UsbRxLength = GetEPRxCount( ENDP3 ); PMAToUserBufferCopy( ( unsigned char* )UsbRxBuffer, ENDP3_RXADDR, UsbRxLength ); for( i = 0; i < UsbRxLength; i++ ) { if( IsFifoFull( &UartUsb.FifoRx ) == false ) { // Read one byte from the receive data register FifoPush( &UartUsb.FifoRx, UsbRxBuffer[i] ); } } if( UartUsb.IrqNotify != NULL ) { UartUsb.IrqNotify( UART_NOTIFY_RX ); } }
uint8_t UartMcuPutChar( Uart_t *obj, uint8_t data ) { if( IsFifoFull( &obj->FifoTx ) == false ) { __disable_irq( ); FifoPush( &obj->FifoTx, data ); __enable_irq( ); // Enable the USART Transmit interrupt switch ( obj->UartId ) { case UART_1: USART_ITConfig( USART1, USART_IT_TXE, ENABLE ); break; case UART_2: USART_ITConfig( USART2, USART_IT_TXE, ENABLE ); break; } //USART_ITConfig( USART1, USART_IT_TXE, ENABLE ); return 0; // OK } return 1; // Busy }