思澈科技软件开发工具包  2.20

Macros

#define CP_MATH_NORMAL   (2)
 
#define CP_MATH_CDE   (1)
 
#define CP_MATH_NORM_OP_SET_XY   (0)
 
#define CP_MATH_NORM_OP_SET_X   (0)
 
#define CP_MATH_NORM_OP_SET_Y   (1)
 
#define CP_MATH_NORM_OP_SET_ANGLE   (2)
 
#define CP_MATH_NORM_OP_SET_ITER_NUM   (3)
 
#define CP_MATH_NORM_OP_SET_SCALE   (4)
 
#define CP_MATH_NORM_OP_SET_MODE   (5)
 
#define CP_MATH_NORM_MODE_COS   (1)
 
#define CP_MATH_NORM_MODE_SIN   (2)
 
#define CP_MATH_NORM_MODE_ATAN   (3)
 
#define CP_MATH_NORM_MODE_MOD   (4)
 
#define CP_MATH_NORM_MODE_ANG   (5)
 
#define CP_MATH_NORM_MODE_ROT   (6)
 
#define CP_MATH_NORM_MODE_MUL   (7)
 
#define CP_MATH_NORM_MODE_DIV   (8)
 
#define CP_MATH_NORM_MODE_COSH   (9)
 
#define CP_MATH_NORM_MODE_SINH   (10)
 
#define CP_MATH_NORM_MODE_ATANH   (11)
 
#define CP_MATH_NORM_MODE_MODH   (12)
 
#define CP_MATH_NORM_MODE_ANGH   (13)
 
#define CP_MATH_NORM_MODE_SQRT   (14)
 
#define CP_MATH_NORM_MODE_EXP   (15)
 
#define CP_MATH_NORM_MODE_LN   (16)
 
#define CP_MATH_CDE_MODE_COS   (0)
 
#define CP_MATH_CDE_MODE_SIN   (0)
 
#define CP_MATH_CDE_MODE_ATAN   (0)
 
#define CP_MATH_CDE_MODE_MOD   (1)
 
#define CP_MATH_CDE_MODE_ANG   (2)
 
#define CP_MATH_CDE_MODE_ROT   (3)
 
#define CP_MATH_CDE_MODE_MUL   (4)
 
#define CP_MATH_CDE_MODE_DIV   (5)
 
#define CP_MATH_CDE_MODE_COSH   (6)
 
#define CP_MATH_CDE_MODE_SINH   (7)
 
#define CP_MATH_CDE_MODE_ATANH   (8)
 
#define CP_MATH_CDE_MODE_MODH   (9)
 
#define CP_MATH_CDE_MODE_ANGH   (10)
 
#define CP_MATH_CDE_MODE_SQRT   (11)
 
#define CP_MATH_CDE_MODE_EXP   (12)
 
#define CP_MATH_CDE_MODE_LN   (13)
 
#define CP_MATH_SET_XY(x, y)   __arm_mcrr(CP_MATH_NORMAL, CP_MATH_NORM_OP_SET_XY, (((uint64_t)((uint32_t)(y))) << 32) | ((uint32_t)(x)), 0)
 Move x and y to 64bit register, y is put in high 32bit and x is put in low 32bit. More...
 
#define CP_MATH_SET_X(x)   __arm_mcr(CP_MATH_NORMAL, CP_MATH_NORM_OP_SET_X, (x), 0, 0, 0)
 
#define CP_MATH_SET_Y(y)   __arm_mcr(CP_MATH_NORMAL, CP_MATH_NORM_OP_SET_Y, (y), 0, 0, 0)
 
#define CP_MATH_SET_ANGLE(angle)   __arm_mcr(CP_MATH_NORMAL, CP_MATH_NORM_OP_SET_ANGLE, (angle), 0, 1, 2)
 
