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

📄 consol.c

📁 这是s3c2410的几个基础实验代码,在ads下编译通过,上机调过,能用
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************
*                                                                         *
*   PROJECT     : ARM port for UCOS-II                                    *
*                                                                         *
*   MODULE      : CONSOL.c                                                *
*                                                                         *
*   AUTHOR      : Michael Anburaj                                         *
*                 URL  : http://geocities.com/michaelanburaj/             *
*                 EMAIL: michaelanburaj@hotmail.com                       *
*                                                                         *
*   PROCESSOR   : S3c2410x (32 bit ARM920T RISC core from Samsung)        *
*                                                                         *
*   IDE         : SDT 2.51 & ADS 1.2                                      *
*                                                                         *
*   DESCRIPTION :                                                         *
*   This is the CONSOL Driver module. Supports multiple RS232 console     *
*   interfaces.                                                           *
*                                                                         *
**************************************************************************/


#include "def.h"
#include "S3c2410x.h"
#include "consol.h"
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>


/* ********************************************************************* */
/* Global definitions */


/* ********************************************************************* */
/* File local definitions */

static int __wChannel=1;

#define __isalpha(c) (c >'9')
#define __isupper(c) !(c & 0x20)


/* ********************************************************************* */
/* Local functions */


/* ********************************************************************* */
/* Global functions */

/*
*********************************************************************************************
*                                       CONSOL_Select
*
* Description: This routine selects the consol port for active usage.
*
* Arguments  : wCh - UART channel number.
*                    1 - UART1.
*                    2 - UART2.
*
* Return     : none.
*
* Note(s)    : 
*********************************************************************************************
*/

void CONSOL_Select(int wCh)
{
        __wChannel = wCh;
}

/*
*********************************************************************************************
*                                       CONSOL_Init
*
* Description: This routine initializes the consol port by setting its baud rate & FIFO
*              buffer.
*
* Arguments  : wBaud     - Baud Rate in bit/sec.
*
* Return     : none.
*
* Note(s)    : Before calling this, CONSOL_Select needs to be called for selecting the consol
*              port.
*********************************************************************************************
*/

void CONSOL_Init(int wBaud)
{
        switch(__wChannel)
        {
        case 0:
                rUFCON0 = (3<<6) | (3<<4) | (1<<2) | (1<<1) | (1<<0);   //UART channel 0 FIFO control register
                rUMCON0 = 0;
                rULCON0 = 0x3;   //Line control register : Normal,No parity,1 stop,8 bits
                rUCON0  = 0x245; // Control register
                rUBRDIV0=( (int)((FCLK/4)/16./wBaud+0.5) -1 );   //Baud rate divisior register 0
                break;

        case 1:
                rUFCON1 = (3<<6) | (3<<4) | (1<<2) | (1<<1) | (1<<0);   //UART channel 0 FIFO control register
                rUMCON1 = 0;
                rULCON1 = 0x3;   //Line control register : Normal,No parity,1 stop,8 bits
                rUCON1  = 0x245; // Control register
                rUBRDIV1=( (int)((FCLK/4)/16./wBaud+0.5) -1 );   //Baud rate divisior register 0
                break;

        case 2:
                rUFCON2 = (3<<6) | (3<<4) | (1<<2) | (1<<1) | (1<<0);   //UART channel 0 FIFO control register
                rULCON2 = 0x3;   //Line control register : Normal,No parity,1 stop,8 bits
                rUCON2  = 0x245; // Control register
                rUBRDIV2=( (int)((FCLK/4)/16./wBaud+0.5) -1 );   //Baud rate divisior register 0
                break;
        }
}

/*
*********************************************************************************************
*                                       CONSOL_GetCh
*
* Description: This routine waits for a character from the CONSOL port & returns it.
*
* Arguments  : none.
*
* Return     : Returns the character read from the consol port.
*
* Note(s)    : 
*********************************************************************************************
*/

char CONSOL_GetCh(void)
{
        switch(__wChannel)
        {
        case 0:
                while(!(rUFSTAT0 & 0x0f)); //Receive data ready
                return rURXH0;

        case 1:
                while(!(rUFSTAT1 & 0x0f)); //Receive data ready
                return rURXH1;

        case 2:
                while(!(rUFSTAT2 & 0x0f)); //Receive data ready
                return rURXH2;
        }
}

/*
*********************************************************************************************
*                                       CONSOL_GetChar
*
* Description: This routine reads a character from the consol port if available.
*
* Arguments  : pbData - Pointer to return the received data.
*
* Return     : The status of the RX buffer.
*              True  - Data returned is valid.
*              False - Data returned is invalid.
*
* Note(s)    : 
*********************************************************************************************
*/

char CONSOL_GetChar(char * pbData)
{
        switch(__wChannel)
        {
        case 0:
                if(rUFSTAT0 & 0x0f)
                {
                        *pbData = rURXH0;
                        return True;
                }
                return False;

        case 1:
                if(rUFSTAT1 & 0x0f)
                {
                        *pbData = rURXH1;
                        return True;
                }
                return False;

        case 2:
                if(rUFSTAT2 & 0x0f)
                {
                        *pbData = rURXH2;
                        return True;
                }
                return False;
        }
}

/*
*********************************************************************************************
*                                       CONSOL_GetString
*
* Description: This routine waits for a string from the CONSOL port & returns it.
*
* Arguments  : pbString - Pointer to return the received string.
*
* Return     : none.
*
* Note(s)    : 
*********************************************************************************************
*/

void CONSOL_GetString(char *pbString)
{
        char *pbString2=pbString;
        char bC;

        while((bC=CONSOL_GetCh())!='\r')
        {
                if(bC=='\b')
                {
                        if((int)pbString2<(int)pbString){CONSOL_Printf("\b \b");pbString--;}
                }
                else
                {
                        *pbString++=bC;CONSOL_SendCh(bC);
                }
        }
        *pbString='\0';
        CONSOL_SendCh('\n');
}

/*
*********************************************************************************************
*                                       CONSOL_GetIntNum
*
* Description: This routine waits for a Integer from the CONSOL port & returns it.
*

⌨️ 快捷键说明

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