# 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
    00076   u8 getPreferredBaudCode() ; // Code 4 is SFBAUD115200.  Often 5==SFBAUD230400 is doable, tbough..
    00077   void setPreferredBaudCode(u8 code) ;
    00078
    00079   u8 getLowBaudCode() { return 0; }
    00080
    00081   u8 getHighBaudCode() ;
    00082   void setHighBaudCode(u8 code) ;
    00083
    00084   void predispatch() { /* nothing to do */ }
    00085
    00086   void start(u32 baud, bool oddParity = false);
    00087   void stop() ;
    00088   void setBaudRate(u32 baud, bool oddParity = false) ;
    00089   void checkTx() ;
    00090   u32 getFD();
    00091   SFBRxByteBuffer & getRx() { return rxBytes; }
    00092   SFBTxByteBuffer & getTx() { return txBytes; }
    00093 private:
    00094
    00095   void uartCommonHandler() ;    /* The interrupt routine */
    00096   friend void Uart0Handler();   /* Which these guys can call*/
    00097   friend void Uart1Handler();
    00098   friend void Uart2Handler();
    00099   friend void Uart3Handler();
    00100
    00101   void reinit();
    00102
    00103   PacketBuffer & rxBuf;         /* Inbound packets are dispatched from here */
    00104   SFBRxByteBuffer rxBytes;      /* Interrupt level writes raw inbound UART RX data to here */
    00105   SFBTxByteBuffer txBytes;      /* Interrupt level reads raw outbound UART TX data from here */
    00106   SFBFrame theFrame;            /* Packets are framed and deframed here */
    00107   u32 lastInputActivity;        /* millis() of last char read */
    00108   u32 currentBaudRate;          /* baud rate we're set for, if active*/
    00109   u8 flags;                     /* flags_and baud speed code */
    00110   const u8 face;
    00111   u8 preferredBaudCode;
    00112   u8 maxBaudCode;               /* maximum user specified baud code, or SFBAUD_CODE_COUNT if unspecified */
    00113
    00114   enum {
    00115     FLAG_TX_ACTIVE =  0x01,     /* Interrupt is TXing, we don't need to initiate it */
    00116     FLAG_STARTED =    0x02,     /* Set if current started and not stopped */
    00117     FLAG_ODD_PARITY = 0x04,     /* Set if odd parity in use */
    00118     FLAG_RESERVED3 =  0x08,     /* Rserved */
    00119     FLAG_RESERVED4 =  0x10,     /* Rserved */
    00120     FLAG_RESERVED5 =  0x20,     /* Rserved */
    00121     FLAG_RESERVED6 =  0x40,     /* Rserved */
    00122     FLAG_RESERVED7 =  0x80      /* Rserved */
    00123   };
    00124
    00125 public:
    00126
    00127   static void reinitAll();
    00128 };
    00129
    00130 #endif  /* SFBHWSERIALBOARD_H */
    00131