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

📄 comm_pc.bak

📁 一个中断驱动的具有缓冲区的串口源码(C)
💻 BAK
📖 第 1 页 / 共 2 页
字号:
*                           COMM1
*                           COMM2
* Note(s)     : This function assumes that the 80x86 is running in REAL mode.
*********************************************************************************************************
*/

void  CommRclIntVect (INT8U ch)
{
    CommRxIntDis(ch);
    CommRxFlush(ch);
    CommTxIntDis(ch);
    switch (ch) {
	case COMM1:
	     PC_VectSet(0x0C, Comm1ISROld);
	     break;

	case COMM2:
	     PC_VectSet(0x0B, Comm1ISROld);
	     break;
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                            FLUSH RX PORT
*
* Description : This function is called to flush any input characters still in the receiver.  This
*               function is useful when you replace the NS16450 with the more powerful NS16550.
* Arguments   : 'ch'    is the COMM port channel number and can either be:
*                           COMM1
*                           COMM2
*********************************************************************************************************
*/

void  CommRxFlush (INT8U ch)
{
    INT8U  ctr;
    INT16U base;


    switch (ch) {
	case COMM1:
	     base = COMM1_BASE;
	     break;

	case COMM2:
	     base = COMM2_BASE;
	     break;
    }
    ctr = COMM_MAX_RX;                                /* Flush Rx input                                */
    OS_ENTER_CRITICAL();
    while (ctr-- > 0) {
	inp(base + COMM_UART_RBR);
    }
    OS_EXIT_CRITICAL();
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                         DISABLE RX INTERRUPTS
*
* Description : This function disables the Rx interrupt.
* Arguments   : 'ch'    is the COMM port channel number and can either be:
*                           COMM1
*                           COMM2
*********************************************************************************************************
*/

void  CommRxIntDis (INT8U ch)
{
    INT8U stat;


    switch (ch) {
	case COMM1:
	     OS_ENTER_CRITICAL();
							   /* Disable Rx interrupts                    */
	     stat = (INT8U)inp(COMM1_BASE + COMM_UART_IER) & ~BIT0;
	     outp(COMM1_BASE + COMM_UART_IER, stat);
	     if (stat == 0x00) {                           /* Both Tx & Rx interrupts are disabled ?   */
							   /* Yes, disable IRQ4 on the PC              */
		 outp(PIC_MSK_REG_PORT, (INT8U)inp(PIC_MSK_REG_PORT) | BIT4);
	     }
	     OS_EXIT_CRITICAL();
	     break;

	case COMM2:
	     OS_ENTER_CRITICAL();
							   /* Disable Rx interrupts                    */
	     stat = (INT8U)inp(COMM2_BASE + COMM_UART_IIR) & ~BIT0;
	     outp(COMM2_BASE + COMM_UART_IER, stat);
	     if (stat == 0x00) {                           /* Both Tx & Rx interrupts are disabled ?   */
							   /* Yes, disable IRQ3 on the PC              */
		 outp(PIC_MSK_REG_PORT, (INT8U)inp(PIC_MSK_REG_PORT) | BIT3);
	     }
	     OS_EXIT_CRITICAL();
	     break;
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                          ENABLE RX INTERRUPTS
*
* Description : This function enables the Rx interrupt.
* Arguments   : 'ch'    is the COMM port channel number and can either be:
*                           COMM1
*                           COMM2
*********************************************************************************************************
*/

void  CommRxIntEn (INT8U ch)
{
    INT8U stat;


    switch (ch) {
	case COMM1:
	     OS_ENTER_CRITICAL();
							   /* Enable Rx interrupts                     */
	     stat = (INT8U)inp(COMM1_BASE + COMM_UART_IER) | BIT0;
	     outp(COMM1_BASE + COMM_UART_IER, stat);
							   /* Enable IRQ4 on the PC                    */
	     outp(PIC_MSK_REG_PORT, (INT8U)inp(PIC_MSK_REG_PORT) & ~BIT4);
	     OS_EXIT_CRITICAL();
	     break;

	case COMM2:
	     OS_ENTER_CRITICAL();
							   /* Enable Rx interrupts                     */
	     stat = (INT8U)inp(COMM2_BASE + COMM_UART_IER) | BIT0;
	     outp(COMM2_BASE + COMM_UART_IER, stat);
							   /* Enable IRQ3 on the PC                    */
	     outp(PIC_MSK_REG_PORT, (INT8U)inp(PIC_MSK_REG_PORT) & ~BIT3);
	     OS_EXIT_CRITICAL();
	     break;
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                          SET INTERRUPT VECTOR
*
* Description : This function installs the interrupt vector for the desired communications channel.
* Arguments   : 'ch'    is the COMM port channel number and can either be:
*                           COMM1
*                           COMM2
* Note(s)     : This function assumes that the 80x86 is running in REAL mode.
*********************************************************************************************************
*/

void  CommSetIntVect (INT8U ch)
{
    switch (ch) {
	case COMM1:
	     Comm1ISROld = PC_VectGet(0x0C);
	     PC_VectSet(0x0C, Comm1ISR);
	     break;

	case COMM2:
	     Comm2ISROld =PC_VectGet(0x0B);
	     PC_VectSet(0x0B, Comm2ISR);
	     break;
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                         DISABLE TX INTERRUPTS
*
* Description : This function disables the character transmission.
* Arguments   : 'ch'    is the COMM port channel number and can either be:
*                           COMM1
*                           COMM2
*********************************************************************************************************
*/

void  CommTxIntDis (INT8U ch)
{
    INT8U  stat;
    INT8U  cmd;


    switch (ch) {
	case COMM1:
	     OS_ENTER_CRITICAL();
							   /* Disable Tx interrupts                    */
	     stat = (INT8U)inp(COMM1_BASE + COMM_UART_IER) & ~BIT1;
	     outp(COMM1_BASE + COMM_UART_IER, stat);
	     if (stat == 0x00) {                           /* Both Tx & Rx interrupts are disabled ?   */
		 cmd = (INT8U)inp(PIC_MSK_REG_PORT) | BIT4;
		 outp(PIC_MSK_REG_PORT, cmd);              /* Yes, disable IRQ4 on the PC              */
	     }
	     OS_EXIT_CRITICAL();
	     break;

	case COMM2:
	     OS_ENTER_CRITICAL();
							   /* Disable Tx interrupts                    */
	     stat = (INT8U)inp(COMM2_BASE + COMM_UART_IER) & ~BIT1;
	     outp(COMM2_BASE + COMM_UART_IER, stat);
	     if (stat == 0x00) {                           /* Both Tx & Rx interrupts are disabled ?   */
		 cmd = (INT8U)inp(PIC_MSK_REG_PORT) | BIT3;
		 outp(PIC_MSK_REG_PORT, cmd);              /* Yes, disable IRQ3 on the PC              */
	     }
	     OS_EXIT_CRITICAL();
	     break;
    }
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                          ENABLE TX INTERRUPTS
*
* Description : This function enables transmission of characters.  Transmission of characters is
*               interrupt driven.  If you are using a multi-drop driver, the code must enable the driver
*               for transmission.
* Arguments   : 'ch'    is the COMM port channel number and can either be:
*                           COMM1
*                           COMM2
*********************************************************************************************************
*/

void  CommTxIntEn (INT8U ch)
{
    INT8U  stat;
    INT8U  cmd;


    switch (ch) {
	case COMM1:
	     OS_ENTER_CRITICAL();
	     stat = (INT8U)inp(COMM1_BASE + COMM_UART_IER) | BIT1;     /* Enable Tx interrupts                     */
	     outp(COMM1_BASE + COMM_UART_IER, stat);
	     cmd  = (INT8U)inp(PIC_MSK_REG_PORT) & ~BIT4;
	     outp(PIC_MSK_REG_PORT, cmd);                              /* Enable IRQ4 on the PC                    */
	     OS_EXIT_CRITICAL();
	     break;

	case COMM2:
	     OS_ENTER_CRITICAL();
	     stat = (INT8U)inp(COMM2_BASE + COMM_UART_IER) | BIT1;     /* Enable Tx interrupts                     */
	     outp(COMM2_BASE + COMM_UART_IER, stat);
	     cmd  = (INT8U)inp(PIC_MSK_REG_PORT) & ~BIT3;
	     outp(PIC_MSK_REG_PORT, cmd);                              /* Enable IRQ3 on the PC                    */
	     OS_EXIT_CRITICAL();
	     break;
    }
}

⌨️ 快捷键说明

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