Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of football_project by
Diff: io/MySerial.cpp
- Revision:
- 6:ef758ac3c928
- Parent:
- 5:1b9734e68327
- Child:
- 7:205ef63d311a
diff -r 1b9734e68327 -r ef758ac3c928 io/MySerial.cpp
--- a/io/MySerial.cpp Fri Apr 17 04:20:07 2015 +0000
+++ b/io/MySerial.cpp Fri Apr 17 20:55:25 2015 +0000
@@ -13,11 +13,19 @@
extern "C"
{
void pin_mode( PinName, PinMode );
+
+ void UART0_My_IRQHandler(); // Rename to UART0_IRQHandler once serial_api.c excludes in lib rebuild.
}
extern int stdio_uart_inited;
extern serial_t stdio_uart;
+// Our versions of serial_api.c's...
+// (serial_free(), etc. in serial_api.c won't work because we have our own copy.)
+#define UART_NUM 1
+static uint32_t serial_irq_ids[UART_NUM] = {0};
+static uart_irq_handler irq_handler;
+
using namespace moo;
@@ -26,9 +34,11 @@
PinName rts, PinName cts ) : _my_serial(), _my_baud( 9600 )
{
my_serial_init( &_my_serial, tx, rx, rts, cts, _my_baud );
- serial_irq_handler( &_my_serial, _irq_handler, (uint32_t)this );
+ my_serial_irq_handler( &_my_serial, _irq_handler, (uint32_t)this );
- // For uart errors
+ // For cts -- Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
+ attach( this, &MySerialBase::cts_handler, (Serial::IrqType)CtsIrq );
+ // For uart errors -- Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
attach( this, &MySerialBase::error_handler, (Serial::IrqType)ErrIrq );
}
void MySerialBase::baud( int baudrate )
@@ -120,6 +130,12 @@
memcpy(&stdio_uart, obj, sizeof(serial_t));
}
}
+void MySerialBase::my_serial_irq_handler( serial_t *obj, uart_irq_handler handler, uint32_t id )
+{
+ irq_handler = handler;
+ serial_irq_ids[obj->index] = id;
+}
+
// Replacement for serial_irq_set() in serial_api.c so we can grab uart errors.
void MySerialBase::my_serial_irq_set( serial_t *obj, IrqType irq, uint32_t enable )
{
@@ -178,6 +194,8 @@
MySerialBase *handler = (MySerialBase*)id;
handler->_my_irq[irq_type].call();
}
+
+// Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
void MySerialBase::error_handler()
{
puts( "\r\nUART ERR! " );
@@ -190,6 +208,13 @@
_my_serial.uart->ERRORSRC = (UART_ERRORSRC_OVERRUN_Clear << UART_ERRORSRC_OVERRUN_Pos);
}
}
+
+// Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
+void MySerialBase::cts_handler()
+{
+ puts( "\r\n[CTS: High]\r\n" );
+}
+
int MySerialBase::_base_getc()
{
return serial_getc( &_my_serial );
@@ -266,4 +291,52 @@
return len;
}
+// Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+void UART0_My_IRQHandler() // Rename to UART0_IRQHandler once serial_api.c excludes in lib rebuild.
+{
+ MySerial::IrqType irq_type;
+
+ if( (NRF_UART0->INTENSET & UART_INTENSET_TXDRDY_Msk) && NRF_UART0->EVENTS_TXDRDY )
+ {
+ irq_type = MySerial::TxIrq;
+
+ } else if( (NRF_UART0->INTENSET & UART_INTENSET_RXDRDY_Msk) && NRF_UART0->EVENTS_RXDRDY )
+ {
+ irq_type = MySerial::RxIrq;
+
+ } else if( (NRF_UART0->INTENSET & UART_INTENSET_ERROR_Msk) && NRF_UART0->EVENTS_ERROR )
+ {
+ irq_type = MySerial::ErrIrq;
+
+ } else if( (NRF_UART0->INTENSET & UART_INTENSET_CTS_Msk) && NRF_UART0->EVENTS_CTS )
+ {
+ irq_type = MySerial::CtsIrq;
+
+ } else if( (NRF_UART0->INTENSET & UART_INTENSET_NCTS_Msk) && NRF_UART0->EVENTS_NCTS )
+ {
+ irq_type = MySerial::NctsIrq;
+
+ } else if( (NRF_UART0->INTENSET & UART_INTENSET_RXTO_Msk) && NRF_UART0->EVENTS_RXTO )
+ {
+ irq_type = MySerial::RxtoIrq;
+
+ } else
+ {
+ return;
+ }
+
+ if( serial_irq_ids[0] != 0 )
+ {
+ irq_handler( serial_irq_ids[0], (SerialIrq)irq_type );
+ }
+}
+#ifdef __cplusplus
+}
+#endif
+
/* EOF */
