|
35 | 35 |
|
36 | 36 | static TIM_HandleTypeDef TimMasterHandle; |
37 | 37 | static int us_ticker_inited = 0; |
38 | | -static bool us_ticker_stabilized = false; |
39 | 38 |
|
40 | 39 | volatile uint16_t SlaveCounter = 0; |
41 | 40 | volatile uint32_t oc_int_part = 0; |
@@ -64,32 +63,24 @@ uint32_t us_ticker_read() |
64 | 63 |
|
65 | 64 | if (!us_ticker_inited) us_ticker_init(); |
66 | 65 |
|
67 | | - // There's a situation where the first tick still may overflow and to avoid |
68 | | - // it we need to check if our ticker has stabilized and due to that we need |
69 | | - // to return only the lower part of your 32 bit software timer. |
70 | | - if (us_ticker_stabilized) { |
71 | | - do { |
72 | | - // For some reason on L0xx series we need to read and clear the |
73 | | - // overflow flag which give extra time to propelry handle possible |
74 | | - // hiccup after ~60s |
75 | | - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF) == SET) { |
76 | | - __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF); |
77 | | - } |
78 | | - cntH_old = SlaveCounter; |
79 | | - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { |
80 | | - cntH_old += 1; |
81 | | - } |
82 | | - cntL = TIM_MST->CNT; |
83 | | - |
84 | | - cntH = SlaveCounter; |
85 | | - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { |
86 | | - cntH += 1; |
87 | | - } |
88 | | - } while(cntH_old != cntH); |
89 | | - } else { |
90 | | - us_ticker_stabilized = true; |
91 | | - return (uint32_t) TIM_MST->CNT; |
92 | | - } |
| 66 | + do { |
| 67 | + // For some reason on L0xx series we need to read and clear the |
| 68 | + // overflow flag which give extra time to propelry handle possible |
| 69 | + // hiccup after ~60s |
| 70 | + if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF) == SET) { |
| 71 | + __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF); |
| 72 | + } |
| 73 | + cntH_old = SlaveCounter; |
| 74 | + if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { |
| 75 | + cntH_old += 1; |
| 76 | + } |
| 77 | + cntL = TIM_MST->CNT; |
| 78 | + |
| 79 | + cntH = SlaveCounter; |
| 80 | + if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { |
| 81 | + cntH += 1; |
| 82 | + } |
| 83 | + } while(cntH_old != cntH); |
93 | 84 |
|
94 | 85 | // Glue the upper and lower part together to get a 32 bit timer |
95 | 86 | return (uint32_t)(cntH << 16 | cntL); |
|
0 commit comments