Пример #1
0
// protected internal void Write7BitEncodedInt(int value) [instance] :580
void BinaryWriter::Write7BitEncodedInt(int value)
{
    uint32_t v = (uint32_t)value;

    while (v >= 128U)
    {
        Write1((uint8_t)(v | 128U));
        v = v >> 7;
    }

    Write1((uint8_t)v);
}
Пример #2
0
/* fetchkey():
   This massages the key into a form that's easier to handle. When it
   returns, the key will be stored in keybuf if keysize <= 4; otherwise,
   it will be in memory.
*/
static void fetchkey(unsigned char *keybuf, glui32 key, glui32 keysize, 
  glui32 options)
{
  int ix;

  if (options & serop_KeyIndirect) {
    if (keysize <= 4) {
      for (ix=0; ix<keysize; ix++)
        keybuf[ix] = Mem1(key+ix);
    }
  }
  else {
    switch (keysize) {
    case 4:
      Write4(keybuf, key);
      break;
    case 2:
      Write2(keybuf, key);
      break;
    case 1:
      Write1(keybuf, key);
      break;
    default:
      fatal_error("Direct search key must hold one, two, or four bytes.");
    }
  }
}
Пример #3
0
/*

  Write a Command to the RFM Module using SPI
  
  Requires: 16bit valid command
  Returns:  16bit result from transaction
  
  This is a bi-directional transfer.  
  A command is clocked out to the RFM a bit at a time.  
  At the same time a result is clocked back in a bit at a time.
   
*/
uint WriteCMD(uint CMD)
{
	
	uint RESULT = 0;							// Holds the received SDI
	uchar n=16;									// number of bits in SPI Command we need to send
	LOW_SCK();									// SCK LOW
	LOW_SEL();									// CS LOW
	while(n--)									// Send All 16 Bits MSB First
	{
		if (CMD&0x8000)
		{
			Write1();							// Write 1 via SDI		
		}
		else
		{
			Write0();							// Write 0 via SPI
		}
		
		RESULT<<=1;								// Shift left for next bit to receive
		if(SDI)									// Check if we received a high on SDI
			RESULT |= 0x0001;					// RESULT LSB = 1		
		CMD<<=1;								// Shift left for next bit to send
	}
	LOW_SCK();									// SCK LOW
	HI_SEL();									// CS HIGH - Finished Sending Command
	return RESULT;
}
Пример #4
0
void WriteCMD(int16 CMD)
{
	int8 n = 16;

	output_low(_SCK);
	RF_EN	= false;

	while (n--){
		if (CMD&0x8000)
			Write1();
		else
			Write0();
		CMD<<=1;
	}
	SCK		= false;
	RF_EN	= true;
}