#define CP_MATH_SET_ITER_NUM(num)   __arm_mcr(CP_MATH_NORMAL, CP_MATH_NORM_OP_SET_ITER_NUM, (num), 0, 1, 3)
 
#define CP_MATH_SET_SCALE(scale)   __arm_mcr(CP_MATH_NORMAL, CP_MATH_NORM_OP_SET_SCALE, (scale), 0, 0, 0)
 
#define CP_MATH_SET_MODE(mode)   __arm_mcr(CP_MATH_NORMAL, CP_MATH_NORM_OP_SET_MODE, (mode), 0, 1, 4)
 
#define CP_MATH_GET_RESULT_UINT64()   __arm_mrrc(CP_MATH_NORMAL, 0, 0)
 
#define CP_MATH_GET_SCALE_AND_VAL(arg_result, arg_scale, arg_val)
 
#define CP_MATH_CDE_MAKE_CTRL_CODE(mode, iter_num)   ((((uint8_t)mode) & 0xF) | (((uint8_t)iter_num & 0x1F) << 4))
 

Functions

__STATIC_INLINE uint32_t HAL_MATH_DisableInterrupt (void)
 
__STATIC_INLINE void HAL_MATH_EnableInterrupt (uint32_t mask)
 
__STATIC_INLINE void HAL_CP_CosSin (int32_t angle, int32_t *cos_val, int32_t *sin_val)
 Calculate cosine and sine of an angle. More...
 
__STATIC_INLINE int32_t HAL_CP_Sin (int32_t angle)
 Calculate sine of an angle. More...
 
__STATIC_INLINE int32_t HAL_CP_Atan (int8_t scale, int32_t data)
 Calculate arctangent formula: atan*pi=atan(data*(2^scale)) More...
 
__STATIC_INLINE void HAL_CP_Mod (int32_t x, int32_t y, int8_t *scale, int32_t *mod)
 Calculate magnitude(i.e. modulus) of the vector v=(x,y), formula: magnitude=mod*(2^scale)=sqrt(x^2 + y^2) More...
 
__STATIC_INLINE int32_t HAL_CP_Ang (int32_t x, int32_t y)
 Calculate phase angle of the vector v=(x,y), formula: angle*pi=arctangent(y/x) More...
 
__STATIC_INLINE void HAL_CP_Rot (int32_t x, int32_t y, int32_t angle, int32_t *x2, int32_t *y2)
 Calculate the rotated vector. More...
 
__STATIC_INLINE void HAL_CP_Mul (int32_t data0, int32_t data1, int8_t *scale, int32_t *val)
 Multiple data0 by data1 formula: val*(2^scale)=data0*data1. More...
 
__STATIC_INLINE void HAL_CP_Div (int32_t num, int32_t den, int8_t *scale, int32_t *val)
 Divide numeritor by denominator formula: num/den=val*(2^scale) More...
 
__STATIC_INLINE void HAL_CP_Cosh (int8_t scale, int32_t angle, int8_t *output_scale, int32_t *cosh)
 Calculate cosineh of an angle formula: cosh*(2^output_scale)=cosh(angle*(2^scale)), angle*(2^scale) range is (-1.118, 1.118) More...
 
__STATIC_INLINE void HAL_CP_Sinh (int8_t scale, int32_t angle, int8_t *output_scale, int32_t *sinh)
 Calculate sineh of an angle formula: sinh*(2^output_scale)=sinh(angle*(2^scale)), angle*(2^scale) range is (-1.118, 1.118) More...
 
__STATIC_INLINE void HAL_CP_Atanh (int32_t data, int8_t *scale, int32_t *atanh)
 Calculate atanh of data, data range is (-0.806, 0.806) formula: atanh*(2^scale)=atanh(data) More...
 
__STATIC_INLINE void HAL_CP_Modh (int32_t x, int32_t y, int8_t *scale, int32_t *modh)
 Calculate sqrt(x^2-y^2) modh*(2^scale)=sqrt(x^2-y^2), x range is (-1, 1), y range is (-0.806, 0.806), and abs(x)>=abs(y) More...
 
