#ifndef UTILBASE_ALX1_HAL_DXX_2020_08_06_H_ #define UTILBASE_ALX1_HAL_DXX_2020_08_06_H_ // **************************************************************************** // // (C) Automotive-Lighting Reutlingen GmbH - ALRT/EEG2 // Tuebinger Strasse 123, 72703 Reutlingen, Germany // // **************************************************************************** // ---------------------------------------------------------------------------- /// \file UtilBase.h /// /// \author /// \owner /// /// \date 13.012.2006 /// /// \brief /// /// \descr Macros for measuring the run time in us of a function. // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // includes // ---------------------------------------------------------------------------- #include // for memset #include // ***************************************************************************** // Function : UtilMemClr(uint8 *pucBuffer, uint16_least unLength) // // Description : Description : Clear Memory with 0 values // // ***************************************************************************** // jk-tbd void UtilMemClr(uint8 *pucBuffer, uint16_least unLength); INLINE void UtilMemClr(uint8 *pucBuffer, uint16_least unLength) { memset((void*) pucBuffer, 0, unLength); } // ***************************************************************************** // Atomar bit manipulations for variables in memory // ***************************************************************************** // This version will work with "BitPos" passed as a variable, address pointer can be of any type. INLINE void UtilClearVarBitAtomic_(uint32 ulBitPos, volatile uint8* pVariable); INLINE void UtilSetVarBitAtomic_(uint32 ulBitPos, volatile uint8* pVariable); // For Lint and Windows we will only supply a normal INLINE C-Function, which is not atomic. INLINE void _VarBitClearAtomar_(volatile void* paddr, uint32 ulBitPos) { *((uint8*)paddr) &= (uint8)(~(1u << ulBitPos)); // ulBitPos will be in a range from 0..7 } INLINE void _VarBitSetAtomar_(volatile void* paddr, uint32 ulBitPos) { *((uint8*)paddr) |= (uint8)(1u << ulBitPos); // ulBitPos will be in a range from 0..7 } //----------------------------------------------------------------------------- /// \brief void UtilClearVarBitAtomic_(uint32 ulBitPos, volatile uint8* pVariable) /// /// \descr Clears one specific bit passed as variable value or as a constant /// value directly in the memory in an atomic way with the help of /// the INLINE assembler macro mechanism. /// This will work only for little endian machines (NEC) controller. /// /// \param ulBitPos Variable or Const bit number which will be cleared 0..X /// X can also be a higher value than 31 and more. /// \param pVariable Address of the memory cell, any type 8,16,32,64 bit variable. /// /// \return void //----------------------------------------------------------------------------- INLINE void UtilClearVarBitAtomic_(uint32 ulBitPos, volatile uint8* pVariable) { // Force the parameter to be a register variable for // using the INLINE assembler macro in a correct way. register uint32 ulRegBitPos = ulBitPos; register volatile void* pRegAddr = pVariable; //if(ulRegBitPos >= 8) { uint32 ulAdrOffset = ulRegBitPos / 8; pRegAddr = ((volatile uint8*)pRegAddr) + ulAdrOffset; ulRegBitPos -= ulAdrOffset * 8; } _VarBitClearAtomar_(pRegAddr, ulRegBitPos); } //----------------------------------------------------------------------------- /// \brief void UtilSetVarBitAtomic_(uint32 ulBitPos, volatile uint8* pVariable) /// /// \descr Setting one specific bit passed as constant value or as a variable /// value directly in the memory in an atomic way with the help of /// the INLINE assembler macro mechanism. /// This will work only for little endian machines (NEC) controller. /// /// \param ulBitPos Variable bit number which will be set 0..X /// X can also be a higher value than 31 and more. /// \param pVariable Address of the memory cell, any type 8,16,32,64 bit variable. /// /// \return void //----------------------------------------------------------------------------- INLINE void UtilSetVarBitAtomic_(uint32 ulBitPos, volatile uint8* pVariable) { // Force the parameter to be a register variable for // using the INLINE assembler macro in a correct way. register uint32 ulRegBitPos = ulBitPos; register volatile void* pRegAddr = pVariable; //if(ulRegBitPos >= 8) { uint32 ulAdrOffset = ulRegBitPos / 8; pRegAddr = ((volatile uint8*)pRegAddr) + ulAdrOffset; ulRegBitPos -= ulAdrOffset * 8; } _VarBitSetAtomar_(pRegAddr, ulRegBitPos); } //----------------------------------------------------------------------------- /// \brief void UtilClearVarBitAtomicU16_(uint32 ulBitPos, volatile uint16* pVariable) /// /// \descr Clears one specific bit passed as variable value or as a constant /// value directly in the memory in an atomic way with the help of /// the INLINE assembler macro mechanism. /// This will work only for little endian machines (NEC) controller. /// /// \param ulBitPos Variable or Const bit number which will be cleared 0..15 /// /// \param pVariable Address of the memory cell, 16 bit variable. /// /// \return void //----------------------------------------------------------------------------- INLINE void UtilClearVarBitAtomicU16_(uint32 ulBitPos, volatile uint16* pVariable) { // Force the parameter to be a register variable for // using the INLINE assembler macro in a correct way. register uint32 ulRegBitPos = ulBitPos; register volatile void* pRegAddr = pVariable; if(ulRegBitPos >= 8) { pRegAddr = ((volatile uint8*)pRegAddr) + 1; ulRegBitPos -= 8; } _VarBitClearAtomar_(pRegAddr, ulRegBitPos); } //----------------------------------------------------------------------------- /// \brief void UtilSetVarBitAtomicU16_(uint32 ulBitPos, volatile uint16* pVariable) /// /// \descr Setting one specific bit passed as constant value or as a variable /// value directly in the memory in an atomic way with the help of /// the INLINE assembler macro mechanism. /// This will work only for little endian machines (NEC) controller. /// /// \param ulBitPos Variable bit number which will be set 0..15 /// /// \param pVariable Address of the memory cell, 16 bit variable. /// /// \return void //----------------------------------------------------------------------------- INLINE void UtilSetVarBitAtomicU16_(uint32 ulBitPos, volatile uint16* pVariable) { // Force the parameter to be a register variable for // using the INLINE assembler macro in a correct way. register uint32 ulRegBitPos = ulBitPos; register volatile void* pRegAddr = pVariable; if(ulRegBitPos >= 8) { pRegAddr = ((volatile uint8*)pRegAddr) + 1; ulRegBitPos -= 8; } _VarBitSetAtomar_(pRegAddr, ulRegBitPos); } //----------------------------------------------------------------------------- /// \brief void UtilClearVarBitAtomicU8_(uint32 ulBitPos, volatile uint8* pVariable) /// /// \descr Clears one specific bit passed as variable value or as a constant /// value directly in the memory in an atomic way with the help of /// the INLINE assembler macro mechanism. /// /// \param ulBitPos Variable or Const bit number which will be cleared 0..7 /// /// \param pVariable Address of the memory cell, bit variable. /// /// \return void //----------------------------------------------------------------------------- INLINE void UtilClearVarBitAtomicU8_(uint32 ulBitPos, volatile uint8* pVariable) { // Force the parameter to be a register variable for // using the INLINE assembler macro in a correct way. register uint32 ulRegBitPos = ulBitPos; register volatile void* pRegAddr = pVariable; _VarBitClearAtomar_(pRegAddr, ulRegBitPos); } //----------------------------------------------------------------------------- /// \brief void UtilSetVarBitAtomicU8_(uint32 ulBitPos, volatile uint8* pVariable) /// /// \descr Setting one specific bit passed as constant value or as a variable /// value directly in the memory in an atomic way with the help of /// the INLINE assembler macro mechanism. /// /// \param ulBitPos Variable bit number which will be set 0..7 /// /// \param pVariable Address of the memory cell, bit variable. /// /// \return void //----------------------------------------------------------------------------- INLINE void UtilSetVarBitAtomicU8_(uint32 ulBitPos, volatile uint8* pVariable) { // Force the parameter to be a register variable for // using the INLINE assembler macro in a correct way. register uint32 ulRegBitPos = ulBitPos; register volatile void* pRegAddr = pVariable; _VarBitSetAtomar_(pRegAddr, ulRegBitPos); } #endif // UTILBASE_ALX1_HAL_DXX_2020_08_06_H_