stf_da_slow_device::SlowAnalogOutEvent::SlowAnalogOutEvent( double time, const std::vector<RawEvent>& sourceEvents, FPGA_Device* device) : FPGA_DynamicEvent(time, device) { eventNotBeingConstructed = false; addSourceEvents(sourceEvents); uInt32 channelBits = sourceEvents.at(0).channel(); bool reset = false; bool update = true; uInt32 registerBits = 3; //Most of the command bits can be set once and for all setBits(update, 14, 14); setBits(channelBits, 15, 20); setBits(registerBits, 21, 22); setBits(reset, 23, 23); //Use the updateValue function to set the actual voltage. This function gets called again //if the value is a DynamicValue and it gets changed remotely. updateValue(sourceEvents); //For setting the voltage. eventNotBeingConstructed = true; }
void writeToCoreRegisters(int regNum, uint32_t valueToWrite) { if(regNum == SP) coreReg[regNum] = setBits(valueToWrite,0b00,1,0); //if the register to write is SP, mask off the last 2 bits else if(regNum == PC) coreReg[regNum] = setBits(valueToWrite,0b0,0,0); //if the register to write is PC, mask off the last bit else coreReg[regNum] = valueToWrite; }
/*************************************************************************** ** expand ** ** Purpose: To uncompress the data contained in the input buffer and store ** the result in the output buffer. The fileLength parameter says how ** many bytes to uncompress. The compression itself is a form of LZW that ** adjusts the number of bits that it represents its codes in as it fills ** up the available codes. Two codes have special meaning: ** ** code 256 = start over ** code 257 = end of data ***************************************************************************/ void lzwExpand(uint8 *in, uint8 *out, int32 len) { int32 c, lzwnext, lzwnew, lzwold; uint8 *s, *end; initLZW(); setBits(START_BITS); // Starts at 9-bits lzwnext = 257; // Next available code to define end = (uint8 *)(out + (uint32)len); lzwold = inputCode(&in); // Read in the first code c = lzwold; lzwnew = inputCode(&in); while ((out < end) && (lzwnew != 0x101)) { if (lzwnew == 0x100) { // Code to "start over" lzwnext = 258; setBits(START_BITS); lzwold = inputCode(&in); c = lzwold; *out++ = (char)c; lzwnew = inputCode(&in); } else { if (lzwnew >= lzwnext) { // Handles special LZW scenario *decodeStack = c; s = decodeString(decodeStack + 1, lzwold); } else s = decodeString(decodeStack, lzwnew); // Reverse order of decoded string and // store in out buffer c = *s; while (s >= decodeStack) *out++ = *s--; if (lzwnext > MAX_CODE) setBits(BITS + 1); prefixCode[lzwnext] = lzwold; appendCharacter[lzwnext] = c; lzwnext++; lzwold = lzwnew; lzwnew = inputCode(&in); } } closeLZW(); }
uint32_t reverseBits(uint32_t n) { int k = sizeof(uint32_t) * 8; for (int i = 0; i < k / 2; ++i) { short a = getBits(i, &n); short b = getBits(k - 1 - i, &n); if (a == b) continue; setBits(i, &n); setBits(k - 1 - i, &n); } return n; }
void Lcd::clear(){ resetRS(); setE(); setBits(0x01); Timer::wait_ms(1); resetE(); Timer::wait_ms(3); resetRS(); setE(); setBits(0x06); Timer::wait_ms(1); resetE(); Timer::wait_ms(2); }
// Sets the byte at position pos to value. void setByte_BE(CF_LONGWord *number, int pos, CF_Byte value) { /*for(int i=pos*8; i<(pos+1)*8 && i<32; i++){ clearBit(number,i); } *number |= value << pos*8;*/ setBits(number, (pos+1)*8, (pos)*8, value); }
VideoFrame::VideoFrame(const QImage& image) : Frame(new VideoFramePrivate(image.width(), image.height(), VideoFormat(image.format()))) { setBits((uchar*)image.constBits(), 0); setBytesPerLine(image.bytesPerLine(), 0); d_func()->qt_image.reset(new QImage(image)); }
void p2(void) { unsigned int b=9131953; int a[5]={1,2,8,18,21}; setBits(a, 5, &b); printf("The result of setting bits is %u\n", b); }
/* StandardFPSCRValue() // ==================== bits(32) StandardFPSCRValue() return ‘00000’ : FPSCR<26> : ‘11000000000000000000000000’; */ uint32_t readSCBRegisters(uint32_t registerName) { if(registerName == FPDSCR) return setBits(FPDSCR_INIT_VALUE, getBits(coreReg[fPSCR],26,26), 26,26); else return loadByteFromMemory(registerName, 4); }
void loadPosition() { FILE *file; int32_t base = 10; printf("Lade Position\n"); file = fopen("minRe.val", "r"); if (file != NULL) { mpf_inp_str(mandelRange.minRe, file, base); } if (file != NULL) { file = fopen("maxRe.val", "r"); mpf_inp_str(mandelRange.maxRe, file, base); } fclose(file); if (file != NULL) { file = fopen("minIm.val", "r"); mpf_inp_str(mandelRange.minIm,file, base); } fclose(file); file = fopen("iter.val", "rb"); if (file != NULL) { fread(&maxIterations, sizeof(maxIterations), 1, file); } fclose(file); file = fopen("bits.val", "rb"); if (file != NULL) { fread(&gmpBit, sizeof(gmpBit), 1, file); setBits(gmpBit); } fclose(file); printf("Position geladen\n"); }
VideoFrame::VideoFrame(const QImage& image) : Frame(*new VideoFramePrivate(image.width(), image.height(), VideoFormat(image.format()))) { // TODO: call const image.bits()? setBits((uchar*)image.bits(), 0); setBytesPerLine(image.bytesPerLine(), 0); }
void NetworkManager::SerialSetting::fromMap(const QVariantMap &setting) { if (setting.contains(QLatin1String(NM_SETTING_SERIAL_BAUD))) { setBaud(setting.value(QLatin1String(NM_SETTING_SERIAL_BAUD)).toUInt()); } if (setting.contains(QLatin1String(NM_SETTING_SERIAL_BITS))) { setBits(setting.value(QLatin1String(NM_SETTING_SERIAL_BITS)).toUInt()); } if (setting.contains(QLatin1String(NM_SETTING_SERIAL_PARITY))) { QChar character = setting.value(QLatin1String(NM_SETTING_SERIAL_PARITY)).toChar(); if (character == 'n') { setParity(NoParity); } else if (character == 'E') { setParity(EvenParity); } else if (character == 'o') { setParity(OddParity); } } if (setting.contains(QLatin1String(NM_SETTING_SERIAL_STOPBITS))) { setStopbits(setting.value(QLatin1String(NM_SETTING_SERIAL_STOPBITS)).toUInt()); } if (setting.contains(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY))) { setSendDelay((Setting::SecretFlagType)setting.value(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY)).toULongLong()); } }
// Sets the byte at position pos to value. void setByte_LE(CF_LONGWord *number, int pos, CF_Byte value){ /* for(int i=(31-pos*8); i>(31-(pos+1)*8) && i>-1; i--){ clearBit(number,i); } *number |= value << (24-pos*8); */ setBits(number, (32-pos*8), (32-(pos+1)*8), value); }
void Lcd::printChar(const char c){ setRS(); setE(); setBits(c); Timer::wait_ms(1); resetE(); Timer::wait_ms(1); }
void GPIO::selectAltFunctionNoLog(uint32_t pin, ALT alt) { assert(pin <= MAX_PIN); auto grp = pin/SEL_OF_EACH_GROUP; auto offset=pin%SEL_OF_EACH_GROUP; setBits(reg32(GPFSELx + grp*4),offset*BITS_PER_SEL,(offset+1)*BITS_PER_SEL-1,alt); signalModify(pin,P_OFF); }
// Set level (0-10) // Level 0 means all leds off // Level 10 means all leds on void Grove_LED_Bar::setLevel(unsigned char level) { level = max(0, min(10, level)); // Set level number of bits from the left to 1 __state = ~(~0 << level); setBits(__state); }
void Config::makeDefault() { setUrl(); version = 0; setOs(); setBits(); makeFile(); }
//Reads a multiplexed pin as a digital value. //Also sets the pin as a digital input if it isn't already. int Multiplexer::muxDigitalRead(int mux_pin) { if (_muxPinSettings[mux_pin] != DIGITAL_IN) { return -1;} checkSignalPin(mux_pin); setBits(mux_pin); return digitalRead(this->channel_pins[4]); }
//Reads a multiplexed pin as an analog value. //Also sets the pin as a analog input if it isn't already. int Multiplexer::muxAnalogRead(int mux_pin) { if (_muxPinSettings[mux_pin] != ANALOG_IN) { return -1;} checkSignalPin(mux_pin); setBits(mux_pin); return analogRead(this->channel_pins[4]); }
NetworkManager::SerialSetting::SerialSetting(const Ptr &other): Setting(other), d_ptr(new SerialSettingPrivate()) { setBaud(other->baud()); setBits(other->bits()); setParity(other->parity()); setStopbits(other->stopbits()); setSendDelay(other->sendDelay()); }
void stf_da_slow_device::SlowAnalogOutEvent::updateValue(const std::vector<RawEvent>& sourceEvents) { uInt32 voltageInt = static_cast<int>((-1*(sourceEvents.at(0).numberValue()) + 10.)*16383./20.); if(eventNotBeingConstructed) { cout << "SlowAnalogOutEvent::updateValue: " << sourceEvents.at(0).numberValue() << endl; } setBits(voltageInt, 0, 13); }
static void sendDMADoneInterrupt(Uns32 chNum) { if (tcdReg[chNum].TCD_CSR.bits.INTMAJOR == 1) { if (diagnosticLevel >= 2) bhmMessage("I", periphName, "Send DMA Interrupt for channel = %d", chNum); ppmWriteNet(tcdReg[chNum].dmaInterrupt, 1); setBits(&(chReg->INT.value), chNum, 1, "INT"); } }
void VideoFrame::init() { Q_D(VideoFrame); AVPicture picture; AVPixelFormat fff = (AVPixelFormat)d->format.pixelFormatFFmpeg(); //int bytes = avpicture_get_size(fff, width(), height()); //d->data.resize(bytes); avpicture_fill(&picture, (uint8_t*)d->data.constData(), fff, width(), height()); setBits(picture.data); setBytesPerLine(picture.linesize); }
//Takes a global array of length 16 and fills it with readings //from all multiplexed pins defined as inputs. int Multiplexer::readPin(int mux_pin) { setBits(mux_pin); if (_muxPinSettings[mux_pin] == ANALOG_IN) { return muxAnalogRead(mux_pin);} if (_muxPinSettings[mux_pin] == DIGITAL_IN) { return muxDigitalRead(mux_pin);} return -1; }
//get to know which the base 10bits opcode from the given string void findBaseOpcode(char *string, BitsInfo *bitsInfo) { uint32_t dummy = 0; int sizeOfString = strlen(string) - 1; int i = 0, numberOfbitsSegment = 0; while(sizeOfString >= 0) { if(string[sizeOfString] == 'X') dummy = setBits(dummy,0b0,i,i); else if(string[sizeOfString] == '0') dummy = setBits(dummy,0b0,i,i); else if(string[sizeOfString] == '1') dummy = setBits(dummy,0b1,i,i); sizeOfString--; i++; } (*bitsInfo).baseOpcode = dummy; }
// Toggle a single led // led (1-10) void Grove_LED_Bar::toggleLed(unsigned char led) { led = max(1, min(10, led)); // Zero based index 0-9 for bitwise operations led--; // Bitwise XOR the leds current value __state ^= (0x01<<led); setBits(__state); }
// Set a single led // led (1-10) // state (0=off, 1=on) void Grove_LED_Bar::setLed(unsigned char led, bool state) { led = max(1, min(10, led)); // Zero based index 0-9 for bitwise operations led--; // Bitwise OR or bitwise AND __state = state ? (__state | (0x01<<led)) : (__state & ~(0x01<<led)); setBits(__state); }
Lcd::Lcd(){ GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_10; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; GPIO_Init(GPIOH, &GPIO_InitStructure); resetRS(); setE(); setBits(0x38); Timer::wait_ms(1); resetE(); Timer::wait_ms(1); resetRS(); setE(); setBits(0x38); Timer::wait_ms(1); resetE(); Timer::wait_ms(1); resetRS(); setE(); setBits(0x0F); Timer::wait_ms(1); resetE(); Timer::wait_ms(1); resetRS(); setE(); setBits(0x01); Timer::wait_ms(1); resetE(); Timer::wait_ms(3); resetRS(); setE(); setBits(0x06); Timer::wait_ms(1); resetE(); Timer::wait_ms(1); resetRS(); setE(); setBits(0x80); Timer::wait_ms(1); resetE(); Timer::wait_ms(1); }
unsigned int assignOneBit(int bitNumber, int bitValue, unsigned int source) { if(bitValue == 0) { return clearBits(bitNumber, bitValue, source); } else if(bitValue == 1) { return setBits(bitNumber, bitNumber, source); } else return 0; }
// TODO: alignment. use av_samples_fill_arrays void AudioFrame::init() { Q_D(AudioFrame); const int nb_planes = d->format.planeCount(); d->line_sizes.resize(nb_planes); d->planes.resize(nb_planes); if (d->data.isEmpty()) return; const int bpl(d->data.size()/nb_planes); for (int i = 0; i < nb_planes; ++i) { setBytesPerLine(bpl, i); setBits((uchar*)d->data.constData() + i*bpl, i); } }