pit_def.cpp

Go to the documentation of this file.
00001 // file to include global functions definitions
00002 #include <sys/time.h>
00003 #include <iostream>
00004 #include <fstream>
00005 #include<sstream>
00006 
00007 #include "pit_def.h"
00008 
00009 
00013 //\param its bits the numbers of bits
00014 //\param input its the register which has the value that we want to extract 
00015 UInt32 extractFromUInt32(int offset, int bits, UInt32 input){
00016         
00017         // creats a mask for the number of bits (already shifetd to the left)
00018         // something like 11111000
00019         UInt32 mask = ~(0xffffffff << bits);
00020         // shifts the input 
00021         UInt32 shifted=input >> offset;
00022         
00023         // returns the masked input
00024         return (shifted & mask);
00025 }
00026 
00027 
00032 UInt32 insertIntoUInt32(int offset, int bits, UInt32 data, UInt32 input){
00033         
00034         //std::cout     << std::endl << "Offset=" << offset << " bits=" << bits
00035                 //              << " data=0x" << std::hex << data << " input=0x" << input << endl;
00036                 
00037                                         // creates the mask in two steps
00038                                         // the mask_part1 is something like 11110000
00039                                         // the mask_part2 is something like 00000011
00040         
00041         UInt32 mask_part1 = 0;
00042         unsigned int shift_mask1 = (unsigned int)(offset+bits); // this is to fix an amazing bug: when the number of bits to shift is (at runtime and only runtime) greater than 31, then there is no bit shift at all.
00043                 if (shift_mask1 > 31) mask_part1 = 0; 
00044                 else mask_part1 = 0xffffffff << (offset+bits);
00045         
00046         UInt32 mask_part2= ~( 0xffffffff << offset);
00047         UInt32 mask= mask_part1 | mask_part2;
00048                 //std::cout << "Mask_part1=0x" << std::hex << mask_part1 << " mask_part2=0x" << mask_part2 
00049                 //      << " mask=0x" <<mask<< std::endl;
00050         
00051                                         // shifts the data to the right place
00052         UInt32 shiftedValue = data<<offset;
00053                 //std::cout << "shiftedValue=0x" << std::hex << shiftedValue << " return=0x"<< ((input & mask) | (shiftedValue & (~mask))) << endl;
00054         
00055         // does the double masking and returns
00056         return (input & mask) | (shiftedValue & (~mask));
00057         
00058 }
00059 
00060 
00061 // Sleep milliseconds
00062 void sleepMilli(long ms) {
00063  const timespec ts = {ms / 1000, ms % 1000 * 1000000};
00064  nanosleep(&ts, NULL);
00065 }
00066 
00067 
00068 // Sleep naroseconds
00069 void sleepNano(long ns) {
00070  const timespec ts = {0, ns};
00071  nanosleep(&ts, NULL);
00072 }
00073 
00074 
00075 vector<string> strsplit(const string &inputstr, char separator){
00076         vector<string> out;
00077         string aux;
00078         std::stringstream str(inputstr);
00079         
00080         //std::stringstream()
00081         
00082         
00083         while(getline(str, aux)){
00084                 
00085         }
00086         
00087         return out;
00088 }

Generated on Sat Mar 29 22:55:54 2008 for pixelTrigger by  doxygen 1.5.0