SFBHWPinsHost.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00125
00126
00127
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