FLEX-FORD-OBC-BM/Source/bsw/Fbl/fbl_hw.c

237 lines
12 KiB
C
Raw Permalink Normal View History

2026-03-19 11:49:16 +01:00
/***********************************************************************************************************************
* FILE DESCRIPTION
* ------------------------------------------------------------------------------------------------------------------*/
/** \file
* \brief Provides hardware abstraction functions for ARM 32 systems
*
* --------------------------------------------------------------------------------------------------------------------
* COPYRIGHT
* --------------------------------------------------------------------------------------------------------------------
* \par Copyright
* \verbatim
* Copyright (c) 2025 by Vector Informatik GmbH. All rights reserved.
*
* This software is copyright protected and proprietary to Vector Informatik GmbH.
* Vector Informatik GmbH grants to you only those rights as set out in the license conditions.
* All other rights remain with Vector Informatik GmbH.
* \endverbatim
*/
/**********************************************************************************************************************/
/***********************************************************************************************************************
* REVISION HISTORY
* --------------------------------------------------------------------------------------------------------------------
* Version Date Author Change Id Description
* --------------------------------------------------------------------------------------------------------------------
* 01.00.00 2018-11-07 vistbe Initial version
* 01.00.01 2019-12-09 vistbe ESCAN00105142 No changes
* 01.01.00 2020-02-07 vistmo FBL-1452 Added support for S32G2xx
* 01.02.00 2020-11-03 vistmo FBL-2090 Added support for XMC4xxx
* 01.03.00 2020-12-09 visjdn FBL-2490 Added support for S32K3xx
* 01.04.00 2020-12-21 visrie FBL-2517 Added support for AWR1
* 01.05.00 2021-01-28 visjdn FBL-2824 Added support for TPR12
* 01.06.00 2021-05-19 visjdn FBL-3038 Added support for iMXRT1172
* Added/adapted MemMap sections
* 01.07.00 2021-05-31 visjdn FBL-3545 Added support for AWR2
* 01.08.00 2021-07-08 visjdn FBL-3694 Added support for Jacinto6
* 01.09.00 2021-11-22 vistmo FBL-4275 Added support for Tayrona
* 01.10.00 2022-01-12 visjdn FBL-3720 Added support for Kinetis KW45B41Z
* 01.11.00 2022-03-09 visrie FBL-4770 No changes
* 01.12.00 2022-07-18 visjdn FBL-5115 Added support for SAF85xx
* 01.13.00 2023-02-09 fmenke FBL-6162 Added support for MSPM0
* ESCAN00113692 Timer current value is too high after timer initialization
* 01.14.00 2023-04-20 jschmitding FBL-5733 Added support for TCC70xx
* 01.15.00 2023-07-12 fmenke FBL-6966 Add support for NCJ29D6
* 01.16.00 2024-01-01 fmenke FBL-7559 No changes
* ESCAN00116504 No changes
* 01.17.00 2024-09-27 jschmitding FBL-9330 No changes
* 01.17.01 2024-10-22 visrie ESCAN00118141 No changes
* 01.18.00 2024-12-02 fmenke FBL-9747 Support StellarSr6
* 01.19.00 2025-11-19 jostravsky FBL-11077 No changes
**********************************************************************************************************************/
#define FBL_HW_SOURCE
/***********************************************************************************************************************
* INCLUDES
**********************************************************************************************************************/
#include "fbl_inc.h"
/***********************************************************************************************************************
* VERSION
**********************************************************************************************************************/
#if ( FBLHAL_ARM32_VERSION != 0x0119u ) || \
( FBLHAL_ARM32_RELEASE_VERSION != 0x00u )
# error "Error in fbl_hw.c: Source and header file are inconsistent!"
#endif
#if ( FBLHAL_ARM32_VERSION != _FBLHAL_ARM32_VERSION ) || \
( FBLHAL_ARM32_RELEASE_VERSION != _FBLHAL_ARM32_RELEASE_VERSION )
# error "Error in fbl_hw.c: Source and v_ver.h are inconsistent!"
#endif
/***********************************************************************************************************************
* DEFINES
**********************************************************************************************************************/
#if !defined( FBL_MEMCPY_WD_POLLING_MASK)
# define FBL_MEMCPY_WD_POLLING_MASK 0x3Fu
#endif
/***********************************************************************************************************************
* GLOBAL FUNCTIONS
**********************************************************************************************************************/
#if defined( FBL_USE_OWN_MEMCPY )
# define FBLHW_MEMCPY_START_SEC_CODE
# include "MemMap.h" /* PRQA S 5087 */ /* MD_MSR_MemMap */
/***********************************************************************************************************************
* FblOwnMemcpy
**********************************************************************************************************************/
/*! \brief Copies a given amount of bytes.
* \details This function copies a given amount of bytes. The Bootloader watchdog handling is called during
* copying. Can be used instead of a compiler library memcopy if watchdog handling is needed.
* \param[out] dest Pointer to destination
* \param[in] source Pointer to source
* \param[in] count Copy length in Byte
* \return Pointer to destination
**********************************************************************************************************************/
void * FblOwnMemcpy (void * dest, const void * source, vuint32 count)
{
vuint8 * localDest;
const vuint8 * localSource;
vuint32 i;
/* Initialize variables */
/* PRQA S 0316 2 */ /* MD_FblHw_0314_0316_0326_MemCpy */
localDest = (vuint8 *)dest;
localSource = (const vuint8 *)source;
for (i = 0u; i < count; i++)
{
if ((i & (FBL_MEMCPY_WD_POLLING_MASK )) == 0u)
{
FblLookForWatchdogVoid();
}
localDest[i] = localSource[i];
}
return dest;
}
# define FBLHW_MEMCPY_STOP_SEC_CODE
# include "MemMap.h" /* PRQA S 5087 */ /* MD_MSR_MemMap */
#endif /* FBL_USE_OWN_MEMCPY */
#define FBLHW_START_SEC_CODE
#include "MemMap.h" /* PRQA S 5087 */ /* MD_MSR_MemMap */
/***********************************************************************************************************************
* FblReadBlock
**********************************************************************************************************************/
/*! \brief This function reads a given amount of bytes from an address.
* \param[in] address Memory address to read out
* \param[out] buffer Target buffer
* \param[in] length Number of bytes to read
* \return Number of actually copied bytes
**********************************************************************************************************************/
tFblLength FblReadBlock( tFblAddress address, vuint8 *buffer, tFblLength length )
{
(void)MEMCPY(buffer, address, length); /* PRQA S 0314, 0326 */ /* MD_FblHw_0314_0316_0326_MemCpy */
return length;
}
/***********************************************************************************************************************
* FblReadByte
**********************************************************************************************************************/
/*! \brief This function can be used to read one byte from the given address.
* \param[in] Read address.
* \return Byte at memory location 'address'
**********************************************************************************************************************/
vuint8 FblReadByte( tFblAddress address )
{
vuint8 buffer;
(void)MEMCPY(&buffer, address, 1u); /* PRQA S 0314, 0326 */ /* MD_FblHw_0314_0316_0326_MemCpy */
return buffer;
}
/***********************************************************************************************************************
* FblTimerInit
**********************************************************************************************************************/
/*! \brief Initialize system timer
**********************************************************************************************************************/
/* PRQA S 0303 TAG_DrvFlash_0303_1 */ /* MD_FblHal_0303 */
void FblTimerInit( void )
{
/* Disable both timers to make modifications */
FBL_RTI_GCTRL &= FblInvert32Bit(FBL_RTI_GCTRL_TIMER_ENABLE);
/* Set prescaler: FRC=RTICLK/(prescaler+1) */
FBL_RTI_CPUC(FBL_RTI_TIMER_MS) = FBL_TIMER_PRESCALER_VALUE;
/* Make sure Compare0 register is used for timer0 */
FBL_RTI_COMPCTRL &= FblInvert32Bit(FBL_RTI_COMPCTRL_TIMER_SELECT);
/* Set Compare0 register (timer runs with half the frequency, see CPUC register) */
FBL_RTI_COMP(0u) = FBL_TIMER_RELOAD_VALUE / (FBL_TIMER_PRESCALER_VALUE + 1uL);
FBL_RTI_UDCP(0u) = FBL_TIMER_RELOAD_VALUE / (FBL_TIMER_PRESCALER_VALUE + 1uL);
/* Make sure timer0 starts at 0 */
FBL_RTI_FRC(FBL_RTI_TIMER_MS) = 0uL;
FBL_RTI_UC(FBL_RTI_TIMER_MS) = 0uL;
/* Enable both timers (millisecond and free running timer) */
FBL_RTI_GCTRL |= FBL_RTI_GCTRL_TIMER_ENABLE;
}
/* PRQA L:TAG_DrvFlash_0303_1 */
/***********************************************************************************************************************
* FblGetTimerValue
**********************************************************************************************************************/
/*! \brief Returns free running timer value
* \pre Timer must be initialized
* \return Current timer value
**********************************************************************************************************************/
/* PRQA S 0303 TAG_DrvFlash_0303_2 */ /* MD_FblHal_0303 */
vuint16 FblGetTimerValue( void )
{
vuint32 timerValue;
timerValue = FBL_RTI_FRC(FBL_RTI_TIMER_FREE);
return (vuint16)(timerValue & 0xFFFFu);
}
/* PRQA L:TAG_DrvFlash_0303_2 */
/***********************************************************************************************************************
* FblTimerStopp
**********************************************************************************************************************/
/*! \brief Stops the system timer
**********************************************************************************************************************/
/* PRQA S 0303 TAG_DrvFlash_0303_3 */ /* MD_FblHal_0303 */
void FblTimerStopp( void )
{
FBL_RTI_GCTRL &= FblInvert32Bit(FBL_RTI_GCTRL_TIMER_ENABLE);
}
#define FBLHW_STOP_SEC_CODE
#include "MemMap.h" /* PRQA S 5087 */ /* MD_MSR_MemMap */
/* PRQA L:TAG_DrvFlash_0303_3 */
/* Justification for module-specific MISRA deviations:
MD_FblHal_0303:
Reason: Cast between a pointer to volatile object and an integral type.
Risk: No identifiable risk as casts are used to define SFRs here.
Prevention: No prevention required.
MD_FblHw_0314_0316_0326_MemCpy:
Reason: The copy function have a void pointer as a function parameter.
Risk: No risk, because the underlying vuint8 pointer type is known.
Prevention: No prevention necessary.
MD_FblHal_2741:
Reason: This is an assembler instruction that is not correctly interpreted during static code analysis.
Risk: No risk, because the assembler instruction will always return the value depending on the register.
Prevention: No prevention required.
*/
/***********************************************************************************************************************
* END OF FILE: FBL_HW.C
**********************************************************************************************************************/