14
14
You should have received a copy of the GNU Lesser General Public
15
15
License along with this library; if not, write to the Free Software
16
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
-
18
- Modified 23 November 2019 by Georg Icking-Konert
19
17
*/
20
18
21
19
#include < stdlib.h>
22
20
#include < stdio.h>
23
21
#include < string.h>
24
22
#include " UARTClass.h"
25
- #include " Arduino.h"
26
23
27
24
// Constructors ////////////////////////////////////////////////////////////////
28
25
@@ -34,9 +31,6 @@ UARTClass::UARTClass( Uart *pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer *p
34
31
_pUart=pUart;
35
32
_dwIrq=dwIrq;
36
33
_dwId=dwId;
37
-
38
- _isrRx = NULL ;
39
- _isrTx = NULL ;
40
34
}
41
35
42
36
// Public Methods //////////////////////////////////////////////////////////////
@@ -168,58 +162,17 @@ size_t UARTClass::write( const uint8_t uc_data )
168
162
{
169
163
// Bypass buffering and send character directly
170
164
_pUart->UART_THR = uc_data;
171
-
172
- // if custom routine attached, activate TXBUFE interrupt -> delay call until transmission finished
173
- // must be done here explicitely because UART_TXRDY interrupt is not activated here
174
- if (_isrTx != NULL ) {
175
- _pUart->UART_IER = UART_IER_TXEMPTY;
176
- }
177
165
}
178
-
179
166
return 1 ;
180
167
}
181
168
182
- void UARTClass::attachInterrupt_Receive ( isrRx_t fn )
183
- {
184
- // pause interrupts
185
- uint8_t oldISR = ((__get_PRIMASK () & 0x1 ) == 0 && (__get_FAULTMASK () & 0x1 ) == 0 ); noInterrupts ();
186
-
187
- // set custom function
188
- _isrRx = fn;
189
-
190
- // restore old interrupt setting
191
- if (oldISR != 0 ) { interrupts (); }
192
- }
193
-
194
- void UARTClass::attachInterrupt_Send ( isrTx_t fn )
195
- {
196
- // pause interrupts
197
- uint8_t oldISR = ((__get_PRIMASK () & 0x1 ) == 0 && (__get_FAULTMASK () & 0x1 ) == 0 ); noInterrupts ();
198
-
199
- // set custom function for TX empty
200
- _isrTx = fn;
201
-
202
- // restore old interrupt setting
203
- if (oldISR != 0 ) { interrupts (); }
204
- }
205
-
206
169
void UARTClass::IrqHandler ( void )
207
170
{
208
171
uint32_t status = _pUart->UART_SR ;
209
172
210
173
// Did we receive data?
211
- if ((status & UART_SR_RXRDY) == UART_SR_RXRDY) {
212
-
213
- // custom function was attached -> call it with data and status byte
214
- if (_isrRx) {
215
- _isrRx (_pUart->UART_RHR , status);
216
- }
217
- // no custom function attached -> store data in ring buffer
218
- else {
219
- _rx_buffer->store_char (_pUart->UART_RHR );
220
- }
221
-
222
- }
174
+ if ((status & UART_SR_RXRDY) == UART_SR_RXRDY)
175
+ _rx_buffer->store_char (_pUart->UART_RHR );
223
176
224
177
// Do we need to keep sending data?
225
178
if ((status & UART_SR_TXRDY) == UART_SR_TXRDY)
@@ -232,29 +185,11 @@ void UARTClass::IrqHandler( void )
232
185
{
233
186
// Mask off transmit interrupt so we don't get it anymore
234
187
_pUart->UART_IDR = UART_IDR_TXRDY;
235
-
236
- // if custom routine attached, activate TXBUFE interrupt -> delay call until transmission finished
237
- if (_isrTx != NULL ) {
238
- _pUart->UART_IER = UART_IER_TXEMPTY;
239
- }
240
- }
241
-
242
- }
243
-
244
- // Is data transmission finished? Used for call of attached custom function at end of transmission?
245
- if ((status & UART_SR_TXEMPTY) == UART_SR_TXEMPTY)
246
- {
247
- // Mask off interrupt so we don't get it anymore
248
- _pUart->UART_IDR = UART_IDR_TXEMPTY;
249
-
250
- // if custom routine attached, call it
251
- if (_isrTx != NULL ) {
252
- _isrTx ();
253
188
}
254
189
}
255
190
256
191
// Acknowledge errors
257
- if ((status & UART_SR_OVRE) == UART_SR_OVRE || (status & UART_SR_FRAME) == UART_SR_FRAME || (status & UART_SR_RXBRK) == UART_SR_RXBRK )
192
+ if ((status & UART_SR_OVRE) == UART_SR_OVRE || (status & UART_SR_FRAME) == UART_SR_FRAME)
258
193
{
259
194
// TODO: error reporting outside ISR
260
195
_pUart->UART_CR |= UART_CR_RSTSTA;
0 commit comments