bool Swdp::seq_in_parity (uint32_t* ret, int ticks) { uint32_t index = 1; uint32_t parity = 0; *ret = 0; turnaround (true); while (ticks--) { if (bit_in ()) { *ret |= index; parity ^= 1; } index <<= 1; } if (bit_in()) parity ^= 1; return (bool) parity; }
uint32_t Swdp::seq_in (int ticks) { uint32_t index = 1; uint32_t ret = 0; turnaround (true); while (ticks--) { if (bit_in ()) ret |= index; index <<= 1; } return ret; }
/******************************************************************** * Function: uint8_t byte_in(uint8_t ack) * * Description: This function inputs a byte from the I2C bus. * Depending on the value of ack, it will also * transmit either an ACK or a NAK bit. *******************************************************************/ uint8_t byte_in(uint8_t ack) { uint8_t i; // Loop counter uint8_t retval; // Return value retval = 0; for (i = 0; i < 8; i++) // Loop through each bit { retval = retval << 1; // Shift left for next bit bit_in(&retval); // Input bit } bit_out(ack); // Output ACK/NAK bit return retval; }
/******************************************************************** * Function: uint8_t byte_out(uint8_t data) * * Description: This function outputs a byte to the I2C bus. * It also receives the ACK bit and returns 0 if * successfully received, or 1 if not. *******************************************************************/ uint8_t byte_out(uint8_t data) { uint8_t i; // Loop counter uint8_t ack; // ACK bit ack = 0; for (i = 0; i < 8; i++) // Loop through each bit { bit_out(data); // Output bit data = data << 1; // Shift left for next bit } bit_in(&ack); // Input ACK bit return ack; }