KurtE
Senior Member+
I was playing around with some different stuff, and ran into an interesting issue.
And I am trying to decide if it is worth fixing.
Here is some quick typed in code (probably has errors) that will likely hang a teensy)
I
}
The HardwareSerial write9 function is protected from this hang, in the case that the Serial1
output buffer is filled and waiting for room to become available. In that case the write9 function, will
detect that it is running at a lower priority and then if the hardware port shows that the TDRE flag is set,
in which case it will stuff the data out into the DATA register.
But the HardwareSerial::flush()
simply:
And since the transmitting_ is cleared in the ISR which is at a lower priority it will not get called.
Also in this case it will call yield, in the write9 case it does not call yield if the current running code is running at a
priority >= 256. Which I am assuming is the main code ....
I guess the question is, is this worth fixing. Or is this simply a case of: doctor doctor, it hurts when I do ...
Kurt
And I am trying to decide if it is worth fixing.
Here is some quick typed in code (probably has errors) that will likely hang a teensy)
I
Code:
ntervalTimer mytimer;
void timer_function();
void setup() {
Serial1.begin(115200);
mytimer.priority(32);
mytimer.begin(&timer_function, 250000);
}
void loop()
{
}
void timer_function() {
Serial1.print("print from interval timer");
Serial1.flush(); // this will likely hang
The HardwareSerial write9 function is protected from this hang, in the case that the Serial1
output buffer is filled and waiting for room to become available. In that case the write9 function, will
detect that it is running at a lower priority and then if the hardware port shows that the TDRE flag is set,
in which case it will stuff the data out into the DATA register.
But the HardwareSerial::flush()
simply:
Code:
void HardwareSerial::flush(void)
{
while (transmitting_) yield(); // wait
}
Also in this case it will call yield, in the write9 case it does not call yield if the current running code is running at a
priority >= 256. Which I am assuming is the main code ....
I guess the question is, is this worth fixing. Or is this simply a case of: doctor doctor, it hurts when I do ...
Kurt