/*******************************************************************************
 * Copyright (c) 2018-2021 Renesas Electronics Corporation. All rights reserved.
 *
 *     RENESAS ELECTRONICS CONFIDENTIAL AND PROPRIETARY
 *
 * This software is provided as reference/sample code under the license
 * agreement between Renesas Electronics Corporation and licensee (the
 * "License Agreement") and shall be treated as specified in the License
 * Agreement.
 * These instructions, statements, and software are the confidential
 * information of Renesas Electronics Corporation. They must be used and
 * modified solely for the purpose for which it was furnished by Renesas
 * Electronics Corporation. All or part of these instructions, statements and
 * software must not be reproduced nor disclosed to any third party in any
 * form, unless permitted by the License Agreement.
 *
 * THIS SOFTWARE IS PROVIDED BY RENESAS ELEOCTRONICS CORPORATION "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
 * SATISFACTORY QUALITY, ACCURACY, TITLE AND NON-INFRINGEMENT ARE DISCLAIMED.
 * IN NO EVENT SHALL RENESAS ELECTRONICS CORPORATION BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * 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.
 ******************************************************************************/

/*******************************************************************************
 * DESCRIPTION   : Log driver
 ******************************************************************************/
/******************************************************************************
 * @file          log.c
 * - Version      : 0.01
 * @brief         Log driver.
 * .
 *****************************************************************************/
/******************************************************************************
 * History : DD.MM.YYYY Version  Description
 *         : 03.07.2020 0.01     First Release
 *****************************************************************************/

#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <log.h>
#include <scif.h>

#define VSPRINTF_OK (0)

void local_printf(const char *fmt, ...)
{
    va_list ap;
    static char s_buffer[1024];
    int32_t num;
    uint32_t loop;

    /* Convert all arguments to one string */
    va_start(ap, fmt);
    num = vsprintf(s_buffer, fmt, ap);
    va_end(ap);

    /* String output */
    if (VSPRINTF_OK <= num)
    {
        for (loop = 0U; loop < num; loop++)
        {
            (void)console_putc((uint8_t)s_buffer[loop]);
            /* If the outputted character is LF, output CR */
            if (s_buffer[loop] == '\n')
            {
                (void)console_putc((uint8_t)'\r');
            }
        }
    }
    else
    {
        while(1)
        {
            /* loop due to error detection. */
        }
    }
}
/* End of function local_printf(const char *fmt, ...) */
