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

📄 uart.c

📁 ARM开发代码以及bootloader的初始化程序参考
💻 C
📖 第 1 页 / 共 4 页
字号:

     return(RxQ[channel].buff[RxQ[channel].rptr++]);
}

/************************************************************************/
/*                                                                      */
/*  FUNCTION                               "UART INTERRUPT FUNCTIONS"   */
/*                                                                      */
/*      i_getc()                                                        */
/*      i_gets()                                                        */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function attempts to get a character from the serial       */
/*      driver's input queue.                                           */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that request serial input                      */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(c)              return character                         */
/*                                                                      */
/* HISTORY                                                              */
/*                                                                      */
/*         NAME            DATE                    REMARKS              */
/*                                                                      */
/*         in4maker     06-01-1999      Created initial version 1.0     */
/*                                                                      */
/************************************************************************/
uint8 i_getc(uint32 channel)
{
    //uint8 InChar;

    UARTRxIntOn(channel);

    //InChar = RxQRd(channel);
    return(RxQRd(channel));

    //if(InChar != NULL) return(InChar);
    //else return(NULL);
}

/* Interrupt get string */
uint32 i_gets(uint32 channel, uint8 *s)
{
     uint32   count;
     uint8    c;

     count = 0; 

     while((c = (uint8)i_getc(channel)) != CR)
     {
            count++;
            *s++ = c;
     }

     *s = (uint8)NULL; 

     return(count);
}


/************************************************************************/
/*                                                                      */
/*  FUNCTION                               "UART INTERRUPT FUNCTIONS"   */
/*                                                                      */
/*      i_putc()     This function attempts to out a character from     */
/*                   the serial                                         */ 
/*      i_puts()     This function prints a null-terminated string to   */
/*                   the terminal.                                      */ 
/*      i_prinf()    Formatted output string.                           */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */ 
/*      driver's transmit queue to uart serial channel.                 */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that request serial output                     */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*                                                                      */
/* HISTORY                                                              */
/*                                                                      */
/*         NAME            DATE                    REMARKS              */
/*                                                                      */
/*         in4maker     06-01-1999      Created initial version 1.0     */
/*                                                                      */
/************************************************************************/
uint32  i_putc(uint32 channel, uint8 ch)
{
    if(U_TX_COMPLETE(channel))               /* check transmit complet */
    {
           if(TxQWr(channel, ch))            /* write data to tx que */
           {
               UARTTxIntOn(channel);         /* Transmit interrupt on */
               while(!U_BUFF_EMPTY(channel)); /* wait for tx buffer empty */

               return(SUCCESS);
           }
    }

    return(ERROR);                 
}

/* UART Interrupt put string */
uint32  i_puts(uint32 channel, uint8 *str)
{    
       uint32     i;      /* Working variable         */
       uint32     sz;    

       sz = strlen((const char *)str); 

        /* Loop to print out all characters.  */
        for(i=0; i < sz ; i++) 
        {
                /* Call i_putc to print each character.  */
                while(!i_putc(channel, *(str + i)));
        }
 
        return(SUCCESS);
}

/* formatted output string */
void i_printf(char *fmt, ...)
{
    va_list argptr;
    char temp_buf[256];

    va_start(argptr, fmt);
    vsprintf(temp_buf, fmt, argptr);
    sputs((uint8 *)temp_buf);
    va_end(argptr);
}


/************************************************************************/
/*                                                                      */
/*  FUNCTION                            "UART POLL FUNCTIONS"           */
/*                                                                      */
/*      put_char               put character to uart channel by polling.*/
/*      get_char               get character from uart channel by       */
/*                             polling method.                          */
/*      put_string             put string to uart channel by polling.   */
/*      dbg_out                formatted output to uart channel.        */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      These serial I/O functions are useful in POLLING mode.          */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Application routines                                            */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(c)              return character                         */
/*                                                                      */
/* HISTORY                                                              */
/*                                                                      */
/*         NAME            DATE                    REMARKS              */
/*                                                                      */
/*         in4maker     10-16-1998      Created initial version 1.0     */
/************************************************************************/
void put_char(uint32 channel,char ch) 
{
    if(channel) {
        WaitXmitter(UARTSTAT1);
        UARTTXH1 = ch;
    }
    else {
        WaitXmitter(UARTSTAT0);
        UARTTXH0 = ch;
    }
}


char get_char(uint32 channel) 
{ 
  char ch;
 
    if(channel) { WaitRcver(UARTSTAT1);
                  ch = UARTRXB1;
    }
    else { WaitRcver(UARTSTAT0);
           ch = UARTRXB0;
    }
    return ch;
}


void put_string(char *ptr ) 
{
    while(*ptr )  
    {
         put_byte(*ptr++ );
    }
}


void dbg_out(char *fmt, ...)
{
    va_list argptr;
    char temp_buf[256];

    va_start(argptr, fmt);
    vsprintf(temp_buf, fmt, argptr);
    put_string(temp_buf);
    va_end(argptr);
}


/************************************************************************/
/*                                                                      */
/*  FUNCTION                                                            */
/*                                                                      */
/*      gethex2dec             get hex-string from hexdecimal digit     */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      s = gethex2dec(3fff);                                           */
/*      return value s = "3fff"                                         */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Application routines                                            */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*                                                                      */

⌨️ 快捷键说明

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