/* File : barebones/ee_printf.c
	This file contains an implementation of ee_printf that only requires a method to output a char to a UART without pulling in library code.

This code is based on a file that contains the following:
 Copyright (C) 2002 Michael Ringgaard. All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 
 1. Redistributions of source code must retain the above copyright 
    notice, this list of conditions and the following disclaimer.  
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.  
 3. Neither the name of the project nor the names of its contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission. 
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 SUCH DAMAGE.

*/
/*
 * Copyright (c) 2017 - 2018 , NXP
 * All rights reserved.
 */
#include <coremark.h>
#include <stdarg.h>

// LPC55xx Chip peripherals & Boards includes
#include "fsl_common.h"
#include "fsl_usart.h"
volatile uint8_t PrintBuf[512];
int ee_printf_template(const char *fmt, ...)
{
    va_list arg;
    uint32_t logLength = 0U;
    //uint8_t *PrintBuf = NULL;
    if(CLOCK_GetFlexCommInputClock(0) != 0)
    {
        //PrintBuf = malloc(512);                                               /* malloc buffer */
        //if(PrintBuf == NULL) {
        //    NVIC_SystemReset();                                               /* Can not malloc enough buffer, should be system issue, reset~ */
        //}
        va_start(arg, fmt);
        logLength = vsprintf((char *)PrintBuf, fmt, arg);            /* format print log first */
        va_end(arg);
        USART_WriteBlocking(USART0, PrintBuf, logLength);                /* Send Log data to BLE uart */
        //free(PrintBuf);                                                       /* free buffer */
    }
    return 0;
}