__STATIC_INLINE void HAL_CP_Angh (int32_t x, int32_t y, int8_t *scale, int32_t *angh)
 Calculate arctanh(y/x) angh*(2^scale)=arctanh(y/x), x range is (-1, 1), y range is (-0.806, 0.806), and abs(x)>=abs(y) More...
 
__STATIC_INLINE void HAL_CP_Sqrt (int8_t input_scale, int32_t input_val, int8_t *output_scale, int32_t *output_val)
 Square root formula: output_val*(2^output_scale)=sqrt(input_val*(2^input_scale)), input_val*(2^input_scale) range is (0.027, 2.34) More...
 
__STATIC_INLINE void HAL_CP_Exp (int8_t input_scale, int32_t input_val, int8_t *output_scale, int32_t *output_val)
 Exp of the given value formula: output_val*(2^output_scale)=exp(input_val*(2^input_scale)), input_val*(2^input_scale) range is (-1.118, 1.118) More...
 
__STATIC_INLINE void HAL_CP_Ln (int8_t input_scale, int32_t input_val, int8_t *output_scale, int32_t *output_val)
 Ln of the given value formula: output_val*(2^output_scale)=ln(input_val*(2^input_scale)), input_val*(2^input_scale) range is (0.107, 9.35) More...
 

Detailed Description

Macro Definition Documentation

◆ CP_MATH_CDE

#define CP_MATH_CDE   (1)

coprocessor used by CDE

◆ CP_MATH_GET_SCALE_AND_VAL

#define CP_MATH_GET_SCALE_AND_VAL (   arg_result,
  arg_scale,
  arg_val 
)
Value:
do \
{ \
if (arg_scale) \
{ \
*arg_scale = (int8_t)((arg_result >> 32) & UINT8_MAX); \
} \
if (arg_val) \
{ \
*arg_val = (int32_t)(arg_result & UINT32_MAX); \
} \
} \
while (0)

◆ CP_MATH_NORMAL

#define CP_MATH_NORMAL   (2)

normal coprocessor for math

◆ CP_MATH_SET_XY

#define CP_MATH_SET_XY (   x,
 
)    __arm_mcrr(CP_MATH_NORMAL, CP_MATH_NORM_OP_SET_XY, (((uint64_t)((uint32_t)(y))) << 32) | ((uint32_t)(x)), 0)

Move x and y to 64bit register, y is put in high 32bit and x is put in low 32bit.

Parameters
[in]xx value
[in]yy value
Returns
void

Function Documentation

◆ HAL_CP_Ang()

__STATIC_INLINE int32_t HAL_CP_Ang ( int32_t  x,
int32_t  y 
)

Calculate phase angle of the vector v=(x,y), formula: angle*pi=arctangent(y/x)

Parameters
[in]xx coordinate, Q1.31 format
[in]yy coordinate, Q1.31 format
Return values
anglein radians devided by pi, range is [-1,1] which is mapped to [-pi, pi]

◆ HAL_CP_Angh()

__STATIC_INLINE void HAL_CP_Angh ( int32_t  x,
int32_t  y,
int8_t *  scale,
int32_t *  angh 
)

Calculate arctanh(y/x) angh*(2^scale)=arctanh(y/x), x range is (-1, 1), y range is (-0.806, 0.806), and abs(x)>=abs(y)

Parameters
[in]xx coordinate, Q1.31 format
[in]yy coordinate, Q1.31 format
[out]scalepoints to output scaling factor in Q8.0 format
[out]anghpoints to output angh, Q1.31 format
Returns
void

◆ HAL_CP_Atan()

__STATIC_INLINE int32_t HAL_CP_Atan ( int8_t  scale,
int32_t  data 
)

Calculate arctangent formula: atan*pi=atan(data*(2^scale))

