@@ -81,8 +81,9 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
81
81
memcpy (& stdio_uart , obj , sizeof (serial_t ));
82
82
}
83
83
84
- // Save transmit pin for break function
85
- obj -> tx_pin = tx ;
84
+ // Record the pins requested
85
+ obj -> tx = tx ;
86
+ obj -> rx = rx ;
86
87
87
88
// Merge pin function requests for use with CMSIS init func
88
89
ioman_req_t io_req = {0 };
@@ -249,26 +250,30 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
249
250
//******************************************************************************
250
251
int serial_getc (serial_t * obj )
251
252
{
252
- int c ;
253
+ int c = 0 ;
253
254
254
- // Wait for data to be available
255
- while ((obj -> uart -> rx_fifo_ctrl & MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY ) == 0 );
255
+ if (obj -> rx != NC ) {
256
+ // Wait for data to be available
257
+ while ((obj -> uart -> rx_fifo_ctrl & MXC_F_UART_RX_FIFO_CTRL_FIFO_ENTRY ) == 0 );
256
258
257
- c = obj -> fifo -> rx ;
259
+ c = obj -> fifo -> rx ;
260
+ }
258
261
259
262
return c ;
260
263
}
261
264
262
265
//******************************************************************************
263
266
void serial_putc (serial_t * obj , int c )
264
267
{
265
- // Wait for room in the FIFO without blocking interrupts.
266
- while (UART_NumWriteAvail (obj -> uart ) == 0 );
267
-
268
- // Must clear before every write to the buffer to know that the FIFO
269
- // is empty when the TX DONE bit is set
270
- obj -> uart -> intfl = MXC_F_UART_INTFL_TX_DONE ;
271
- obj -> fifo -> tx = (uint8_t )c ;
268
+ if (obj -> tx != NC ) {
269
+ // Wait for room in the FIFO without blocking interrupts.
270
+ while (UART_NumWriteAvail (obj -> uart ) == 0 );
271
+
272
+ // Must clear before every write to the buffer to know that the FIFO
273
+ // is empty when the TX DONE bit is set
274
+ obj -> uart -> intfl = MXC_F_UART_INTFL_TX_DONE ;
275
+ obj -> fifo -> tx = (uint8_t )c ;
276
+ }
272
277
}
273
278
274
279
//******************************************************************************
@@ -300,10 +305,10 @@ void serial_break_set(serial_t *obj)
300
305
while (!(obj -> uart -> intfl & MXC_F_UART_INTFL_TX_DONE ));
301
306
302
307
// Configure TX to output 0
303
- usurp_pin (obj -> tx_pin , 0 );
308
+ usurp_pin (obj -> tx , 0 );
304
309
305
310
// GPIO is setup now, but we need to unmap UART from the pin
306
- pin_function_t * pin_func = (pin_function_t * )pinmap_find_function (obj -> tx_pin , PinMap_UART_TX );
311
+ pin_function_t * pin_func = (pin_function_t * )pinmap_find_function (obj -> tx , PinMap_UART_TX );
307
312
* pin_func -> reg_req &= ~MXC_F_IOMAN_UART_REQ_IO_REQ ;
308
313
MBED_ASSERT ((* pin_func -> reg_ack & MXC_F_IOMAN_UART_ACK_IO_ACK ) == 0 );
309
314
}
@@ -312,9 +317,9 @@ void serial_break_set(serial_t *obj)
312
317
void serial_break_clear (serial_t * obj )
313
318
{
314
319
// Configure TX to output 1
315
- usurp_pin (obj -> tx_pin , 1 );
320
+ usurp_pin (obj -> tx , 1 );
316
321
// Return TX to UART control
317
- serial_pinout_tx (obj -> tx_pin );
322
+ serial_pinout_tx (obj -> tx );
318
323
}
319
324
320
325
//******************************************************************************
0 commit comments