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 #ifndef MYSERIAL_H
AntonLS 1:0ba687d4196f 12 #define MYSERIAL_H
AntonLS 1:0ba687d4196f 13
AntonLS 1:0ba687d4196f 14 #include "mbed.h"
AntonLS 3:388e441be8df 15 // #include "Stream.h"
AntonLS 3:388e441be8df 16 // #include "FunctionPointer.h"
AntonLS 3:388e441be8df 17 #include "serial_api.h"
AntonLS 1:0ba687d4196f 18 #include <cstdarg>
AntonLS 1:0ba687d4196f 19
AntonLS 4:17b8edf264c3 20 #define STRING_STACK_LIMIT 120
AntonLS 4:17b8edf264c3 21
AntonLS 1:0ba687d4196f 22 namespace moo
AntonLS 1:0ba687d4196f 23 {
AntonLS 1:0ba687d4196f 24
AntonLS 1:0ba687d4196f 25 /** A base class for serial port implementations
AntonLS 1:0ba687d4196f 26 * Can't be instantiated directly (use MySerial)
AntonLS 1:0ba687d4196f 27 */
AntonLS 1:0ba687d4196f 28 class MySerialBase
AntonLS 1:0ba687d4196f 29 {
AntonLS 1:0ba687d4196f 30 public:
AntonLS 5:1b9734e68327 31
AntonLS 5:1b9734e68327 32 enum IrqType
AntonLS 5:1b9734e68327 33 {
AntonLS 5:1b9734e68327 34 RxIrq = 0,
AntonLS 5:1b9734e68327 35 TxIrq,
AntonLS 6:ef758ac3c928 36 ErrIrq,
AntonLS 6:ef758ac3c928 37 RxtoIrq,
AntonLS 6:ef758ac3c928 38 CtsIrq,
AntonLS 7:205ef63d311a 39 NctsIrq,
AntonLS 7:205ef63d311a 40 NUM_IRQ_TYPES
AntonLS 5:1b9734e68327 41 };
AntonLS 5:1b9734e68327 42
AntonLS 1:0ba687d4196f 43 /** Set the baud rate of the serial port
AntonLS 1:0ba687d4196f 44 *
AntonLS 1:0ba687d4196f 45 * @param baudrate The baudrate of the serial port (default = 9600).
AntonLS 1:0ba687d4196f 46 */
AntonLS 1:0ba687d4196f 47 void baud( int baudrate );
AntonLS 1:0ba687d4196f 48
AntonLS 1:0ba687d4196f 49 /** Set the transmission format used by the serial port
AntonLS 1:0ba687d4196f 50 *
AntonLS 1:0ba687d4196f 51 * @param bits The number of bits in a word (5-8; default = 8)
AntonLS 1:0ba687d4196f 52 * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
AntonLS 1:0ba687d4196f 53 * @param stop The number of stop bits (1 or 2; default = 1)
AntonLS 1:0ba687d4196f 54 */
AntonLS 1:0ba687d4196f 55 void format( int bits=8, SerialBase::Parity parity=SerialBase::None, int stop_bits=1 );
AntonLS 1:0ba687d4196f 56
AntonLS 1:0ba687d4196f 57 /** Determine if there is a character available to read
AntonLS 1:0ba687d4196f 58 *
AntonLS 1:0ba687d4196f 59 * @returns
AntonLS 1:0ba687d4196f 60 * 1 if there is a character available to read,
AntonLS 1:0ba687d4196f 61 * 0 otherwise
AntonLS 1:0ba687d4196f 62 */
AntonLS 1:0ba687d4196f 63 int readable();
AntonLS 1:0ba687d4196f 64
AntonLS 1:0ba687d4196f 65 /** Determine if there is space available to write a character
AntonLS 1:0ba687d4196f 66 *
AntonLS 1:0ba687d4196f 67 * @returns
AntonLS 1:0ba687d4196f 68 * 1 if there is space to write a character,
AntonLS 1:0ba687d4196f 69 * 0 otherwise
AntonLS 1:0ba687d4196f 70 */
AntonLS 1:0ba687d4196f 71 int writeable();
AntonLS 1:0ba687d4196f 72
AntonLS 1:0ba687d4196f 73 /** Attach a function to call whenever a serial interrupt is generated
AntonLS 1:0ba687d4196f 74 *
AntonLS 1:0ba687d4196f 75 * @param fptr A pointer to a void function, or 0 to set as none
AntonLS 5:1b9734e68327 76 * @param type Which serial interrupt to attach the member function to (MySerial::RxIrq for receive, TxIrq for transmit buffer empty)
AntonLS 1:0ba687d4196f 77 */
AntonLS 5:1b9734e68327 78 void attach( void (*fptr)(void), Serial::IrqType type=Serial::RxIrq );
AntonLS 1:0ba687d4196f 79
AntonLS 1:0ba687d4196f 80 /** Attach a member function to call whenever a serial interrupt is generated
AntonLS 1:0ba687d4196f 81 *
AntonLS 1:0ba687d4196f 82 * @param tptr pointer to the object to call the member function on
AntonLS 1:0ba687d4196f 83 * @param mptr pointer to the member function to be called
AntonLS 5:1b9734e68327 84 * @param type Which serial interrupt to attach the member function to (MySerial::RxIrq for receive, TxIrq for transmit buffer empty)
AntonLS 1:0ba687d4196f 85 */
AntonLS 1:0ba687d4196f 86 template<typename T>
AntonLS 5:1b9734e68327 87 void attach( T* tptr, void (T::*mptr)(void), Serial::IrqType type=Serial::RxIrq )
AntonLS 1:0ba687d4196f 88 {
AntonLS 1:0ba687d4196f 89 if( (mptr != NULL) && (tptr != NULL) )
AntonLS 1:0ba687d4196f 90 {
AntonLS 1:0ba687d4196f 91 _my_irq[type].attach( tptr, mptr );
AntonLS 5:1b9734e68327 92 my_serial_irq_set( &_my_serial, (IrqType)type, 1 );
AntonLS 1:0ba687d4196f 93 }
AntonLS 1:0ba687d4196f 94 }
AntonLS 1:0ba687d4196f 95
AntonLS 1:0ba687d4196f 96 /** Generate a break condition on the serial line
AntonLS 1:0ba687d4196f 97 */
AntonLS 1:0ba687d4196f 98 void send_break();
AntonLS 1:0ba687d4196f 99
AntonLS 1:0ba687d4196f 100 static void _irq_handler( uint32_t id, SerialIrq irq_type );
AntonLS 1:0ba687d4196f 101
AntonLS 1:0ba687d4196f 102 protected:
AntonLS 2:fe1566cdb6e7 103 MySerialBase( PinName tx, PinName rx, PinName rts=RTS_PIN_NUMBER, PinName cts=CTS_PIN_NUMBER );
AntonLS 1:0ba687d4196f 104 virtual ~MySerialBase()
AntonLS 1:0ba687d4196f 105 {
AntonLS 1:0ba687d4196f 106 }
AntonLS 1:0ba687d4196f 107
AntonLS 2:fe1566cdb6e7 108 void my_serial_init( serial_t *obj, PinName tx, PinName rx, PinName rts, PinName cts, int baudrate );
AntonLS 6:ef758ac3c928 109 void my_serial_irq_handler( serial_t *obj, uart_irq_handler handler, uint32_t id );
AntonLS 5:1b9734e68327 110 void my_serial_irq_set( serial_t *obj, IrqType irq, uint32_t enable );
AntonLS 5:1b9734e68327 111
AntonLS 5:1b9734e68327 112 void error_handler();
AntonLS 6:ef758ac3c928 113 void cts_handler();
AntonLS 5:1b9734e68327 114
AntonLS 1:0ba687d4196f 115 int _base_getc();
AntonLS 1:0ba687d4196f 116 int _base_putc( int c );
AntonLS 1:0ba687d4196f 117
AntonLS 1:0ba687d4196f 118 serial_t _my_serial;
AntonLS 7:205ef63d311a 119 FunctionPointer _my_irq[NUM_IRQ_TYPES];
AntonLS 1:0ba687d4196f 120 int _my_baud;
AntonLS 1:0ba687d4196f 121 };
AntonLS 1:0ba687d4196f 122
AntonLS 1:0ba687d4196f 123 class MySerial : public MySerialBase, public Stream
AntonLS 1:0ba687d4196f 124 {
AntonLS 1:0ba687d4196f 125 public:
AntonLS 1:0ba687d4196f 126 /** Create a Serial port, connected to the specified transmit and receive pins
AntonLS 1:0ba687d4196f 127 *
AntonLS 1:0ba687d4196f 128 * @param tx Transmit pin
AntonLS 1:0ba687d4196f 129 * @param rx Receive pin
AntonLS 1:0ba687d4196f 130 *
AntonLS 1:0ba687d4196f 131 * @note
AntonLS 1:0ba687d4196f 132 * Either tx or rx may be specified as NC if unused
AntonLS 1:0ba687d4196f 133 */
AntonLS 3:388e441be8df 134 MySerial( PinName tx, PinName rx, const char *name=NULL,
AntonLS 3:388e441be8df 135 PinName rts=NC, PinName cts=NC ); // Defaults to using no flow control.
AntonLS 1:0ba687d4196f 136
AntonLS 1:0ba687d4196f 137 /** Write a string to the serial port
AntonLS 1:0ba687d4196f 138 *
AntonLS 1:0ba687d4196f 139 * @param str The string to write
AntonLS 1:0ba687d4196f 140 *
AntonLS 1:0ba687d4196f 141 * @returns 0 if the write succeeds, EOF for error
AntonLS 1:0ba687d4196f 142 */
AntonLS 1:0ba687d4196f 143 int puts( const char *str );
AntonLS 1:0ba687d4196f 144
AntonLS 1:0ba687d4196f 145 int printf( const char *format, ... );
AntonLS 1:0ba687d4196f 146
AntonLS 1:0ba687d4196f 147 int vprintf( const char *format, va_list arg );
AntonLS 1:0ba687d4196f 148
AntonLS 1:0ba687d4196f 149 protected:
AntonLS 1:0ba687d4196f 150 virtual int _getc();
AntonLS 1:0ba687d4196f 151 virtual int _putc( int c );
AntonLS 1:0ba687d4196f 152 };
AntonLS 1:0ba687d4196f 153
AntonLS 1:0ba687d4196f 154 } // namespace moo
AntonLS 1:0ba687d4196f 155
AntonLS 1:0ba687d4196f 156 #endif /* MYSERIAL_H */