Files
microchip-application-pec93…/Drivers/PEC930/HAL_Lib/inc/hal_device.h
T

139 lines
3.4 KiB
C

/**
* Copyright (c) 2024 Wei-Lun Hsu. All Rights Reserved.
*/
/** @file hal_device.h
*
* @author Wei-Lun Hsu
* @version 0.1
* @date 2024/09/10
* @license
* @description
*/
#ifndef __hal_device_H_wh21It4q_lc5o_HN4v_sYN9_uMvM6ZVOvOoN__
#define __hal_device_H_wh21It4q_lc5o_HN4v_sYN9_uMvM6ZVOvOoN__
#ifdef __cplusplus
extern "C" {
#endif
#include "hal_conf.h"
//=============================================================================
// Constant Definition
//=============================================================================
#if defined(USE_FULL_ASSERT)
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((char*)__func__, __LINE__))
void assert_failed(char *func, uint32_t line);
#else
#define assert_param(expr)
#endif
//=============================================================================
// Macro Definition
//=============================================================================
/**
* \brief Count leading zeros
*
* \param [in] x Value to count the leading zeros
* \return
* Number of leading zeros in value
*/
__STATIC_FORCEINLINE int HAL_CLZ(uint32_t x)
{
return __builtin_clz(x);
}
/**
* \brief Count the amount of bit-1
*
* \param [in] x Value to count the amount of bit-1
* \return
* The amount of bit-1
*/
__STATIC_FORCEINLINE int HAL_PopCount(uint32_t x)
{
return __builtin_popcount(x);
}
/**
* \brief Get UID-1 value
* \return UID-1
*/
__STATIC_FORCEINLINE uint32_t HAL_GetUID1(void)
{
return REG_READ(UID->UID1);
}
/**
* \brief Get UID-2 value
* \return UID-2
*/
__STATIC_FORCEINLINE uint32_t HAL_GetUID2(void)
{
return REG_READ(UID->UID2);
}
/**
* \brief Get UID-3 value
* \return UID-3
*/
__STATIC_FORCEINLINE uint32_t HAL_GetUID3(void)
{
return REG_READ(UID->UID3);
}
/**
* \brief Initialize the peripherals of this device
*
* \return
* None
*/
__STATIC_FORCEINLINE void HAL_DeviceInit(void)
{
REG_WRITE(SYSCFG->PRSTEN1, 0xFFFFFFFFul);
REG_WRITE(SYSCFG->PRSTEN, 0xFFFFFFFFul);
REG_WRITE(SYSCFG->PRSTEN1, 0x0ul);
REG_WRITE(SYSCFG->PRSTEN, 0x0ul);
return;
}
#define HAL_SetBits(_val_, _bit_mak_) REG_SET_BITS(_val_, _bit_mak_)
#define HAL_ClearBits(_val_, _bit_mak_) REG_CLR_BITS(_val_, _bit_mak_)
//=============================================================================
// Structure Definition
//=============================================================================
//=============================================================================
// Global Data Definition
//=============================================================================
//=============================================================================
// Private Function Definition
//=============================================================================
//=============================================================================
// Public Function Definition
//=============================================================================
/**
* \brief Set the seed to initialize pseudo-random number generator
*
* \param [in] seed The seed value
* \return
* None
*/
void HAL_SRand(uint32_t seed);
/**
* \brief Generate pseudo-random number
*
* \return
* The pseudo-random value
*/
uint32_t HAL_Rand(void);
#ifdef __cplusplus
}
#endif
#endif