1212 * from the real FRC2 timer ISR handler and calls former ISR handler.
1313 * So, timer callbacks are called from the task context rather than an interrupt.
1414 *
15- * Modifications from the original reverese engineered version:
15+ * Modifications from the original reverse engineered version:
1616 * - FreeRTOS queue is replaced with Task notifications.
17- * - Removed unknown queue lenght monitoring and parameters allocation.
17+ * - Removed unknown queue length monitoring and parameters allocation.
1818 * - Removed unused debug variables
1919 * - xTaskGenericCreate is replaced with xTaskCreate
20+ * - simplified time to ticks conversion (simply multiply by 5)
2021 *
21- * This timer should be used with coution together with other tasks. As the
22+ * This timer should be used with caution together with other tasks. As the
2223 * timer callback is executed within timer task context, access to data that
2324 * other tasks accessing should be protected.
2425 */
@@ -175,20 +176,9 @@ void sdk_ets_timer_arm_ms_us(ets_timer_t *timer, uint32_t value,
175176 }
176177
177178 if (value_in_ms ) {
178- value *= 1000 ;
179- }
180-
181- if (value != 0 ) {
182- // Why to do multiplication for values greater than 858
183- // and do 'shift and add' for other?
184- // What is the magic number 858 ?
185- if (858 < value ) {
186- ticks = (value << 2 ) + value ; // ticks = value * 5
187- } else {
188- // It is the same as just multiply by 5
189- // No idea why to do it this way
190- ticks = (value * 5000000 ) / 1000000 ;
191- }
179+ ticks = value * 5000 ;
180+ } else {
181+ ticks = value * 5 ;
192182 }
193183
194184 if (repeat_flag ) {
@@ -206,6 +196,13 @@ void sdk_ets_timer_arm(ets_timer_t *timer, uint32_t milliseconds,
206196 /*value in ms=*/ true);
207197}
208198
199+ void sdk_ets_timer_arm_us (ets_timer_t * timer , uint32_t useconds ,
200+ bool repeat_flag )
201+ {
202+ sdk_ets_timer_arm_ms_us (timer , useconds , repeat_flag ,
203+ /*value in ms=*/ false);
204+ }
205+
209206/**
210207 * Function removes a timer from the pending timers list.
211208 */
@@ -233,9 +230,8 @@ void sdk_ets_timer_disarm(ets_timer_t *timer)
233230
234231/**
235232 * Check the list of pending timers for expired ones and process them.
236- * This function is not called from the interrupt regardless of its name.
237233 */
238- void IRAM sdk_ets_timer_handler_isr ()
234+ static inline void process_pending_timers ()
239235{
240236 vPortEnterCritical ();
241237 int32_t ticks = TIMER_FRC2 .COUNT ;
@@ -290,7 +286,7 @@ static void timer_task(void* param)
290286{
291287 while (true) {
292288 if (xTaskNotifyWait (0 , 0 , NULL , portMAX_DELAY ) == pdTRUE ) {
293- sdk_ets_timer_handler_isr ();
289+ process_pending_timers ();
294290 }
295291 }
296292}
0 commit comments