00001
00002 #include <sys/time.h>
00003 #include <iostream>
00004 #include <fstream>
00005 #include<sstream>
00006
00007 #include "pit_def.h"
00008
00009
00013
00014
00015 UInt32 extractFromUInt32(int offset, int bits, UInt32 input){
00016
00017
00018
00019 UInt32 mask = ~(0xffffffff << bits);
00020
00021 UInt32 shifted=input >> offset;
00022
00023
00024 return (shifted & mask);
00025 }
00026
00027
00032 UInt32 insertIntoUInt32(int offset, int bits, UInt32 data, UInt32 input){
00033
00034
00035
00036
00037
00038
00039
00040
00041 UInt32 mask_part1 = 0;
00042 unsigned int shift_mask1 = (unsigned int)(offset+bits);
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
00049
00050
00051
00052 UInt32 shiftedValue = data<<offset;
00053
00054
00055
00056 return (input & mask) | (shiftedValue & (~mask));
00057
00058 }
00059
00060
00061
00062 void sleepMilli(long ms) {
00063 const timespec ts = {ms / 1000, ms % 1000 * 1000000};
00064 nanosleep(&ts, NULL);
00065 }
00066
00067
00068
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
00081
00082
00083 while(getline(str, aux)){
00084
00085 }
00086
00087 return out;
00088 }