HPM SDK
HPMicro Software Development Kit
hpm_mcl_common.h File Reference
#include "hpm_common.h"
#include "hpm_mcl_cfg.h"
#include "hpm_mcl_physical.h"
#include "hpm_mcl_math.h"
#include "stdio.h"

Go to the source code of this file.

Data Structures

struct  mcl_user_value_t
 User-defined data with data and enable bits. More...
 
struct  mcl_cfg_t
 

Macros

#define MCL_DEBUG   printf
 
#define MCL_PI   HPM_PI
 
#define MCL_2PI   HPM_2_PI
 
#define MCL_PI_DIV3   (MCL_PI / 3.0f)
 
#define MCL_DELAY_US(x)   mcl_user_delay_us(x)
 
#define MCL_DELAY_MS(x)   MCL_DELAY_US(1000*x)
 
#define MCL_EMPTY
 
#define MCL_ASSERT_BOOL(b, code_extend, errcode)
 
#define MCL_ASSERT_EXEC_CODE_BOOL(b, code_extend)
 
#define MCL_ASSERT(x, return_errcode)   MCL_ASSERT_BOOL(((uint32_t)(x) != 0), MCL_EMPTY, return_errcode)
 
#define MCL_ASSERT_EXEC_CODE(x, code)   MCL_ASSERT_EXEC_CODE_BOOL((x), code)
 
#define MCL_ASSERT_EXEC_CODE_AND_RETURN(x, code, return_errcode)   MCL_ASSERT_BOOL((x), code, return_errcode)
 
#define MCL_ASSERT_EXEC_CODE_OPT   MCL_ASSERT_EXEC_CODE
 
#define MCL_ASSERT_OPT   MCL_ASSERT
 
#define MCL_ASSERT_EXEC_CODE_AND_RETURN_OPT   MCL_ASSERT_EXEC_CODE_AND_RETURN
 
#define MCL_FUNCTION_EXC_IF_ENABLE(b, str_f, f)
 
#define MCL_FUNCTION_EXC_IF_ELSE_ENABLE(b, str_f, _if, _else)
 
#define MCL_FUNCTION_INIT_IF_EMPTY(str_function, function)   MCL_FUNCTION_EXC_IF_ENABLE((str_function == NULL), str_function, function)
 
#define MCL_FUNCTION_INIT_IF_NO_EMPTY(function, str_function)   MCL_FUNCTION_EXC_IF_ENABLE((str_function != NULL), function, str_function)
 
#define MCL_STATUS_SET_IF_TRUE(real, str, status)   MCL_FUNCTION_EXC_IF_ENABLE((real), str, status)
 
#define MCL_VALUE_SET_IF_TRUE(real, str, value)   MCL_FUNCTION_EXC_IF_ENABLE((real), str, value)
 
#define MCL_FUNCTION_SET_IF_ELSE_TRUE(real, str, _if, _else)   MCL_FUNCTION_EXC_IF_ELSE_ENABLE((real), str, _if, _else)
 
#define MCL_ANGLE_MOD_X(down, up, val)
 Remainder of angle. More...
 
#define MCL_GET_ANGLE_DELTA(val, offset)
 Calculate the difference in angle, because the angle is then changed between 0-360 degrees, there are 350 degrees to 0 degrees of the process of change, as well as 10 degrees to 360 degrees of the process of change, in this process, the actual angle change is 10 degrees, but it may be calculated as 350 degrees, so the role of the calculation is to strive for an angle value of 10 degrees, the offset value of the maximum angle value, the default is 2pi. More...
 
#define MCL_VALUE_LIMIT(val, min, max)
 Data Range Limits. More...
 
#define MCL_GET_ADC_12BIT_VALID_DATA(x)   ((x & 0xffff) >> 4)
 Get ADC data with 12bit valid bits. More...
 
#define MCL_USEC_TO_HZ(usec)   (1000000.0f / (usec))
 Macro to convert microseconds period to frequency in Hertz. The macro takes an unsigned integer representing a time period in microseconds, and returns the corresponding frequency as a floating-point number. More...
 
#define MCL_PERIOD_TO_FREQUENCY(period)   (1.0f / (period))
 Macro to convert a time period in seconds to frequency in Hertz (Hz). The macro takes a floating-point number representing a time period in seconds, and returns the corresponding frequency as a floating-point number. More...
 
#define MCL_FREQUENCY_TO_PERIOD(frequency)   (1.0f / (frequency))
 Macro to convert a frequency in Hertz (Hz) to a time period in seconds. The macro takes a floating-point number representing a frequency in Hertz. More...
 
#define MCL_USEC_TO_SEC(usec)   ((usec) / 1000000.0f)
 Converts microseconds (us) to seconds (s). More...
 
