HPM SDK
HPMicro Software Development Kit
COMMON driver APIs

COMMON driver APIs. More...

Macros

#define ARRAY_SIZE(a)   (sizeof(a) / sizeof((a)[0]))
 
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define HPM_ALIGN_DOWN(a, n)   ((uint32_t)(a) & ~(n-1U))
 
#define HPM_ALIGN_UP(a, n)   (((uint32_t)(a) + (n-1U)) & ~(n-1U))
 
#define HPM_BITSMASK(val, offset)   ((uint32_t)(val) << (offset))
 
#define IS_HPM_BITMASK_SET(val, mask)   (((uint32_t)(val) & (uint32_t)(mask)) != 0U)
 
#define IS_HPM_BIT_SET(val, offset)   (((uint32_t)(val) & (1UL << (offset))) != 0U)
 
#define IS_HPM_BITMASK_CLR(val, mask)   (((uint32_t)(val) & (uint32_t)(mask)) == 0U)
 
#define IS_HPM_BIT_CLR(val, offset)   (((uint32_t)(val) & (1UL << (offset))) == 0U)
 
#define HPM_BREAK_IF(cond)   if (cond) { break; }
 
#define HPM_CONTINUE_IF(cond)   if (cond) { continue; }
 
#define HPM_DIV_ROUND_CLOSEST(x, div)   (((x) + (div) / 2) / (div))
 
#define HPM_DIV_ROUND_UP(x, div)   (((x) + (div) - 1) / (div))
 
#define HPM_NUM_TO_EVEN_CEILING(x)   ((x + 1) & 0xFFFFFFFEUL)
 
#define HPM_NUM_TO_EVEN_FLOOR(x)   ((x) & 0xFFFFFFFEUL)
 
#define HPM_CHECK_RET(x)
 
#define HPM_STRINGIFY(x)   _HPM_STRINGIFY(x)
 
#define SIZE_1KB   (1024UL)
 
#define SIZE_1MB   (1048576UL)
 
#define BIT0_MASK   (0x00000001UL)
 
#define BIT1_MASK   (0x00000002UL)
 
#define BIT2_MASK   (0x00000004UL)
 
#define BIT3_MASK   (0x00000008UL)
 
#define BIT4_MASK   (0x00000010UL)
 
#define BIT5_MASK   (0x00000020UL)
 
#define BIT6_MASK   (0x00000040UL)
 
#define BIT7_MASK   (0x00000080UL)
 
#define BIT8_MASK   (0x00000100UL)
 
#define BIT9_MASK   (0x00000200UL)
 
#define BIT10_MASK   (0x00000400UL)
 
#define BIT11_MASK   (0x00000800UL)
 
#define BIT12_MASK   (0x00001000UL)
 
#define BIT13_MASK   (0x00002000UL)
 
#define BIT14_MASK   (0x00004000UL)
 
#define BIT15_MASK   (0x00008000UL)
 
#define BIT16_MASK   (0x00010000UL)
 
#define BIT17_MASK   (0x00020000UL)
 
#define BIT18_MASK   (0x00040000UL)
 
#define BIT19_MASK   (0x00080000UL)
 
#define BIT20_MASK   (0x00100000UL)
 
#define BIT21_MASK   (0x00200000UL)
 
#define BIT22_MASK   (0x00400000UL)
 
#define BIT23_MASK   (0x00800000UL)
 
#define BIT24_MASK   (0x01000000UL)
 
#define BIT25_MASK   (0x02000000UL)
 
#define BIT26_MASK   (0x04000000UL)
 
#define BIT27_MASK   (0x08000000UL)
 
#define BIT28_MASK   (0x10000000UL)
 
#define BIT29_MASK   (0x20000000UL)
 
#define BIT30_MASK   (0x40000000UL)
 
#define BIT31_MASK   (0x80000000UL)
 
#define HPM_PI   (3.14159265358979323846)
 
