MCPcopy Create free account
hub / github.com/MCUdude/MiniCore / recv

Method recv

avr/libraries/SoftwareSerial/src/SoftwareSerial.cpp:125–209  ·  view source on GitHub ↗

The receive routine called by the interrupt handler

Source from the content-addressed store, hash-verified

123// The receive routine called by the interrupt handler
124//
125void SoftwareSerial::recv()
126{
127
128#if GCC_VERSION < 40302
129// Work-around for avr-gcc 4.3.0 OSX version bug
130// Preserve the registers that the compiler misses
131// (courtesy of Arduino forum user *etracer*)
132 asm volatile(
133 "push r18 \n\t"
134 "push r19 \n\t"
135 "push r20 \n\t"
136 "push r21 \n\t"
137 "push r22 \n\t"
138 "push r23 \n\t"
139 "push r26 \n\t"
140 "push r27 \n\t"
141 ::);
142#endif
143
144 uint8_t d = 0;
145
146 // If RX line is high, then we don't see any start bit
147 // so interrupt is probably not for us
148 if (_inverse_logic ? rx_pin_read() : !rx_pin_read())
149 {
150 // Disable further interrupts during reception, this prevents
151 // triggering another interrupt directly after we return, which can
152 // cause problems at higher baudrates.
153 setRxIntMsk(false);
154
155 // Wait approximately 1/2 of a bit width to "center" the sample
156 tunedDelay(_rx_delay_centering);
157 DebugPulse(_DEBUG_PIN2, 1);
158
159 // Read each of the 8 bits
160 for (uint8_t i=8; i > 0; --i)
161 {
162 tunedDelay(_rx_delay_intrabit);
163 d >>= 1;
164 DebugPulse(_DEBUG_PIN2, 1);
165 if (rx_pin_read())
166 d |= 0x80;
167 }
168
169 if (_inverse_logic)
170 d = ~d;
171
172 // if buffer full, set the overflow flag and return
173 uint8_t next = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF;
174 if (next != _receive_buffer_head)
175 {
176 // save new data in buffer: tail points to where byte goes
177 _receive_buffer[_receive_buffer_tail] = d; // save new byte
178 _receive_buffer_tail = next;
179 }
180 else
181 {
182 DebugPulse(_DEBUG_PIN1, 1);

Callers 1

handle_interruptMethod · 0.80

Calls 1

DebugPulseFunction · 0.85

Tested by

no test coverage detected