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

📄 probe_rs232c.c

📁 ucos-ii 的完整代码
💻 C
字号:
/*
*********************************************************************************************************
*                                      uC/Probe Communication
*
*                           (c) Copyright 2007; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*               Knowledge of the source code may NOT be used to develop a similar product.
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                              uC/Probe
*
*                                      Communication: RS-232
*                                  Port for the Freescale MC9S08
*
* Filename      : probe_rs232c.c
* Version       : V1.00
* Programmer(s) : Eric Shufro
*********************************************************************************************************
*/

#include  <includes.h>
#include  <probe_rs232.h>
#include  <probe_com_cfg.h>

/*
*********************************************************************************************************
*                                              CONSTANTS
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                        FUNCTION PROTOTYPES
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                       Initialize COM port for uC/Probe RS-232 Communication Module
*
* Description: Initialize the UART for uC/Probe communication.
*
* Argument(s): baud    intended baud rate of the RS-232.
*
* Returns    : None
*
* Note(s)    : 1) The baud rate is computed as the (bus clock) / (2 * 16 * baud), where
*                 the bus clock = cpu clock / 2.
*********************************************************************************************************
*/

void  ProbeRS232_InitTarget (CPU_INT32U baud)
{
    CPU_INT32U  bus_freq;
    CPU_INT32U  div;
    
    
    bus_freq  =   BSP_CPU_ClkFreq();                                    /* Obtain the CPU clock frequency                           */
    bus_freq /=   2;                                                    /* Convert the CPU clock frequency to the bus clock freq    */
    div       =   bus_freq / (16 * baud);                               /* Compute the baud rate divider                            */
  
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)                           
    SCGC1    |=   SCGC1_SCI1_MASK;                                      /* Enable the SCI1 module clock                             */
    SCI1C2    =   0x00;                                                 /* disable the receiver, transmitter and interrupts         */
    SCI1C1    =   0x00;                                                 /* 8 data bits, no parity, 1 stop bit                       */
    SCI1BDH   =   div >> 8;	                                            /* Calculated Baudrate                                      */
    SCI1BDL   =   div & 0xFF;
   (void)SCI1S1;                                                        /* Clear pending interrupt flags                            */                                                  
   (void)SCI1D;
    SCI1C2    =   SCI1C2_TE_MASK | SCI1C2_RE_MASK;                      /* Enable the receiver and transmiter                       */                  
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
    SCGC1    |=   SCGC1_SCI2_MASK;                                      /* Enable the SCI2 module clock                             */
    SCI2C2    =   0x00;                                                 /* disable the receiver, transmitter and interrupts         */
    SCI2C1    =   0x00;                                                 /* 8 data bits, no parity, 1 stop bit                       */
    SCI2BDH   =   div >> 8;	                                            /* Calculated Baudrate                                      */
    SCI2BDL   =   div & 0xFF;
   (void)SCI2S1;                                                        /* Clear pending interrupt flags                            */                                                  
   (void)SCI2D;
    SCI2C2    =   SCI2C2_TE_MASK | SCI2C2_RE_MASK;                      /* Enable the receiver and transmiter                       */  
#endif   
}

/*
*********************************************************************************************************
*                                 Rx and Tx Communication Handler
*
* Description: This function handles both Rx and Tx interrupts.
*
* Argument(s): None
*
* Returns    : None
*
* Note(s)    : 1) This function has been intentionally left empty since individual handlers
*                 have been configured for each SCI event.
*********************************************************************************************************
*/

void  ProbeRS232_RxTxISRHandler (void)
{
}

/*
*********************************************************************************************************
*                                 Rx Communication Handler
*
* Description: This functions handle Rx interrupts
*
* Argument(s): None
*
* Returns    : None
*
* Note(s)    : 1) The receive and transmit interrupts are clearned by reading the status register
*                 and then either reading from or writing to the SCI data register.
*              2) The vector table should use OSView_RxTxISR (See os_view_nba.s) 
*                 for both Rx and Tx SCI interrupts. 
*              3) When changing the value of OS_VIEW_COMM_SEL from within app_cfg.h,
*                 the interrupt vector table within vectors.c must be updated as well.
*********************************************************************************************************
*/

