Пример #1
0
char *gsmInflate(char *bytes)
{
    int i, temp, j;
    int length = strlen(bytes), endLength = length + (length / 7);
    char *tempBytes = (char *)malloc(sizeof(char)*endLength + 1);
    for(i = 0; i < length; i++)
    {
        tempBytes[i] = bytes[i];
    }
    
    tempBytes[(endLength - 1)] = tempBytes[(endLength - 1)] >> 1;
    for(j = 0; j < endLength; j++)
    {
        for(i = endLength; i > j; i--)
        {
            if(bitIsSet(tempBytes + i - 1,0))
                setBit(tempBytes + i,7);
            else
                clearBit(tempBytes + i,7);
            tempBytes[(i - 1)] = tempBytes[(i - 1)] >> 1;
            clearBit(tempBytes+(i - 1),7);
        }
    }
    // Hvis strengen er escapet med CR
    if(tempBytes[(endLength - 1)] == 13)
        endLength--;
        
    tempBytes[endLength] = '\0';
    return tempBytes;
}
Пример #2
0
void buildBitMaps(void)
{
  /* allocate and initialize the inode bitmap */
  IMap = (__u8*)malloc(SB->sb_imap_bcnt*WUFS_BLOCKSIZE);
  if (!IMap) {
    fprintf(stderr,"Could not allocate memory for inode bitmap.\n");
    exit(1);
  }
  /* we set the bits so that no "non-inodes" are ever available */
  memset(IMap,0xff,SB->sb_imap_bcnt*WUFS_BLOCKSIZE);
  int inode;
  /* remember: inodes start counting at 1, thus <= and inode-1 */
  for (inode = 1; inode <= SB->sb_inodes; inode++) {
    clearBit(IMap,inode-1);
  }

  /* allocate and initialize the blockmap bitmap */
  BMap = (__u8*)malloc(SB->sb_bmap_bcnt*WUFS_BLOCKSIZE);
  if (!BMap) {
    fprintf(stderr,"Could not allocate memory for the data block bitmap.\n");
    exit(1);
  }
  memset(BMap,0xff,SB->sb_bmap_bcnt*WUFS_BLOCKSIZE);
  int block;
  for (block = SB->sb_first_block; block < SB->sb_blocks; block++) {
    clearBit(BMap,block);
  }
}
Пример #3
0
void BitArray::setValue(int const beginIndex, int const endIndex, unsigned long value)
{
	DEBUG_FATAL(beginIndex < 0, ("BitArray::setValue beginIndex [%d] out of range", beginIndex));
	DEBUG_FATAL(endIndex < 0, ("BitArray::setValue endIndex [%d] out of range", endIndex));
	DEBUG_FATAL(beginIndex > endIndex, ("BitArray::setValue beginIndex [%d] > endIndex [%d]", beginIndex, endIndex));

	if ((beginIndex >= 0) && (endIndex >= 0) && (beginIndex <= endIndex))
	{
		int currentIndex = beginIndex;
		while (currentIndex <= endIndex)
		{
			if (value == 0)
				break;

			if (value & 0x1)
				setBit(currentIndex++);
			else
				clearBit(currentIndex++);

			value >>= 1;
		}

		for (int i = currentIndex; i <= endIndex; ++i)
			clearBit(i);
	}
Пример #4
0
/* Enable the compare function: A conversion will be completed only when the ADC value
*  is inside (insideRange=1) or outside (=0) the range given by (lowerLimit, upperLimit),
*  including (inclusive=1) the limits or not (inclusive=0).
*  See Table 31-78, p. 617 of the freescale manual.
*  Call it after changing the resolution
*/
void ADC_Module::enableCompareRange(int16_t lowerLimit, int16_t upperLimit, bool insideRange, bool inclusive) {

    if (calibrating) wait_for_cal(); // if we modify the adc's registers when calibrating, it will fail

    // *ADC_SC2_cfe = 1; // enable compare
    // *ADC_SC2_cren = 1; // enable compare range
    setBit(ADC_SC2, ADC_SC2_ACFE_BIT);
    setBit(ADC_SC2, ADC_SC2_ACREN_BIT);

    if(insideRange && inclusive) { // True if value is inside the range, including the limits. CV1 <= CV2 and ACFGT=1
        // *ADC_SC2_cfgt = 1;
        setBit(ADC_SC2, ADC_SC2_ACFGT_BIT);

        *ADC_CV1 = (int16_t)lowerLimit;
        *ADC_CV2 = (int16_t)upperLimit;
    } else if(insideRange && !inclusive) {// True if value is inside the range, excluding the limits. CV1 > CV2 and ACFGT=0
        // *ADC_SC2_cfgt = 0;
        clearBit(ADC_SC2, ADC_SC2_ACFGT_BIT);

        *ADC_CV2 = (int16_t)lowerLimit;
        *ADC_CV1 = (int16_t)upperLimit;
    } else if(!insideRange && inclusive) { // True if value is outside of range or is equal to either limit. CV1 > CV2 and ACFGT=1
        // *ADC_SC2_cfgt = 1;
        setBit(ADC_SC2, ADC_SC2_ACFGT_BIT);

        *ADC_CV2 = (int16_t)lowerLimit;
        *ADC_CV1 = (int16_t)upperLimit;
    } else if(!insideRange && !inclusive) { // True if value is outside of range and not equal to either limit. CV1 > CV2 and ACFGT=0
        // *ADC_SC2_cfgt = 0;
        clearBit(ADC_SC2, ADC_SC2_ACFGT_BIT);

        *ADC_CV1 = (int16_t)lowerLimit;
        *ADC_CV2 = (int16_t)upperLimit;
    }
}
Пример #5
0
/*
  Function:  encode
  Purpose:   To encode the values of plaintext or cyphertext
       in:   the source bit from the plaintext or cyphertext
       in:   the key to encode the bits with
       in:   the count to ensure that the same letters will be encoded differntly
   return:   the new encoded value to be stored


 */
unsigned char encode(unsigned char pt, unsigned char key, int count)
{
  unsigned char byte;
  int i;
  
  byte = pt;

  switch (count%3) {
    case 0:
      
      for(i=0; i<7; i+=2){
	byte = getBit(pt,i) ^ getBit(key,i) == 0 ?  clearBit(byte, i) : setBit(byte,i);	
      }		 
      break;
      
    case 1:

      for(i=1; i<7; i+=2){
	byte = getBit(pt,i) ^ getBit(key,i) == 0 ? clearBit(byte, i) : setBit(byte,i);
      }
      
      break;
      
    case 2:
      
      for(i=0; i<7; i++){
        byte = getBit(pt,i) ^ getBit(key,i) == 0 ? clearBit(byte, i) : setBit(byte,i);
      }
     
      break;
  }

  return byte;
}
Пример #6
0
void findPrimes(bignum topCandidate)
{
    BITARRAY *ba = createBitArray(topCandidate);
    assert(ba != NULL);		/* SET ALL BUT 0 AND 1 TO PRIME STATUS */
    setAll(ba);
    clearBit(ba, 0);
    clearBit(ba, 1);		/* MARK ALL THE NON-PRIMES */
    bignum thisFactor = 2;
    bignum lastSquare = 0;
    bignum thisSquare = 0;
    while (thisFactor * thisFactor <= topCandidate) {	/* MARK THE MULTIPLES OF THIS FACTOR */
	bignum mark = thisFactor + thisFactor;
	while (mark <= topCandidate) {
	    clearBit(ba, mark);
	    mark += thisFactor;
	}			/* PRINT THE PROVEN PRIMES SO FAR */
	thisSquare = thisFactor * thisFactor;
	for (; lastSquare < thisSquare; lastSquare++) {
	    if (getBit(ba, lastSquare))
		printPrime(lastSquare);
	}			/* SET thisFactor TO NEXT PRIME */
	thisFactor++;
	while (getBit(ba, thisFactor) == 0)
	    thisFactor++;
	assert(thisFactor <= topCandidate);
    }				/* PRINT THE REMAINING PRIMES */
    for (; lastSquare <= topCandidate; lastSquare++) {
	if (getBit(ba, lastSquare))
	    printPrime(lastSquare);
    }
    freeBitArray(ba);
}
Пример #7
0
// *****************************************************************************
// function to clear the GPIO and maintain the state during sleep.
// Port is 0 for port a, 1 for port b, and 2 for port c.
void halLedBlinkSleepyClearGpio( uint8_t port, uint8_t pin )
{
  assert( port < 3 );
  assert( pin < 8 );

  *((volatile uint32_t *)(GPIO_PxCLR_BASE+(GPIO_Px_OFFSET*(port)))) = BIT(pin);

  // Make sure this stays clear during the next power cycle
  clearBit(&(gpioOutPowerUp[port]), pin);
  clearBit(&(gpioOutPowerDown[port]), pin);
}
Пример #8
0
/**
 * Clears a bit from bitArray if the respective usage
 * counter on the disk hits/is zero.
 *
 * @param bitArray memory area to set the bit in
 * @param bitIdx which bit to test
 * @param fh A file to keep the 4bit address usage counters in
 */
static void
decrementBit (char *bitArray, unsigned int bitIdx,
              const struct GNUNET_DISK_FileHandle *fh)
{
  off_t fileslot;
  unsigned char value;
  unsigned int high;
  unsigned int low;
  unsigned int targetLoc;

  if (GNUNET_DISK_handle_invalid (fh))
    return;                     /* cannot decrement! */
  /* Each char slot in the counter file holds two 4 bit counters */
  fileslot = bitIdx / 2;
  targetLoc = bitIdx % 2;
  if (GNUNET_SYSERR == GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
    {
      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
      return;
    }
  if (1 != GNUNET_DISK_file_read (fh, &value, 1))
    value = 0;
  low = value & 0xF;
  high = (value & 0xF0) >> 4;

  /* decrement, but once we have reached the max, never go back! */
  if (targetLoc == 0)
  {
    if ((low > 0) && (low < 0xF))
      low--;
    if (low == 0)
    {
      clearBit (bitArray, bitIdx);
    }
  }
  else
  {
    if ((high > 0) && (high < 0xF))
      high--;
    if (high == 0)
    {
      clearBit (bitArray, bitIdx);
    }
  }
  value = ((high << 4) | low);
  if (GNUNET_SYSERR == GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
    {
      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
      return;
    }
  GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
}
Пример #9
0
/* Increase the sampling speed for low impedance sources, decrease it for higher impedance ones.
* \param speed can be ADC_VERY_LOW_SPEED, ADC_LOW_SPEED, ADC_MED_SPEED, ADC_HIGH_SPEED or ADC_VERY_HIGH_SPEED
    ADC_VERY_LOW_SPEED is the lowest possible sampling speed (+24 ADCK).
    ADC_LOW_SPEED adds +16 ADCK.
    ADC_MED_SPEED adds +10 ADCK.
    ADC_HIGH_SPEED (or ADC_HIGH_SPEED_16BITS) adds +6 ADCK.
    ADC_VERY_HIGH_SPEED is the highest possible sampling speed (0 ADCK added).
* It doesn't recalibrate at the end.
*/
void ADC_Module::setSamplingSpeed(uint8_t speed) {

    if(speed==sampling_speed) { // no change
        return;
    }

    if (calibrating) wait_for_cal();

    // Select between the settings
    if(speed == ADC_VERY_LOW_SPEED) {
        // *ADC_CFG1_adlsmp = 1; // long sampling time enable
        // *ADC_CFG2_adlsts1 = 0; // maximum sampling time (+24 ADCK)
        // *ADC_CFG2_adlsts0 = 0;
        setBit(ADC_CFG1, ADC_CFG1_ADLSMP_BIT);
        clearBit(ADC_CFG2, ADC_CFG2_ADLSTS1_BIT);
        clearBit(ADC_CFG2, ADC_CFG2_ADLSTS0_BIT);

    } else if(speed == ADC_LOW_SPEED) {
        // *ADC_CFG1_adlsmp = 1; // long sampling time enable
        // *ADC_CFG2_adlsts1 = 0;// high sampling time (+16 ADCK)
        // *ADC_CFG2_adlsts0 = 1;
        setBit(ADC_CFG1, ADC_CFG1_ADLSMP_BIT);
        clearBit(ADC_CFG2, ADC_CFG2_ADLSTS1_BIT);
        setBit(ADC_CFG2, ADC_CFG2_ADLSTS0_BIT);

    } else if(speed == ADC_MED_SPEED) {
        // *ADC_CFG1_adlsmp = 1; // long sampling time enable
        // *ADC_CFG2_adlsts1 = 1;// medium sampling time (+10 ADCK)
        // *ADC_CFG2_adlsts0 = 0;
        setBit(ADC_CFG1, ADC_CFG1_ADLSMP_BIT);
        setBit(ADC_CFG2, ADC_CFG2_ADLSTS1_BIT);
        clearBit(ADC_CFG2, ADC_CFG2_ADLSTS0_BIT);

    } else if( (speed == ADC_HIGH_SPEED) || (speed == ADC_HIGH_SPEED_16BITS) ) {
        // *ADC_CFG1_adlsmp = 1; // long sampling time enable
        // *ADC_CFG2_adlsts1 = 1;// low sampling time (+6 ADCK)
        // *ADC_CFG2_adlsts0 = 1;
        setBit(ADC_CFG1, ADC_CFG1_ADLSMP_BIT);
        setBit(ADC_CFG2, ADC_CFG2_ADLSTS1_BIT);
        setBit(ADC_CFG2, ADC_CFG2_ADLSTS0_BIT);

    } else if(speed == ADC_VERY_HIGH_SPEED) {
        // *ADC_CFG1_adlsmp = 0; // shortest sampling time
        clearBit(ADC_CFG1, ADC_CFG1_ADLSMP_BIT);

    } else { // incorrect speeds have no effect.
        return;
    }

    sampling_speed =  speed;

}
Пример #10
0
/* Change the resolution of the measurement
*  For single-ended measurements: 8, 10, 12 or 16 bits.
*  For differential measurements: 9, 11, 13 or 16 bits.
*  If you want something in between (11 bits single-ended for example) select the inmediate higher
*  and shift the result one to the right.
*
*  It doesn't recalibrate
*/
void ADC_Module::setResolution(uint8_t bits) {

    if(analog_res_bits==bits) {
        return;
    }

    uint8_t config;

    if (calibrating) wait_for_cal();

    if (bits <8) {
        config = 8;
    } else if (bits >= 14) {
        config = 16;
    } else {
        config = bits;
    }

    // conversion resolution
    // single-ended 8 bits is the same as differential 9 bits, etc.
    if ( (config == 8) || (config == 9) )  {
        // *ADC_CFG1_mode1 = 0;
        // *ADC_CFG1_mode0 = 0;
        clearBit(ADC_CFG1, ADC_CFG1_MODE1_BIT);
        clearBit(ADC_CFG1, ADC_CFG1_MODE0_BIT);
        analog_max_val = 255; // diff mode 9 bits has 1 bit for sign, so max value is the same as single 8 bits
    } else if ( (config == 10 )|| (config == 11) ) {
        // *ADC_CFG1_mode1 = 1;
        // *ADC_CFG1_mode0 = 0;
        setBit(ADC_CFG1, ADC_CFG1_MODE1_BIT);
        clearBit(ADC_CFG1, ADC_CFG1_MODE0_BIT);
        analog_max_val = 1023;
    } else if ( (config == 12 )|| (config == 13) ) {
        // *ADC_CFG1_mode1 = 0;
        // *ADC_CFG1_mode0 = 1;
        clearBit(ADC_CFG1, ADC_CFG1_MODE1_BIT);
        setBit(ADC_CFG1, ADC_CFG1_MODE0_BIT);
        analog_max_val = 4095;
    } else {
        // *ADC_CFG1_mode1 = 1;
        // *ADC_CFG1_mode0 = 1;
        setBit(ADC_CFG1, ADC_CFG1_MODE1_BIT);
        setBit(ADC_CFG1, ADC_CFG1_MODE0_BIT);
        analog_max_val = 65535;
    }

    analog_res_bits = config;

    // no recalibration is needed when changing the resolution, p. 619

}
Пример #11
0
uint8_t Life::evolve()
{
  uint8_t changecount = 0;

  
  for (char y=0; y<NUM_RINGS; y++) {
    for (char x=0; x<LEDS_PER_RING; x++) {
      
      // Count the neighbors
      int n = countNeighborsWithWraparound(x,y);
      
      // implement the rules
      if (getBit(universe, y, x)) {
	// Any live cell with < 2 live neighbors dies.
	// Any live cell with 2-3 neighbors is good.
	// Any live cell with > 3 neighbors dies.
	if (n == 2 || n == 3) {
	  setBit(newUniverse, y, x);
	} else {
	  clearBit(newUniverse, y, x);
	}
      }
      // Any dead cell with == 3 neighbors becomes live.
      else if (n == 3) {
	setBit(newUniverse, y, x);
      } else {
	// (else it stays dead)
	clearBit(newUniverse, y, x);
      }
    }
  }
  
  // Put the new universe in place, counting the number
  // of changes
  for (char y=0; y<NUM_RINGS; y++) {
    for (char x=0; x<LEDS_PER_RING; x++) {
      uint8_t oldState = getBit(universe, y, x);
      if (getBit(newUniverse, y, x)) {
	if (!oldState)
	  changecount++;
        setBit(universe, y, x);
      } else {
	if (oldState)
	  changecount++;
        clearBit(universe, y, x);
      }
    }
  }
  
  return changecount;
}
void checkStatus() {
	//if bit changed , then change the pin accordingly
	if(bitVar.bit5 ^ (PORTD & (1 << 5))) {
		if(bitVar.bit5)PORTD = setBit(PORTD,5); //make output 10(connect to GPRS);
	   	else PORTD = clearBit(PORTD,5);
	}

	//if bit changed , then change the pin accordingly
   	if(bitVar.bit4 ^ (PORTD & (1 << 4))) {
    	if(bitVar.bit4)PORTD = setBit(PORTD,4); //make output 10(connect to GPRS);
    	else PORTD = clearBit(PORTD,4);
    }

}
Пример #13
0
void test_bitTasks()
{
	assert(getBit(4,1) == 0);
	assert(getBit(4,2) == 1);

	assert(setBit(4,1) == 6);
	assert(setBit(4,2) == 4);

	assert(clearBit(4,1) == 4);
	assert(clearBit(4,2) == 0);

	assert(updateBit(4,1,0) == 4);
	assert(updateBit(4,2,1) == 4);
}
Пример #14
0
void ILI9325i2c_16::initTFT() {

  if (displayModel == SS2_8) {

    pinMode(RS, OUTPUT);
    pinMode(WR, OUTPUT);
    pinMode(RST, OUTPUT);
    pinMode(CS, OUTPUT);
  } else {

    RS = 0x01;
    WR = 0x02;
    RST = 0x04;
    CS = 0x08;
  }


  Wire.begin();

  Wire.beginTransmission(address);
  Wire.write(IODIRA); // Select IODIRA Register
  Wire.write(0x00); // set directions to output
  Wire.endTransmission();

  Wire.beginTransmission(address);
  Wire.write(IODIRB); // Select IODIRB Register
  Wire.write(0x00); // set directions to output
  Wire.endTransmission();

  // clear prt b
  Wire.beginTransmission(address);
  Wire.write(PRTB); // Select IODIRB Register
  Wire.write(0x00); // set directions to output
  Wire.endTransmission();
  //orient = LANDSCAPE;

  setBit(RST);

  delay(5);
  clearBit(RST);

  delay(5);
  setBit(RST);

  clearBit(CS);
  setTFTProperties();

}
Пример #15
0
int main(int argc, char *argv[])
{
    if(argc != 3)
    {
        printf("Usage: %s <number> <bit index>\n", argv[0]);
        return 0;
    }

    unsigned int number = (unsigned int) atoi(argv[1]);
    int i = atoi(argv[2]);

    printf("Number: %d (0x%x)\n", number, number);
    printf("Modifying bit: %d\n", i);

    // Check if bit i is set
    unsigned int result = isBitISet(number, i);
    printResult(i, number, result);

    // Set it
    number = setBit(number, i);

    // Make sure it was set
    result = isBitISet(number, i);
    printResult(i, number, result);

    // Clear bit
    number = clearBit(number, i);

    // Make sure it was cleared
    result = isBitISet(number, i);
    printResult(i, number, result);

    return 0;
}
Пример #16
0
void Life::addGlider(uint8_t x, uint8_t y, uint8_t rotation)
{
  // 3x3 array of glider, little-bittian
  uint8_t glider[] = { 0xAC, 0x01 };

  for (int8_t dx = 0; dx < 3; dx++) {
    for (int8_t dy = 0; dy < 3; dy++) {
      int fx;
      int fy;
      if (rotation % 2) {
	fx = (x + dx) % (LEDS_PER_RING);
      } else {
	fx = (x - dx);
	if (fx < 0) fx += LEDS_PER_RING;
      }
      if (rotation / 2) {
	fy = (y + dy) % (NUM_RINGS);
      } else {
	fy = (y - dy);
	if (fy < 0) fy += NUM_RINGS;
      }

      if (unpackBit(glider, dy, dx, 3)) {
	setBit(universe, fy, fx);
      } else {
	clearBit(universe, fy, fx);
      }
    }
  }
}
Пример #17
0
void Life::addSwitch(uint8_t x, uint8_t y, uint8_t rotation)
{
  // 5x5 array of a block-laying switch engine
  uint8_t blse[] = { 0x37, 0x60, 0x5B, 0x01 };
  for (int8_t dx = 0; dx < 5; dx++) {
    for (int8_t dy = 0; dy < 5; dy++) {
      int8_t fx;
      int8_t fy;
      if (rotation % 2) {
	fx = (x + dx) % (LEDS_PER_RING);
      } else {
	fx = (x - dx);
	if (fx < 0) fx += LEDS_PER_RING;
      }
      if (rotation / 2) {
	fy = (y + dy) % (NUM_RINGS);
      } else {
	fy = (y - dy);
	if (fy < 0) fy += NUM_RINGS;
      }

      if (unpackBit(blse, dy, dx, 5)) {
	setBit(universe, fy, fx);
      } else {
	clearBit(universe, fy, fx);
      }
    }
  }      
}
Пример #18
0
/* Set the voltage reference you prefer, default is 3.3V
*   It needs to recalibrate
*  Use ADC_REF_3V3, ADC_REF_1V2 (not for Teensy LC) or ADC_REF_EXT
*/
void ADC_Module::setReference(uint8_t type) {
    if (analog_reference_internal==type) { // don't need to change anything
        return;
    }

    if (type == ADC_REF_ALT) { // 1.2V ref for Teensy 3.x, 3.3 VDD for Teensy LC
        // internal reference requested

        startInternalReference(); // enable VREF if Teensy 3.x

        analog_reference_internal = ADC_REF_ALT;

        // *ADC_SC2_ref = 1; // uses bitband: atomic
        setBit(ADC_SC2, ADC_SC2_REFSEL0_BIT);

    } else if(type == ADC_REF_DEFAULT) { // ext ref for all Teensys, vcc also for Teensy 3.x
        // vcc or external reference requested

        stopInternalReference(); // disable 1.2V reference source when using the external ref (p. 102, 3.7.1.7)

        analog_reference_internal = ADC_REF_DEFAULT;

        // *ADC_SC2_ref = 0; // uses bitband: atomic
        clearBit(ADC_SC2, ADC_SC2_REFSEL0_BIT);
    }

    calibrate();
}
Пример #19
0
//! Disable PGA
void ADC_Module::disablePGA() {
#if defined(ADC_USE_PGA)
    // *ADC_PGA_pgaen = 0;
    clearBit(ADC_PGA, ADC_PGA_PGAEN_BIT);
#endif
    pga_value = 1;
}
Пример #20
0
void ILI9325i2c_16::printChar(byte c, int x, int y)
{
  byte i, ch;
  word j;
  word temp;

  clearBit(CS);

  if (orient == PORTRAIT)
  {
    setXY(x, y, x + cfont.x_size - 1, y + cfont.y_size - 1);

    temp = ((c - cfont.offset) * ((cfont.x_size / 8) * cfont.y_size)) + 4;

    for (j = 0; j < ((cfont.x_size / 8)*cfont.y_size); j++)
    {
      ch = pgm_read_byte(&cfont.font[temp]);
      for (i = 0; i < 8; i++)
      {
        if ((ch & (1 << (7 - i))) != 0)
        {
          setPixel(fcolorr, fcolorg, fcolorb);
        }
        else
        {
          setPixel(bcolorr, bcolorg, bcolorb);
        }
      }
      temp++;
    }
  }
  else
  {
    temp = ((c - cfont.offset) * ((cfont.x_size / 8) * cfont.y_size)) + 4;

    for (j = 0; j < ((cfont.x_size / 8)*cfont.y_size); j += (cfont.x_size / 8))
    {
      setXY(x, y + (j / (cfont.x_size / 8)), x + cfont.x_size - 1, y + (j / (cfont.x_size / 8)));
      for (int zz = (cfont.x_size / 8) - 1; zz >= 0; zz--)
      {
        ch = pgm_read_byte(&cfont.font[temp + zz]);
        for (i = 0; i < 8; i++)
        {
          if ((ch & (1 << i)) != 0)
          {
            setPixel(fcolorr, fcolorg, fcolorb);
          }
          else
          {
            setPixel(bcolorr, bcolorg, bcolorb);
          }
        }
      }
      temp += (cfont.x_size / 8);
    }
  }
  setBit(CS);
  clrXY();
}
/*! \sa PacketProcessor
 */
Packet& PacketProcessor::buildIPPacket(string p_DestinationIP, string p_SourceIP, string p_Payload)
{

    //store the arguments
    m_DestinationIP = p_DestinationIP;
    m_SourceIP = p_SourceIP;
    m_Payload = p_Payload;    
   
    //set version
    m_PacketBuffer[0] = (unsigned char)setSubField((unsigned)m_PacketBuffer[0], VERSION, 7, 4);

    //set standard header length
    m_PacketBuffer[0] = (unsigned char)setSubField((unsigned)m_PacketBuffer[0], IHL, 3, 0);

    //set the second field to zero (DSCP[7-2] and ECN[1-0])

    //set identification
    setMultipleFields(&m_PacketBuffer[5], m_Identification++, SHORT);
    //set flags
    clearBit(&m_PacketBuffer[6], 7); //reserved
    clearBit(&m_PacketBuffer[6], 6); //Don't fragment DF
    clearBit(&m_PacketBuffer[6], 5); //More fragments MF
    //set fragment offset

    //set TTL
    m_PacketBuffer[8] = TTL;
    //set Protocol
    m_PacketBuffer[9] = PROTOCOL;

    //set source IP
    m_Converter.ipToUChar(m_SourceIP, &m_PacketBuffer[12]);
    //set destination IP
    m_Converter.ipToUChar(m_DestinationIP, &m_PacketBuffer[16]);


    //set paylod and packet length
    setMultipleFields(&m_PacketBuffer[3], setPayload(&m_PacketBuffer[20]), SHORT);    

    addCheckSum(m_PacketBuffer);
    //set the IP packet into the frame
    m_Frame.setPDU(m_PacketBuffer);
    resetPacketBuffer();

    return m_Frame;

}
void testBitFunctions()
{
    assert(getBit(5, 0) == 1);
    assert(setBit(8, 1) == 10);
    assert(clearBit(10, 1) == 8);
    assert(clearBitsMSBThroughI(10, 3) == 2);
    assert(clearBitsIThrough0(10, 2) == 8);
    assert(udpateBit(8, 1, 1) == 10);
}
Пример #23
0
int BitOperations::modifyBit(int x, int t, int r){

    if(r % 2){
        return setBit(x,t);
    }else{
        return clearBit(x,t);
    }

}
Пример #24
0
/* Disable interrupts
*
*/
void ADC_Module::disableInterrupts() {

    var_enableInterrupts = 0;
    // *ADC_SC1A_aien = 0;
    clearBit(ADC_SC1A, ADC_SC1A_AIEN_BIT);

    NVIC_DISABLE_IRQ(IRQ_ADC);

}
Пример #25
0
int BitOperations::flipBit(int x, int t){

    int v = (0x01 << t) & x;

    if(!v){
        return setBit(x,t);
    }else{
        return clearBit(x,t);
    }
}
int main()
{

    //This algorithm zeroes the products i*j which means not prime
    //In conclusion bits took more time , but less space when compared to the char
    //representation
    //Array of bits
	std::array<int,N_bits> a_bits;

	for(std::size_t i = 2; i != N; i++)
		setBit(a_bits, i);
    auto start = std::chrono::steady_clock::now();
	//array indexes are accessed using helper functions above.
	for(std::size_t i = 2; i != N; i++){
		if(getBitValue(a_bits,i)){
			for(std::size_t j = i; j * i < N; i++){
				clearBit(a_bits, i * j);
            }
		}
	}

    auto end = std::chrono::steady_clock::now();
    auto  diff1 = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();

    //Array of chars
    std::array<char,N> a_char;

    for(std::size_t i = 2; i != N; i++)
        a_char[i] = '1';

    start = std::chrono::steady_clock::now();
    for(std::size_t i = 2; i != N; i++){
        if(a_char[i] == '1'){
            for(std::size_t j = i; j * i < N; i++){
               a_char[i * j] = '0';
            }
        }
    }

    end = std::chrono::steady_clock::now();
    auto  diff2 = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();

    for(std::size_t i = 2; i < N; i++){
		if(getBitValue(a_bits,i))
			std::cout << "bits :" << i << "       ";

		if(a_char[i] == '1')
			std::cout << "chars : " << i << std::endl;
	}

	std::cout<< "Execution time for array of bits  : " << diff1 << " microseconds" << std::endl;
	std::cout<< "Execution time for array of chars : " << diff2 << " microseconds" << std::endl;

    return 0;
}
Пример #27
0
int main(){
	setOutput(DDRB,PINB0);
	setInput(DDRB,PINB1);
	PCICR = _BV(PCIE0);
	PCMSK0 = _BV(PCINT1);
	sei();
	while(1){
		clearBit(PORTB,PINB0);
		_delay_ms(1000);
	}
}
Пример #28
0
void unweightedUndirected::clearBit(int r, int c)
/* make the bit in row r and column c have the value 0 without changing the
   values of any other bits. */
{
   if (c > r)
      clearBit(c,r);
   else if (c == 0)
      main_diagonal = 0;
   else
      (*matrix)[t(r)+c] = 0;
}
Пример #29
0
// Returns the value of bits from hpos to lpos in CF_LONGWord number.
CF_LONGWord getBits(CF_LONGWord number, int hpos, int lpos) {
	CF_LONGWord ret = number;
	
	// Clear any bits not within the hpos and lpos range
	for(int i = LONG_WORD_BITS-1; i >= 0; i--) {
		if(i > hpos || i < lpos) {
			clearBit(&ret, i);
		}
	}
	
	return ret;
}
Пример #30
0
void Life::init()
{
  for (char x=0; x<LEDS_PER_RING; x++) {
    for (char y=0; y<NUM_RINGS; y++) {
      if (random(0,10) >= 8) {
	setBit(universe, y, x);
      } else {
        clearBit(universe, y, x);
      }
    }
  }
}