Make sure that USB_STREAM_TIMEOUT_MS is set in the MassStorageHost ClassDriver demo...
[pub/USBasp.git] / Projects / AVRISP / Lib / PDITarget.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #if defined(ENABLE_PDI_PROTOCOL) || defined(__DOXYGEN__)
32
33 /** \file
34 *
35 * Target-related functions for the PDI Protocol decoder.
36 */
37
38 #define INCLUDE_FROM_PDITARGET_C
39 #include "PDITarget.h"
40
41 /** Writes a given byte to the attached XMEGA device, using a RS232 frame via software through the
42 * PDI interface.
43 *
44 * \param[in] Byte Byte to send to the attached device
45 */
46 void PDITarget_SendByte(uint8_t Byte)
47 {
48 PDIDATA_LINE_PORT &= ~PDIDATA_LINE_MASK;
49
50 TOGGLE_PDI_CLOCK;
51
52 for (uint8_t i = 0; i < 8; i++)
53 {
54 if (Byte & 0x01)
55 PDIDATA_LINE_PORT |= PDIDATA_LINE_MASK;
56 else
57 PDIDATA_LINE_PORT &= ~PDIDATA_LINE_MASK;
58
59 Byte >>= 1;
60
61 TOGGLE_PDI_CLOCK;
62 }
63
64 PDIDATA_LINE_PORT |= PDIDATA_LINE_MASK;
65
66 TOGGLE_PDI_CLOCK;
67 TOGGLE_PDI_CLOCK;
68 }
69
70 /** Reads a given byte from the attached XMEGA device, encoded in a RS232 frame through the PDI interface.
71 *
72 * \return Received byte from the attached device
73 */
74 uint8_t PDITarget_ReceiveByte(void)
75 {
76 uint8_t ReceivedByte = 0;
77
78 PDIDATA_LINE_DDR &= ~PDIDATA_LINE_MASK;
79
80 while (PDIDATA_LINE_PIN & PDIDATA_LINE_MASK);
81 TOGGLE_PDI_CLOCK;
82
83 for (uint8_t i = 0; i < 8; i++)
84 {
85 if (PDIDATA_LINE_PIN & PDIDATA_LINE_MASK)
86 ReceivedByte |= 0x01;
87
88 ReceivedByte <<= 1;
89
90 TOGGLE_PDI_CLOCK;
91 }
92
93 TOGGLE_PDI_CLOCK;
94 TOGGLE_PDI_CLOCK;
95
96 PDIDATA_LINE_DDR |= PDIDATA_LINE_MASK;
97
98 return ReceivedByte;
99 }
100
101 #endif