PDL for FM0+  Version1.0
Peripheral Driverl Library for FM0+
C:/pdl_v10/library/utility/printf/uart_printf.c
Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
00003 *
00004 * This software is owned and published by:
00005 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA  94088-3453 ("Spansion").
00006 *
00007 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
00008 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
00009 *
00010 * This software contains source code for use with Spansion
00011 * components. This software is licensed by Spansion to be adapted only
00012 * for use in systems utilizing Spansion components. Spansion shall not be
00013 * responsible for misuse or illegal use of this software for devices not
00014 * supported herein.  Spansion is providing this software "AS IS" and will
00015 * not be responsible for issues arising from incorrect user implementation
00016 * of the software.
00017 *
00018 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
00019 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
00020 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
00021 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
00022 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
00023 * WARRANTY OF NONINFRINGEMENT.
00024 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
00025 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
00026 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
00027 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
00028 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
00029 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
00030 * SAVINGS OR PROFITS,
00031 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00032 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
00033 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
00034 * FROM, THE SOFTWARE.
00035 *
00036 * This software may be replicated in part or whole for the licensed use,
00037 * with the restriction that this Disclaimer and Copyright notice must be
00038 * included with each copy of this software, whether used in part or whole,
00039 * at all times.
00040 */
00041 /******************************************************************************/
00054 #include "uart_printf.h"
00055 #include "mfs\mfs.h"
00056 #include "gpio\gpio.h"   
00057 
00058 #if (PDL_UTILITY_ENABLE_UART_PRINTF == PDL_ON)
00059 /*****************************************************************************/
00060 /* Local pre-processor symbols/macros ('#define')                            */
00061 /*****************************************************************************/
00062 #define InitPrintfIo()     {SetPinFunc_SIN0_0();SetPinFunc_SOT0_0();}   
00063 /*****************************************************************************/
00064 /* Global variable definitions (declared in header file with 'extern')       */
00065 /*****************************************************************************/
00066 volatile stc_mfsn_uart_t* UartCh = &UART0;
00067 /*****************************************************************************/
00068 /* Local type definitions ('typedef')                                        */
00069 /*****************************************************************************/
00070 /*****************************************************************************/
00071 /* Local function prototypes ('static')                                      */
00072 /*****************************************************************************/
00073 /*****************************************************************************/
00074 /* Local variable definitions ('static')                                     */
00075 /*****************************************************************************/
00080 void Uart_Printf_Init(void)
00081 {
00082     stc_mfs_uart_config_t stcUartConfig;
00083 
00084     /* Initialize UART function I/O */
00085     InitPrintfIo();
00086 
00087     /* Initialize UART TX channel  */
00088     stcUartConfig.enMode = UartNormal;
00089     stcUartConfig.u32BautRate = 115200;
00090     stcUartConfig.enDataLength = UartEightBits;
00091     stcUartConfig.enParity = UartParityNone;
00092     stcUartConfig.enStopBit = UartOneStopBit;
00093     stcUartConfig.enBitDirection = UartDataLsbFirst;
00094     stcUartConfig.bInvertData = FALSE;
00095     stcUartConfig.bHwFlow = FALSE;
00096     stcUartConfig.bEnableFifo = FALSE;
00097 
00098     Mfs_Uart_Init(UartCh, &stcUartConfig);
00099 
00100     /* Enable TX function of UART0   */
00101     Mfs_Uart_EnableFunc(UartCh, UartTx);
00102 }
00103 
00108 #if defined ( __ICCARM__ )
00109 int putchar(int ch)
00110 #else
00111 int fputc(int ch, FILE *f)
00112 #endif
00113 {
00114     if(((uint8_t)ch) == '\n')
00115     {
00116         while (TRUE != Mfs_Uart_GetStatus(UartCh, UartTxEmpty)); /* wait until TX buffer empty */
00117         Mfs_Uart_SendData(UartCh, '\r');
00118     }
00119 
00120     while (TRUE != Mfs_Uart_GetStatus(UartCh, UartTxEmpty)); /* wait until TX buffer empty */
00121     Mfs_Uart_SendData(UartCh, ch);
00122 
00123     return ch;
00124 }
00125 
00126 #endif
00127 
00128 /******************************************************************************/
00129 /* EOF (not truncated)                                                        */
00130 /******************************************************************************/