add IPL
This commit is contained in:
109
IPL/Customer/Mobis/Gen4_ICUMX_Loader/common/timer/micro_wait.c
Normal file
109
IPL/Customer/Mobis/Gen4_ICUMX_Loader/common/timer/micro_wait.c
Normal file
@@ -0,0 +1,109 @@
|
||||
/*******************************************************************************
|
||||
* 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 2021-2022 Renesas Electronics Corporation All rights reserved.
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* DESCRIPTION : Time wait driver
|
||||
******************************************************************************/
|
||||
/******************************************************************************
|
||||
* @file micro_wait.c
|
||||
* - Version : 0.03
|
||||
* @brief Wait of micro second
|
||||
* .
|
||||
*****************************************************************************/
|
||||
/******************************************************************************
|
||||
* History : DD.MM.YYYY Version Description
|
||||
* : 28.07.2021 0.01 First Release
|
||||
* : 15.10.2021 0.02 modify register access to read modify write.
|
||||
* : 03.12.2021 0.03 fix incorrect configuration process.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <micro_wait.h>
|
||||
#include <mem_io.h>
|
||||
|
||||
/************************************************************************************************/
|
||||
/* Definitions */
|
||||
/************************************************************************************************/
|
||||
|
||||
#define INTICUOSTM0 (0xFFFEEA14U)
|
||||
#define INTCR_RF ((uint16_t)1U << 12U)
|
||||
#define INTCR_RF_NO_REQ ((uint16_t)0U << 12U)
|
||||
|
||||
#define OSTM0_BASE (0xFFFEE000U)
|
||||
#define OSTM0CMP (OSTM0_BASE)
|
||||
#define OSTM0TS (OSTM0_BASE + 0x0014U)
|
||||
#define OSTM0TT (OSTM0_BASE + 0x0018U)
|
||||
#define OSTM0CTL (OSTM0_BASE + 0x0020U)
|
||||
|
||||
#define OSTM0TS_TS (uint8_t)(0x01U) /* b0:1: Start */
|
||||
#define OSTM0TT_TT (uint8_t)(0x01U) /* b0:1: Stop */
|
||||
#define OSTM0CMP_MICRO_VALUE (0x00000190U) /* PCLK=400MHz(400=0x190 = 1us) */
|
||||
|
||||
#define OSTM0CTL_MD10 (uint8_t)(0x02U) /* b1:1: Free-run compare mode(Start:0 Counting Direction:up) */
|
||||
/* b0:0: Interrupts when counting starts are enabled */
|
||||
|
||||
#define MAX_MICRO_WAIT (10737418U) /* 0xFFFFFFFF / 400 */
|
||||
|
||||
void micro_wait(uint32_t count_us)
|
||||
{
|
||||
uint32_t val;
|
||||
uint16_t reg16;
|
||||
uint8_t reg8;
|
||||
|
||||
if (count_us != 0U)
|
||||
{
|
||||
/* When the timer count is an argument that exceeds 0xFFFFFFFF */
|
||||
if(MAX_MICRO_WAIT < count_us)
|
||||
{
|
||||
count_us = MAX_MICRO_WAIT;
|
||||
}
|
||||
val = count_us * OSTM0CMP_MICRO_VALUE;
|
||||
/* timer start */
|
||||
reg8 = mem_read8(OSTM0TT);
|
||||
reg8 |= OSTM0TT_TT;
|
||||
mem_write8(OSTM0TT, reg8);
|
||||
mem_write32(OSTM0CMP, val);
|
||||
reg8 = mem_read8(OSTM0CTL);
|
||||
reg8 |= OSTM0CTL_MD10;
|
||||
mem_write8(OSTM0CTL, reg8);
|
||||
reg8 = mem_read8(OSTM0TS);
|
||||
reg8 |= OSTM0TS_TS;
|
||||
mem_write8(OSTM0TS, reg8);
|
||||
|
||||
while (1)
|
||||
{
|
||||
reg16 = mem_read16(INTICUOSTM0);
|
||||
if ((reg16 & (INTCR_RF)) != INTCR_RF_NO_REQ)
|
||||
{
|
||||
/* timer stop */
|
||||
reg16 = (reg16 & (uint16_t)(~(INTCR_RF)));
|
||||
mem_write16(INTICUOSTM0, reg16);
|
||||
reg8 = mem_read8(OSTM0TT);
|
||||
reg8 |= OSTM0TT_TT;
|
||||
mem_write8(OSTM0TT, reg8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* End of function micro_wait(uint32_t count_us) */
|
||||
108
IPL/Customer/Mobis/Gen4_ICUMX_Loader/common/timer/scmt.c
Normal file
108
IPL/Customer/Mobis/Gen4_ICUMX_Loader/common/timer/scmt.c
Normal file
@@ -0,0 +1,108 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <mem_io.h>
|
||||
#include <scmt.h>
|
||||
#include <scmt_config.h>
|
||||
#include <scmt_register.h>
|
||||
|
||||
#if SCMT_DEBUG
|
||||
#include <log.h>
|
||||
#endif /* SCMT_DEBUG */
|
||||
|
||||
#if SCMT_TOGGLE_GPIO
|
||||
#include <pfc.h>
|
||||
void gpio_set(void)
|
||||
{
|
||||
/* V4H: SCL3_V::Pin AK5::GP8_06
|
||||
GPIO Group 8 Base: H’E606 8000
|
||||
INOUTSELn +0x184 (set pin to output mode)
|
||||
OUTDTn +0x188 (set pin output value)
|
||||
*/
|
||||
pfc_reg_write(PFC_INOUTSEL8_RW, 1<<6); /* Set GP8_06 to output mode */
|
||||
pfc_reg_write(PFC_OUTDT8_RW, 1<<6); /* Set GP8_06 to 'high' */
|
||||
}
|
||||
static int gpio_reset_cnt = 3;
|
||||
void gpio_clear(void)
|
||||
{
|
||||
if (gpio_reset_cnt>0) {
|
||||
gpio_reset_cnt--;
|
||||
}
|
||||
else
|
||||
{
|
||||
pfc_reg_write(PFC_OUTDT8_RW, 0); /* Set GP8_06 to 'low' */
|
||||
}
|
||||
|
||||
}
|
||||
#endif /* SCMT_TOGGLE_GPIO */
|
||||
|
||||
void scmt_module_start(void)
|
||||
{
|
||||
/* For boot time measurement, signal start of SCMT by GPIO pin toggle */
|
||||
#if SCMT_TOGGLE_GPIO
|
||||
gpio_set();
|
||||
#endif /* SCMT_TOGGLE_GPIO */
|
||||
|
||||
/* If you have issues with the code getting stuck or reading zero from the timer,
|
||||
you can debug the init seqence with SCMT_DEBUG.
|
||||
Just make sure that printing debug data is already possible. */
|
||||
#if SCMT_DEBUG
|
||||
PRINTFN("SCMT A\n");
|
||||
#endif /* SCMT_DEBUG */
|
||||
#if SCMT_INIT
|
||||
mem_write32(SCMT_CMSCNT,(SCMT_START_VALUE)); /* Set counter value to zero */
|
||||
#endif /* SCMT_INIT */
|
||||
#if SCMT_DEBUG
|
||||
PRINTFN("SCMT B: SCMT_CMSCNT (0x%x) = 0x%x\n", SCMT_CMSCNT, mem_read32(SCMT_CMSCNT) );
|
||||
#endif /* SCMT_DEBUG */
|
||||
#if SCMT_INIT
|
||||
mem_write32(SCMT_CMSCOR,0xffffffff); /* Set compare value to maximum, we use it as 32-bit counter only */
|
||||
#endif /* SCMT_INIT */
|
||||
#if SCMT_DEBUG
|
||||
PRINTFN("SCMT C: SCMT_CMSCOR (0x%x) = 0x%x\n", SCMT_CMSCOR, mem_read32(SCMT_CMSCOR) );
|
||||
#endif /* SCMT_DEBUG */
|
||||
#if SCMT_INIT
|
||||
while(mem_read16(SCMT_CMSCSR)&(1<<13)); /* Wait for write clearance */
|
||||
#endif /* SCMT_INIT */
|
||||
#if SCMT_DEBUG
|
||||
PRINTFN("SCMT D: SCMT_CMSCSR (0x%x) = 0x%x\n", SCMT_CMSCSR, mem_read16(SCMT_CMSCSR) );
|
||||
#endif /* SCMT_DEBUG */
|
||||
#if SCMT_INIT
|
||||
mem_write16(SCMT_CMSSTR,1<<5); /* Start counter */
|
||||
#endif /* SCMT_INIT */
|
||||
#if SCMT_DEBUG
|
||||
PRINTFN("SCMT E: SCMT_CMSSTR (0x%x) = 0x%x\n", SCMT_CMSSTR, mem_read16(SCMT_CMSSTR) );
|
||||
PRINTFN("SCMT F: SCMT_CMSCNT (0x%x) = 0x%x\n", SCMT_CMSCNT, mem_read32(SCMT_CMSCNT) );
|
||||
PRINTFN("SCMT G: SCMT_CMSCNT (0x%x) = 0x%x\n", SCMT_CMSCNT, mem_read32(SCMT_CMSCNT) );
|
||||
PRINTFN("SCMT H: SCMT_CMSCNT (0x%x) = 0x%x\n", SCMT_CMSCNT, mem_read32(SCMT_CMSCNT) );
|
||||
PRINTFN("SCMT I: SCMT_CMSCNT (0x%x) = 0x%x\n", SCMT_CMSCNT, mem_read32(SCMT_CMSCNT) );
|
||||
#endif /* SCMT_DEBUG */
|
||||
}
|
||||
|
||||
uint32_t scmt_module_read(void)
|
||||
{
|
||||
uint32_t last = 0, current = 0;
|
||||
|
||||
/* For boot time measurement, signal start of SCMT by GPIO pin toggle, reset after some time */
|
||||
#if SCMT_TOGGLE_GPIO
|
||||
gpio_clear();
|
||||
#endif /* SCMT_TOGGLE_GPIO */
|
||||
|
||||
/* From UM:
|
||||
When CMSCNT is read during the counter operation, the read value may be wrong because of an asynchronous clock between counter and bus-interface.
|
||||
For exact value, read this register continuously, until same values are read from this register. */
|
||||
current = mem_read32(SCMT_CMSCNT);
|
||||
do {
|
||||
last = current;
|
||||
current = mem_read32(SCMT_CMSCNT);
|
||||
} while (last != current);
|
||||
return current;
|
||||
}
|
||||
|
||||
/* NOT SAFE FOR OVERLFOWS */
|
||||
void scmt_wait_ticks(uint32_t ticks)
|
||||
{
|
||||
uint32_t start = scmt_module_read();
|
||||
uint32_t stop = start + ticks;
|
||||
|
||||
while (stop > scmt_module_read()) { /* NOP */ };
|
||||
}
|
||||
Reference in New Issue
Block a user