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
00011 namespace SctApi {
00012 namespace Utility {
00013 inline void getpcrc(UINT32 mid, unsigned int &partition, unsigned int &crate, unsigned int &rod, unsigned &channel)
00014 {
00015 partition = (mid & 0xff000000) >> 24;
00016 crate = (mid & 0xff0000) >> 16;
00017 rod = (mid & 0xff00) >> 8;
00018 channel = (mid & 0xff) >> 0;
00019 }
00020
00021 inline UINT32 packpcrc(unsigned int &partition, unsigned int &crate, unsigned int &rod, unsigned &channel)
00022 {
00023 UINT32 mid = 0;
00024 mid |= (partition & 0xff) << 24;
00025 mid |= (crate & 0xff) << 16;
00026 mid |= (rod & 0xff) << 8;
00027 mid |= (channel & 0xff) << 0;
00028 return mid;
00029 }
00030
00031 inline void printHex(UINT32 num, int width) {
00032 std::cout << "0x";
00033 char saveFill = std::cout.fill('0');
00034 std::cout.width(width);
00035 std::cout.setf(std::ios::right);
00036 std::cout << std::hex << num << std::dec;
00037 std::cout.fill(saveFill);
00038 }
00039
00040 void printMemoryBlock(std::ostream &os, unsigned long *mem, unsigned long words, int wordsPerLine, int level = 0);
00041
00042 int translateBank(BankType bank);
00043
00044 class MemoryBlock {
00045 unsigned int words;
00046 boost::shared_array<unsigned long> buffer;
00047
00048 public:
00049 MemoryBlock() : words(0), buffer(0) {}
00050 MemoryBlock(unsigned int size, unsigned long *pointer) : words(size), buffer(pointer) {}
00051
00052 operator bool() { return buffer; }
00053
00054 unsigned int size() { return words; }
00055
00056 unsigned long operator[] (unsigned int i) {return buffer[i]; }
00057
00058 unsigned long *address() {return buffer.get(); }
00059 };
00060 }
00061 }
00062
00063 #endif