# SFBHWPinsHost.h

Go to the documentation of this file.

    00001 /*                                       -*- mode:C++; fill-column: 100 -*-
    00002   SFBHWPinsHost.h Host-specific shims around pin definitions
    00003   Copyright (C) 2008 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 SFBHWPINSBOARD_H
    00030 #error SFBHWPinsHost.h and SFBHWPinsBoard.h must not be #included together!
    00031 #endif
    00032
    00033 #ifndef SFBHWPINSHOST_H
    00034 #define SFBHWPINSHOST_H
    00035
    00036 #include "SFBTypes.h"
    00037
    00038 #ifdef __cplusplus
    00039 extern "C" {
    00040 #endif
    00041
    00046 class SFBHWHostRegister {
    00047 public:
    00048   SFBHWHostRegister(u32 address, u32 initVal = 0, u32 (*toRead)(u32,u32) = 0, u32 (*toWrite)(u32,u32) = 0) :
    00049     reg(initVal),
    00050     addr(address),
    00051     doRead(toRead),
    00052     doWrite(toWrite)
    00053   { }
    00054
    00055   operator u32() {
    00056     return doRead?doRead(addr,reg):reg;
    00057   }
    00058   SFBHWHostRegister & operator=(u32 val) {
    00059     if (doWrite) reg = doWrite(addr,val);
    00060     else reg = val;
    00061     return *this;
    00062   }
    00063   SFBHWHostRegister & operator&=(u32 val) {
    00064     if (doWrite) reg = doWrite(addr,reg&val);
    00065     else reg &= val;
    00066     return *this;
    00067   }
    00068   SFBHWHostRegister & operator|=(u32 val) {
    00069     if (doWrite) reg = doWrite(addr,reg|val);
    00070     else  reg |= val;
    00071     return *this;
    00072   }
    00073
    00074 private:
    00075   u32 reg;
    00076   u32 addr;
    00077   u32 (*doRead)(u32 addr, u32 oldval);
    00078   u32 (*doWrite)(u32 addr, u32 newval);
    00079 };
    00080
    00085 class SFBHWHostRegisterMap {
    00086 public:
    00087   SFBHWHostRegister & portInMap(u32 offset, u32 port) ;
    00088   enum { PINMODE_REGISTER_PORT = 0 };
    00089 };
    00090
    00092 extern SFBHWHostRegisterMap hostRegisters;
    00093
    00094 #define SFB_PORT_IN_MAP(offset, port) hostRegisters.portInMap(offset,port)
    00095
    00096 #define SFB_PORT_PINMODE_REGISTER(offset) hostRegisters.portInMap(offset,SFBHWHostRegisterMap::PINMODE_REGISTER_PORT)
    00097
    00098 #define REFLEX_RGB_RED_ON BUG_UNIMPLEMENTED()
    00099 #define REFLEX_RGB_RED_OFF BUG_UNIMPLEMENTED()
    00100 #define REFLEX_RGB_GREEN_ON BUG_UNIMPLEMENTED()
    00101 #define REFLEX_RGB_GREEN_OFF BUG_UNIMPLEMENTED()
    00102 #define REFLEX_RGB_BLUE_ON BUG_UNIMPLEMENTED()
    00103 #define REFLEX_RGB_BLUE_OFF BUG_UNIMPLEMENTED()
    00104
    00105 #define SFB_PORT_DIR_REGISTER(port)  SFB_PORT_IN_MAP(0x00,port)
    00106 #define SFB_PORT_MASK_REGISTER(port) SFB_PORT_IN_MAP(0x10,port)
    00107 #define SFB_PORT_PIN_REGISTER(port)  SFB_PORT_IN_MAP(0x14,port)
    00108 #define SFB_PORT_SET_REGISTER(port)  SFB_PORT_IN_MAP(0x18,port)
    00109 #define SFB_PORT_CLR_REGISTER(port)  SFB_PORT_IN_MAP(0x1C,port)
    00110
    00111 #define SFB_PORT_GET_BIT_MASK(port,bit) (SFB_PORT_PIN_REGISTER(port)&(bit))
    00112
    00113 #define SFB_PORT_SET_BIT_MASK(port,mask) (SFB_PORT_SET_REGISTER(port) |= (mask))
    00114 #define SFB_PORT_CLR_BIT_MASK(port,mask) (SFB_PORT_CLR_REGISTER(port) |= (mask))
    00115 #define SFB_PORT_WRITE_BIT_MASK(port,mask,value) \
    00116   ((value==LOW)?SFB_PORT_CLR_BIT_MASK(port,mask):SFB_PORT_SET_BIT_MASK(port,mask))
    00117
    00118 extern void reenterBootloader() __attribute__ ((noreturn));
    00119
    00120 extern void reenterBrainstem() __attribute__ ((noreturn));
    00121
    00122 extern void hwpins_startup_initialization();
    00123
    00124 /* Low-level last ditch routine to set the rbg leds, bypassing (and
    00125    thereby breaking) all the normal pin management stuff.  So don't
    00126    use this unless the situation is dire enough that you don't case
    00127    about that. */
    00128 extern void debugRGB(int rgbBits, int wait);
    00129
    00130 extern void debugRGBNum(int num, int bits, int loops);
    00131
    00132 extern void _dieOnBoard_(u32 blinkCode, const char * file, int lineno) __attribute__ ((noreturn));
    00133
    00140 extern u32 micros();
    00141
    00146 extern u32 millis();
    00147
    00153 extern u64 microseconds();
    00154
    00160 extern u32 milliseconds();
    00161
    00166 extern u32 seconds();
    00167
    00168 #ifdef __cplusplus
    00169 }
    00170 #endif
    00171
    00172 #endif  /* SFBHWPINSHOST_H */