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 preferredBaudCode; } // Code 4 is SFBAUD115200.  Often 5==SFBAUD230400 is doable, tbough..
00076   void setPreferredBaudCode(u8 code) ;
00077   u8 getLowBaudCode() { return 0; }
00078   u8 getHighBaudCode() { return 6; }
00079 
00080   void predispatch() { /* nothing to do */ }
00081 
00082   void start(u32 baud, bool oddParity = false);
00083   void stop() ;
00084   void setBaudRate(u32 baud, bool oddParity = false) ;
00085   void checkTx() ;
00086   u32 getFD();
00087 
00088 private:
00089 
00090   void uartCommonHandler() ;    /* The interrupt routine */
00091   friend void Uart0Handler();   /* Which these guys can call*/ 
00092   friend void Uart1Handler();
00093   friend void Uart2Handler();
00094   friend void Uart3Handler();
00095 
00096   PacketBuffer & rxBuf;         /* Inbound packets are dispatched from here */
00097   SFBRxByteBuffer rxBytes;      /* Interrupt level writes raw inbound UART RX data to here */
00098   SFBTxByteBuffer txBytes;      /* Interrupt level reads raw outbound UART TX data from here */
00099   SFBFrame theFrame;            /* Packets are framed and deframed here */
00100   u32 lastInputActivity;        /* millis() of last char read */ 
00101   bool txActive;
00102   const u8 face;
00103   u8 preferredBaudCode;
00104 
00105   enum {
00106     FLAG_TX_ACTIVE = 0x02     /* Interrupt is TXing, we don't need to initiate it */
00107   };
00108 
00109 public:
00110   //  static void startup_initialization() ;
00111 };
00112 
00113 #endif  /* SFBHWSERIALBOARD_H */
00114 

Generated on Tue Nov 17 08:37:18 2009 for SFB by doxygen 1.5.9