#define MCL_USEC_TO_MSEC(usec)   ((usec) / 1000.0f)
 Converts microseconds (us) to milliseconds (ms). More...
 

Typedefs

typedef uint32_t hpm_mcl_stat_t
 

Enumerations

enum  {
  mcl_group_common = 0 , mcl_group_motor = 1 , mcl_group_encoder = 2 , mcl_group_analog = 3 ,
  mcl_group_drivers = 4
}
 
enum  {
  mcl_success = MAKE_STATUS(mcl_group_common, 0) , mcl_fail = MAKE_STATUS(mcl_group_common, 1) , mcl_invalid_argument = MAKE_STATUS(mcl_group_common, 2) , mcl_invalid_pointer = MAKE_STATUS(mcl_group_common, 3) ,
  mcl_timeout = MAKE_STATUS(mcl_group_common, 4) , mcl_in_development = MAKE_STATUS(mcl_group_common, 5) , mcl_running = MAKE_STATUS(mcl_group_common, 6)
}
 

Functions

void mcl_user_delay_us (uint64_t tick)
 user define code More...
 

Macro Definition Documentation

◆ MCL_2PI

#define MCL_2PI   HPM_2_PI

◆ MCL_ANGLE_MOD_X

#define MCL_ANGLE_MOD_X (   down,
  up,
  val 
)
Value:
({ \
float val_; \
if ((val) > up) { \
val_ = (val); \
do { \
val_ = (val_) - (up - down); \
} while ((val_) > up); \
} else if ((val) < down) { \
val_ = (val); \
do { \
val_ = (val_) + (up - down); \
} while ((val_) < down); \
} else { \
val_ = (val); \
} \
(val_); \
})

Remainder of angle.

◆ MCL_ASSERT

#define MCL_ASSERT (   x,
  return_errcode 
)    MCL_ASSERT_BOOL(((uint32_t)(x) != 0), MCL_EMPTY, return_errcode)

◆ MCL_ASSERT_BOOL

#define MCL_ASSERT_BOOL (   b,
  code_extend,
  errcode 
)
Value:
do { \
if (!b) { \
code_extend; \
MCL_DEBUG("errcode:%d, file:%s, line:%d.\r\n", errcode, __FILE__, __LINE__); \
return errcode; \
} \
} while (0)

◆ MCL_ASSERT_EXEC_CODE

#define MCL_ASSERT_EXEC_CODE (   x,
  code 
)    MCL_ASSERT_EXEC_CODE_BOOL((x), code)

◆ MCL_ASSERT_EXEC_CODE_AND_RETURN

#define MCL_ASSERT_EXEC_CODE_AND_RETURN (   x,
  code,
  return_errcode 
)    MCL_ASSERT_BOOL((x), code, return_errcode)

◆ MCL_ASSERT_EXEC_CODE_AND_RETURN_OPT

#define MCL_ASSERT_EXEC_CODE_AND_RETURN_OPT   MCL_ASSERT_EXEC_CODE_AND_RETURN

◆ MCL_ASSERT_EXEC_CODE_BOOL

#define MCL_ASSERT_EXEC_CODE_BOOL (   b,
  code_extend 
)
Value:
do { \
if (!b) { \
code_extend; \
} \
} while (0)

◆ MCL_ASSERT_EXEC_CODE_OPT

#define MCL_ASSERT_EXEC_CODE_OPT   MCL_ASSERT_EXEC_CODE

◆ MCL_ASSERT_OPT

#define MCL_ASSERT_OPT   MCL_ASSERT

◆ MCL_DEBUG

#define MCL_DEBUG   printf

◆ MCL_DELAY_MS

#define MCL_DELAY_MS (   x)    MCL_DELAY_US(1000*x)

◆ MCL_DELAY_US

#define MCL_DELAY_US (   x)    mcl_user_delay_us(x)

◆ MCL_EMPTY

#define MCL_EMPTY

◆ MCL_FREQUENCY_TO_PERIOD

#define MCL_FREQUENCY_TO_PERIOD (   frequency)    (1.0f / (frequency))

Macro to convert a frequency in Hertz (Hz) to a time period in seconds. The macro takes a floating-point number representing a frequency in Hertz.

◆ MCL_FUNCTION_EXC_IF_ELSE_ENABLE

#define MCL_FUNCTION_EXC_IF_ELSE_ENABLE (   b,
  str_f,
  _if,
  _else 
)
Value:
do { \
if (b) { \
str_f = _if; \
} else { \
str_f = _else; \
} \
} while (0)

◆ MCL_FUNCTION_EXC_IF_ENABLE

#define MCL_FUNCTION_EXC_IF_ENABLE (   b,
  str_f,
 
)
Value:
do { \
if (b) { \
str_f = f; \
} \
} while (0)

