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

📄 blscidrv.c

📁 本程序为ST公司开发的源代码
💻 C
字号:
/**************************(c) STMicroelectronics *****************************/
/*! \file
 *
 * CVS ID:   $Id: blscidrv.c,v 1.11 2007/09/07 08:07:43 marcucci Exp $
 * Author:   Maurizio Marcucci [MM] - STM
 * Date:     $Date: 2007/09/07 08:07:43 $
 * Revision: $Revision: 1.11 $
 *
 *  Project Scope:  CDM M8
 *
 *  Organisation:   Optical Media Storage B.U.
 *                  AGRATE ITALY Application Lab
 *
 *  Version Control:
 *    \source       sources/debug/scidrv.c
 *    \version      0.1
 *    \author       ST Agrate
 *    \date         00-00-00
 *
 *******************************************************************************
 *  \brief        RS232 Drivers
 *
 *  \par          Change History:
 *
 * - BB041104     Fixed writing to RS232_RxBuffer buffer.
 *
 ***************************************************
 *
 * STM CVS Log:
 *
 * $Log: blscidrv.c,v $ * Revision 1.11  2007/09/07 08:07:43  marcucci * UART Rx configured as input port *
 * Revision 1.10  2007/09/03 14:21:51  marcucci
 * Removed Compiler Warning
 *
 * Revision 1.9  2007/07/02 08:41:37  marcucci
 * I2C Bootloader
 *
 * Revision 1.8  2007/02/15 13:10:21  marcucci
 * Bootloader Optimization
 *
 * Revision 1.7  2006/09/18 09:55:20  belardi
 * Corrected CVS keyword usage
 *
 * Revision 1.6  2006/09/18 09:22:15  belardi
 * Added Log CVS keyword into file header
 *
 *
 ******************************************************************************/

#include "blgendef.h"
#include "blmsgdef.h"
#include "hwreg.h"
#include "blscidef.h"

extern BL_STRUCT * bl;
extern __irq void bl_RS232_Int(void);
extern void configure_gpio(unsigned int port, unsigned int bit, unsigned int function);

/* STATIC DECLARATIONS */

/******************************************************************************/
/* Function:  RS232_Int (interrupt)                                           */
/*                                                                            */
/*! \brief
 *  \param    void
 *  \return   void
 *  \remark
 */
/******************************************************************************/



/******************************************************************************/
/* Function:  RS232_GetStatus                                                 */
/*                                                                            */
/*! \brief    This function returns the status of the RS232 driver
 *  \param    void
 *  \return   RS232 driver status
 *  \remark
 */
/******************************************************************************/
#if 0 // [RB] commented out to reduce ROM space
uint8 bl_RS232_GetStatus(void)
{
    return(bl->RS232_Status);
}
#endif


/******************************************************************************/
/* 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
 */
/******************************************************************************/

uint32 bl_RS232_Send(void)
{

    if(bl->RS232_Status & BL_RS232_TX_READY)   //BitMsk(RS232_Status,RS232_TX_READY))
    {
     /* {{{ Release the receiver */
        //BitSet(RS232_Status,RS232_RX_READY);
        bl->RS232_Status |= BL_RS232_RX_READY;
        //BitClr(RS232_Status,RS232_NEW_MSG);
        bl->RS232_Status &= ~BL_RS232_NEW_MSG;
        //SCICR2.field.rie = 1;
        #if  (BL_UART == 0)
        UART0_IER.field.RxBuffNotEmptyIe = 1;
        #else
        UART1_IER.field.RxBuffNotEmptyIe = 1;
        #endif

     /* }}} */

     /* {{{ Start the transmition */
        //BitClr(RS232_Status,RS232_TX_READY);
        bl->RS232_Status &= ~BL_RS232_TX_READY;
        //SCICR2.field.tcie = 1;
        #if (BL_UART == 0)
        UART0_IER.field.TxEmptyIe = 1;
        #else
        UART1_IER.field.TxEmptyIe = 1;
        #endif

     /* }}} */
        return BL_RS232_TX_STARTED;
    }
    else
    {
        return BL_RS232_TX_NOT_READY;
    }



}



