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... | |
#define CP_MATH_CDE (1) |
coprocessor used by CDE
#define CP_MATH_GET_SCALE_AND_VAL | ( | arg_result, | |
arg_scale, | |||
arg_val | |||
) |
#define CP_MATH_NORMAL (2) |
normal coprocessor for math
#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.
[in] | x | x value |
[in] | y | y value |
__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)
[in] | x | x coordinate, Q1.31 format |
[in] | y | y coordinate, Q1.31 format |
angle | in radians devided by pi, range is [-1,1] which is mapped to [-pi, pi] |
__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)
[in] | x | x coordinate, Q1.31 format |
[in] | y | y coordinate, Q1.31 format |
[out] | scale | points to output scaling factor in Q8.0 format |
[out] | angh | points to output angh, Q1.31 format |
__STATIC_INLINE int32_t HAL_CP_Atan | ( | int8_t | scale, |
int32_t | data | ||
) |
Calculate arctangent formula: atan*pi=atan(data*(2^scale))
[in] | scale | scaling factor, range is [0,12] |
[in] | data | data in Q1.31 format |
arctangent | in radians, divided by pi, Q1.31 format, range is [-1, 1] which is mapped to [-pi, pi] |
__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)
[in] | data | data in Q1.31 format |
[out] | scale | points to output scaling factor, Q8.0 format, range is [0, 1] |
[out] | atanh | points to output atanh value |
__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)
[in] | scale | scaling factor, Q8.0 format, range is [0, 1] |
[in] | angle | angle in Q1.31 format, range: [-1, 1) |
[out] | output_scale | points to output scaling factor, Q8.0 format, range is [0, 1] |
[out] | cosh | points to output cosh value |
__STATIC_INLINE void HAL_CP_CosSin | ( | int32_t | angle, |
int32_t * | cos_val, | ||
int32_t * | sin_val | ||
) |
Calculate cosine and sine of an angle.
[in] | angle | angle in radians, devided by pi, Q1.31 format, range: [-1, 1], it's mapped to [-pi, pi] |
[out] | cos_val | cosine of the angle, Q1.31 format |
[out] | sin_val | sine of the angle, Q1.31 format |
cosine | value |
__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)
[in] | num | numerator in Q1.31 format |
[in] | den | denominator in Q1.31 format |
[out] | scale | points to scaling factor, Q8.0 format, range is [-30,30] |
[out] | val | points to output vallue, Q1.31 format |
__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)
[in] | input_scale | input scaling factor in Q8.0 format, range is [0, 1] |
[in] | input_val | input value in Q1.31 format |
[out] | output_scale | ponits to output scaling factor in Q8.0 format, range is [0, 2] |
[out] | output_val | points to output value in Q1.31 format |
__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)
[in] | input_scale | input scaling factor in Q8.0 format, range is [0, 4] |
[in] | input_val | input value in Q1.31 format |
[out] | output_scale | ponits to output scaling factor in Q8.0 format, range is [1, 2] |
[out] | output_val | points to output value in Q1.31 format |
__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)
[in] | x | x coordinate, Q1.31 format |
[in] | y | y coordinate, Q1.31 format |
[out] | scale | points to output scaling value, range is [-30, 1] |
[out] | mod | points to output modulus, Q1.31 format |
void |
__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)
[in] | x | x coordinate, Q1.31 format |
[in] | y | y coordinate, Q1.31 format |
[out] | scale | points to output scaling factor in Q8.0 format |
[out] | modh | points to output modulush, Q1.31 format |
__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.
[in] | data0 | data0 in Q1.31 format |
[in] | data1 | data1 in Q1.31 format |
[out] | scale | points to scaling factor, Q8.0 format, range is [-60,0] |
[out] | val | points to output value, Q1.31 format |
__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.
[in] | x | x coordinate, Q1.31 format, range is (-0.707, 0.707) |
[in] | y | y coordinate, Q1.31 format, range is (-0.707, 0.707) |
[in] | angle | angle in radians, devided by pi, Q1.31 format, range: [-1, 1], which is mapped to [-pi, pi] |
[out] | x2 | points to x coordinate of the rotated vector |
[out] | y2 | points to y coordinate of the rotated vector |
__STATIC_INLINE int32_t HAL_CP_Sin | ( | int32_t | angle | ) |
Calculate sine of an angle.
[in] | angle | angle in radians, devided by pi, Q1.31 format, range: [-1, 1], it's mapped to [-pi, pi] |
sine | value in Q1.31 format |
__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)
[in] | scale | scaling factor, Q8.0 format, range is [0,1] |
[in] | angle | angle in Q1.31 format, range: [-1, 1) |
[out] | output_scale | points to output scaling factor, Q8.0 format, range is [0, 1] |
[out] | sinh | points to output sinh value |
__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)
[in] | input_scale | input scaling factor in Q8.0 format, range is [0, 2] |
[in] | input_val | input value in Q1.31 format |
[out] | output_scale | ponits to output scaling factor in Q8.0 format, range is [0, 2] |
[out] | output_val | points to output value in Q1.31 format |