FU68xx_5_MDU.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef __FU68XX_5_MDU_H__
  2. #define __FU68XX_5_MDU_H__
  3. #include <FU68xx_5_MCU.h>
  4. /**
  5. * @brief 运行SMDU且不等待运行结束
  6. *
  7. * @param stan (0-3) 要启动的计算单元编号
  8. * @param mode (0-7) 指定计算单元的模式, 可使用@see ETypeSMDUMode 作为计算模式的设置\n
  9. * @ref S1MUL 有符号乘法, 计算结果左移1位 \n
  10. * @ref SMUL 有符号乘法 \n
  11. * @ref UMUL 无符号乘法 \n
  12. * @ref DIV 32/16无符号除法 \n
  13. * @ref SIN_COS Sin/Cos \n
  14. * @ref ATAN ATan \n
  15. * @ref LPF 低通 \n
  16. * @ref PI PI \n
  17. */
  18. typedef enum
  19. {
  20. S1MUL = 0, /**< 有符号乘法, 计算结果左移1位 */
  21. SMUL = 1, /**< 有符号乘法 */
  22. UMUL = 2, /**< 无符号乘法 */
  23. DIV = 3, /**< 32/16无符号除法 */
  24. SIN_COS = 4, /**< Sin/Cos */
  25. ATAN = 5, /**< ATan */
  26. LPF = 6, /**< 低通滤波 */
  27. PI = 7 /**< PI */
  28. } ETypeSMDUMode;
  29. #define SMDU_RunNoBlock(stan, mode) do \
  30. { \
  31. MDU_CR = MDUSTA0 << stan | (unsigned char)mode; \
  32. } while (0)
  33. /**
  34. * @brief 运行SMDU且等待运行结束
  35. *
  36. * @param stan (0-3) 要启动的计算单元编号
  37. * @param mode (0-7) 指定计算单元的模式, 可使用@see ETypeSMDUMode 作为计算模式的设置\n
  38. * @ref S1MUL 有符号乘法, 计算结果左移1位 \n
  39. * @ref SMUL 有符号乘法 \n
  40. * @ref UMUL 无符号乘法 \n
  41. * @ref DIV 32/16无符号除法 \n
  42. * @ref SIN_COS Sin/Cos \n
  43. * @ref ATAN ATan \n
  44. * @ref LPF 低通 \n
  45. * @ref PI PI \n
  46. */
  47. #define SMDU_RunBlock(stan, mode) do \
  48. { \
  49. SMDU_RunNoBlock(stan, mode); \
  50. while ((MDU_CR & MDUBSY) == MDUBSY); \
  51. } while (0);
  52. #define MuiltS1_H_MDU(iA, iB, iCh) do \
  53. { \
  54. MUL0_MA = iA;MUL0_MB = iB; SMDU_RunBlock(0 , 0); iCh = MUL0_MCH; \
  55. } while (0);
  56. #define SinCos_MDU(iCos0, iTheta, iSin0, iCos, iSin) do \
  57. { \
  58. SCAT2_COS = iCos0;\
  59. SCAT2_THE = iTheta;\
  60. SCAT2_SIN = 0; \
  61. SMDU_RunBlock(2,4);\
  62. iSin = SCAT2_RES2 ;\
  63. iCos = SCAT2_RES1;\
  64. } while (0);
  65. #define LPF_MDU(iX, ucK, iYh, iYl) do { \
  66. LPF3_K = ucK;\
  67. LPF3_X = iX;\
  68. LPF3_YH = iYh;\
  69. LPF3_YL = iYl;\
  70. SMDU_RunBlock(3,6);\
  71. iYh = LPF3_YH;\
  72. iYl = LPF3_YL;\
  73. } while (0) ;
  74. #define SqrtI_alpbet(i_alp, i_bet, is) do { \
  75. SCAT0_COS = i_alp; \
  76. SCAT0_SIN = i_bet; \
  77. SMDU_RunBlock(0,5); \
  78. is = SCAT0_RES1; \
  79. } while (0) ;
  80. #define SqrtU_alpbet(u_alp, u_bet, us) do{ \
  81. SCAT1_COS = u_alp; \
  82. SCAT1_SIN = u_bet; \
  83. SMDU_RunBlock(1,5); \
  84. us = SCAT1_RES1; \
  85. } while (0) ;
  86. #endif