◆ MCL_FUNCTION_INIT_IF_EMPTY

#define MCL_FUNCTION_INIT_IF_EMPTY (   str_function,
  function 
)    MCL_FUNCTION_EXC_IF_ENABLE((str_function == NULL), str_function, function)

◆ MCL_FUNCTION_INIT_IF_NO_EMPTY

#define MCL_FUNCTION_INIT_IF_NO_EMPTY (   function,
  str_function 
)    MCL_FUNCTION_EXC_IF_ENABLE((str_function != NULL), function, str_function)

◆ MCL_FUNCTION_SET_IF_ELSE_TRUE

#define MCL_FUNCTION_SET_IF_ELSE_TRUE (   real,
  str,
  _if,
  _else 
)    MCL_FUNCTION_EXC_IF_ELSE_ENABLE((real), str, _if, _else)

◆ MCL_GET_ADC_12BIT_VALID_DATA

#define MCL_GET_ADC_12BIT_VALID_DATA (   x)    ((x & 0xffff) >> 4)

Get ADC data with 12bit valid bits.

◆ MCL_GET_ANGLE_DELTA

#define MCL_GET_ANGLE_DELTA (   val,
  offset 
)
Value:
({ \
float val_; \
float temp; \
val_ = 0; \
temp = 0; \
if ((val) > 0) { \
temp = (val) - offset; \
} else if ((val) < 0) { \
temp = (val) + offset; \
} else { \
val_ = 0; \
} \
if (fabs(val) < fabs(temp)) { \
val_ = val; \
} else {\
val_ = temp; \
} \
(val_); \
})

Calculate the difference in angle, because the angle is then changed between 0-360 degrees, there are 350 degrees to 0 degrees of the process of change, as well as 10 degrees to 360 degrees of the process of change, in this process, the actual angle change is 10 degrees, but it may be calculated as 350 degrees, so the role of the calculation is to strive for an angle value of 10 degrees, the offset value of the maximum angle value, the default is 2pi.

◆ MCL_PERIOD_TO_FREQUENCY

#define MCL_PERIOD_TO_FREQUENCY (   period)    (1.0f / (period))

Macro to convert a time period in seconds to frequency in Hertz (Hz). The macro takes a floating-point number representing a time period in seconds, and returns the corresponding frequency as a floating-point number.

◆ MCL_PI

#define MCL_PI   HPM_PI

◆ MCL_PI_DIV3

#define MCL_PI_DIV3   (MCL_PI / 3.0f)

◆ MCL_STATUS_SET_IF_TRUE

#define MCL_STATUS_SET_IF_TRUE (   real,
  str,
  status 
)    MCL_FUNCTION_EXC_IF_ENABLE((real), str, status)

◆ MCL_USEC_TO_HZ

#define MCL_USEC_TO_HZ (   usec)    (1000000.0f / (usec))

Macro to convert microseconds period to frequency in Hertz. The macro takes an unsigned integer representing a time period in microseconds, and returns the corresponding frequency as a floating-point number.

◆ MCL_USEC_TO_MSEC

#define MCL_USEC_TO_MSEC (   usec)    ((usec) / 1000.0f)

Converts microseconds (us) to milliseconds (ms).

This macro takes an unsigned integer or floating-point number representing a time period in microseconds and returns the corresponding time period as a floating-point number in milliseconds.

◆ MCL_USEC_TO_SEC

#define MCL_USEC_TO_SEC (   usec)    ((usec) / 1000000.0f)

Converts microseconds (us) to seconds (s).

This macro takes an unsigned integer or floating-point number representing a time period in microseconds and returns the corresponding time period as a floating-point number in seconds.

◆ MCL_VALUE_LIMIT

#define MCL_VALUE_LIMIT (   val,
  min,
  max 
)
Value:
do { \
if ((val) > (max)) { \
val = max; \
} else if ((val) < (min)) { \
val = min; \
} \
} while (0)

Data Range Limits.

◆ MCL_VALUE_SET_IF_TRUE

#define MCL_VALUE_SET_IF_TRUE (   real,
  str,
  value 
)    MCL_FUNCTION_EXC_IF_ENABLE((real), str, value)

Typedef Documentation

◆ hpm_mcl_stat_t

typedef uint32_t hpm_mcl_stat_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
mcl_group_common 
mcl_group_motor 
mcl_group_encoder 
mcl_group_analog 
mcl_group_drivers 

◆ anonymous enum

anonymous enum
Enumerator
mcl_success 
mcl_fail 
mcl_invalid_argument 
mcl_invalid_pointer 
mcl_timeout 
mcl_in_development 

Functions under development

mcl_running 

Function Documentation

◆ mcl_user_delay_us()

void mcl_user_delay_us ( uint64_t  tick)

user define code