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

📄 scidrv.c

📁 本程序为ST公司开发的源代码
💻 C
字号:
/************************************************** * * scidrv.c * * CVS ID:   $Id: scidrv.c,v 1.18 2007/08/14 15:28:41 dellorto Exp $ * Author:   Raffaele Belardi [RB] - STM * Date:     $Date: 2007/08/14 15:28:41 $ * Revision: $Revision: 1.18 $ *  * Description: *  *   Serial interface driver for debugging interface * *************************************************** *  * COPYRIGHT (C) ST Microelectronics  2005 *            All Rights Reserved * *************************************************** * * STM CVS Log: * * $Log: scidrv.c,v $ * Revision 1.18  2007/08/14 15:28:41  dellorto * multiple mechanisms * * Revision 1.17  2006/09/18 09:55:24  belardi * Corrected CVS keyword usage * * Revision 1.16  2006/09/18 09:25:05  belardi * Added Log CVS keyword into file header * * ***************************************************/#include "gendef.h"#if (DEBUG_INCLUDE_PCDEB == 1)#include "osal.h"#include "msgdef.h"#include "hwreg.h"#include "scidef.h"#include "dbgram.h"#include "dbgdef.h"#include "dbgext.h"#define PCDEB_BAUDRATE	(19200)#define UARTBR(br) (S_APB_CLK/(16*(br)))/* STATIC DECLARATIONS *//******************************************************************************//* Function:  RS232_Int_irq (interrupt)                                       *//*                                                                            *//*! \brief *  \param    void *  \return   void *  \remark *//******************************************************************************/#if (DEBUG_INCLUDE_PCDEB == 1)#define UART1#else#if (0 != HAVE_USB)#define UART0#else#define UART1#endif#endif#include "pcdeb.h"#include "lld_eic.h"void RS232_Int_irq(void){   UART_SR_UNION uart_sr;   #ifdef UART0   uart_sr = UART0_SR;   #else   uart_sr = UART1_SR;   #endif       if (uart_sr.field.RxBuffNotEmpty  &&  (RS232_Status & RS232_RX_READY))    {        if (RS232_RxIndex < sizeof(RS232_RxBuffer))        {          #ifdef UART0          RS232_RxBuffer[RS232_RxIndex] = UART0_RXBUF; /* Store the receive data */          #else          RS232_RxBuffer[RS232_RxIndex] = UART1_RXBUF; /* Store the receive data */          #endif                    RS232_RxBuffer[RS232_RxIndex] &= 0xFF;        }        RS232_RxIndex++;     /* {{{  Check if the frame all the frame have been received */        if(RS232_RxIndex > RS232_RxBuffer[0])        {            RS232_Status &= ~RS232_RX_READY;            RS232_Status |= RS232_NEW_MSG;            #ifdef UART0            UART0_IER.field.RxBuffNotEmptyIe = 0;            #else            UART1_IER.field.RxBuffNotEmptyIe = 0;            #endif            RS232_RxIndex = 0;        }    }    #ifdef UART0        if ((uart_sr.field.TxEmpty) && (UART0_IER.field.TxEmptyIe))  //(Interrupt, RS232_TRANSMIT_IT))    #else    if ((uart_sr.field.TxEmpty) && (UART1_IER.field.TxEmptyIe))  //(Interrupt, RS232_TRANSMIT_IT))    #endif    {        #ifdef UART0        UART0_TXBUF = RS232_TxBuffer[RS232_TxIndex++];        #else        UART1_TXBUF = RS232_TxBuffer[RS232_TxIndex++];        #endif                if (RS232_TxIndex > RS232_TxBuffer[0])        {            RS232_Status |= RS232_TX_READY;            RS232_TxIndex = 0;            #ifdef UART0            UART0_IER.field.TxEmptyIe = 0;            #else            UART1_IER.field.TxEmptyIe = 0;            #endif        }    }     }/* PUBLIC FUNCTIONS *//******************************************************************************//* Function:  RS232_GetStatus                                                 *//*                                                                            *//*! \brief    This function returns the status of the RS232 driver *  \param    void *  \return   RS232 driver status *  \remark *//******************************************************************************/uint8 RS232_GetStatus(void){    return(RS232_Status);}/******************************************************************************//* Function:  RS232_Send                                                      *//*                                                                            *//*! \brief    This function starts a frame transmition if the driver is *            ready to send. The receiver is released. The user should not *            modify the transmit buffer until the end of the transmition. *  \param    unsigned char, pointer to message buffer *  \return   RS232_TX_STARTED / RS232_TX_NOT_READY *  \remark *//******************************************************************************/uint8 RS232_Send(void){    if(RS232_Status & RS232_TX_READY)   //BitMsk(RS232_Status,RS232_TX_READY))    {        RS232_Status |= RS232_RX_READY;        RS232_Status &= ~RS232_NEW_MSG;        #ifdef UART0        UART0_IER.field.RxBuffNotEmptyIe = 1;        #else        UART1_IER.field.RxBuffNotEmptyIe = 1;        #endif                RS232_Status &= ~RS232_TX_READY;        #ifdef UART0        UART0_IER.field.TxEmptyIe = 1;        #else        UART1_IER.field.TxEmptyIe = 1;        #endif                return RS232_TX_STARTED;    }    else    {        return RS232_TX_NOT_READY;    }}void pcint_init(void){  micro_command_result = OK;  debug_error_reason = NO_ERROR_REASON;  current_micro_command = MC_IDLE;  buffer_mode = BUFFER_MODE_ESP;  #ifdef UART0  UART0_CR.field.Run = 0; // UART1 Inactive  //UART0_CR.field.FifoEnable = 0; // FIFO Disabled  UART0_CR.field.FifoEnable = 1; // FIFO Enabled [RB]  UART0_RXRSTR = 1; // reset RX FIFO to clean from garbage [RB]  UART0_CR.field.RxEnable = 1; // Receiver Enabled  UART0_CR.field.Mode = 1; // 8 bit No Parity  UART0_CR.field.StopBits = 1; // 1 Stop Bit  UART0_BR = UARTBR(PCDEB_BAUDRATE);  OSAL_isr_install(OSAL_ISR_UART0, 0x0f, RS232_Int_irq);  UART0_IER.field.RxBuffNotEmptyIe = 1; //     RS232_TxIndex = 0;  RS232_RxIndex = 0;  RS232_RxBuffer[0] = 0; // Clear Msg Length  RS232_TxBuffer[0] = 0;    RS232_Status = RS232_TX_READY | RS232_RX_READY;  /* Enable transmitter and receiver */  UART0_CR.field.Run = 1; // UART0 Active    #else  UART1_CR.field.Run = 0; // UART1 Inactive  //UART1_CR.field.FifoEnable = 0; // FIFO Disabled [RB]  UART1_CR.field.FifoEnable = 1; // FIFO Enabled [RB]  UART1_RXRSTR = 1; // reset RX FIFO to clean from garbage [RB]  UART1_CR.field.RxEnable = 1; // Receiver Enabled  UART1_CR.field.Mode = 1; // 8 bit No Parity  UART1_CR.field.StopBits = 1; // 1 Stop Bit  UART1_BR = UARTBR(PCDEB_BAUDRATE);  OSAL_isr_install(OSAL_ISR_UART1, 0x0f, RS232_Int_irq);  UART1_IER.field.RxBuffNotEmptyIe = 1;    RS232_TxIndex = 0;  RS232_RxIndex = 0;  RS232_RxBuffer[0] = 0; // Clear Msg Length  RS232_TxBuffer[0] = 0;    RS232_Status = RS232_TX_READY | RS232_RX_READY;  /* Enable transmitter and receiver */  UART1_CR.field.Run = 1; // UART10 Active    #endif}#endif // (DEBUG_INCLUDE_PCDEB==1)/*** (c) 2003  STMicroelectronics **************************** END OF FILE ***/

⌨️ 快捷键说明

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