Parameters
[in]scalescaling factor, range is [0,12]
[in]datadata in Q1.31 format
Return values
arctangentin radians, divided by pi, Q1.31 format, range is [-1, 1] which is mapped to [-pi, pi]

◆ HAL_CP_Atanh()

__STATIC_INLINE void HAL_CP_Atanh ( int32_t  data,
int8_t *  scale,
int32_t *  atanh 
)

Calculate atanh of data, data range is (-0.806, 0.806) formula: atanh*(2^scale)=atanh(data)

Parameters
[in]datadata in Q1.31 format
[out]scalepoints to output scaling factor, Q8.0 format, range is [0, 1]
[out]atanhpoints to output atanh value
Returns
void

◆ HAL_CP_Cosh()

__STATIC_INLINE void HAL_CP_Cosh ( int8_t  scale,
int32_t  angle,
int8_t *  output_scale,
int32_t *  cosh 
)

Calculate cosineh of an angle formula: cosh*(2^output_scale)=cosh(angle*(2^scale)), angle*(2^scale) range is (-1.118, 1.118)

Parameters
[in]scalescaling factor, Q8.0 format, range is [0, 1]
[in]angleangle in Q1.31 format, range: [-1, 1)
[out]output_scalepoints to output scaling factor, Q8.0 format, range is [0, 1]
[out]coshpoints to output cosh value
Returns
void

◆ HAL_CP_CosSin()

__STATIC_INLINE void HAL_CP_CosSin ( int32_t  angle,
int32_t *  cos_val,
int32_t *  sin_val 
)

Calculate cosine and sine of an angle.

Parameters
[in]angleangle in radians, devided by pi, Q1.31 format, range: [-1, 1], it's mapped to [-pi, pi]
[out]cos_valcosine of the angle, Q1.31 format
[out]sin_valsine of the angle, Q1.31 format
Return values
cosinevalue

◆ HAL_CP_Div()

__STATIC_INLINE void HAL_CP_Div ( int32_t  num,
int32_t  den,
int8_t *  scale,
int32_t *  val 
)

Divide numeritor by denominator formula: num/den=val*(2^scale)

Parameters
[in]numnumerator in Q1.31 format
[in]dendenominator in Q1.31 format
[out]scalepoints to scaling factor, Q8.0 format, range is [-30,30]
[out]valpoints to output vallue, Q1.31 format
Returns
void

◆ HAL_CP_Exp()

__STATIC_INLINE void HAL_CP_Exp ( int8_t  input_scale,
int32_t  input_val,
int8_t *  output_scale,
int32_t *  output_val 
)

Exp of the given value formula: output_val*(2^output_scale)=exp(input_val*(2^input_scale)), input_val*(2^input_scale) range is (-1.118, 1.118)

Parameters
[in]input_scaleinput scaling factor in Q8.0 format, range is [0, 1]
[in]input_valinput value in Q1.31 format
[out]output_scaleponits to output scaling factor in Q8.0 format, range is [0, 2]
[out]output_valpoints to output value in Q1.31 format
Returns
void

◆ HAL_CP_Ln()

__STATIC_INLINE void HAL_CP_Ln ( int8_t  input_scale,
int32_t  input_val,
int8_t *  output_scale,
int32_t *  output_val 
)

Ln of the given value formula: output_val*(2^output_scale)=ln(input_val*(2^input_scale)), input_val*(2^input_scale) range is (0.107, 9.35)

Parameters
[in]input_scaleinput scaling factor in Q8.0 format, range is [0, 4]
[in]input_valinput value in Q1.31 format
[out]output_scaleponits to output scaling factor in Q8.0 format, range is [1, 2]
[out]output_valpoints to output value in Q1.31 format
Returns
void

◆ HAL_CP_Mod()

__STATIC_INLINE void HAL_CP_Mod ( int32_t  x,
int32_t  y,
int8_t *  scale,
int32_t *  mod 
)

