PackedParity getParity(const vector<SliceValue>& state)
{
    PackedParity parities = 0;
    for(unsigned int z=0; z<state.size(); z++)
        parities ^= getPackedParityFromParity(getParity(state[z]), z);
    return parities;
}
// Enable parity generation for outgoing bytes and parity checking for
// incoming bytes.
void SerialPortImplWin32::setParityGeneration(bool enableParity)
{
   DCB dcb;
   GetCommState(mHandle, &dcb);
   dcb.fParity = enableParity;

   if ( enableParity )
   {
      vpr::SerialTypes::ParityType p = getParity();
      if ( dcb.Parity == NOPARITY )
      {
         dcb.Parity = ODDPARITY;
      }
      else
      {
         dcb.Parity = p;
      }
   }
   else
   {
      dcb.Parity = NOPARITY;
   }

   if ( ! SetCommState(mHandle, &dcb) )
   {
      std::stringstream msg_stream;
      msg_stream << "Failed to set parity generation state: "
                 << getErrorMessageWithCode(GetLastError());
      throw IOException(msg_stream.str(), VPR_LOCATION);
   }
}
Exemple #3
0
void
SerialPort::getSerial(int& baud, int& dataBits, int& parity, int& stopBits)
{
    baud = getBaud();
    dataBits = getDataBits();
    parity = getParity();
    stopBits = getStopBits();
}
/* Driver program to test getParity() */
int main()
{
    unsigned int n = 7;
    printf("Parity of no %d = %s",  n,
             (getParity(n)? "odd": "even"));

    getchar();
    return 0;
}
void modify_rt_address(uint16_t brt_base_addr,  uint8_t rtaddr) {

	uint16_t   rt_ctrl_status_reg, rt_addr;
	uint8_t  parity;



	uint16_t test1, test2, test3, test4, test5,rt_ctrl_status_reg_new;

	parity =  getParity(rtaddr); // get parity of the adress;

	test1 = rtaddr; //0x05;

	test2 =   (test1 << 1);
	test3 =   (test1 << 2);
	test4 =   (test1 << 8);
	//test5 =   (test1 << 8);


	test5 = (rtaddr << 8);
	rt_addr =  (rtaddr << 8);  // move the rtaddr to bit position (12 to 8)

	//rt_addr = (0x1f00 & (rtaddr));

	//rt_addr = (rt_addr & 0xff00); // shift the rtaddr to 12th bit position
	rt_ctrl_status_reg = HW_get_16bit_reg( brt_base_addr + BRT_CONTROL_REG);

	rt_ctrl_status_reg  = rt_ctrl_status_reg | rt_addr;  // replace the rtaddress in the contrl register
    if ( parity) {
    	   rt_ctrl_status_reg_new   = (0xDFFF & rt_addr);// if already odd parity, clear the parity bit ( position 13)
    	            	                                             //at position 13
                } else
    	        {

    	        	rt_ctrl_status_reg_new = (0x2000 | rt_addr);  // if even parity, make it odd by setting the parity bit
    	        	                                              // at bit position 13;

    	        }


    // finally  clear the RTLOCK to accept software RTADDR value ( clear bit 15 of the register

             rt_ctrl_status_reg_new  = (rt_ctrl_status_reg_new & 0x7fff); // clear lock bit
             rt_ctrl_status_reg      = (rt_ctrl_status_reg_new & 0x00ff); // mask the lsb bits and clear the msb bit
                                                                          //for adding updated values

             rt_ctrl_status_reg      = (rt_ctrl_status_reg | rt_ctrl_status_reg_new); // update the rtaddr,ock bits to the register


			HW_set_16bit_reg(brt_base_addr + BRT_CONTROL_REG ,rt_ctrl_status_reg);




}
Exemple #6
0
void printSeatalkChar(uint8_t c, int parerr, int * cmdFlag) {

  /* generally per definition: 
     - even parity bit set (1, high) if count of 1s is odd
     - even parity bit set (0, low) if count of 1s is even
  
  // 9th bit for command flag is interpreted as parity bit here
     we check for even parity

  // if the command flag is set then that means that parity even bit is set in the data stream

     
  */

  int parity = getParity(c); // 1 == odd, 0 == even

  if(!parity) {
    // input char has even parity
    if(parerr) {
      // and the parity error is signaled 
      // which means parity bit is 1
      *cmdFlag = 1;
       
    } else {
      // and no parity error is signaled
      // which means that the parity bit is not set
      *cmdFlag = 0;
    }

  } else {
    // input has odd parity
    if(parerr) {
      // and parity error is signaled
      // -> parity bit 0
      *cmdFlag = 0;
    } else {
      *cmdFlag = 1;
    }
  }

  // printf("%02X %s  ", c, cmdFlag?"(C)":"");

}
void getParity(const vector<SliceValue>& state, vector<RowValue>& parity)
{
    parity.resize(state.size());
    for(unsigned int z=0; z<state.size(); z++)
        parity[z] = getParity(state[z]);
}