tool.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "tool.h"
  2. #include "bsp_time.h"
  3. #include "system.h"
  4. #if JS_RTT_DEBUG_EN
  5. char JS_RTT_UpBuffer[4096]; // J-Scope RTT Buffer
  6. int JS_RTT_Channel = 1; // J-Scope RTT Channel
  7. acValBuffer_t acValBuffer;
  8. void JS_RTT_Init(void)
  9. {
  10. SEGGER_RTT_ConfigUpBuffer(JS_RTT_Channel, "JScope_I4I4I4I4I4I4", &JS_RTT_UpBuffer[0], sizeof(JS_RTT_UpBuffer), SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
  11. }
  12. void JS_RTT_Print(signed int Sine1,signed int Sine2,signed int Sine3)
  13. {
  14. acValBuffer.Sine1 = Sine1;
  15. acValBuffer.Sine2 = Sine2;
  16. acValBuffer.Sine3 = Sine3;
  17. SEGGER_RTT_Write(JS_RTT_Channel, &acValBuffer, sizeof(acValBuffer));
  18. }
  19. void JS_RTT_Print_06(signed int Sine1,signed int Sine2,signed int Sine3,signed int Sine4,signed int Sine5,signed int Sine6)
  20. {
  21. acValBuffer.Sine1 = Sine1;
  22. acValBuffer.Sine2 = Sine2;
  23. acValBuffer.Sine3 = Sine3;
  24. acValBuffer.Sine4 = Sine4;
  25. acValBuffer.Sine5 = Sine5;
  26. acValBuffer.Sine6 = Sine6;
  27. SEGGER_RTT_Write(JS_RTT_Channel, &acValBuffer, sizeof(acValBuffer));
  28. }
  29. static void Tool_Process(void)
  30. {
  31. static uint32_t toogle = 60000;
  32. if(toogle == 60000)toogle = 1;
  33. else toogle = 60000;
  34. acValBuffer.Sine1 = toogle;
  35. // SEGGER_RTT_Write(JS_RTT_Channel, &acValBuffer, sizeof(acValBuffer));
  36. }
  37. #endif
  38. /**
  39. @brief 求变异系数的绝对值
  40. @param p_array-[in] 数组地址
  41. @param len-[in] 数组成员个数
  42. @return 变异系数的绝对值
  43. */
  44. float32_t CoefficientVariation(double *p_array, uint32_t len)
  45. {
  46. int i;
  47. float32_t sum = 0; //总和
  48. float32_t avg; //平均值
  49. float32_t spow = 0;
  50. for(i=0;i<len;i++)sum += p_array[i];//求总和
  51. avg = sum/len;//计算平均值
  52. for(i=0;i<len;i++)spow += (p_array[i]-avg)*(p_array[i]-avg);//平方累加
  53. float32_t standardDeviation=0,Coefficient_variation=0;
  54. // static char string[200];
  55. if(!arm_sqrt_f32((spow/len),&standardDeviation))
  56. {
  57. // sprintf(string,"standardDeviation:%f\r\n",standardDeviation);
  58. // SEGGER_RTT_printf(0,"%s",string);
  59. standardDeviation = (standardDeviation)/avg;
  60. arm_abs_f32(&standardDeviation,&Coefficient_variation,1);
  61. // sprintf(string,"Coefficient_variation:%f\r\n",Coefficient_variation);
  62. // SEGGER_RTT_printf(0,"%s",string);
  63. }
  64. return Coefficient_variation;
  65. }
  66. void Tool_Init(void)
  67. {
  68. #if JS_RTT_DEBUG_EN
  69. Process_Start(10,"Tool_Process",Tool_Process);
  70. JS_RTT_Init();
  71. #endif
  72. }