#define HPM_2_PI   (6.28318530717958647692)
 
#define HPM_HALF_PI   (1.57079632679489661923)
 
#define MAKE_STATUS(group, code)   ((uint32_t)(group)*1000U + (uint32_t)(code))
 

Typedefs

typedef uint32_t hpm_stat_t
 

Enumerations

enum  {
  status_group_common = 0 , status_group_uart = 1 , status_group_i2c = 2 , status_group_spi = 3 ,
  status_group_usb = 4 , status_group_i2s = 5 , status_group_xpi = 6 , status_group_l1c ,
  status_group_dma , status_group_femc , status_group_sdp , status_group_xpi_nor ,
  status_group_otp , status_group_lcdc , status_group_mbx , status_group_rng ,
  status_group_pdma , status_group_wdg , status_group_pmic_sec , status_group_can ,
  status_group_sdxc , status_group_pcfg , status_group_clk , status_group_pllctl ,
  status_group_pllctlv2 , status_group_ffa , status_group_mcan , status_group_ewdg ,
  status_group_esc , status_group_middleware_start = 500 , status_group_sdmmc = status_group_middleware_start , status_group_audio_codec ,
  status_group_dma_manager , status_group_spi_nor_flash , status_group_touch , status_group_plb_qei_encoder ,
  status_group_pmbus
}
 
enum  { status_success = ((uint32_t)( status_group_common )*1000U + (uint32_t)( 0 )) , status_fail = ((uint32_t)( status_group_common )*1000U + (uint32_t)( 1 )) , status_invalid_argument = ((uint32_t)( status_group_common )*1000U + (uint32_t)( 2 )) , status_timeout = ((uint32_t)( status_group_common )*1000U + (uint32_t)( 3 )) }
 

Functions

static uint32_t count_set_bits (uint32_t value)
 Count bits set to 1. More...
 
static uint32_t get_first_set_bit_from_lsb (uint32_t value)
 Count bits set to 1 from least significant bit. More...
 
static uint32_t get_first_set_bit_from_msb (uint32_t value)
 Count bits set to 1 from most significant bit. More...
 
static uint32_t hpm_convert_ticks_to_us (uint32_t ticks, uint32_t src_clk_freq)
 Convert the elapsed ticks to microseconds according to the source clock frequency. More...
 
static uint32_t hpm_convert_ticks_to_ms (uint32_t ticks, uint32_t src_clk_freq)
 Convert the elapsed ticks to milliseconds according to the source clock frequency. More...
 

Detailed Description

COMMON driver APIs.

Macro Definition Documentation

◆ ARRAY_SIZE

#define ARRAY_SIZE (   a)    (sizeof(a) / sizeof((a)[0]))

◆ BIT0_MASK

#define BIT0_MASK   (0x00000001UL)

◆ BIT10_MASK

#define BIT10_MASK   (0x00000400UL)

◆ BIT11_MASK

#define BIT11_MASK   (0x00000800UL)

◆ BIT12_MASK

#define BIT12_MASK   (0x00001000UL)

◆ BIT13_MASK

#define BIT13_MASK   (0x00002000UL)

◆ BIT14_MASK

#define BIT14_MASK   (0x00004000UL)

◆ BIT15_MASK

#define BIT15_MASK   (0x00008000UL)

◆ BIT16_MASK

#define BIT16_MASK   (0x00010000UL)

◆ BIT17_MASK

#define BIT17_MASK   (0x00020000UL)

◆ BIT18_MASK

#define BIT18_MASK   (0x00040000UL)

◆ BIT19_MASK

#define BIT19_MASK   (0x00080000UL)

◆ BIT1_MASK

#define BIT1_MASK   (0x00000002UL)

◆ BIT20_MASK

#define BIT20_MASK   (0x00100000UL)

◆ BIT21_MASK

#define BIT21_MASK   (0x00200000UL)

◆ BIT22_MASK

#define BIT22_MASK   (0x00400000UL)

◆ BIT23_MASK

#define BIT23_MASK   (0x00800000UL)

◆ BIT24_MASK

#define BIT24_MASK   (0x01000000UL)

◆ BIT25_MASK

#define BIT25_MASK   (0x02000000UL)

◆ BIT26_MASK

#define BIT26_MASK   (0x04000000UL)

◆ BIT27_MASK

#define BIT27_MASK   (0x08000000UL)

◆ BIT28_MASK

#define BIT28_MASK   (0x10000000UL)

◆ BIT29_MASK

#define BIT29_MASK   (0x20000000UL)

◆ BIT2_MASK

#define BIT2_MASK   (0x00000004UL)

◆ BIT30_MASK

#define BIT30_MASK   (0x40000000UL)

◆ BIT31_MASK

#define BIT31_MASK   (0x80000000UL)

◆ BIT3_MASK

#define BIT3_MASK   (0x00000008UL)

◆ BIT4_MASK

#define BIT4_MASK   (0x00000010UL)

◆ BIT5_MASK

#define BIT5_MASK   (0x00000020UL)

◆ BIT6_MASK

#define BIT6_MASK   (0x00000040UL)

◆ BIT7_MASK

#define BIT7_MASK   (0x00000080UL)

◆ BIT8_MASK

#define BIT8_MASK   (0x00000100UL)

◆ BIT9_MASK

#define BIT9_MASK   (0x00000200UL)

◆ HPM_2_PI

#define HPM_2_PI   (6.28318530717958647692)

◆ HPM_ALIGN_DOWN

#define HPM_ALIGN_DOWN (   a,
 
)    ((uint32_t)(a) & ~(n-1U))

◆ HPM_ALIGN_UP

#define HPM_ALIGN_UP (   a,
 
)    (((uint32_t)(a) + (n-1U)) & ~(n-1U))

◆ HPM_BITSMASK

#define HPM_BITSMASK (   val,
  offset 
)    ((uint32_t)(val) << (offset))

◆ HPM_BREAK_IF

#define HPM_BREAK_IF (   cond)    if (cond) { break; }

◆ HPM_CHECK_RET

#define HPM_CHECK_RET (   x)

#include <drivers/inc/hpm_common.h>

Value:
do { \
stat = (x); \
if (status_success != stat) { \
return stat; \
} \
} while (false)
@ status_success
Definition: hpm_common.h:180

◆ HPM_CONTINUE_IF

#define HPM_CONTINUE_IF (   cond)    if (cond) { continue; }

◆ HPM_DIV_ROUND_CLOSEST

#define HPM_DIV_ROUND_CLOSEST (   x,
  div 
)    (((x) + (div) / 2) / (div))

◆ HPM_DIV_ROUND_UP

#define HPM_DIV_ROUND_UP (   x,
  div 
)    (((x) + (div) - 1) / (div))

◆ HPM_HALF_PI

#define HPM_HALF_PI   (1.57079632679489661923)

◆ HPM_NUM_TO_EVEN_CEILING

#define HPM_NUM_TO_EVEN_CEILING (   x)    ((x + 1) & 0xFFFFFFFEUL)

◆ HPM_NUM_TO_EVEN_FLOOR

#define HPM_NUM_TO_EVEN_FLOOR (   x)    ((x) & 0xFFFFFFFEUL)

◆ HPM_PI

#define HPM_PI   (3.14159265358979323846)

◆ HPM_STRINGIFY

#define HPM_STRINGIFY (   x)    _HPM_STRINGIFY(x)

◆ IS_HPM_BIT_CLR

#define IS_HPM_BIT_CLR (   val,
  offset 
)    (((uint32_t)(val) & (1UL << (offset))) == 0U)

◆ IS_HPM_BIT_SET

#define IS_HPM_BIT_SET (   val,
  offset 
)    (((uint32_t)(val) & (1UL << (offset))) != 0U)

◆ IS_HPM_BITMASK_CLR

