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

📄 uart.c

📁 ARM开发代码以及bootloader的初始化程序参考
💻 C
📖 第 1 页 / 共 4 页
字号:
/*************************************************************************/
/*                                                                       */
/* FILE NAME                                      VERSION                */
/*                                                                       */
/*      uart.c                     KS32C5000(A)/50100  SNDS100 Ver1.0    */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      UART library functions.                                          */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Young Sun KIM, Samsung Electronics, Inc.                         */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*       UART_Initialize                    Initialize serial driver     */
/*       i_getc                             Get a character from buffer  */
/*       i_gets                             Get a string from buffer     */
/*       i_putc                             print a character            */
/*       i_puts                             Print a string               */
/*       i_printf                           formmatted print             */
/*       BaudRateVal                        return baudrate divisor val. */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*         in4maker     05-31-1999      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
//#include "apdialog.h"
#include "s3c4510.h"
#include "uart.h"
#include "isr.h"
//#include "pollio.h"
#include "sysconf.h"

/********************************************************************/
/*               INITIALIZE UART GLOBAL VARIABLE                    */
/********************************************************************/

/* Define references to external structures */
SERIAL_DEV   uart_dev_init;
UART_BUFFER  RxQ[NUM_OF_SERIAL_DEV],TxQ[NUM_OF_SERIAL_DEV]; 



BaudTable U_BaudRate[BAUD_TABLE] = {

#ifdef EX_UCLK
/* for 29.4912MHz UART clock */
           9600,  0x000bf,
          19200,  0x0005f,
          38400,  0x0002f,
          57600,  0x0001f,
          115200, 0x0000f,
          230400, 0x00007,
          460800, 0x00003
#else
#ifdef KS32C50100
/* for 50MHz/2 UART clock */
           9600,  0x00a20,
          19200,  0x00500,
          38400,  0x00280,
          57600,  0x001a0,
          115200, 0x000d0,
          230400, 0x00060,
          460800, 0x00020   // not available 

#else
/* for 33MHz UART clock */
           9600,  0x000d6,
          19200,  0x0006a,
          38400,  0x00035,
          57600,  0x00023,
          115200, 0x00011,
          230400, 0x00008,
          460800, 0x00008   // not available 
#endif
#endif
};


/************************************************************************/
/*                                                                      */
/*  FUNCTION                               "UART_Initialize"            */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function is used to initialize the input and output        */
/*      control variables.                                              */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      Initialization of global structures                             */
/*                                                                      */
/************************************************************************/
uint32  UART_Initialize()
{

    Disable_Int(nGLOBAL_INT);  /* Global interrupt disabled */

    /*****************************/
    /* Initialize UART channel 0 */
    /*****************************/
    uart_dev_init.com_port  = SERIAL_DEV0;    /* com 0 */
    uart_dev_init.baud_rate = baudrate;
    uart_dev_init.data_mode = (UCON_RXM_INTREQ|UCON_TXM_INTREQ|UCON_RXSTAT_INT);
    uart_dev_init.parity    = ULCON_PMD_NO;   /* No parity */
    uart_dev_init.stop_bits = 0;              /* one bit */
    uart_dev_init.data_bits = ULCON_WL8;      /* 8bits */
#ifdef EX_UCLK  
    uart_dev_init.clk_sel = ULCON_UCLK;       /* external clock,29.4912MHz */
#else
    uart_dev_init.clk_sel = 0;                /* internal clock */
#endif
    UART_Init(&uart_dev_init);             

    /*****************************/
    /* Initialize UART channel 1 */
    /*****************************/
    uart_dev_init.com_port = SERIAL_DEV1;     /* com 0 */
    UART_Init(&uart_dev_init);

    Enable_Int(nGLOBAL_INT);  /* Global interrupt disabled */

    return(SUCCESS);
}

/***************************/
/* Uart main Init function */
/***************************/
uint32 UART_Init(SERIAL_DEV *s) 
{
     uint32    rUARTBRD;

     /* UART interrupt off */
     UARTRxIntOff(s->com_port);
     UARTTxIntOff(s->com_port);

     /* Initialize UART transmit & receive Queue */
     TxQInit(s->com_port);
     RxQInit(s->com_port);

     /* default baud rate will be set. sysconf.h */
     rUARTBRD = U_BaudRate[BaudRateVal(s->baud_rate)].div;

     if(s->com_port) 
     {   
          /* Interrupt service routine setup */
        SysSetInterrupt(nUART1_TX_INT, Uart1TxLisr);
#ifdef KS32C50100
        SysSetInterrupt(nUART1_RX_ERR_INT, Uart1RxErrLisr);
#else
        SysSetInterrupt(nUART1_RX_INT, Uart1RxErrLisr);
        SysSetInterrupt(nUART1_ERROR_INT, Uart1RxErrLisr);
#endif

        UARTLCON1 = s->data_bits|s->stop_bits|s->parity|s->clk_sel;
        UARTCONT1 = s->data_mode;
        UARTBRD1  = rUARTBRD;
     } 
     else 
     {
        /* Interrupt service routine setup */
        SysSetInterrupt(nUART0_TX_INT, Uart0TxLisr);
#ifdef KS32C50100
        SysSetInterrupt(nUART0_RX_ERR_INT, Uart0RxErrLisr);
#else
        SysSetInterrupt(nUART0_RX_INT, Uart0RxErrLisr);
        SysSetInterrupt(nUART0_ERROR_INT, Uart0RxErrLisr);
#endif
          /* UART mode, default baud rate setup */
        UARTLCON0 = s->data_bits|s->stop_bits|s->parity|s->clk_sel;
        UARTCONT0 = s->data_mode;
        UARTBRD0  = rUARTBRD; 
     }

     //UARTRxIntOn(s->com_port);
     //UARTTxIntOn(s->com_port);

     return(SUCCESS);
}


/************************************************************************/
/*                                                                      */
/*  FUNCTION                               "UART_Que_Init"              */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function is used to initialize the input and output        */
/*      control variables.                                              */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      Initialization of global structures                             */
/*                                                                      */
/************************************************************************/

/* Transmit Que initialize */
void TxQInit(uint32 channel)
{
    int i;

    for(i=0; i < MAXEVENT; i++)  
    {
          TxQ[channel].buff[i] = '\0';
    }

    TxQ[channel].wptr = 0;
    TxQ[channel].rptr = 0;
}

/* Receive Que initialize */
void RxQInit(uint32 channel)
{
    int i;

    for(i=0; i < MAXEVENT; i++) 
    {
         RxQ[channel].buff[i] = '\0';
    }

⌨️ 快捷键说明

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