예제 #1
0
/*
 *  SIOの割込みサービスルーチン
 */
void
sio_isr(intptr_t exinf)
{
	SIOPCB          *p_siopcb;

	p_siopcb = get_siopcb(exinf);

	/*
	 *  割込みのクリア
	 */
	UARTIntClear(p_siopcb->p_siopinib->base,
				 UARTIntStatus(p_siopcb->p_siopinib->base, true));

	if (UARTCharsAvail(p_siopcb->p_siopinib->base)) {
		/*
		 *  受信通知コールバックルーチンを呼び出す.
		 */
		sio_irdy_rcv(p_siopcb->exinf);
	}
	if (UARTSpaceAvail(p_siopcb->p_siopinib->base)) {
		/*
		 *  送信可能コールバックルーチンを呼び出す.
		 */
		sio_irdy_snd(p_siopcb->exinf);
	}
}
예제 #2
0
/*
 *  シリアルI/Oポートへの文字送信
 */
bool_t
sio_snd_chr(SIOPCB *p_siopcb, char c)
{
	if(UARTSpaceAvail(p_siopcb->p_siopinib->base)){
		UARTCharPutNonBlocking(p_siopcb->p_siopinib->base, c);
		return(true);
	}
	return(false);
}
예제 #3
0
static void _putchar(char_device *dev,char ch)
{
    unsigned char ucData;
    xQueueSend(dev->TxQueue, &ch, dev->QueueWait);
    if(UARTSpaceAvail(dev->PortBase)){
        xQueueReceive(dev->TxQueue,&ucData,dev->QueueWait);
        UARTCharPut(dev->PortBase, ucData);
    }
}
예제 #4
0
/*********************************************************************************************************
** Function name:           Uart0Send
** Descriptions:            发送多个字节数据
** input parameters:        Buffer:发送数据存储位置
**                          NByte:发送数据个数
** Output parameters::      无
** Returned value:          无
** Created by:             
** Created Date:             2014.10.03
**--------------------------------------------------------------------------------------------------------
** Modified by:             
** Modified date:           2014.10.03
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void UartSend (u8  *Buffer, u16  NByte)
{
    while (NByte) {
        if ( UARTSpaceAvail(UART1_BASE) ) {
            UARTCharPutNonBlocking(UART1_BASE, *Buffer++);
            NByte--;
        }
    }
    while (UARTBusy(UART1_BASE) ) {
        ;
    }
}
//*****************************************************************************
//
// Take as many bytes from the transmit buffer as we have space for and move
// them into the USB UART's transmit FIFO.
//
//*****************************************************************************
static void
USBUARTPrimeTransmit(uint32_t ui32Base)
{
    uint32_t ui32Read;
    uint8_t ui8Char;

    //
    // If we are currently sending a break condition, don't receive any
    // more data. We will resume transmission once the break is turned off.
    //
    if(HWREGBITW(&g_ui32Flags, FLAG_SENDING_BREAK))
    {
        return;
    }

    //
    // If there is space in the UART FIFO, try to read some characters
    // from the receive buffer to fill it again.
    //
    while(UARTSpaceAvail(ui32Base))
    {
        //
        // Get a character from the buffer.
        //
        ui32Read = USBBufferRead((tUSBBuffer *)&g_sRxBuffer, &ui8Char, 1);

        //
        // Did we get a character?
        //
        if(ui32Read)
        {
            //
            // Place the character in the UART transmit FIFO.
            //
            ROM_UARTCharPutNonBlocking(ui32Base, ui8Char);

            //
            // Update our count of bytes transmitted via the UART.
            //
            g_ui32UARTTxCount++;
        }
        else
        {
            //
            // We ran out of characters so exit the function.
            //
            return;
        }
    }
}
예제 #6
0
static void
USBUARTPrimeTransmit(unsigned int ulBase)
{
   unsigned int ulRead;
    unsigned char ucChar;

    //
    // If we are currently sending a break condition, don't receive any
    // more data. We will resume transmission once the break is turned off.
    //
    if(g_bSendingBreak)
    {
        return;
    }

    //
    // If there is space in the UART FIFO, try to read some characters
    // from the receive buffer to fill it again.
    //
    while(UARTSpaceAvail(ulBase))
    {
        //
        // Get a character from the buffer.
        //
        ulRead = USBBufferRead((tUSBBuffer *)&g_sRxBuffer, &ucChar, 1);

        //
        // Did we get a character?
        //
        if(ulRead)
        {
            //
            // Place the character in the UART transmit FIFO.
            //
            UARTCharPutNonBlocking(ulBase, ucChar);

            //
            // Update our count of bytes transmitted via the UART.
            //
            g_ulUARTTxCount++;
        }
        else
        {
            //
            // We ran out of characters so exit the function.
            //
            return;
        }
    }
}
예제 #7
0
uint8_t uart_transmit(char* formatted, uint8_t length) {
    //FOR TESTING PURPOSES ONLY
    uint8_t uart_counter = 0;
    
    while( uart_counter < 8 ) {
	    while( !UARTSpaceAvail(UART0_BASE)  ) {}
	    if (uart_counter == 0) {
	    	UARTCharPutNonBlocking(UART0_BASE, (char) 0xFF);
	    } else UARTCharPutNonBlocking(UART0_BASE, formatted[uart_counter-1]);
	    uart_counter++;
	}
    
    //Api_rx_all(formatted, vars);
    
    return 1;
}
예제 #8
0
파일: uartDrv.c 프로젝트: ikerexxe/BroadCar
/**
 * @brief  Guarda los datos en el buffer del hardware.
 *
 * @return    -
 *
 * Guardado de los datos del buffer de software en el buffer de
 * hardware para su posterior envio.
*/
static int toHwFIFO(int nPort)
{
	unsigned char c; /*Variable temporal donde se guardan los caracteres a enviar*/
	int n; /*Numero de huecos en el buffer de hardware*/
	int m; /*Valor de retorno*/

	n=nElementosOut(nPort);
	m=0;
	while((n-->0)&&(UARTSpaceAvail(gs_ul_uarts_bases[nPort])))
	{
		c=gs_cu_uarts[nPort].outBuf[gs_cu_uarts[nPort].outTail];
		gs_cu_uarts[nPort].outTail++;
		if(gs_cu_uarts[nPort].outTail==BUFF_SIZE) gs_cu_uarts[nPort].outTail=0;
		UARTCharPutNonBlocking(gs_ul_uarts_bases[nPort], c);
	}
	return m;
}
예제 #9
0
void UART1IntHandler()
{
    unsigned long ulStatus;

    //
    // Get the interrrupt status.
    //
    ulStatus = UARTIntStatus(UART1_BASE, true);
    //
    // Clear the asserted interrupts.
    //
    UARTIntClear(UART1_BASE, ulStatus);

    if(ulStatus & UART_INT_TX)
    {
     // TX int
     // Push next char to transmitter
     bRc = true;
     while((m_nTxBuffIn1 > 0) && (bRc == true) && UARTSpaceAvail(UART1_BASE))
     {
               //
               // Write the next character into the transmit FIFO.
               //
      bRc = UARTCharPutNonBlocking(UART1_BASE,m_tTxBuff1[m_nTxNextNdx1]);
       if(bRc == true)
      {
       m_nTxNextNdx1++;
       m_nTxBuffIn1--;
      }
     }

    }
    else if(ulStatus & UART_INT_RX || ulStatus & UART_INT_RT)
    {
     // RX int
     // Read all RX fifo data
     while(UARTCharsAvail(UART1_BASE))
     {
      // Read the next character from the UART
      // (and write it back to the UART) ?
      OmapMessageLoop(UART1_BASE,1);
     }
    }

}
예제 #10
0
void arm_uart_interrupt_handler( void ) {
  //clear interrupt flag
  unsigned long ul = UARTIntStatus( UART0_BASE, true );
  UARTIntClear( UART0_BASE, ul );

  //receive chars if any
  while ( UARTCharsAvail( UART0_BASE) ) arm_uart_receive_data();

  //transmit characters if possible
  while ( UARTSpaceAvail( UART0_BASE ) && !transmit_buffer_empty() ) arm_uart_send_data();

  //if nothing to transmit, then switch off transmit interrupt, otherwise enable TX interrupt
  if ( !UARTBusy( UART0_BASE ) && transmit_buffer_empty() ) {
    UARTIntDisable( UART0_BASE, UART_INT_TX );
  } else {
    UARTIntEnable( UART0_BASE, UART_INT_TX );
  }
}
예제 #11
0
파일: hooks.c 프로젝트: x893/OpenBLT
/************************************************************************************//**
** \brief     Callback that gets called each time new log information becomes 
**            available during a firmware update.
** \param     info_string Pointer to a character array with the log entry info.
** \return    none.
**
****************************************************************************************/
void FileFirmwareUpdateLogHook(blt_char *info_string)
{
  /* write the string to the log file */
  if (logfile.canUse == BLT_TRUE)
  {
    if (f_puts(info_string, &logfile.handle) < 0)
    {
      logfile.canUse = BLT_FALSE;
      f_close(&logfile.handle);
    }
  }
  /* echo all characters in the string on UART */
  while(*info_string != '\0')
  {
    /* write character to transmit holding register */
    UARTCharPutNonBlocking(UART0_BASE, *info_string);
    /* wait for tx holding register to be empty */
    while(UARTSpaceAvail(UART0_BASE) == false);
    /* point to the next character in the string */
    info_string++;
  }
} /*** end of FileFirmwareUpdateLogHook ***/
예제 #12
0
//*****************************************************************************
//! Handles the UART interrupt.
//!
//! \param ucPort is the serial port number to be accessed.
//!
//! This function is called when either of the UARTs generate an interrupt.
//! An interrupt will be generated when data is received and when the transmit
//! FIFO becomes half empty.  The transmit and receive FIFOs are processed as
//! appropriate.
//!
//! \return None.
//*****************************************************************************
static void SerialUARTIntHandler(uint8_t ucPort)
{
    // Get the cause of the interrupt.
    uint32_t ulStatus = UARTIntStatus(g_ulUARTBase[ucPort], true);

    // Clear the cause of the interrupt.
    UARTIntClear(g_ulUARTBase[ucPort], ulStatus);

    // See if there is data to be processed in the receive FIFO.
    if(ulStatus & (UART_INT_RT | UART_INT_RX))
    {
        // Loop while there are characters available in the receive FIFO.
        while(UARTCharsAvail(g_ulUARTBase[ucPort]))
        {
            // Get the next character from the receive FIFO.
            uint8_t ucChar = UARTCharGet(g_ulUARTBase[ucPort]);

#ifdef PROTOCOL_TELNET
            // If Telnet protocol enabled, check for incoming IAC character,
            // and escape it.
            if((g_sParameters.sPort[ucPort].ucFlags &
                        PORT_FLAG_PROTOCOL) == PORT_PROTOCOL_TELNET)
            {
                // If this is a Telnet IAC character, write it twice.
                if((ucChar == TELNET_IAC) &&
                   (RingBufFree(&g_sRxBuf[ucPort]) >= 2))
                {
                    RingBufWriteOne(&g_sRxBuf[ucPort], ucChar);
                    RingBufWriteOne(&g_sRxBuf[ucPort], ucChar);
                }

                // If not a Telnet IAC character, only write it once.
                else if((ucChar != TELNET_IAC) &&
                        (RingBufFree(&g_sRxBuf[ucPort]) >= 1))
                {
                    RingBufWriteOne(&g_sRxBuf[ucPort], ucChar);
                }
            }

            // if not Telnet, then only write the data once.
            else
#endif

            {
                if (fDataDebugFlag)
                  CONSOLE("%u: from UART %02X\n", ucPort, ucChar);

                if (IsModemModeCommand(ucPort))
                  ProcessModemModeCommand(ucPort, ucChar);
                else
                {
                  ProcessModemModeData(ucPort, ucChar);
                  RingBufWriteOne(&g_sRxBuf[ucPort], ucChar);
                }

                ProcessModemToServerData(ucPort);
                ProcessServerToModemData(ucPort, ucChar);
            }
        }
    }

#ifdef SERIAL_FLOW_CONTROL
    // If flow control is enabled, check the status of the RX buffer to
    // determine if flow control GPIO needs to be asserted.
    if(g_sParameters.sPort[ucPort].ucFlowControl == SERIAL_FLOW_CONTROL_HW)
    {
        // If the ring buffer is down to less than 25% free, assert the
        // outbound flow control pin.
        if(RingBufFree(&g_sRxBuf[ucPort]) <
           (RingBufSize(&g_sRxBuf[ucPort]) / 4))
        {
            GPIOPinWrite(g_ulFlowOutBase[ucPort], g_ulFlowOutPin[ucPort],
                         g_ulFlowOutPin[ucPort]);
        }
    }
#endif

    // See if there is space to be filled in the transmit FIFO.
    if(((ulStatus & UART_INT_TX) != 0) || (ulStatus == 0))
    {
        bool fInMode = true;

        // Loop while there is space in the transmit FIFO and characters to be sent.
        while(!RingBufEmpty(&g_sTxBuf[ucPort]) && UARTSpaceAvail(g_ulUARTBase[ucPort]))
        {
            uint8_t ucChar = RingBufReadOne(&g_sTxBuf[ucPort]);

            if (fDataDebugFlag)
              CONSOLE("%u: to UART %02X\n", ucPort, ucChar);

            // Write the next character into the transmit FIFO.
            UARTCharPut(g_ulUARTBase[ucPort], ucChar);

            CustomerSettings1_SerialProcessCharacter(ucPort, ucChar);

            mcwUARTTxOut[ucPort]--;

            fInMode = false;
        }

        if((ulStatus & UART_INT_TX) != 0)
        {
          if ((mcwUARTTxOut[ucPort] == 0) && (fInMode)) {
              InMode(ucPort);
          }
        }
    }
}