void  ProbeRS232_RxISRHandler (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
   (void)SCI1S1;                                                        /* Read the status register (part of interrupt clearing)    */
    ProbeRS232_RxHandler(SCI1D);                                        /* Call the generic Rx handler with the received data       */
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
   (void)SCI2S1;                                                        /* Read the status register (part of interrupt clearing)    */
    ProbeRS232_RxHandler(SCI2D);                                        /* Call the generic Rx handler with the received data       */
#endif
}

/*
*********************************************************************************************************
*                                 Tx Communication Handler
*
* Description: This functions handle Tx interrupts
*
* Argument(s): None
*
* Returns    : None
*
* Note(s)    : 1) The receive and transmit interrupts are clearned by reading the status register
*                 and then either reading from or writing to the SCI data register.
*              2) The vector table should use OSView_RxTxISR (See os_view_nba.s) 
*                 for both Rx and Tx SCI interrupts. 
*              3) When changing the value of OS_VIEW_COMM_SEL from within app_cfg.h,
*                 the interrupt vector table within vectors.c must be updated as well.
*********************************************************************************************************
*/

void  ProbeRS232_TxISRHandler (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
   (void)SCI1S1;                                                        /* Read the status register (part of interrupt clearing)    */
    ProbeRS232_TxHandler();
#endif    

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
   (void)SCI2S1;                                                        /* Read the status register (part of interrupt clearing)    */
    ProbeRS232_TxHandler();
#endif    
}

/*
*********************************************************************************************************
*                                 SCI Error Handler
*
* Description: This functions handles SCI error interrupts
*
* Argument(s): None
*
* Returns    : None
*
* Note(s)    : 1) The receive and transmit interrupts are clearned by reading the status register
*                 and then either reading from or writing to the SCI data register.
*              2) The vector table should use OSView_RxTxISR (See os_view_nba.s) 
*                 for both Rx and Tx SCI interrupts. 
*              3) When changing the value of OS_VIEW_COMM_SEL from within app_cfg.h,
*                 the interrupt vector table within vectors.c must be updated as well.
*********************************************************************************************************
*/

void  ProbeRS232_ErrISRHandler (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
   (void)SCI1S1;                                                        /* Read the status register (part of interrupt clearing)    */
   (void)SCI1D;                                                         /* Read the SCI data register (part of interrupt clearing)  */
#endif    

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
   (void)SCI2S1;                                                        /* Read the status register (part of interrupt clearing)    */
   (void)SCI2D;                                                         /* Read the SCI data register (part of interrupt clearing)  */
#endif    
}

/*
*********************************************************************************************************
*                                      Transmit One Byte
*
* Description: This function transmits one byte.
*
* Argument(s): c   byte to transmit.
*
* Returns    : None
*********************************************************************************************************
*/

void  ProbeRS232_Tx1 (CPU_INT08U c)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    SCI1D   =   c; 
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
    SCI2D   =   c; 
#endif
}

/*
*********************************************************************************************************
*                                      Enable/disable Tx Interrupts
*
* Description: Enables or disables Tx interrupts.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

void  ProbeRS232_TxIntDis (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    SCI1C2  &= ~SCI1C2_TCIE_MASK;                                       /* Disable Tx interrupts				                    */
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
    SCI2C2  &= ~SCI2C2_TCIE_MASK;                                       /* Disable Tx interrupts				                    */
#endif
}

void  ProbeRS232_TxIntEn (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    SCI1C2  |=  SCI1C2_TCIE_MASK;                                       /* Enable Tx interrupts			                            */
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
    SCI2C2  |=  SCI2C2_TCIE_MASK;                                       /* Enable Tx interrupts			                            */
#endif
}


/*
*********************************************************************************************************
*                                      Enable/disable Rx Interrupts
*
* Description: Enables or disables Rx interrupts.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

void  ProbeRS232_RxIntDis (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    SCI1C2 &= ~SCI1C2_RIE_MASK;                                         /* Disable Rx interrupts				                    */
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
    SCI2C2 &= ~SCI2C2_RIE_MASK;                                         /* Disable Rx interrupts				                    */
#endif
}

void  ProbeRS232_RxIntEn (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    SCI1C2 |=  SCI1C2_RIE_MASK;                                         /* Enable Rx interrupts				                        */
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
    SCI2C2 |=  SCI2C2_RIE_MASK;                                         /* Enable Rx interrupts				                        */
#endif
}

⌨️ 快捷键说明

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