# SFBHWSerialBoard.h

Go to the documentation of this file.

    00001 /*                                             -*- mode:C++; fill-column:100 -*-
    00002   SFBHWSerialBoard.h Low-level serial support for the board
    00003   Copyright (C) 2009 The Regents of the University of New Mexico.  All rights reserved.
    00004
    00005   This library is free software; you can redistribute it and/or
    00006   modify it under the terms of the GNU Lesser General Public
    00007   License as published by the Free Software Foundation; either
    00008   version 2.1 of the License, or (at your option) any later version.
    00009
    00010   This library is distributed in the hope that it will be useful,
    00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013   Lesser General Public License for more details.
    00014
    00015   You should have received a copy of the GNU General Public License
    00016   along with this library; if not, write to the Free Software
    00017   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00018   USA
    00019
    00020   $Id$
    00021 */
    00029 #ifdef SFBHWSERIALHOST_H
    00030 #error SFBHWSerialBoard.h and SFBHWSerialHost.h must not be #included together!
    00031 #endif
    00032
    00033 #ifndef SFBHWSERIALBOARD_H
    00034 #define SFBHWSERIALBOARD_H
    00035
    00036 #include "SFBFrame.h"
    00037 #include "lpc/LPC23xx.h" /* get the hardware definitions */
    00038
    00039 class SFBSerial; /* FORWARD DECLARATION */
    00040
    00041 #define CAN_WRITE(fd) (REGISTER_OFFSET(fd,UxLSR) & 0x20)
    00042 #define WRITE_BYTE(fd,byte) (REGISTER_OFFSET(fd,UxTHR) = (byte))
    00043 #define CAN_READ(fd) (REGISTER_OFFSET(fd,UxLSR) & 0x01)
    00044 #define READ_BYTE(fd) REGISTER_OFFSET(fd,UxRBR)
    00045
    00058 class SFBHWSerial {  /* Note we are defining 'SFBHWSerial', not 'SFBHWSerialBoard'! */
    00059
    00060 public:
    00061
    00062   SFBHWSerial(int face) ;
    00063
    00064   SFBFrame & getFrame() { return theFrame; }
    00065
    00066   void putcBlocking(const u8 byte) ;
    00067
    00068   static u32 getFirstFace() { return NORTH; }
    00069   static bool moreFaces(u32 face) ;
    00070   static u32 nextFace(u32 face) ;
    00071
    00072   static SFBSerial & getFace(u32 face) ;
    00073
    00074   bool getPreferOddParity() { return true; } // N(one) wins unless both sides say O(dd).  But we like odd for robustness.
    00075   u8 getPreferredBaudCode() { return 4; } // Code 4 is SFBAUD115200.  Often 5==SFBAUD230400 is doable, tbough..
    00076   u8 getLowBaudCode() { return 0; }
    00077   u8 getHighBaudCode() { return 6; }
    00078
    00079   void predispatch() { /* nothing to do */ }
    00080
    00081   void start(u32 baud, bool oddParity = false);
    00082   void stop() ;
    00083   void setBaudRate(u32 baud, bool oddParity = false) ;
    00084   void checkTx() ;
    00085   u32 getFD();
    00086
    00087 private:
    00088
    00089   void uartCommonHandler() ;    /* The interrupt routine */
    00090   friend void Uart0Handler();   /* Which these guys can call*/
    00091   friend void Uart1Handler();
    00092   friend void Uart2Handler();
    00093   friend void Uart3Handler();
    00094
    00095   PacketBuffer & rxBuf;         /* Inbound packets are dispatched from here */
    00096   SFBRxByteBuffer rxBytes;      /* Interrupt level writes raw inbound UART RX data to here */
    00097   SFBTxByteBuffer txBytes;      /* Interrupt level reads raw outbound UART TX data from here */
    00098   SFBFrame theFrame;            /* Packets are framed and deframed here */
    00099   u32 lastInputActivity;        /* millis() of last char read */
    00100   bool txActive;
    00101   const u8 face;
    00102
    00103   enum {
    00104     FLAG_TX_ACTIVE = 0x02     /* Interrupt is TXing, we don't need to initiate it */
    00105   };
    00106
    00107 public:
    00108   //  static void startup_initialization() ;
    00109 };
    00110
    00111 #endif  /* SFBHWSERIALBOARD_H */
    00112