tool.c 2.1 KB

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