#define IS_HPM_BITMASK_CLR (   val,
  mask 
)    (((uint32_t)(val) & (uint32_t)(mask)) == 0U)

◆ IS_HPM_BITMASK_SET

#define IS_HPM_BITMASK_SET (   val,
  mask 
)    (((uint32_t)(val) & (uint32_t)(mask)) != 0U)

◆ MAKE_STATUS

#define MAKE_STATUS (   group,
  code 
)    ((uint32_t)(group)*1000U + (uint32_t)(code))

◆ MAX

#define MAX (   a,
 
)    ((a) > (b) ? (a) : (b))

◆ MIN

#define MIN (   a,
 
)    ((a) < (b) ? (a) : (b))

◆ SIZE_1KB

#define SIZE_1KB   (1024UL)

◆ SIZE_1MB

#define SIZE_1MB   (1048576UL)

Typedef Documentation

◆ hpm_stat_t

typedef uint32_t hpm_stat_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

#include <drivers/inc/hpm_common.h>

Enumerator
status_group_common 
status_group_uart 
status_group_i2c 
status_group_spi 
status_group_usb 
status_group_i2s 
status_group_xpi 
status_group_l1c 
status_group_dma 
status_group_femc 
status_group_sdp 
status_group_xpi_nor 
status_group_otp 
status_group_lcdc 
status_group_mbx 
status_group_rng 
status_group_pdma 
status_group_wdg 
status_group_pmic_sec 
status_group_can 
status_group_sdxc 
status_group_pcfg 
status_group_clk 
status_group_pllctl 
status_group_pllctlv2 
status_group_ffa 
status_group_mcan 
status_group_ewdg 
status_group_esc 
status_group_middleware_start 
status_group_sdmmc 
status_group_audio_codec 
status_group_dma_manager 
status_group_spi_nor_flash 
status_group_touch 
status_group_plb_qei_encoder 
status_group_pmbus 

◆ anonymous enum

anonymous enum

#include <drivers/inc/hpm_common.h>

Enumerator
status_success 
status_fail 
status_invalid_argument 
status_timeout 

Function Documentation

◆ count_set_bits()

static uint32_t count_set_bits ( uint32_t  value)
inlinestatic

#include <drivers/inc/hpm_common.h>

Count bits set to 1.

Parameters
valueData to be counted
Returns
number of bits set to 1

◆ get_first_set_bit_from_lsb()

static uint32_t get_first_set_bit_from_lsb ( uint32_t  value)
inlinestatic

#include <drivers/inc/hpm_common.h>

Count bits set to 1 from least significant bit.

Parameters
valueData to be counted
Returns
number of bits set to 1
0xFFFFFFFF if no bit was set to 1

◆ get_first_set_bit_from_msb()

static uint32_t get_first_set_bit_from_msb ( uint32_t  value)
inlinestatic

#include <drivers/inc/hpm_common.h>

Count bits set to 1 from most significant bit.

Parameters
valueData to be counted
Returns
number of bits set to 1
0xFFFFFFFF if no bit was set to 1

◆ hpm_convert_ticks_to_ms()

static uint32_t hpm_convert_ticks_to_ms ( uint32_t  ticks,
uint32_t  src_clk_freq 
)
inlinestatic

#include <drivers/inc/hpm_common.h>

Convert the elapsed ticks to milliseconds according to the source clock frequency.

Parameters
[in]tickselapsed ticks
[in]src_clk_freqThe Frequency of the source
Returns
elapsed milliseconds

◆ hpm_convert_ticks_to_us()

static uint32_t hpm_convert_ticks_to_us ( uint32_t  ticks,
uint32_t  src_clk_freq 
)
inlinestatic

#include <drivers/inc/hpm_common.h>

Convert the elapsed ticks to microseconds according to the source clock frequency.

Parameters
[in]tickselapsed ticks
[in]src_clk_freqThe Frequency of the source
Returns
elapsed microseconds