⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ma_uart1.c

📁 NXP LPC系列AMR7的开发程序源码(LCD
💻 C
📖 第 1 页 / 共 2 页
字号:
**      None
**
**---------------------------------------------------------------------------
*/
{
    /*--- Handle user code on function entry ---*/
    ENTER_MA_PUTSTRING_UART1;
    
    /*--- Transmit data bytes ---*/
    while( *pString )
    {
        /*--- Transmit a data byte ---*/
        MA_PutChar_UART1( (U8)(*pString++) );
    }

    /*--- Handle user code on function exit ---*/
    EXIT_MA_PUTSTRING_UART1;
    
    return;

} /* MA_PutString_UART1 */





void MA_PutData_UART1( U8 *pData, U8 Length ) 
/*
**---------------------------------------------------------------------------
**
**  Abstract:
**      Send a number of characters to the UART 1 channel. 
**      This function waits indefinitely until the string has been sent 
**      successfully.
**
**  Parameters:
**      pData       A pointer to the data to transmit
**      Length      The number of bytes to write
**
**  Returns:
**      None
**
**---------------------------------------------------------------------------
*/
{
    /*--- Handle user code on function entry ---*/
    ENTER_MA_PUTDATA_UART1;
    
    /*--- Transmit data bytes ---*/
    while( Length-- )
    {
        /*--- Transmit a data byte ---*/
        MA_PutChar_UART1( *pData++ );
    }

    /*--- Handle user code on function exit ---*/
    EXIT_MA_PUTDATA_UART1;
    
    return;

} /* MA_PutData_UART1 */





S8 MA_GetChar_UART1( U8 *pChar ) 
/*
**---------------------------------------------------------------------------
**
**  Abstract:
**      Receive a character from the UART 1 channel. This function returns
**      immediately if a character cannot be received successfully.
**
**  Parameters:
**      pChar       A pointer to where the received character shall be saved.
**
**  Returns:
**      MA_OK       on success
**      MA_ERROR    if Break indicator, Framing, Parity or Overrun error 
**                  detected
**      MA_EMPTY    if the receive buffer is empty
**
**---------------------------------------------------------------------------
*/
{
    U8  Status;
    
    /*--- Handle user code on function entry ---*/
    ENTER_MA_GETCHAR_UART1;
    
    Status = U1LSR;

    /*--- Any characters received? ---*/
    if( Status & U1LSR_DR_VALID )
    {
        /*--- Detect potential errors ---*/
        if(( Status & U1LSR_ERR ) != 0 )
        {
            /*--- Parity, framing, overrun, fifo - error, or break indication detected ---*/
            *pChar = U1RBR;

            /*--- Handle user code on function exit ---*/
            EXIT_MA_GETCHAR_UART1;

            return MA_ERROR;
        }
        else
        {    
            /*--- Read the character ---*/
            *pChar = U1RBR;
        }
    }
    else
    {
        /*--- Handle user code on function exit ---*/
        EXIT_MA_GETCHAR_UART1;

        /*--- UART1 is empty ---*/
        return MA_EMPTY;
    }
    
    /*--- Handle user code on function exit ---*/
    EXIT_MA_GETCHAR_UART1;
    
    return MA_OK;

} /* MA_GetChar_UART1 */





S8 MA_GetString_UART1( C8 *pString , U8 Size ) 
/*
**---------------------------------------------------------------------------
**
**  Abstract:
**      Receive a string of characters from the UART 1 channel. Use the
**      function MA_SetEOS_UART1() to configure the end of string symbol,
**      if it is different from '\n'.
**
**      This function waits indefinitely until the string has been received 
**      successfully.
**	
**  Parameters:
**      pString     A pointer to the receive buffer
**      Size        The size of the receive buffer
**
**  Returns:
**      MA_OK       on success
**      MA_ERROR    if error detected
**      MA_FULL     if the receive buffer became full
**
**---------------------------------------------------------------------------
*/
{
    U8 Count;
    S8 Status;

    /*--- Handle user code on function entry ---*/
    ENTER_MA_GETSTRING_UART1;
    
    /*--- Receive data bytes ---*/
    Count = 0;

    /*--- Wait for received string ---*/
    do
    {
        /*--- Wait for received character ---*/
        do 
        {
            Status = MA_GetChar_UART1( (U8 *)pString );
            if( Status == MA_ERROR )
            {
                /*--- Append zero termination ---*/
                *pString = '\0';

                /*--- Handle user code on function exit ---*/
                EXIT_MA_GETSTRING_UART1;
    
                /*--- Problem detected ---*/
                return MA_ERROR;
            }
        } while( Status != MA_OK );

    } while( ( *pString++ != UART1.EOS ) && ( ++Count < ( Size-1 ) ) );

    /*--- Append zero termination ---*/
    *pString = '\0';

    /*--- Determine return code ---*/
    if( ++Count == Size )
    {
        /*--- Handle user code on function exit ---*/
        EXIT_MA_GETSTRING_UART1;

        return MA_FULL;
    }
    /*--- Handle user code on function exit ---*/
    EXIT_MA_GETSTRING_UART1;

    return MA_OK;        

} /* MA_GetString_UART1 */





S8 MA_GetData_UART1( U8 *pData, U8 Length ) 
/*
**---------------------------------------------------------------------------
**
**  Abstract:
**      Receive a number of characters from the UART 1 channel. 
**
**      This function waits indefinitely until the data has been received 
**      successfully.
**	
**  Parameters:
**      pData       A pointer to the receive buffer
**      Length      The number of bytes to read
**
**  Returns:
**      MA_OK       on success
**      MA_ERROR    if error detected
**
**---------------------------------------------------------------------------
*/
{
    S8 Status;

    /*--- Handle user code on function entry ---*/
    ENTER_MA_GETDATA_UART1;
    
    /*--- Wait for received data ---*/
    do
    {
        /*--- Wait for received character ---*/
        do 
        {
            Status = MA_GetChar_UART1( pData );
            if( Status == MA_ERROR )
            {
                /*--- Handle user code on function exit ---*/
                EXIT_MA_GETDATA_UART1;
    
                /*--- Problem detected ---*/
                return MA_ERROR;
            }
        } while( Status != MA_OK );

        *pData++;

    } while( --Length );

    /*--- Handle user code on function exit ---*/
    EXIT_MA_GETDATA_UART1;

    return MA_OK;        

} /* MA_GetData_UART1 */





void MA_SetEOS_UART1( U8 Symbol ) 
/*
**---------------------------------------------------------------------------
**
**  Abstract:
**      Set the end of string symbol used by the MA_GetString_UART1() 
**      function.
**
**  Parameters:
**      Symbol	    End of string symbol
**
**  Returns:
**      None
**
**---------------------------------------------------------------------------
*/
{
   /*--- Handle user code on function entry ---*/
    ENTER_MA_SETEOS_UART1;

    /*--- Set end of string symbol ---*/
    UART1.EOS = Symbol;

    /*--- Handle user code on function exit ---*/
    EXIT_MA_SETEOS_UART1;
      
} /* MA_SetEOS_UART1 */






/*
**===========================================================================
**  5.      INTERNAL FUNCTIONS (declared in Section 3.5)
**===========================================================================
*/

/*
**===========================================================================
** END OF FILE
**===========================================================================
*/ 



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -