HPM SDK
HPMicro Software Development Kit
hpm_common.h File Reference
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>

Go to the source code of this file.

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...