📄 serial.h
字号:
/******************************************************************************
* Filename : serial.h *
* Program : loader. *
* Copyright : Copyright (C) 2001, Young-Su, Ahn. *
* Author : Young-Su, Ahn <nurie@dreamwiz.com> *
* Description : Header file for serial.c. *
* Created at : Wed Mar 13 2001. *
* Based on : blob-1.0.8-pre2 (http://www.lart.tudelft.nl) *
* Modified by : *
* Modified at : *
******************************************************************************/
/* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _SERIAL_H_467646493264924
#define _SERIAL_H_467646493264924
#include "types.h"
#include "config.h"
// 盔夯篮 linux狼 include/asm/arch-sa1100/SA-1100.h涝聪促. 炼陛 函版窍看嚼聪促.
// Serial Port 1.
#define Ser1SDCR0 (*((volatile ulong *)(0x80020060)))
#define Ser1UTCR0 (*((volatile ulong *)(0x80010000)))
#define Ser1UTCR1 (*((volatile ulong *)(0x80010004)))
#define Ser1UTCR2 (*((volatile ulong *)(0x80010008)))
#define Ser1UTCR3 (*((volatile ulong *)(0x8001000C)))
#define Ser1UTDR (*((volatile ulong *)(0x80010014)))
#define Ser1UTSR0 (*((volatile ulong *)(0x8001001C)))
#define Ser1UTSR1 (*((volatile ulong *)(0x80010020)))
// Serial Port 3.
#define Ser3UTCR0 (*((volatile ulong *)(0x80050000)))
#define Ser3UTCR1 (*((volatile ulong *)(0x80050004)))
#define Ser3UTCR2 (*((volatile ulong *)(0x80050008)))
#define Ser3UTCR3 (*((volatile ulong *)(0x8005000C)))
#define Ser3UTDR (*((volatile ulong *)(0x80050014)))
#define Ser3UTSR0 (*((volatile ulong *)(0x8005001C)))
#define Ser3UTSR1 (*((volatile ulong *)(0x80050020)))
#define UTCR0_PE 0x00000001 // Parity Enable.
#define UTCR0_OES 0x00000002 // Odd/Even parity Select.
#define UTCR0_OddPar (UTCR0_OES*0) // Odd Parity.
#define UTCR0_EvenPar (UTCR0_OES*1) // Even Parity.
#define UTCR0_SBS 0x00000004 // Stop Bit Select.
#define UTCR0_1StpBit (UTCR0_SBS*0) // 1 Stop Bit per frame.
#define UTCR0_2StpBit (UTCR0_SBS*1) // 2 Stop Bits per frame.
#define UTCR0_DSS 0x00000008 // Data Size Select.
#define UTCR0_7BitData (UTCR0_DSS*0) // 7-Bit Data.
#define UTCR0_8BitData (UTCR0_DSS*1) // 8-Bit Data.
#define UTCR0_SCE 0x00000010 // Sample Clock Enable.
#define UTCR0_RCE 0x00000020 // Receive Clock Edge select.
#define UTCR0_RcRsEdg (UTCR0_RCE*0) // Receive clock Rising-Edge.
#define UTCR0_RcFlEdg (UTCR0_RCE*1) // Receive clock Falling-Edge.
#define UTCR0_TCE 0x00000040 // Transmit Clock Edge select.
#define UTCR0_TrRsEdg (UTCR0_TCE*0) // Transmit clock Rising-Edge.
#define UTCR0_TrFlEdg (UTCR0_TCE*1) // Transmit clock Falling-Edge.
#define UTCR0_Ser2IrDA (UTCR0_1StpBit + UTCR0_8BitData)
#define UTCR3_RXE 0x00000001 // Receive Enable.
#define UTCR3_TXE 0x00000002 // Transmit Enable.
#define UTCR3_BRK 0x00000004 // BReaK mode.
#define UTCR3_RIE 0x00000008 // Receive FIFO 1/3-to-2/3-full or more Interrupt Enable.
#define UTCR3_TIE 0x00000010 // Transmit FIFO 1/2-full or less Interrupt Enable.
#define UTCR3_LBM 0x00000020 // Look-Back Mode.
#define UTCR3_Ser2IrDA (UTCR3_RXE + UTCR3_TXE)
#define UTCR4_HSE 0x00000001 // Hewlett-Packard Serial InfraRed.
#define UTCR4_NRZ (UTCR4_HSE*0) // Non-Return to Zero modulation.
#define UTCR4_HPSIR (UTCR4_HSE*1) // HP-SIR modulation.
#define UTCR4_LPM 0x00000002 // Low-Power Mode.
#define UTCR4_Z3_16Bit (UTCR4_LPM*0) // Zero pulse = 3/16 Bit time.
#define UTCR4_Z1_6us (UTCR4_LPM*1) // Zero pulse = 1.6 us.
#define UTSR0_TFS 0x00000001 // Transmit FIFO 1/2-full or less Service request (read).
#define UTSR0_RFS 0x00000002 // Receive FIFO 1/3-to-2/3-full or more Service request (read).
#define UTSR0_RID 0x00000004 // Receiver IDle
#define UTSR0_RBB 0x00000008 // Receive Beginning of Break
#define UTSR0_REB 0x00000010 // Receive End of Break
#define UTSR0_EIF 0x00000020 // Error In FIFO (read).
#define UTSR1_TBY 0x00000001 // Transmitter Busy (read).
#define UTSR1_RNE 0x00000002 // Receive FIFO Not Empty (read).
#define UTSR1_TNF 0x00000004 // Transmit FIFO Not Full (read).
#define UTSR1_PRE 0x00000008 // receive PaRity Error (read).
#define UTSR1_FRE 0x00000010 // receive FRaming Error (read).
#define UTSR1_ROR 0x00000020 // Receive FIFO Over-Run (read).
#ifdef USE_SERIAL1
#define UTCR0 Ser1UTCR0
#define UTCR1 Ser1UTCR1
#define UTCR2 Ser1UTCR2
#define UTCR3 Ser1UTCR3
#define UTDR Ser1UTDR
#define UTSR0 Ser1UTSR0
#define UTSR1 Ser1UTSR1
#else
#define UTCR0 Ser3UTCR0
#define UTCR1 Ser3UTCR1
#define UTCR2 Ser3UTCR2
#define UTCR3 Ser3UTCR3
#define UTDR Ser3UTDR
#define UTSR0 Ser3UTSR0
#define UTSR1 Ser3UTSR1
#endif
// Data Bit.
// 捞巴捞 define登绢 乐绢具, 酒贰狼 Default蔼捞 利侩凳.
#ifndef SERIAL_CONFIG
#define SERIAL_CONFIG
//#define SERIAL_DATA_BIT UTCR0_7BitData // Data Bit 7.
#define SERIAL_DATA_BIT UTCR0_8BitData // Data Bit 8.
// Stop Bit.
#define SERIAL_STOP_BIT UTCR0_1StpBit // Stop Bit 1.
//#define SERIAL_STOP_BIT UTCR0_2StpBit // Stop Bit 2.
// Parity Bit.
// Parity甫 荤侩且 版快
#define SERIAL_PARITY_ENABLE 0 // Parity Bit 荤侩 救窃.
//#define SERIAL_PARITY_ENABLE UTCR0_PE // parity Bit 荤侩.
#define SERIAL_PARITY 0 // Parity Bit 荤侩 救窃.
//#define SERIAL_PARITY UTCR0_OddPar // Odd Parity Bit 荤侩.
//#define SERIAL_PARITY UTCR0_EvenPar // Even Parity Bit 荤侩.
#endif
typedef enum { // Some useful Baudrates for sa-1110;
BAUD1200 = 191,
BAUD9600 = 23,
BAUD19200 = 11,
BAUD38400 = 5,
BAUD57600 = 3,
BAUD115200 = 1
} SCR;
/*
typedef int (*serial_init_func_t)(serial_baud_t);
typedef int (*serial_read_func_t)(void);
typedef int (*serial_write_func_t)(int);
typedef int (*serial_poll_func_t)(void);
typedef int (*serial_flush_input_func_t)(void);
typedef int (*serial_flush_output_func_t)(void);
*/
/*
typedef struct {
serial_init_func_t init;
serial_read_func_t read;
serial_write_func_t write;
serial_poll_func_t poll;
serial_flush_input_func_t flush_input;
serial_flush_output_func_t flush_output;
} serial_driver_t;
*/
/* implemented serial drivers */
//extern serial_driver_t sa11x0_serial_driver;
/* should be filled out by the architecture dependent files */
//extern serial_driver_t *serial_driver;
// Function prototypes.
void SerialInit(SCR scr);
int serial_poll(void);
void SerialOutputByte(const char c);
int SerialInputByte(char *c);
//extern void SerialInit(eBauds baudrate); // 皋牢 矫府倔 檬扁拳
extern void SerialOutChar( const char c ); // 矫府倔俊 茄 巩磊甫 免仿茄促.
extern int SerialOutStr( char *str, int size ); // 矫府倔俊 滚欺狼 郴侩阑 免仿茄促.
extern void SerialOutChar_CheckCR( const char c ); // 矫府倔俊 茄 巩磊甫 免仿茄促.
extern int SerialOutStr_CheckCR( char *str, int size ); // 矫府倔俊 滚欺狼 郴侩阑 免仿茄促.
extern int SerialIsReadyChar( void );
extern char SerialIsGetChar( void );
extern char SerialIsClearError( void );
extern int SerialIsGetError( void );
int SerialInputString(char *s, const int len, const int timeout);
int SerialInputBlock(char *buf, int bufsize, const int timeout);
#endif // end _SERIAL_H_467646493264924.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -