This commit is contained in:
2025-12-24 17:21:08 +09:00
parent a96323de19
commit 96dc62d8dc
2302 changed files with 455822 additions and 0 deletions

View File

@@ -0,0 +1,264 @@
/*******************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only
* intended for use with Renesas products. No other uses are authorized. This
* software is owned by Renesas Electronics Corporation and is protected under
* all applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software
* and to discontinue the availability of this software. By using this software,
* you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
* Copyright 2018-2023 Renesas Electronics Corporation All rights reserved.
*******************************************************************************/
/*******************************************************************************
* DESCRIPTION : log
******************************************************************************/
/******************************************************************************
* @file log.c
* - Version : 0.04
* @brief Access protection setting driver.
* .
*****************************************************************************/
/******************************************************************************
* History : DD.MM.YYYY Version Description
* : 03.07.2020 0.01 First Release
* : 16.06.2022 0.02 Change log output
* : 31.10.2022 0.03 License notation change.
* : 04.04.2023 0.04 Removed sprintf.
*****************************************************************************/
#include "stdarg.h"
#include "stdint.h"
#include "math.h"
#include "log.h"
#include "scif.h"
#define NULL_CHAR '\0'
/***********************************************************
* log_printf
***********************************************************/
#define DOUBLE_PRINT_RES (0.001)
static uint32_t double_print(double num)
{
uint8_t num_buf[10];
uint32_t count = 0U;
uint32_t i = 0U;
uint32_t rem;
double unum;
double res = 1/DOUBLE_PRINT_RES;
if (num < 0) {
(void)console_putc((uint8_t)'-');
count = 1U;
unum = -num;
} else {
unum = num;
}
unum /= (DOUBLE_PRINT_RES);
while (1) {
if (i == 0) {
rem = fmin(9, round( fmod(unum, 10.0) ) ); //last digit is rounded to correctly handle hidden digits. (last digit is processed first)
} else {
rem = fmod(unum, 10.0);
}
num_buf[i] = (uint8_t)('0' + rem);
i++;
unum = unum / 10.0;
res = res / 10.0;
if ( (res <= 5.0) && (res > 0.5) ) {
num_buf[i] = (uint8_t)('.');
i++;
}
if ( (unum < 1.0) && (res < 1.0) ) {
break;
}
}
while (i != 0U) {
i--;
(void)console_putc(num_buf[i]);
count++;
};
return count;
}
static uint32_t uint32_print(uint32_t num)
{
uint8_t num_buf[10];
uint32_t count = 0U;
uint32_t i = 0U;
uint32_t rem;
uint32_t unum = num;
while (1) {
rem = unum % 10U;
num_buf[i] = (uint8_t)('0' + rem);
i++;
unum = unum / 10U;
if (unum < 1U) {
break;
}
}
while (i != 0U) {
i--;
(void)console_putc(num_buf[i]);
count++;
};
return count;
}
static uint32_t int32_print(int32_t num)
{
uint32_t unum;
uint32_t count = 0U;
if (num < 0) {
(void)console_putc((uint8_t)'-');
count = 1U;
unum = (uint32_t)-num;
} else {
unum = (uint32_t)num;
}
count += uint32_print(unum);
return count;
}
static uint32_t uint32_hex_print(uint32_t num)
{
uint32_t i;
uint32_t count = 0U;
uint8_t c;
for (i = 0U; i < 8U; i++) {
/* 0-F */
c = (uint8_t)((num >> ((7U - i) * 4U)) & 0x0FU);
if (c >= 0x0AU) {
/* A-F */
c += (uint8_t)('a' - 0x0AU);
} else {
/* 0-9 */
c += (uint8_t)'0';
}
(void)console_putc(c);
count++;
}
return count;
}
static uint32_t uint8_hex_print(uint8_t num)
{
uint32_t i;
uint32_t count = 0U;
uint8_t c;
for (i = 0U; i < 2U; i++) {
/* 0-F */
c = ((num >> ((1U - i) * 4U)) & 0x0FU);
if (c >= 0x0AU) {
/* A-F */
c += (uint8_t)('a' - 0x0AU);
} else {
/* 0-9 */
c += (uint8_t)'0';
}
(void)console_putc(c);
count++;
}
return count;
}
static uint32_t str_print(const char *str)
{
uint32_t count = 0;
while (*str != NULL_CHAR) {
(void)console_putc((uint8_t)*str);
str++;
count++;
}
return count;
}
void log_printf(const char *fmt, ...)
{
va_list args;
double dnum;
int32_t num;
uint32_t unum;
char *str;
uint32_t count = 0U;
va_start(args, fmt);
while (*fmt != NULL_CHAR) {
if (*fmt == '%') {
fmt++;
switch (*fmt) {
case 'i':
/* No break */
case 'd':
num = va_arg(args, int32_t);
count += int32_print(num);
break;
case 's':
str = va_arg(args, char *);
count += str_print(str);
break;
case 'x':
unum = va_arg(args, uint32_t);
count += uint32_hex_print(unum);
break;
case 'b':
unum = (uint8_t)va_arg(args, uint32_t);
count += uint8_hex_print(unum);
break;
case 'u':
unum = va_arg(args, uint32_t);
count += uint32_print(unum);
break;
case 'f':
dnum = va_arg(args, double);
count += double_print(dnum);
break;
default:
break;
}
} else {
(void)console_putc((uint8_t)*fmt);
count++;
}
fmt++;
}
va_end(args);
}

View File

@@ -0,0 +1,172 @@
/*******************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only
* intended for use with Renesas products. No other uses are authorized. This
* software is owned by Renesas Electronics Corporation and is protected under
* all applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software
* and to discontinue the availability of this software. By using this software,
* you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
* Copyright 2018-2022 Renesas Electronics Corporation All rights reserved.
*******************************************************************************/
/*******************************************************************************
* DESCRIPTION : SCIF driver
******************************************************************************/
/******************************************************************************
* @file scif.c
* - Version : 0.07
* @brief 1. Initial setting of SCIF.
* 2. Initial setting of HSCIF.
* 3. Log output function.
* .
*****************************************************************************/
/******************************************************************************
* History : DD.MM.YYYY Version Description
* : 28.07.2021 0.01 First Release
* : 03.09.2021 0.02 Modify the timing of MODEMR judgement.
* : 15.10.2021 0.03 Modify register access to read modify write.
* : 03.12.2021 0.04 Fix incorrect configuration process.
* : 06.01.2022 0.05 Static analysis support
* : 16.06.2022 0.06 Change line feed code
* : 31.10.2022 0.07 License notation change.
*****************************************************************************/
#include <stdint.h>
#include <types.h>
#include <scif.h>
#include <mem_io.h>
#include <rst_register.h>
/* Define */
#define SCIF_SCFSR_TEND (uint16_t)((uint16_t)1U << 6U)
#define SCIF_SCFSR_TDFE (uint16_t)((uint16_t)1U << 5U)
#define TRANS_END_CHECK (uint16_t)(SCIF_SCFSR_TEND | SCIF_SCFSR_TDFE)
static void (*rcar_putc)(uint8_t outchar);
static void scif_console_init(uint32_t modemr);
static void scif_console_putc(uint8_t outchar);
static void hscif_console_putc(uint8_t outchar);
static void scif_console_init(uint32_t modemr)
{
switch(modemr)
{
case MODEMR_HSCIF_DLMODE_3000000:
{
/* Set the pointer to a function that outputs one character. */
rcar_putc = hscif_console_putc;
break;
}
case MODEMR_HSCIF_DLMODE_1843200:
{
/* Set the pointer to a function that outputs one character. */
rcar_putc = hscif_console_putc;
break;
}
case MODEMR_HSCIF_DLMODE_921600:
{
/* Set the pointer to a function that outputs one character. */
rcar_putc = hscif_console_putc;
break;
}
case MODEMR_SCIF_DLMODE:
default:
{
/* Set the pointer to a function that outputs one character. */
rcar_putc = scif_console_putc;
break;
}
}
}
/* End of function scif_console_init(void) */
void scif_init(void)
{
uint32_t modemr;
#ifdef FORCE_115200 /* force to serial speed to 115200 bps */
#define _MODE31 (0xEB22FFF0) /* Gen4_ICUMX_loader at RT-VRAM */
#define _MODE_115200 0x00115200
modemr = mem_read32(_MODE31);
if (modemr == _MODE_115200)
modemr = MODEMR_SCIF_DLMODE;
else
#endif
{
modemr = ((mem_read32(RST_MODEMR0) & RST_MODEMR0_MD31) >> 31U);
modemr |= ((mem_read32(RST_MODEMR1) & RST_MODEMR1_MD32) << 1U);
}
scif_console_init(modemr);
}
/* End of function scif_init(void) */
void console_putc(uint8_t outchar)
{
if (outchar == 0x0A) /* \n */
{
rcar_putc( 0x0D ); /* \r */
}
rcar_putc(outchar);
}
/* End of function console_putc(void) */
static void scif_console_putc(uint8_t outchar)
{
uint16_t reg;
/* Check that transfer of SCIF0 is completed */
while (!((TRANS_END_CHECK & mem_read16(SCIF_SCFSR)) == TRANS_END_CHECK))
{
;
}
mem_write8(SCIF_SCFTDR, outchar); /* Transfer one character */
reg = mem_read16(SCIF_SCFSR);
reg &= (uint16_t)(~(TRANS_END_CHECK)); /* TEND,TDFE clear */
mem_write16(SCIF_SCFSR, reg);
/* Check that transfer of SCIF0 is completed */
while (!((TRANS_END_CHECK & mem_read16(SCIF_SCFSR)) == TRANS_END_CHECK))
{
;
}
}
/* End of function scif_console_putc(uint8_t outchar) */
static void hscif_console_putc(uint8_t outchar)
{
uint16_t reg;
/* Check that transfer of SCIF0 is completed */
while (!((TRANS_END_CHECK & mem_read16(HSCIF_HSFSR)) == TRANS_END_CHECK))
{
;
}
mem_write8(HSCIF_HSFTDR, outchar); /* Transfer one character */
reg = mem_read16(HSCIF_HSFSR);
reg &= (uint16_t)(~(TRANS_END_CHECK)); /* TEND,TDFE clear */
mem_write16(HSCIF_HSFSR, reg);
/* Check that transfer of SCIF0 is completed */
while (!((TRANS_END_CHECK & mem_read16(HSCIF_HSFSR)) == TRANS_END_CHECK))
{
;
}
}
/* End of function hscif_console_putc(uint8_t outchar) */