MODSERIAL with support for more devices
Dependents: 1D-Pong BMT-K9_encoder BMT-K9-Regelaar programma_filter ... more
Check the cookbook page for more information: https://mbed.org/cookbook/MODSERIAL
Did you add a device? Please send a pull request so we can keep everything in one library instead of many copies. In that case also send a PM, since currently mbed does not inform of new pull requests. I will then also add you to the developers of this library so you can do other changes directly.
Diff: INIT.cpp
- Revision:
- 8:775f860e94d3
- Parent:
- 4:28de979b77cf
- Child:
- 9:b3cdae80e7a9
--- a/INIT.cpp Mon Nov 22 09:19:50 2010 +0000 +++ b/INIT.cpp Mon Nov 22 09:58:34 2010 +0000 @@ -40,7 +40,7 @@ if (_base != NULL) { buffer_size[RxIrq] = rxSize; - buffer[RxIrq] = (char *)malloc(buffer_size[RxIrq]); + buffer[RxIrq] = rxSize > 0 ? (char *)malloc(buffer_size[RxIrq]) : (char *)NULL; buffer_in[RxIrq] = 0; buffer_out[RxIrq] = 0; buffer_count[RxIrq] = 0; @@ -48,7 +48,7 @@ Serial::attach(this, &MODSERIAL::isr_rx, Serial::RxIrq); buffer_size[TxIrq] = txSize; - buffer[TxIrq] = (char *)malloc(buffer_size[TxIrq]); + buffer[TxIrq] = txSize > 0 ? (char *)malloc(buffer_size[TxIrq]) : (char *)NULL; buffer_in[TxIrq] = 0; buffer_out[TxIrq] = 0; buffer_count[TxIrq] = 0; @@ -59,14 +59,6 @@ error("MODSERIAL must have a defined UART to function."); } - if (!txBufferSane()) { - error("Failed to allocate memory for TX buffer"); - } - - if (!rxBufferSane()) { - error("Failed to allocate memory for RX buffer"); - } - _FCR = MODSERIAL_FIFO_ENABLE | MODSERIAL_FIFO_RX_RESET | MODSERIAL_FIFO_TX_RESET; enableIrq();