void CRenderer::SetTransform( const Base::Math::CMatrix4x4 &_transform, const eMatrixTransformType _type ) { switch( _type ) { case eWorld: m_WorldMat = _transform; break; case eView: m_ViewMat = _transform; break; case eProjection: m_ProjMat = _transform; break; default: g_Log->Warning( "Unknown transformation type..." ); } setBit( m_bDirtyMatrices, _type ); }
unsigned char OLED::read(void) { char data=0; clrBit(OLED_scl_port,OLED_scl_pin); setBit(OLED_sda_port,OLED_sda_pin); //make sda high clrBit(OLED_sda_port,OLED_sda_pin); //make sda input for(int i=0 ; i<8 ;i++) { //make scl high setBit(OLED_scl_port,OLED_scl_pin); _delay_us(usDelay);//delay if(ifHigh(OLED_sda_read,OLED_sda_pin)) //check if sda then update data { data|=0x01; } clrBit(OLED_scl_port,OLED_scl_pin); //make scl low _delay_us(usDelay); //delay data=data<<1; //left shift data } //not sending ack!! return data; //return data }
/* * Find (add allocate) a free data block. * The approach simply involves a scan of the block map for a zero. * It's fatal, at this point, if none is found. */ int allocBlock(void) { int block = findNextClear(BMap, SB->sb_first_block, SB->sb_blocks); if (block == -1) { fprintf(stderr,"Could not allocate free data block (necessary).\n"); exit(1); } /* mark it as allocated */ setBit(BMap,block); return block; }
/* Set the number of averages: 0, 4, 8, 16 or 32. * */ void ADC_Module::setAveraging(uint8_t num) { if (calibrating) wait_for_cal(); if (num <= 1) { num = 0; // *ADC_SC3_avge = 0; clearBit(ADC_SC3, ADC_SC3_AVGE_BIT); } else { // *ADC_SC3_avge = 1; setBit(ADC_SC3, ADC_SC3_AVGE_BIT); if (num <= 4) { num = 4; // *ADC_SC3_avgs0 = 0; // *ADC_SC3_avgs1 = 0; clearBit(ADC_SC3, ADC_SC3_AVGS0_BIT); clearBit(ADC_SC3, ADC_SC3_AVGS1_BIT); } else if (num <= 8) { num = 8; // *ADC_SC3_avgs0 = 1; // *ADC_SC3_avgs1 = 0; setBit(ADC_SC3, ADC_SC3_AVGS0_BIT); clearBit(ADC_SC3, ADC_SC3_AVGS1_BIT); } else if (num <= 16) { num = 16; // *ADC_SC3_avgs0 = 0; // *ADC_SC3_avgs1 = 1; clearBit(ADC_SC3, ADC_SC3_AVGS0_BIT); setBit(ADC_SC3, ADC_SC3_AVGS1_BIT); } else { num = 32; // *ADC_SC3_avgs0 = 1; // *ADC_SC3_avgs1 = 1; setBit(ADC_SC3, ADC_SC3_AVGS0_BIT); setBit(ADC_SC3, ADC_SC3_AVGS1_BIT); } } analog_num_average = num; }
void hardware_light_enable(uint8_t level) { hardware_flashlight(0); if(level > 2) level = 2; DDRA &= ~0b00000111; // clear all // PORTA &= ~0b00000111; // clear all // setBit(level, DDRA); // Powers Sensor // clrBit(level, PORTA); }
void BitWriter::addBit(LBit input) { setBit(work_on, bitPointer, input); bitPointer++; if(bitPointer >= 8) { data->push_back(work_on); work_on = 0x00; bitPointer = 0; dataSize++; } }
Packet ProcessingElement::trafficShuffle() { int nbits = (int) log2ceil((double) (GlobalParams::mesh_dim_x * GlobalParams::mesh_dim_y)); int dnode = 0; for (int i = 0; i < nbits - 1; i++) setBit(dnode, i + 1, getBit(local_id, i)); setBit(dnode, 0, getBit(local_id, nbits - 1)); Packet p; p.src_id = local_id; p.dst_id = dnode; p.timestamp = sc_time_stamp().to_double() / GlobalParams::clock_period_ps; p.size = p.flit_left = getRandomSize(); return p; }
void digitalWrite(const PIN pin, unsigned int value) { unsigned long addr; unsigned long bitMask; pinToMem(pin, &addr, &bitMask); unsigned long reg = getReg(addr + GPIO_DATAOUT); if (value) reg = setBit(reg, bitMask); else reg = clearBit(reg, bitMask); setReg(addr + GPIO_DATAOUT,reg); }
Cspi::Cspi(u08 spiNum, Cpin* _pinSS, SPI_INTLVL_t _intLevel, SPI_PRESCALER_t _prescaler, SPI_MODE_t _mode, bool msbFirst, bool master, bool clk2X) { switch (spiNum) { case 0: base = &SPIC; break; case 1: base = &SPID; break; default: while (1) { } break; } this->pinSS = _pinSS; this->intLevel = _intLevel; this->mode = _mode; setGroup(base->INTCTRL, SPI_INTLVL_gm, _intLevel); setGroup(base->CTRL, SPI_PRESCALER_gm, _prescaler); setGroup(base->CTRL, SPI_MODE_gm, _mode); if (msbFirst) { clrBit(base->CTRL, SPI_DORD_bp); } else { setBit(base->CTRL, SPI_DORD_bp); } if (master) { setBit(base->CTRL, SPI_MASTER_bp); } else { clrBit(base->CTRL, SPI_MASTER_bp); } if (clk2X) { setBit(base->CTRL, SPI_CLK2X_bp); } else { clrBit(base->CTRL, SPI_CLK2X_bp); } setBit(base->CTRL, SPI_ENABLE_bp); }
int test (void) { size_t a = 0; for (size_t i = 0; i < 8*sizeof(a); ++i) { setBit(a, i, true); if (a != (0x01llu << i)) { std::cout << "error setting bit " << i << " to true " << std::endl; } printBit(a); a = 0; } return 0; a = ~0; for (size_t i = 0; i < 8*sizeof(a); ++i) { setBit(a, i, false); if (a != (~(0x01llu << i))) { std::cout << "error setting bit " << i << " to true " << std::endl; } a = ~0; } return 0; }
/** * Scrubs an image of all secret messages so you can hide your tracks! * * @param image the image to scrub */ void Steg::scrub(const std::string &image) { std::vector<char> scrubbedBytes; read(scrubbedBytes, image); auto throwOut = getHeaderSize(scrubbedBytes); for (int i = throwOut; i < scrubbedBytes.size(); i++) { // set all low-order bits to 1 setBit(scrubbedBytes.at(i), 0, 1); } write(scrubbedBytes, image); }
inline bool testPixel(const QPoint& pos) { if ( !_rect.contains(pos) ) return false; const int idx = _rect.width() * (pos.y() - _rect.y()) + (pos.x() - _rect.x()); const bool marked = testBit(idx); if ( !marked ) setBit(idx, true); return !marked; }
NoximPacket NoximProcessingElement::trafficButterfly() { int nbits = (int) log2ceil((double) (NoximGlobalParams::mesh_dim_x * NoximGlobalParams::mesh_dim_y)); int dnode = 0; for (int i = 1; i < nbits - 1; i++) setBit(dnode, i, getBit(local_id, i)); setBit(dnode, 0, getBit(local_id, nbits - 1)); setBit(dnode, nbits - 1, getBit(local_id, 0)); NoximPacket p; p.src_id = local_id; p.dst_id = dnode; p.timestamp = sc_time_stamp().to_double() / 1000; p.size = p.flit_left = getRandomSize(); return p; }
void strat_init(struct strategy * strat){ strat->flags = 0; strat->loaded_elts = 0; rand_disp_position=0; strat_flags=0; setBit(strat_flags,LINT_IS_LOADED); //we got one at the beginning... //Strat_State = STRAT_GET_ELT_ON_TABLE; /*everything is f****d up ... playing with emergency behaviour :'( */ Strat_State = STRAT_EMERGENCY_BEHAVIOUR; current_building_area = 1; //we start by building in our area... }
int main(){ int x; bitSet bs = makeBitSet(); printf("display test \n"); displayBitSet(bs); printf("set test \n"); setBit(&bs, 3); displayBitSet(bs); setBit(&bs, 5); displayBitSet(bs); printf("value test \n"); x = bitValue(bs, 3); printf("bit value: %d \n", x); x = bitValue(bs, 2); printf("bit value: %d \n", x); printf("bit clear test \n"); clearBit(&bs, 3); displayBitSet(bs); }
NoximPacket NoximProcessingElement::trafficShuffle() { int nbits = (int)log2ceil( (double)(NoximGlobalParams::mesh_dim_x * NoximGlobalParams::mesh_dim_y * NoximGlobalParams::mesh_dim_z )); int dnode = 0; for (int i = 0; i < nbits - 1; i++) setBit(dnode, i + 1, getBit(local_id, i )); setBit(dnode, 0 , getBit(local_id, nbits - 1)); NoximPacket p; p.src_id = local_id; p.dst_id = dnode ; p.timestamp = sc_time_stamp().to_double() / 1000; p.size = p.flit_left = getRandomSize(); // if (p.src_id == p.dst_id) // cout << "Traffic generator has generated a packet is sent from a node to itself !!! \n"; return p; }
/* Initialize stuff: * - Start Vref module * - Clear all fail flags * - Internal reference (default: external vcc) * - Mux between a and b channels (b channels) * - Calibrate with 32 averages and low speed * - When first calibration is done it sets: * - Resolution (default: 10 bits) * - Conversion speed and sampling time (both set to medium speed) * - Averaging (set to 4) */ void ADC_Module::analog_init() { // default settings: /* - 10 bits resolution - 4 averages - vcc reference - no interrupts - pga gain=1 - conversion speed = medium - sampling speed = medium initiate to 0 (or 1) so the corresponding functions change it to the correct value */ analog_res_bits = 0; analog_max_val = 0; analog_num_average = 0; analog_reference_internal = 2; var_enableInterrupts = 0; pga_value = 1; conversion_speed = 0; sampling_speed = 0; calibrating = 0; fail_flag = ADC_ERROR_CLEAR; // clear all errors num_measurements = 0; // select b channels // *ADC_CFG2_muxsel = 1; setBit(ADC_CFG2, ADC_CFG2_MUXSEL_BIT); // set reference to vcc setReference(ADC_REF_3V3); // set resolution to 10 setResolution(10); // the first calibration will use 32 averages and lowest speed, // when this calibration is over the averages and speed will be set to default by wait_for_cal and init_calib will be cleared. init_calib = 1; setAveraging(32); setConversionSpeed(ADC_LOW_SPEED); setSamplingSpeed(ADC_LOW_SPEED); // begin init calibration calibrate(); }
//int mgetline(char s[], int lim); int main() { unsigned int x; unsigned char p; int* x1; scanf_s("%x\n", &x); p = getchar(); printf("%x\n", x); printf("%u\n", p); x1=setBit(x,p); printf("%x", x1); getchar(); return 0; }
void CRenderer::Reset( const uint32 _flags ) { if( isBit( _flags, eShader ) ) m_spSelectedShader = NULL; if( isBit( _flags, eBlend ) ) m_spSelectedBlend = m_BlendMap[ "none" ]; if( isBit( _flags, eTexture ) ) { for( uint32 i=0; i<MAX_TEXUNIT; i++ ) m_aspSelectedTextures[ i ] = NULL; } if( isBit( _flags, eMatrices ) ) { m_WorldMat.Identity(); m_ViewMat.Identity(); m_ProjMat.Identity(); setBit( m_bDirtyMatrices, eWorld ); setBit( m_bDirtyMatrices, eView ); setBit( m_bDirtyMatrices, eProjection ); } }
/*Add a single (at least 8x over-) sampling of the data and clock lines to the circular buffer. Note: dataVal and clockVal represent a single bit, but need not actually be 0 or 1-- they can be 0 and 15, or 0 and 3, or whatever. Analog signals (0,1,2, or 3) are even OK. */ void JRS_PCM_add_sample(JRS_PCM *p,int clockVal,int dataVal) { p->data_bits[p->end]=dataVal; p->clk_bits[p->end]=clockVal; p->end++;p->len++; p->end&=PCM_bit_mask; if (p->len>16) {/*We have a long string of data and clock bits-- cut them back a bit*/ int trough=clock_trough(p); setBit(p,extract_bit(p,trough)); p->len=PCM_bit_mask&(p->end-trough);/*Set the new end-of-buffer to the clock trough*/ p->prevTrough=trough; } }
void setTempoScale(uint8_t state){ switch (state) { case D1_1: default: setAsOutput(TEMPOSCALE); setBit(PORTB, TEMPOSCALE); break; case D1_2: setAsOutput(TEMPOSCALE); unsetBit(PORTB, TEMPOSCALE); break; case D3_4: setAsInput(TEMPOSCALE); break; } }
int main(int argc, char** argv) { if(argc < 3) { if(argc == 0) puts("Missing argument."); else printf("Missing argument. Usage:\n%s [on|off] [0..7]\n" "%s int [0..255]\n", argv[0], argv[0]); exit(1); } if(str_cmp(argv[1], "int")) dispByte(atoi(argv[2])); else if(str_cmp(argv[1],"on")) setBit(atoi(argv[2]), true); else if(str_cmp(argv[1], "off")) setBit(atoi(argv[2]), false); else if(str_cmp(argv[1], "xmas")) dispXMas(atoi(argv[2])); else { printf("Invalid action: %s\n", argv[1]); exit(1); } return 0; }
// ============================================================================ void RotaryEncoder::setFlipped(boolean value) { // flip the step if needed: if (value != isBit(_rotary_status, BIT_FLIP)) { _rotary_step = -_rotary_step; } // set the flag if (value) { setBit(_rotary_status, BIT_FLIP); } else { deleteBit(_rotary_status, BIT_FLIP); } }
void abcdefg( char* c, Node* x, int* bitptr ){ printf("BIT:%d", *bitptr);fflush(stdout); if( x->parent->parent == NULL ){ // Reached the top // Set bit. char bit = traceBit( x ); setBit( c + (int)((*bitptr)/8), (*bitptr)%8, bit ); printf("T:%d@%d\n", (int)(bit), *bitptr);fflush(stdout); (*bitptr)++; return; }else{ // Go up the tree and set the corresponding bits on the way down. //printf("In:%c@%d", x->src, *bitptr); abcdefg( c, x->parent, bitptr ); // We use recursion to set bits from the top rather than form the bottom. char bit = traceBit( x ); setBit( c + (int)((*bitptr)/8), (*bitptr)%8, bit ); printf("S:%d@%d\n", (int)(bit), *bitptr );fflush(stdout); (*bitptr)++; return; } }
/** * Function: convertToBytes * in: int to be converted to byte array * out: resulting byte array * Purpose: separate int into 4 bytes */ void convertToBytes(int num, unsigned char *bytes) { int i, j; unsigned char tmpChar; for (i = 0; i < MAX_BYTES; ++i) { tmpChar = 0; for (j = 0; j < 8; ++j) { if (getIntBit(num, j + (i * 8)) == 0) tmpChar = clearBit(tmpChar, j); else tmpChar = setBit(tmpChar, j); } bytes[i] = tmpChar; } }
/** Buffer from_bin64(Buffer str) 0,1のバイト列(64Byte, bin64形式)を 8byteのビット列に変換する. @param str ビット列に変換するバイト列.64Byte. bin64形式. @return 変換されたビット列.8Byte. 64bit. */ Buffer from_bin64(Buffer str) { int i; Buffer ret; ret = init_Buffer(); if (str.vldsz!=64) return ret; ret = make_Buffer(8); if (ret.buf==NULL) return ret; for (i=0; i<64; i++) setBit(ret.buf, i, (int)str.buf[i]); ret.vldsz = 8; return ret; }
BitKey & BitKey::operator=(const char * string_ptr) { if(iv_Capacity) { BitString bs(iv_Capacity,DataPtr()); bs.Pattern(0x00000000); } while(*string_ptr != '\0') { uint32_t bit_position = (uint32_t) ((*string_ptr) - 1); setBit(bit_position); ++string_ptr; } return(*this); }
void CBC_DefaultPlacement::module(int32_t row, int32_t col, int32_t pos, int32_t bit) { if (row < 0) { row += m_numrows; col += 4 - ((m_numrows + 4) % 8); } if (col < 0) { col += m_numcols; row += 4 - ((m_numcols + 4) % 8); } int32_t v = m_codewords.GetAt(pos); v &= 1 << (8 - bit); setBit(col, row, v != 0); }
/** * Get the next free chunk * * @param size The size of the chunk to allocate * @param allocated The address to store the address of the allocated chunk * * @return 0 if successful, -42 is something went terribly wrong */ int cgc_getNextFreeChunk(int size, void** allocated) { int ret=0; int chunk_size=0; int bitmap_size=0; int index; Run* run_ptr; // Get the next run with free space chunk_size = (1 << size); bitmap_size = _SC_PAGESIZE/(1 << size); for(run_ptr=pool[size-1]; run_ptr != NULL && testBit(run_ptr->bitmap, bitmap_size-1); run_ptr=run_ptr->next) { int found=0; for(int i=0; i<bitmap_size; i++) { if(!testBit(run_ptr->bitmap, i)) { found=1; break; } } if(found) break; } // If all runs are full if(run_ptr == NULL) { cgc_initRun(&run_ptr, chunk_size); run_ptr->next = pool[size-1]; pool[size-1] = run_ptr; *allocated = run_ptr->memory; return 0; } // Find free space in run for(int i=0; i<bitmap_size; i++) { if(!testBit(run_ptr->bitmap, i)) { char* mem_ptr; mem_ptr = (char *)run_ptr->memory; *allocated = mem_ptr + i*chunk_size; setBit(run_ptr->bitmap,i); return 0; } } // Should never get here return -42; }
/** * Initialize the Run * * @param run_ptr The address of the Run * @param size The number of bytes of chunks provided by the Run * * @return 0 if successfull, else the error number returned by allocate */ int cgc_initRun(Run** run_ptr, unsigned int size) { int ret; if((ret = cgc_allocate(_SC_PAGESIZE, 0, (void**) run_ptr))) return ret; Run* run; run = *run_ptr; if((ret = cgc_allocate(_SC_PAGESIZE, 0, &run->memory))) return ret; setBit(run->bitmap, 0); run->size = size; run->next = NULL; return 0; }