00001 #ifndef SCTAPI_UTILITY_H
00002 #define SCTAPI_UTILITY_H
00003
00004 #include <iostream>
00005 #include <boost/shared_array.hpp>
00006
00007 #include "SctApiFwd.h"
00008
00009 #include "processor.h"
00010 #include "registerIndices.h"
00011 #include <list>
00012
00013 namespace SctApi {
00014 namespace Utility {
00015 inline UINT32 EfbErrorMask(UINT32 efb, UINT32 link){
00016 #ifdef EFB_ERROR_MASK
00017 return EFB_ERROR_MASK(efb, link);
00018 #elif (defined(ERROR_MASK))
00019 return ERROR_MASK(efb, link)
00020 #else
00021 #error "Can't work out how to find an error mask - cant compile"
00022 #endif
00023 }
00024
00025 inline void getpcrc(UINT32 mid, unsigned int &partition, unsigned int &crate, unsigned int &rod, unsigned &channel)
00026 {
00027 partition = (mid & 0xff000000) >> 24;
00028 crate = (mid & 0xff0000) >> 16;
00029 rod = (mid & 0xff00) >> 8;
00030 channel = (mid & 0xff) >> 0;
00031 }
00032
00033 inline UINT32 packpcrc(unsigned int &partition, unsigned int &crate, unsigned int &rod, unsigned &channel)
00034 {
00035 UINT32 mid = 0;
00036 mid |= (partition & 0xff) << 24;
00037 mid |= (crate & 0xff) << 16;
00038 mid |= (rod & 0xff) << 8;
00039 mid |= (channel & 0xff) << 0;
00040 return mid;
00041 }
00042
00043 inline void printHex(UINT32 num, int width) {
00044 std::cout << "0x";
00045 char saveFill = std::cout.fill('0');
00046 std::cout.width(width);
00047 std::cout.setf(std::ios::right);
00048 std::cout << std::hex << num << std::dec;
00049 std::cout.fill(saveFill);
00050 }
00051
00052 void printMemoryBlock(std::ostream &os, unsigned long *mem, unsigned long words, int wordsPerLine, int level = 0);
00053
00054 int translateBank(BankType bank);
00055
00056 UINT32 translateApiBanksToRodCfgBitSet(std::list<BankType> banks);
00057
00059 unsigned translateConfigType(ConfigType cfg);
00060
00062 unsigned translateConfigTypeForSendPrimitive(ConfigType cfg);
00063
00065 unsigned translateChip(unsigned chip);
00066
00069 UINT32 translateConfigTypeBitset(UINT32 api_bits, bool verbose=false);
00070
00076 UINT32 getSetableConfigType(UINT32 cfgType, bool verbose=false);
00077
00078 class MemoryBlock {
00079 unsigned int words;
00080 boost::shared_array<unsigned long> buffer;
00081
00082 public:
00083 MemoryBlock() : words(0), buffer(0) {}
00084 MemoryBlock(unsigned int size, unsigned long *pointer) : words(size), buffer(pointer) {}
00085
00086 operator bool() { return buffer; }
00087
00088 unsigned int size() { return words; }
00089
00090 unsigned long operator[] (unsigned int i) {return buffer[i]; }
00091
00092 unsigned long *address() {return buffer.get(); }
00093 };
00094 }
00095 }
00096
00097 #endif