void bl_pcint_init(void)
{
  uint32 bl_isr_addr;

 #if (BL_UART == 1)
  configure_gpio(BL_PORT_B, BL_GPIO_6,BL_GPIO_AF_PP);  // TX UART1  
  configure_gpio(BL_PORT_B, BL_GPIO_7,BL_GPIO_IN);  // RX UART1    
 #else  
  configure_gpio(BL_PORT_B, BL_GPIO_4, BL_GPIO_AF_PP);  // TX UART0
  configure_gpio(BL_PORT_B, BL_GPIO_5, BL_GPIO_IN);  // RX UART0
 #endif
  //bl_deb_rs232_rx_buf_idx = 0;
  //bl_deb_rs232_tx_buf_idx = 0;

  bl->RS232_TxIndex = 0;
  bl->RS232_RxIndex = 0;
  bl->RS232_RxBuffer[0] = 0; // Clear Msg Length
  bl->RS232_TxBuffer[0] = 0;

  bl->RS232_Status = BL_RS232_TX_READY | BL_RS232_RX_READY;



  #if (BL_UART == 0)
  //Suppose AMBA Clock 33.33Mhz
  UART0_CR.field.Run = 0; // UART1 Inactive
  UART0_CR.field.FifoEnable = 0; // FIFO Disabled
  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_CR.field.ParityOdd = 0; // Re-Write the Reset Value
  UART0_CR.field.LoopBack = 0;  // Re-Write the Reset Value
  //UART1_BR = 217; // 9600 at 12Mhz
  //UART0_BR = 440;

  UART0_TXRSTR = 0; //Clear FIFO
  UART0_RXRSTR = 0; //Clear FIFO

  UART0_BR = BL_BR_19200;

  // EIC Init
  bl_isr_addr = (uint32) RS232_Int;
  EIC_SIR_7.all =  (bl_isr_addr << 16) | 0x0F;
  EIC_IVR.all =  bl_isr_addr;
  EIC_IER |= BL_EIC_UART0_MASK;

  UART0_IER.field.RxBuffNotEmptyIe = 1;
  UART0_IER.field.TxEmptyIe = 0; // Re-Write The Resets Value
  UART0_IER.field.TxHalfEmptyIe = 0;
  UART0_IER.field.ParityErrorIe = 0;
  UART0_IER.field.FrameErrorIe = 0;
  UART0_IER.field.OverrunErrorIe = 0;
  UART0_IER.field.TimeoutNotEmptyIe = 0;
  UART0_IER.field.TimeoutIdleIe = 0;
  UART0_IER.field.RxHalfFullIe = 0;

  /* Stop RS232 transmitter and receiver*/
  //SCICR1.all = 0x00;
  //SCICR2.all = 0x00;

  //SCIBRR.field.scp = 0;
  //SCIBRR.field.sct = 0;
  //SCIBRR.field.scr = 0;
  //SCIERPR  = 55;
  //SCIETPR  = 55;

  //SCICR1.field.pce  = 0;
  //SCICR1.field.m    = 0;

  //SCICR2.field.tie  = 0;
  //SCICR2.field.rie  = 0;

  /* Enable transmitter and receiver */
  //SCICR2.field.te = 1;
  //SCICR2.field.re = 1;
  UART0_CR.field.Run = 1; // UART10 Active

  /* Enable interrupt */
  //IT_MASK1.field.RS232_int  = 1;

  //SCICR2.field.rie          = 1;
  //  RS232_Init(RS232_BR_9600, RS232_NO_PARITY);
  #else
  //Suppose AMBA Clock 33.33Mhz
  UART1_CR.field.Run = 0; // UART1 Inactive
  UART1_CR.field.FifoEnable = 0; // FIFO Disabled
  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_CR.field.ParityOdd = 0; // Re-Write the Reset Value
  UART1_CR.field.LoopBack = 0;  // Re-Write the Reset Value
  //UART1_BR = 217; // 9600 at 12Mhz
  UART1_BR = BL_BR_19200;

  UART1_TXRSTR = 0; //Clear FIFO
  UART1_RXRSTR = 0; //Clear FIFO

  // EIC Init
  bl_isr_addr = (uint32) bl_RS232_Int;
  EIC_SIR_8.all =  (bl_isr_addr << 16) | 0x0F;
  EIC_IVR.all =  bl_isr_addr;
  EIC_IER |= BL_EIC_UART1_MASK;

  UART1_IER.field.RxBuffNotEmptyIe = 1;
  UART1_IER.field.TxEmptyIe = 0; // Re-Write The Resets Value
  UART1_IER.field.TxHalfEmptyIe = 0;
  UART1_IER.field.ParityErrorIe =0;
  UART1_IER.field.FrameErrorIe  =0;
  UART1_IER.field.OverrunErrorIe =0;
  UART1_IER.field.TimeoutNotEmptyIe =0;
  UART1_IER.field.TimeoutIdleIe = 0;
  UART1_IER.field.RxHalfFullIe = 0;

  /* Stop RS232 transmitter and receiver*/
  //SCICR1.all = 0x00;
  //SCICR2.all = 0x00;

  //SCIBRR.field.scp = 0;
  //SCIBRR.field.sct = 0;
  //SCIBRR.field.scr = 0;
  //SCIERPR  = 55;
  //SCIETPR  = 55;

  //SCICR1.field.pce  = 0;
  //SCICR1.field.m    = 0;

  //SCICR2.field.tie  = 0;
  //SCICR2.field.rie  = 0;

  //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 */
  //SCICR2.field.te = 1;
  //SCICR2.field.re = 1;
  UART1_CR.field.Run = 1; // UART10 Active

  /* Enable interrupt */
  //IT_MASK1.field.RS232_int  = 1;

  //SCICR2.field.rie          = 1;
  //  RS232_Init(RS232_BR_9600, RS232_NO_PARITY);
  #endif


}

/*** (c) 2003  STMicroelectronics **************************** END OF FILE ***/

⌨️ 快捷键说明

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