Calculate magnitude(i.e. modulus) of the vector v=(x,y), formula: magnitude=mod*(2^scale)=sqrt(x^2 + y^2)

Parameters
[in]xx coordinate, Q1.31 format
[in]yy coordinate, Q1.31 format
[out]scalepoints to output scaling value, range is [-30, 1]
[out]modpoints to output modulus, Q1.31 format
Return values
void

◆ HAL_CP_Modh()

__STATIC_INLINE void HAL_CP_Modh ( int32_t  x,
int32_t  y,
int8_t *  scale,
int32_t *  modh 
)

Calculate sqrt(x^2-y^2) modh*(2^scale)=sqrt(x^2-y^2), x range is (-1, 1), y range is (-0.806, 0.806), and abs(x)>=abs(y)

Parameters
[in]xx coordinate, Q1.31 format
[in]yy coordinate, Q1.31 format
[out]scalepoints to output scaling factor in Q8.0 format
[out]modhpoints to output modulush, Q1.31 format
Returns
void

◆ HAL_CP_Mul()

__STATIC_INLINE void HAL_CP_Mul ( int32_t  data0,
int32_t  data1,
int8_t *  scale,
int32_t *  val 
)

Multiple data0 by data1 formula: val*(2^scale)=data0*data1.

Parameters
[in]data0data0 in Q1.31 format
[in]data1data1 in Q1.31 format
[out]scalepoints to scaling factor, Q8.0 format, range is [-60,0]
[out]valpoints to output value, Q1.31 format
Returns
void

◆ HAL_CP_Rot()

__STATIC_INLINE void HAL_CP_Rot ( int32_t  x,
int32_t  y,
int32_t  angle,
int32_t *  x2,
int32_t *  y2 
)

Calculate the rotated vector.

Parameters
[in]xx coordinate, Q1.31 format, range is (-0.707, 0.707)
[in]yy coordinate, Q1.31 format, range is (-0.707, 0.707)
[in]angleangle in radians, devided by pi, Q1.31 format, range: [-1, 1], which is mapped to [-pi, pi]
[out]x2points to x coordinate of the rotated vector
[out]y2points to y coordinate of the rotated vector
Returns
void

◆ HAL_CP_Sin()

__STATIC_INLINE int32_t HAL_CP_Sin ( int32_t  angle)

Calculate sine of an angle.

Parameters
[in]angleangle in radians, devided by pi, Q1.31 format, range: [-1, 1], it's mapped to [-pi, pi]
Return values
sinevalue in Q1.31 format

◆ HAL_CP_Sinh()

__STATIC_INLINE void HAL_CP_Sinh ( int8_t  scale,
int32_t  angle,
int8_t *  output_scale,
int32_t *  sinh 
)

Calculate sineh of an angle formula: sinh*(2^output_scale)=sinh(angle*(2^scale)), angle*(2^scale) range is (-1.118, 1.118)

Parameters
[in]scalescaling factor, Q8.0 format, range is [0,1]
[in]angleangle in Q1.31 format, range: [-1, 1)
[out]output_scalepoints to output scaling factor, Q8.0 format, range is [0, 1]
[out]sinhpoints to output sinh value
Returns
void

◆ HAL_CP_Sqrt()

__STATIC_INLINE void HAL_CP_Sqrt ( int8_t  input_scale,
int32_t  input_val,
int8_t *  output_scale,
int32_t *  output_val 
)

Square root formula: output_val*(2^output_scale)=sqrt(input_val*(2^input_scale)), input_val*(2^input_scale) range is (0.027, 2.34)

Parameters
[in]input_scaleinput scaling factor in Q8.0 format, range is [0, 2]
[in]input_valinput value in Q1.31 format
[out]output_scaleponits to output scaling factor in Q8.0 format, range is [0, 2]
[out]output_valpoints to output value in Q1.31 format
Returns
void