@@ -91,9 +91,6 @@ void pulsein_interrupt_handler(uint8_t channel) {
91
91
uint32_t current_count = tc -> COUNT16 .COUNT .reg ;
92
92
93
93
pulseio_pulsein_obj_t * self = get_eic_channel_data (channel );
94
- if (self -> len == 0 ) {
95
- update_background_ticks ();
96
- }
97
94
if (self -> first_edge ) {
98
95
self -> first_edge = false;
99
96
pulsein_set_config (self , false);
@@ -115,17 +112,14 @@ void pulsein_interrupt_handler(uint8_t channel) {
115
112
}
116
113
117
114
uint16_t i = (self -> start + self -> len ) % self -> maxlen ;
118
- self -> buffer [i ] = duration ;
119
- if (self -> len < self -> maxlen ) {
115
+ if (self -> len <= self -> maxlen ) {
120
116
self -> len ++ ;
121
117
} else {
122
- self -> start ++ ;
118
+ self -> errored_too_fast = true;
119
+ common_hal_mcu_enable_interrupts ();
120
+ return ;
123
121
}
124
- }
125
- if (!supervisor_background_tasks_ok () ) {
126
- common_hal_mcu_enable_interrupts ();
127
- mp_raise_RuntimeError (translate ("Input taking too long" ));
128
- return ;
122
+ self -> buffer [i ] = duration ;
129
123
}
130
124
self -> last_overflow = current_overflow ;
131
125
self -> last_count = current_count ;
@@ -161,6 +155,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self,
161
155
self -> start = 0 ;
162
156
self -> len = 0 ;
163
157
self -> first_edge = true;
158
+ self -> errored_too_fast = false;
164
159
165
160
if (refcount == 0 ) {
166
161
// Find a spare timer.
@@ -303,6 +298,10 @@ uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
303
298
if (self -> len == 0 ) {
304
299
mp_raise_IndexError (translate ("pop from an empty PulseIn" ));
305
300
}
301
+ if (self -> errored_too_fast ) {
302
+ self -> errored_too_fast = false;
303
+ mp_raise_RuntimeError (translate ("Input taking too long" ));
304
+ }
306
305
common_hal_mcu_disable_interrupts ();
307
306
uint16_t value = self -> buffer [self -> start ];
308
307
self -> start = (self -> start + 1 ) % self -> maxlen ;
0 commit comments