分享

STM32 时间戳

 心不留意外尘 2016-12-11
http://blog.csdn.net/liang890319/article/details/52456224
2016
  1.     typedef _BYTE uint8_t;  
  2.     typedef _WORD uint16_t;  
  3.     typedef _DWORD uint32_t;  
  4.       
  5. //---------------------------------------------------------  
  6. //定时器3更新中断  
  7. //---------------------------------------------------------  
  8. int Timer3_int_handle(void)  
  9. {  
  10.     //控制IO PORTB  PORTA   TIM9  TIM4  
  11.     return 1;  
  12. }  
  13.   
  14. //---------------------------------------------------------  
  15. //定时器4更新中断  
  16. //---------------------------------------------------------  
  17. int Timer4_int_handle(void)  
  18. {  
  19. {  
  20.   int result; // r0@1  
  21.   
  22. //  sub_800E3EA(1073809408, 64);  
  23. //  sub_800764E(1073872896, 0x8000);  
  24. //  result = (unsigned __int8)byte_20000B11;  
  25. //  if ( !byte_20000B11 )  
  26. //    result = sub_800764E(1073873920, 256);  
  27.   return result;  
  28.   
  29. }  
  30.   
  31. //----------------------------------------  
  32. //  
  33. //定时器2更新中断  
  34. //  
  35. //---------------------------------------------------------  
  36. unsigned long dword_20000B64=0;  
  37. int Timer2_int_handle(void)  
  38. {  
  39.   
  40.  int *result; // r0@1  
  41.   
  42.   result = &dword_20000B64;  
  43.   dword_20000B64 += 0x10000;  
  44.       
  45.     Gen_time12(1);  
  46.     Gen_time34();  
  47.       
  48.   return result;  
  49.    
  50. }  
  51. //  
  52. //  
  53. //  
  54. //  
  55. int get_counter1_cntORb64()  
  56. {  
  57.   int v0; // r5@1  
  58.   unsigned int v1; // r0@1  
  59.   int result; // r0@3  
  60.   
  61.   v0 = dword_20000B64;  
  62.   __dmb();  
  63.   v1 = get_timer2reg_cnt();  
  64.   __dmb();  
  65.   if ( v0 != dword_20000B64 && v1 >> 15 )  
  66.     result = v1 | v0;  
  67.   else  
  68.     result = v1 | dword_20000B64;  
  69.   return result;  
  70. }  
  71.   
  72.   
  73. //---------------------------------------------------------  
  74. //定时器2CCR3中断  
  75. //产生时间戳12    INPUT:var_BCF  
  76. //---------------------------------------------------------  
  77. unsigned long dword_20000B90=0;  
  78. unsigned long dword_20000B94=0;  
  79. unsigned char unk_200009C8[32]={0};  
  80.   
  81. int Gen_time12(int a1){  
  82.    
  83.   int v1; // r4@1  
  84.   char *v2; // r6@1  
  85.   unsigned int v3; // r0@1  
  86.   unsigned __int16 v4; // r7@1  
  87.   int v5; // r0@1  
  88.   
  89.   v1 = a1;  
  90.   v2 = (char *)&unk_200009C8 + 8 * (((uint8_t)dword_20000B90 + 1) & 3);  
  91.   *((uint16_t *)v2 + 2) = dword_20000B90 + 1;  
  92.       
  93.   v3 = get_counter1_cntORb64();  //reg cnt || var_B64  
  94.   v4 = v3;  
  95.   v5 = get_ccr3_reg() | (v3 >> 16 << 16);  
  96.   if ( v1 && v4 < (unsigned int) v5 )    v5 -= 0x10000;  
  97.   *(uint16_t *)v2 = v5;  
  98.   return dword_20000B90++ + 1;  
  99. }  
  100.   
  101.   
  102.   
  103. //  
  104. //  
  105. //  
  106. int   mem_cpy(int a1, char *a2, unsigned int a3)  
  107. {  
  108.   char v3; // t1@2  
  109.   char v5; // cf@7  
  110.   unsigned int i; // r2@7  
  111.   int v7; // r3@9  
  112.   int v8; // r12@9  
  113.   _DWORD *v9; // r0@9  
  114.   
  115.   while ( (_DWORD)a2 << 30 )  
  116.   {  
  117.     --a3;  
  118.     v3 = *a2++;  
  119.     *(_BYTE *)a1++ = v3;  
  120.     if ( !a3 )  break;  
  121.   }  
  122.   return sub_8007324(a1, (int)a2, a3);  
  123. }  
  124. //  
  125. //  
  126. //  
  127. //  
  128.  int   if_copy_timer12(int dstarr)  
  129. {  
  130.   int result; // r0@2  
  131.   
  132.   if ( *(uint16_t *)(dstarr + 4) == dword_20000B90 )   //除非定时器死了 否则不会相等?  
  133.   {  
  134.     result = 0;  
  135.   }  
  136.   else  
  137.   {  
  138.     mem_cpy(dstarr, &byte_200009C8[8 * (dword_20000B90 & 3)], 8u);  
  139.     result = 1;  
  140.   }  
  141.   return result;  
  142. }  
  143.   
  144. //  
  145. //  
  146. //  
  147. //  
  148.  int   prepare_timer12_data_8bytes(int a1)  
  149. {  
  150.    
  151.   int v2; // r8@1  
  152.   signed int v3; // r5@1  
  153.   int v9; // r2@17  
  154.   int v15; // [sp+Ch] [bp-24h]@11  
  155.   uint16_t v16; // [sp+10h] [bp-20h]@13  
  156.       
  157.    
  158.   v2 = a1;  
  159.   v3 = 0;  
  160.   
  161.   if ( if_copy_timer12((int)&v15) )  
  162.   {  
  163.       v9 = *(_DWORD *)&v16;  
  164.       *(_DWORD *)v2 = v15;  
  165.       *(_DWORD *)(v2 + 4) = v9;  
  166.       v3 = 1;  
  167.   }  
  168.   return v3;  
  169. }  
  170.   
  171. char  cpy_time12to_hidbuf(char *result)  
  172. {  
  173.         *(uint16_t *)(packet_buf+50) =  *((_WORD *)result + 2);  
  174.       *(uint32_t *)(packet_buf+52) =  *(_DWORD *)result;  
  175.   return 1;  
  176. }  
  177.   
  178.   
  179.   
  180.   
  181.   
  182.   
  183. //---------------------------------------------------------  
  184. //定时器2ccr2中断  
  185. //产生时间戳34    INPUT:var_BD0  
  186. //---------------------------------------------------------  
  187. unsigned long dword_200004EC=0;  
  188. unsigned char unk_20000988[64]={0};  
  189. int Gen_time34(int a1){  
  190.   
  191.   int v1; // r4@1  
  192.   char *v2; // r6@1  
  193.   unsigned int v3; // r0@1  
  194.   unsigned __int16 v4; // r7@1  
  195.   int v5; // r0@1  
  196.   
  197.   v1 = a1;  
  198.   v2 = (char *)&unk_20000988 + 8 * (((_BYTE)dword_200004EC + 1) & 3);  
  199.       
  200.   *((_DWORD *)v2 + 1) = dword_200004EC + 1;  
  201.   v3 = get_counter1_cntORb64();   //中断发生时cnt值  
  202.   v4 = v3;  
  203.   v5 = get_reg_ccr2() | (v3 >> 16 << 16);   //中断发生计时  
  204.   if ( v1 && (v4 < (uint16_t)v5 )  v5 -= 0x10000;  
  205.   *(_DWORD *)v2 = v5;  
  206.   return dword_200004EC++ + 1;  
  207. }  
  208.   
  209. //  
  210. //  
  211. //生成时间戳34的数据    
  212. //  
  213. signed int __fastcall prepare_timer34_data_8bytes(int dst_arr, int a2)  
  214. {  
  215.   int v2; // r4@1  
  216.   unsigned int v3; // r0@2  
  217.   signed int result; // r0@5  
  218.   char *v5; // r0@8  
  219.   int v6; // r11@8  
  220.   int v30; // [sp+18h] [bp-28h]@1  
  221.   
  222.   v30 = a2;  
  223.   v2 = dst_arr;  
  224.   if ( dword_200004EC == dword_200004F0 )   //若下次定时还没到 那么不更新时间戳  
  225.     v3 = 0;  
  226.   else  
  227.     v3 = 1;  
  228.    
  229.     if ( v3 ) dword_200004F0 = dword_200004EC;  
  230.     v5 = (char *)&unk_20000988 + 8 * (dword_200004F0 & 3);  
  231.       
  232.     *(_WORD *)v2        = *((_DWORD *)v5 + 1);  
  233.     *(_DWORD *)(v2 + 4) = *(_DWORD *)v5;  
  234.    
  235.   return 1;  
  236. }  
  237.   
  238. char unk_20000420[64]={0}  
  239.   
  240.    
  241. //  
  242. //把时间戳34数据拷贝到buf中准备发送  
  243. //  
  244. //  
  245. char  cpy_time34to_hidbuf(char *time34Buf)  
  246. {  
  247.   char *v1; // r8@1  
  248.   signed int v2; // r4@4  
  249.   char v3; // r1@4  
  250.   int v4; // r4@6  
  251.   int v5; // r10@7  
  252.   char *v6; // r1@9  
  253.   char *v7; // r0@9  
  254.   int v8; // r0@11  
  255.   char *result; // r0@13  
  256.   
  257.   v1 = time34Buf;  
  258.   if ( system_run_counter )  
  259.   {  
  260.     if ( (uint8_t)system_run_counter == 254 )  
  261.     {  
  262.       v2 = 0;  
  263.       v3 = 2 - 1;  
  264.       system_run_counter = v3;  
  265.       *(_WORD *)&byte_20000920[4] = *(_WORD *)time34Buf -v3; //arr[2]=4 time 2 byres  
  266.     }  
  267.   }  
  268.   else  
  269.   {  
  270.     *(_WORD *)&byte_20000920[4] = *(_WORD *)time34Buf;  //arr[2]=4 time stamp  
  271.   }  
  272.    
  273.   *(_DWORD *)&byte_20000920[*(_BYTE *)(dword_20000B48 + 7)] = *((_DWORD *)v1 + 1);  //arr[7]  //4bytes time  
  274.   *(_WORD *)&byte_20000920[*(_BYTE *)(v8 + 4)] = *((_WORD *)v1 + 4);                //arr[4]=6  temple  
  275.   ++system_run_counter;    //time34 cpy counter= main loop run counter  
  276.    
  277.   return 1;  
  278. }  
  279.   
  280. //  
  281. //  
  282. //  
  283. //  
  284. signed int data_packet_generate()  
  285. {  
  286.   int v0; // r0@1  
  287.   unsigned int v1; // r1@1  
  288.   unsigned int v2; // r0@1  
  289.   signed int v3; // r5@2  
  290.   int v4; // r6@2  
  291.   signed int v5; // r5@2  
  292.   char *v6; // r4@2  
  293.   unsigned int v7; // r4@4  
  294.   signed int v8; // r5@4  
  295.   int v9; // r7@7  
  296.   int v10; // r11@7  
  297.   int v11; // r1@7  
  298.   int v12; // r8@7  
  299.   int v13; // r1@7  
  300.   int v14; // r9@7  
  301.   int v15; // r6@8  
  302.   unsigned int v16; // r0@8  
  303.   
  304.   v0 = dword_20000B48;  
  305.   v1 = (unsigned __int8)system_run_counter;//time34 cpy counter= main loop run counter  
  306.   byte_20000920[3] = system_run_counter;//arr[1]   time34 cpy counter= main loop run counter  
  307.   v2 = *(_BYTE *)(v0 + 8);                                       //arr[8]  
  308.       
  309.   if ( v2 >= v1 )  
  310.   {  
  311.     if ( v1 == 1 )  
  312.     {  
  313.       LOBYTE(v7) = 1;  
  314.       v8 = 16;  
  315.       if ( v2 >= 2 )  
  316.       {  
  317.         do  
  318.         {  
  319.           sub_800D408(&byte_20000920[*(_BYTE *)(dword_20000B48 + 5)] + v8, 16, 0);//arr[5]=12  
  320.           v8 += 16;  
  321.           v7 = (unsigned __int8)(v7 + 1);  
  322.         }  
  323.         while ( v7 < *(_BYTE *)(dword_20000B48 + 8) );  //arr[8]=8  
  324.       }  
  325.     }  
  326.     v5 = 0;  
  327.     v6 = (char *)&unk_20000420;  
  328.   }  
  329.    
  330.   while ( 1 )  
  331.   {  
  332.     v15 = dword_20000B48;  
  333.     v16 = 2;  
  334.     if ( v16 >= (unsigned __int8)system_run_counter )  v16 = (unsigned __int8)system_run_counter;  
  335.     if ( v5 >= (signed int)v16 )  break;  
  336.     v9 = (int)&v6[36 * v5];  
  337.     v10 = accumulate_cast(*(_DWORD *)(v9 + 24), (unsigned __int8)system_run_counter);  
  338.     v12 = accumulate_cast(*(_DWORD *)(v9 + 28), v11);  
  339.     v14 = accumulate_cast(*(_DWORD *)(v9 + 32), v13);  
  340.     data_packet_pack_sensor(  
  341.       &byte_20000920[16 * v5] + *(_BYTE *)(v15 + 5),  
  342.       *(_DWORD *)(v9 + 12),  
  343.       *(_DWORD *)(v9 + 16),  
  344.       *(_DWORD *)(v9 + 20));  
  345.     data_packet_pack_sensor(&byte_20000920[16 * v5 + 8] + *(_BYTE *)(dword_20000B48 + 5), v10, v12, v14);  
  346.     v5 ++;  
  347.   }  
  348.       
  349.    USB_SIL_Write(EP1_IN, packet_buf, DATA_PACKET_SIZE);           //这个函数已经查看过,没有作其他处理  
  350.                                                                    //把数据发送出去  
  351.    // Mark that the endpoint has valid data  
  352.    SetEPTxValid(ENDP1);  
  353.   byte_20000BC1 = 0;   
  354.   system_run_counter = 0;  
  355.   return 1;  
  356. }  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多