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

📄 commrtos.h

📁 一个简单易用的可裁减的小型实时操作系统 移植非常简单
💻 H
字号:
/*
 *******************************************************************************
 *
 * MicroROS
 *
 * Copyright (C) 2007 <amwox@163.com>			
 *
 * Description	: 异步串口通信
 *				参考Jean J. Labrosse的<<Embedded Systems Building Blocks>>
 * File			: commrtos.h
 * Author		: amwox
 * Edition		: V0.01
 * History		: 2008-01-29  created 
 *******************************************************************************
 */
#ifndef __COMMRTOS_H__
#define __COMMRTOS_H__

#define	COMM_RX_BUFF_SIZE		64
#define COMM_TX_BUFF_SIZE		64

#define COMM0					1
#define COMM1					2

#define  COMM0_BASE        0x03F8                /* Base address of PC's COM1                          */
#define  COMM1_BASE        0x02F8                /* Base address of PC's COM2                          */

                                              	 /* ERROR CODES                                        */
#define  COMM_NO_ERR            0                /* Function call was successful                       */
#define  COMM_BAD_CH            1                /* Invalid communications port channel                */
#define  COMM_RX_EMPTY          2                /* Rx buffer is empty, no character available         */
#define  COMM_TX_FULL           3                /* Tx buffer is full, could not deposit character     */
#define  COMM_TX_EMPTY          4                /* If the Tx buffer is empty.                         */
#define  COMM_RX_TIMEOUT        5                /* If a timeout occurred while waiting for a character*/
#define  COMM_TX_TIMEOUT        6                /* If a timeout occurred while waiting to send a char.*/


#define  COMM_PARITY_NONE       0                /* Defines for setting parity                         */
#define  COMM_PARITY_ODD        1
#define  COMM_PARITY_EVEN       2

#define COMM_TRANSMIT_EN0		DDRD |= BV(4);PORTD |= BV(4)	/*485通信时切换到发送控制*/
#define COMM_RECIEV_EN0			DDRD |= BV(4);PORTD &= ~BV(4) /*485通信时切换到接收控制*/
#define COMM_TRANSMIT_EN1		DDRD |= BV(4);PORTD |= BV(4)	/*485通信时切换到发送控制*/
#define COMM_RECIEV_EN1			DDRD |= BV(4);PORTD &= ~BV(4) /*485通信时切换到接收控制*/
#define COMM_PORT(X)			PORT##X
#define COMM_PORT_DIR(X)		DDR##X
#define COMM_TX_BIT0			0
#define COMM_RX_BIT0			1
#define COMM_TX_BIT1			3
#define COMM_RX_BIT1			2

#define COMM_UBRRH(x)			UBRR##x##H	/* USART1 Baud Rate Register High */
#define COMM_UBRRL(x)			UBRR##x##L	/* USART1 Baud Rate Register Low */
#define COMM_UCSRB(x)			UCSR##x##B	/* USART1 Control and Status Register B */
#define COMM_UCSRA(x)			UCSR##x##A	/* USART1 Control and Status Register A */
#define COMM_UDR(x)				UDR##x		/* USART1 I/O Data Register */
#define COMM_UCSRC(x)			UCSR##x##C	/* USART1 Control and Status Register C */

#define COMM_TXEN(x)			TXEN##x
#define COMM_RXEN(x)			RXEN##x
#define COMM_TXIE(x)			TXCIE##x
#define COMM_RXIE(x)			RXCIE##x
#define COMM_UDRIE(x)			UDRIE##x

#define COMM_INT_EN()			OS_ENABLE_INTERRUPT()
#define COMM_INT_DS()			OS_DISABLE_INTERRUPT()

/*
*********************************************************************************************************
* 接口函数列表 
*********************************************************************************************************
*/
BYTE CommGetChar(BYTE ch, WORD to, BYTE *err);
BYTE CommGetTxChar(BYTE ch, BYTE *err);
void CommInit(void);
BOOL CommIsEmpty(BYTE ch);
BOOL CommIsFull(BYTE ch);
BYTE CommPutChar(BYTE ch, BYTE c, WORD to);
void CommPutRxChar(BYTE ch, BYTE c);

#endif

⌨️ 快捷键说明

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