Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
AntonLS
Date:
Fri Apr 17 22:12:43 2015 +0000
Revision:
7:205ef63d311a
Parent:
6:ef758ac3c928
Child:
8:d5d055be2bb8
Works again.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AntonLS 1:0ba687d4196f 1 /*
AntonLS 1:0ba687d4196f 2 *
AntonLS 1:0ba687d4196f 3 * Replacement for Serial, so UART flow control is inited properly. ALS 20150412
AntonLS 1:0ba687d4196f 4 *
AntonLS 1:0ba687d4196f 5 * MySerialBase is a replacement for SerialBase, to prevent it from calling
AntonLS 1:0ba687d4196f 6 * the faulty-for-nRF51822-uart-init serial_init()
AntonLS 1:0ba687d4196f 7 * in mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/serial_api.c
AntonLS 1:0ba687d4196f 8 *
AntonLS 1:0ba687d4196f 9 */
AntonLS 1:0ba687d4196f 10
AntonLS 1:0ba687d4196f 11 #include "MySerial.h"
AntonLS 1:0ba687d4196f 12
AntonLS 1:0ba687d4196f 13 extern "C"
AntonLS 1:0ba687d4196f 14 {
AntonLS 1:0ba687d4196f 15 void pin_mode( PinName, PinMode );
AntonLS 6:ef758ac3c928 16
AntonLS 6:ef758ac3c928 17 void UART0_My_IRQHandler(); // Rename to UART0_IRQHandler once serial_api.c excludes in lib rebuild.
AntonLS 1:0ba687d4196f 18 }
AntonLS 1:0ba687d4196f 19
AntonLS 1:0ba687d4196f 20 extern int stdio_uart_inited;
AntonLS 1:0ba687d4196f 21 extern serial_t stdio_uart;
AntonLS 1:0ba687d4196f 22
AntonLS 6:ef758ac3c928 23 // Our versions of serial_api.c's...
AntonLS 7:205ef63d311a 24 // (serial_free(), etc. in serial_api.c won't work wehn we use our own copy.)
AntonLS 6:ef758ac3c928 25 #define UART_NUM 1
AntonLS 6:ef758ac3c928 26 static uint32_t serial_irq_ids[UART_NUM] = {0};
AntonLS 6:ef758ac3c928 27 static uart_irq_handler irq_handler;
AntonLS 6:ef758ac3c928 28
AntonLS 1:0ba687d4196f 29
AntonLS 1:0ba687d4196f 30 using namespace moo;
AntonLS 1:0ba687d4196f 31
AntonLS 1:0ba687d4196f 32
AntonLS 1:0ba687d4196f 33 MySerialBase::MySerialBase( PinName tx, PinName rx,
AntonLS 1:0ba687d4196f 34 PinName rts, PinName cts ) : _my_serial(), _my_baud( 9600 )
AntonLS 1:0ba687d4196f 35 {
AntonLS 2:fe1566cdb6e7 36 my_serial_init( &_my_serial, tx, rx, rts, cts, _my_baud );
AntonLS 7:205ef63d311a 37 serial_irq_handler( &_my_serial, _irq_handler, (uint32_t)this ); // serial_api.c only calls handler for Tx & Rx.
AntonLS 7:205ef63d311a 38
AntonLS 7:205ef63d311a 39 // Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
AntonLS 7:205ef63d311a 40 // my_serial_irq_handler( &_my_serial, _irq_handler, (uint32_t)this );
AntonLS 5:1b9734e68327 41
AntonLS 6:ef758ac3c928 42 // For cts -- Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
AntonLS 7:205ef63d311a 43 // attach( this, &MySerialBase::cts_handler, (Serial::IrqType)CtsIrq );
AntonLS 6:ef758ac3c928 44 // For uart errors -- Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
AntonLS 7:205ef63d311a 45 // attach( this, &MySerialBase::error_handler, (Serial::IrqType)ErrIrq );
AntonLS 1:0ba687d4196f 46 }
AntonLS 1:0ba687d4196f 47 void MySerialBase::baud( int baudrate )
AntonLS 1:0ba687d4196f 48 {
AntonLS 1:0ba687d4196f 49 serial_baud( &_my_serial, baudrate );
AntonLS 1:0ba687d4196f 50 _my_baud = baudrate;
AntonLS 1:0ba687d4196f 51 }
AntonLS 1:0ba687d4196f 52 void MySerialBase::format( int bits, SerialBase::Parity parity, int stop_bits )
AntonLS 1:0ba687d4196f 53 {
AntonLS 1:0ba687d4196f 54 serial_format( &_my_serial, bits, (SerialParity)parity, stop_bits );
AntonLS 1:0ba687d4196f 55 }
AntonLS 1:0ba687d4196f 56 int MySerialBase::readable()
AntonLS 1:0ba687d4196f 57 {
AntonLS 1:0ba687d4196f 58 return serial_readable( &_my_serial );
AntonLS 1:0ba687d4196f 59 }
AntonLS 1:0ba687d4196f 60 int MySerialBase::writeable()
AntonLS 1:0ba687d4196f 61 {
AntonLS 1:0ba687d4196f 62 return serial_writable( &_my_serial );
AntonLS 1:0ba687d4196f 63 }
AntonLS 5:1b9734e68327 64 void MySerialBase::attach( void (*fptr)(void), Serial::IrqType type )
AntonLS 1:0ba687d4196f 65 {
AntonLS 1:0ba687d4196f 66 if( fptr )
AntonLS 1:0ba687d4196f 67 {
AntonLS 1:0ba687d4196f 68 _my_irq[type].attach( fptr );
AntonLS 5:1b9734e68327 69 my_serial_irq_set( &_my_serial, (IrqType)type, 1 );
AntonLS 5:1b9734e68327 70
AntonLS 1:0ba687d4196f 71 } else
AntonLS 5:1b9734e68327 72 {
AntonLS 5:1b9734e68327 73 my_serial_irq_set( &_my_serial, (IrqType)type, 0 );
AntonLS 5:1b9734e68327 74 }
AntonLS 1:0ba687d4196f 75 }
AntonLS 2:fe1566cdb6e7 76 void MySerialBase::my_serial_init( serial_t *obj, PinName tx, PinName rx, PinName rts, PinName cts, int baudrate )
AntonLS 2:fe1566cdb6e7 77 {
AntonLS 2:fe1566cdb6e7 78 UARTName uart = UART_0;
AntonLS 2:fe1566cdb6e7 79 obj->uart = (NRF_UART_Type *)uart;
AntonLS 2:fe1566cdb6e7 80
AntonLS 2:fe1566cdb6e7 81 // pin configurations --
AntonLS 2:fe1566cdb6e7 82 NRF_GPIO->DIR |= (1 << tx); // TX_PIN_NUMBER
AntonLS 2:fe1566cdb6e7 83 NRF_GPIO->DIR |= ((NC == rts) ? 0 : (1 << rts)); // RTS_PIN_NUMBER
AntonLS 2:fe1566cdb6e7 84
AntonLS 2:fe1566cdb6e7 85 NRF_GPIO->DIR &= ~(1 << rx); // RX_PIN_NUMBER
AntonLS 2:fe1566cdb6e7 86 NRF_GPIO->DIR &= ~((NC == cts) ? 0 : (1 << cts)); // CTS_PIN_NUMBER
AntonLS 2:fe1566cdb6e7 87
AntonLS 2:fe1566cdb6e7 88 obj->uart->PSELRTS = ((NC == rts) ? 0xFFFFFFFF : rts); // RTS_PIN_NUMBER
AntonLS 2:fe1566cdb6e7 89 obj->uart->PSELTXD = tx; // TX_PIN_NUMBER
AntonLS 2:fe1566cdb6e7 90 obj->uart->PSELCTS = ((NC == cts) ? 0xFFFFFFFF : cts); // CTS_PIN_NUMBER
AntonLS 2:fe1566cdb6e7 91 obj->uart->PSELRXD = rx; // RX_PIN_NUMBER
AntonLS 2:fe1566cdb6e7 92
AntonLS 2:fe1566cdb6e7 93 if( (NC != rts) || (NC != cts) )
AntonLS 2:fe1566cdb6e7 94 {
AntonLS 2:fe1566cdb6e7 95 obj->uart->CONFIG |= 0x01; // Enable HWFC
AntonLS 2:fe1566cdb6e7 96
AntonLS 2:fe1566cdb6e7 97 } else
AntonLS 2:fe1566cdb6e7 98 {
AntonLS 2:fe1566cdb6e7 99 obj->uart->CONFIG &= ~0x01; // Disable HWFC;
AntonLS 2:fe1566cdb6e7 100 }
AntonLS 2:fe1566cdb6e7 101
AntonLS 2:fe1566cdb6e7 102 // set default baud rate and format
AntonLS 2:fe1566cdb6e7 103 serial_baud ( obj, baudrate );
AntonLS 2:fe1566cdb6e7 104 serial_format( obj, 8, ParityNone, 1 );
AntonLS 2:fe1566cdb6e7 105
AntonLS 2:fe1566cdb6e7 106 obj->uart->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
AntonLS 2:fe1566cdb6e7 107 obj->uart->TASKS_STARTTX = 1;
AntonLS 2:fe1566cdb6e7 108 obj->uart->TASKS_STARTRX = 1;
AntonLS 2:fe1566cdb6e7 109 obj->uart->EVENTS_RXDRDY = 0;
AntonLS 2:fe1566cdb6e7 110 // dummy write needed or TXDRDY trails write rather than leads write.
AntonLS 2:fe1566cdb6e7 111 // pins are disconnected so nothing is physically transmitted on the wire
AntonLS 2:fe1566cdb6e7 112 obj->uart->TXD = 0;
AntonLS 2:fe1566cdb6e7 113
AntonLS 2:fe1566cdb6e7 114 obj->index = 0;
AntonLS 2:fe1566cdb6e7 115
AntonLS 2:fe1566cdb6e7 116 // set rx/tx pins in PullUp mode
AntonLS 2:fe1566cdb6e7 117 if (tx != NC) {
AntonLS 2:fe1566cdb6e7 118 pin_mode(tx, PullUp);
AntonLS 2:fe1566cdb6e7 119 }
AntonLS 2:fe1566cdb6e7 120 if (rx != NC) {
AntonLS 2:fe1566cdb6e7 121 pin_mode(rx, PullUp);
AntonLS 2:fe1566cdb6e7 122 }
AntonLS 2:fe1566cdb6e7 123
AntonLS 2:fe1566cdb6e7 124 // Set CTS pin to PullDown mode if used.
AntonLS 2:fe1566cdb6e7 125 if( cts != NC )
AntonLS 2:fe1566cdb6e7 126 {
AntonLS 2:fe1566cdb6e7 127 pin_mode( cts, PullDown );
AntonLS 2:fe1566cdb6e7 128 }
AntonLS 2:fe1566cdb6e7 129
AntonLS 2:fe1566cdb6e7 130
AntonLS 2:fe1566cdb6e7 131 if (uart == STDIO_UART) {
AntonLS 2:fe1566cdb6e7 132 stdio_uart_inited = 1;
AntonLS 2:fe1566cdb6e7 133 memcpy(&stdio_uart, obj, sizeof(serial_t));
AntonLS 2:fe1566cdb6e7 134 }
AntonLS 2:fe1566cdb6e7 135 }
AntonLS 7:205ef63d311a 136
AntonLS 7:205ef63d311a 137 // Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
AntonLS 6:ef758ac3c928 138 void MySerialBase::my_serial_irq_handler( serial_t *obj, uart_irq_handler handler, uint32_t id )
AntonLS 6:ef758ac3c928 139 {
AntonLS 6:ef758ac3c928 140 irq_handler = handler;
AntonLS 6:ef758ac3c928 141 serial_irq_ids[obj->index] = id;
AntonLS 6:ef758ac3c928 142 }
AntonLS 6:ef758ac3c928 143
AntonLS 7:205ef63d311a 144 // Replacement for serial_irq_set() in serial_api.c so we can eventually grab uart errors.
AntonLS 5:1b9734e68327 145 void MySerialBase::my_serial_irq_set( serial_t *obj, IrqType irq, uint32_t enable )
AntonLS 5:1b9734e68327 146 {
AntonLS 5:1b9734e68327 147 IRQn_Type irq_n = (IRQn_Type)0;
AntonLS 5:1b9734e68327 148
AntonLS 5:1b9734e68327 149 switch( (int)obj->uart )
AntonLS 5:1b9734e68327 150 {
AntonLS 5:1b9734e68327 151 case UART_0:
AntonLS 5:1b9734e68327 152 irq_n = UART0_IRQn;
AntonLS 5:1b9734e68327 153 break;
AntonLS 5:1b9734e68327 154 }
AntonLS 5:1b9734e68327 155
AntonLS 5:1b9734e68327 156 if( enable )
AntonLS 5:1b9734e68327 157 {
AntonLS 5:1b9734e68327 158 switch( irq )
AntonLS 5:1b9734e68327 159 {
AntonLS 5:1b9734e68327 160 case RxIrq:
AntonLS 5:1b9734e68327 161 obj->uart->INTEN |= (UART_INTENSET_RXDRDY_Msk);
AntonLS 5:1b9734e68327 162 break;
AntonLS 5:1b9734e68327 163 case TxIrq:
AntonLS 5:1b9734e68327 164 obj->uart->INTEN |= (UART_INTENSET_TXDRDY_Msk);
AntonLS 5:1b9734e68327 165 break;
AntonLS 5:1b9734e68327 166 case ErrIrq:
AntonLS 5:1b9734e68327 167 obj->uart->INTEN |= (UART_INTENSET_ERROR_Msk);
AntonLS 5:1b9734e68327 168 break;
AntonLS 7:205ef63d311a 169 case CtsIrq:
AntonLS 7:205ef63d311a 170 obj->uart->INTEN |= (UART_INTENCLR_CTS_Msk);
AntonLS 7:205ef63d311a 171 break;
AntonLS 7:205ef63d311a 172 case NctsIrq:
AntonLS 7:205ef63d311a 173 obj->uart->INTEN |= (UART_INTENCLR_NCTS_Msk);
AntonLS 7:205ef63d311a 174 break;
AntonLS 7:205ef63d311a 175 case RxtoIrq:
AntonLS 7:205ef63d311a 176 obj->uart->INTEN |= (UART_INTENCLR_RXTO_Msk);
AntonLS 7:205ef63d311a 177 break;
AntonLS 5:1b9734e68327 178 }
AntonLS 5:1b9734e68327 179 NVIC_SetPriority( irq_n, 3 );
AntonLS 5:1b9734e68327 180 NVIC_EnableIRQ( irq_n );
AntonLS 5:1b9734e68327 181
AntonLS 5:1b9734e68327 182 } else
AntonLS 5:1b9734e68327 183 { // disable
AntonLS 5:1b9734e68327 184 // masked writes to INTENSET dont disable and masked writes to
AntonLS 5:1b9734e68327 185 // INTENCLR seemed to clear the entire register, not bits.
AntonLS 5:1b9734e68327 186 // Added INTEN to memory map and seems to allow set and clearing of specific bits as desired
AntonLS 5:1b9734e68327 187 switch( irq )
AntonLS 5:1b9734e68327 188 {
AntonLS 5:1b9734e68327 189 case RxIrq:
AntonLS 5:1b9734e68327 190 obj->uart->INTEN &= ~(UART_INTENCLR_RXDRDY_Msk);
AntonLS 5:1b9734e68327 191 break;
AntonLS 5:1b9734e68327 192 case TxIrq:
AntonLS 5:1b9734e68327 193 obj->uart->INTEN &= ~(UART_INTENCLR_TXDRDY_Msk);
AntonLS 5:1b9734e68327 194 break;
AntonLS 5:1b9734e68327 195 case ErrIrq:
AntonLS 5:1b9734e68327 196 obj->uart->INTEN &= ~(UART_INTENCLR_ERROR_Msk);
AntonLS 5:1b9734e68327 197 break;
AntonLS 7:205ef63d311a 198 case CtsIrq:
AntonLS 7:205ef63d311a 199 obj->uart->INTEN &= ~(UART_INTENCLR_CTS_Msk);
AntonLS 7:205ef63d311a 200 break;
AntonLS 7:205ef63d311a 201 case NctsIrq:
AntonLS 7:205ef63d311a 202 obj->uart->INTEN &= ~(UART_INTENCLR_NCTS_Msk);
AntonLS 7:205ef63d311a 203 break;
AntonLS 7:205ef63d311a 204 case RxtoIrq:
AntonLS 7:205ef63d311a 205 obj->uart->INTEN &= ~(UART_INTENCLR_RXTO_Msk);
AntonLS 7:205ef63d311a 206 break;
AntonLS 5:1b9734e68327 207 }
AntonLS 5:1b9734e68327 208
AntonLS 5:1b9734e68327 209 if( 0 == obj->uart->INTENCLR )
AntonLS 5:1b9734e68327 210 {
AntonLS 5:1b9734e68327 211 NVIC_DisableIRQ( irq_n );
AntonLS 5:1b9734e68327 212 }
AntonLS 5:1b9734e68327 213 }
AntonLS 5:1b9734e68327 214 }
AntonLS 1:0ba687d4196f 215 void MySerialBase::_irq_handler( uint32_t id, SerialIrq irq_type )
AntonLS 1:0ba687d4196f 216 {
AntonLS 1:0ba687d4196f 217 MySerialBase *handler = (MySerialBase*)id;
AntonLS 1:0ba687d4196f 218 handler->_my_irq[irq_type].call();
AntonLS 1:0ba687d4196f 219 }
AntonLS 6:ef758ac3c928 220
AntonLS 6:ef758ac3c928 221 // Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
AntonLS 5:1b9734e68327 222 void MySerialBase::error_handler()
AntonLS 5:1b9734e68327 223 {
AntonLS 5:1b9734e68327 224 puts( "\r\nUART ERR! " );
AntonLS 5:1b9734e68327 225
AntonLS 5:1b9734e68327 226 if( (UART_ERRORSRC_OVERRUN_Present << UART_ERRORSRC_OVERRUN_Pos) == (UART_ERRORSRC_OVERRUN_Msk & _my_serial.uart->ERRORSRC) )
AntonLS 5:1b9734e68327 227 {
AntonLS 5:1b9734e68327 228 puts( "\r\n[ERR: OVERRUN]\r\n" );
AntonLS 5:1b9734e68327 229
AntonLS 5:1b9734e68327 230 // Clear the error
AntonLS 5:1b9734e68327 231 _my_serial.uart->ERRORSRC = (UART_ERRORSRC_OVERRUN_Clear << UART_ERRORSRC_OVERRUN_Pos);
AntonLS 5:1b9734e68327 232 }
AntonLS 5:1b9734e68327 233 }
AntonLS 6:ef758ac3c928 234
AntonLS 6:ef758ac3c928 235 // Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
AntonLS 6:ef758ac3c928 236 void MySerialBase::cts_handler()
AntonLS 6:ef758ac3c928 237 {
AntonLS 6:ef758ac3c928 238 puts( "\r\n[CTS: High]\r\n" );
AntonLS 6:ef758ac3c928 239 }
AntonLS 6:ef758ac3c928 240
AntonLS 1:0ba687d4196f 241 int MySerialBase::_base_getc()
AntonLS 1:0ba687d4196f 242 {
AntonLS 1:0ba687d4196f 243 return serial_getc( &_my_serial );
AntonLS 1:0ba687d4196f 244 }
AntonLS 1:0ba687d4196f 245 int MySerialBase::_base_putc( int c )
AntonLS 1:0ba687d4196f 246 {
AntonLS 1:0ba687d4196f 247 serial_putc( &_my_serial, c );
AntonLS 1:0ba687d4196f 248 return c;
AntonLS 1:0ba687d4196f 249 }
AntonLS 1:0ba687d4196f 250 void MySerialBase::send_break()
AntonLS 1:0ba687d4196f 251 {
AntonLS 1:0ba687d4196f 252 // Wait for 1.5 frames before clearing the break condition
AntonLS 1:0ba687d4196f 253 // This will have different effects on our platforms, but should
AntonLS 1:0ba687d4196f 254 // ensure that we keep the break active for at least one frame.
AntonLS 1:0ba687d4196f 255 // We consider a full frame (1 start bit + 8 data bits bits +
AntonLS 1:0ba687d4196f 256 // 1 parity bit + 2 stop bits = 12 bits) for computation.
AntonLS 1:0ba687d4196f 257 // One bit time (in us) = 1000000/_my_baud
AntonLS 1:0ba687d4196f 258 // Twelve bits: 12000000/baud delay
AntonLS 1:0ba687d4196f 259 // 1.5 frames: 18000000/baud delay
AntonLS 1:0ba687d4196f 260 serial_break_set( &_my_serial );
AntonLS 1:0ba687d4196f 261 wait_us( 18000000/_my_baud );
AntonLS 1:0ba687d4196f 262 serial_break_clear( &_my_serial );
AntonLS 1:0ba687d4196f 263 }
AntonLS 1:0ba687d4196f 264
AntonLS 1:0ba687d4196f 265
AntonLS 1:0ba687d4196f 266 MySerial::MySerial( PinName tx, PinName rx, const char *name,
AntonLS 1:0ba687d4196f 267 PinName rts, PinName cts ) : MySerialBase( tx, rx, rts, cts ), Stream( name )
AntonLS 1:0ba687d4196f 268 {
AntonLS 1:0ba687d4196f 269 }
AntonLS 1:0ba687d4196f 270 int MySerial::_getc()
AntonLS 1:0ba687d4196f 271 {
AntonLS 1:0ba687d4196f 272 return _base_getc();
AntonLS 1:0ba687d4196f 273 }
AntonLS 1:0ba687d4196f 274 int MySerial::_putc( int c )
AntonLS 1:0ba687d4196f 275 {
AntonLS 1:0ba687d4196f 276 return _base_putc( c );
AntonLS 1:0ba687d4196f 277 }
AntonLS 1:0ba687d4196f 278 int MySerial::puts( const char *str )
AntonLS 1:0ba687d4196f 279 {
AntonLS 1:0ba687d4196f 280 while( *str )
AntonLS 1:0ba687d4196f 281 putc( *str ++ );
AntonLS 1:0ba687d4196f 282
AntonLS 1:0ba687d4196f 283 return 0;
AntonLS 1:0ba687d4196f 284 }
AntonLS 4:17b8edf264c3 285
AntonLS 1:0ba687d4196f 286 int MySerial::printf( const char *format, ... )
AntonLS 1:0ba687d4196f 287 {
AntonLS 1:0ba687d4196f 288 va_list arg;
AntonLS 1:0ba687d4196f 289 va_start( arg, format );
AntonLS 1:0ba687d4196f 290
AntonLS 1:0ba687d4196f 291 int len = MySerial::vprintf( format, arg );
AntonLS 1:0ba687d4196f 292
AntonLS 1:0ba687d4196f 293 va_end( arg );
AntonLS 1:0ba687d4196f 294
AntonLS 1:0ba687d4196f 295 return len;
AntonLS 1:0ba687d4196f 296 }
AntonLS 1:0ba687d4196f 297 int MySerial::vprintf( const char *format, va_list arg )
AntonLS 1:0ba687d4196f 298 {
AntonLS 1:0ba687d4196f 299 int len = vsnprintf( NULL, 0, format, arg );
AntonLS 1:0ba687d4196f 300 if( len < STRING_STACK_LIMIT )
AntonLS 1:0ba687d4196f 301 {
AntonLS 1:0ba687d4196f 302 char temp[STRING_STACK_LIMIT];
AntonLS 1:0ba687d4196f 303 vsprintf( temp, format, arg );
AntonLS 1:0ba687d4196f 304 puts( temp );
AntonLS 1:0ba687d4196f 305
AntonLS 1:0ba687d4196f 306 } else
AntonLS 1:0ba687d4196f 307 {
AntonLS 1:0ba687d4196f 308 char *temp = new char[len + 1];
AntonLS 1:0ba687d4196f 309 vsprintf( temp, format, arg );
AntonLS 1:0ba687d4196f 310 puts( temp );
AntonLS 1:0ba687d4196f 311 delete[] temp;
AntonLS 1:0ba687d4196f 312 }
AntonLS 1:0ba687d4196f 313
AntonLS 1:0ba687d4196f 314 return len;
AntonLS 1:0ba687d4196f 315 }
AntonLS 1:0ba687d4196f 316
AntonLS 6:ef758ac3c928 317 // Won't work until we use our own UART0_IRQHandler (alter serial_api.c / rebuild mbed lib.)
AntonLS 6:ef758ac3c928 318
AntonLS 6:ef758ac3c928 319 #ifdef __cplusplus
AntonLS 6:ef758ac3c928 320 extern "C"
AntonLS 6:ef758ac3c928 321 {
AntonLS 6:ef758ac3c928 322 #endif
AntonLS 6:ef758ac3c928 323 void UART0_My_IRQHandler() // Rename to UART0_IRQHandler once serial_api.c excludes in lib rebuild.
AntonLS 6:ef758ac3c928 324 {
AntonLS 6:ef758ac3c928 325 MySerial::IrqType irq_type;
AntonLS 6:ef758ac3c928 326
AntonLS 6:ef758ac3c928 327 if( (NRF_UART0->INTENSET & UART_INTENSET_TXDRDY_Msk) && NRF_UART0->EVENTS_TXDRDY )
AntonLS 6:ef758ac3c928 328 {
AntonLS 6:ef758ac3c928 329 irq_type = MySerial::TxIrq;
AntonLS 6:ef758ac3c928 330
AntonLS 6:ef758ac3c928 331 } else if( (NRF_UART0->INTENSET & UART_INTENSET_RXDRDY_Msk) && NRF_UART0->EVENTS_RXDRDY )
AntonLS 6:ef758ac3c928 332 {
AntonLS 6:ef758ac3c928 333 irq_type = MySerial::RxIrq;
AntonLS 6:ef758ac3c928 334
AntonLS 6:ef758ac3c928 335 } else if( (NRF_UART0->INTENSET & UART_INTENSET_ERROR_Msk) && NRF_UART0->EVENTS_ERROR )
AntonLS 6:ef758ac3c928 336 {
AntonLS 6:ef758ac3c928 337 irq_type = MySerial::ErrIrq;
AntonLS 6:ef758ac3c928 338
AntonLS 6:ef758ac3c928 339 } else if( (NRF_UART0->INTENSET & UART_INTENSET_CTS_Msk) && NRF_UART0->EVENTS_CTS )
AntonLS 6:ef758ac3c928 340 {
AntonLS 6:ef758ac3c928 341 irq_type = MySerial::CtsIrq;
AntonLS 6:ef758ac3c928 342
AntonLS 6:ef758ac3c928 343 } else if( (NRF_UART0->INTENSET & UART_INTENSET_NCTS_Msk) && NRF_UART0->EVENTS_NCTS )
AntonLS 6:ef758ac3c928 344 {
AntonLS 6:ef758ac3c928 345 irq_type = MySerial::NctsIrq;
AntonLS 6:ef758ac3c928 346
AntonLS 6:ef758ac3c928 347 } else if( (NRF_UART0->INTENSET & UART_INTENSET_RXTO_Msk) && NRF_UART0->EVENTS_RXTO )
AntonLS 6:ef758ac3c928 348 {
AntonLS 6:ef758ac3c928 349 irq_type = MySerial::RxtoIrq;
AntonLS 6:ef758ac3c928 350
AntonLS 6:ef758ac3c928 351 } else
AntonLS 6:ef758ac3c928 352 {
AntonLS 6:ef758ac3c928 353 return;
AntonLS 6:ef758ac3c928 354 }
AntonLS 6:ef758ac3c928 355
AntonLS 6:ef758ac3c928 356 if( serial_irq_ids[0] != 0 )
AntonLS 6:ef758ac3c928 357 {
AntonLS 6:ef758ac3c928 358 irq_handler( serial_irq_ids[0], (SerialIrq)irq_type );
AntonLS 6:ef758ac3c928 359 }
AntonLS 6:ef758ac3c928 360 }
AntonLS 6:ef758ac3c928 361 #ifdef __cplusplus
AntonLS 6:ef758ac3c928 362 }
AntonLS 6:ef758ac3c928 363 #endif
AntonLS 6:ef758ac3c928 364
AntonLS 7:205ef63d311a 365
AntonLS 1:0ba687d4196f 366 /* EOF */