/****************************************************************************** * Function Name: Swd_ReceiveByte ******************************************************************************* * * Summary: * Receives a byte of data on the SWD lines (SWDIO, SWDCK) * * Parameters: * None. * * Return: * rxByte: Data byte received by host on SWDIO line (Least significant bit is * first received bit) * * Note: * This function is called for reading data bytes in a SWD Read Packet * ******************************************************************************/ static u8 Swd_ReceiveByte(void) { u8 loop = 0; u8 rxBit = 0; u8 rxByte = 0; /* Loop for 8-bits of a byte */ for(loop = 0; loop < 8; loop++) { SWDCK_OUTPUT_LOW; /* Read the SWDIO input line */ rxBit = ReadSwdio(); SWDCK_OUTPUT_HIGH; rxByte = rxByte >> 1; if(rxBit) /* Received a '1' */ { rxByte = rxByte | MSB_BIT_MASK; } else /* Received a '0' */ { rxByte = rxByte & (~MSB_BIT_MASK); } } return(rxByte); }
/****************************************************************************** * Function Name: Swd_ReceiveParity ******************************************************************************* * * Summary: * Receives the 1-bit parity data on SWD lines * * Parameters: * None. * * Return: * parity: * 1-bit parity data returned as a byte (either '1' or '0') * * Note: * This function is called during SWD Read packet * ******************************************************************************/ static u8 Swd_ReceiveParity(void) { u8 parity; /* Make the clock low, Read SWDIO data, Make Clock high */ SetSwdckLow(); parity = ReadSwdio(); SetSwdckHigh(); return(parity); }
/****************************************************************************** * Function Name: Swd_GetAckSegment ******************************************************************************** * * Summary: * Gets the 3-bit ACK response in a SWD packet * * Parameters: * None. * * Return: * ack: * 3-bit ACK response is returned as a byte. Three possible return values are: * 0x01 - SWD_OK_ACK * 0x02 - SWD_WAIT_ACK * 0x04 - SWD_FAULT_ACK * Any other return value - Undefined ACK code. * Treat it similar to SWD_FAULT_ACK and abort operation. * * Note: * This function is called during SWD Read/Write packets * ******************************************************************************/ static u8 Swd_GetAckSegment(void) { u8 ack = 0; u8 receiveBit = 0; u8 loop = 0; /* ACK bits are received lsb bit first */ for (loop = 0; loop < NUMBER_OF_ACK_BITS; loop++) { SetSwdckLow(); /* Store the ACK bit received */ receiveBit = ReadSwdio(); SetSwdckHigh(); /* Concatenate the ACK bit with ACK data byte */ ack = ack | (receiveBit << loop); } return (ack); }