aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/XPLAINBridge/Lib
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-05-08 03:12:14 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-05-08 03:12:14 +0000
commit071e02c6b6b4837fa9cf0b6d4c749994e02638d7 (patch)
tree960446788703b69f0bb285450be80c5b3d8cc22c /Projects/XPLAINBridge/Lib
parente331b531c6e6d93eb0eee42b9002074e8090ad18 (diff)
downloadlufa-071e02c6b6b4837fa9cf0b6d4c749994e02638d7.tar.gz
lufa-071e02c6b6b4837fa9cf0b6d4c749994e02638d7.tar.bz2
lufa-071e02c6b6b4837fa9cf0b6d4c749994e02638d7.zip
Add svn:eol-style property to source files, so that the line endings are correctly converted to the target system's native end of line style.
Diffstat (limited to 'Projects/XPLAINBridge/Lib')
-rw-r--r--Projects/XPLAINBridge/Lib/RingBuff.c240
-rw-r--r--Projects/XPLAINBridge/Lib/RingBuff.h232
-rw-r--r--Projects/XPLAINBridge/Lib/SoftUART.c286
-rw-r--r--Projects/XPLAINBridge/Lib/SoftUART.h118
4 files changed, 438 insertions, 438 deletions
diff --git a/Projects/XPLAINBridge/Lib/RingBuff.c b/Projects/XPLAINBridge/Lib/RingBuff.c
index 2109f8cc0..91c61d06b 100644
--- a/Projects/XPLAINBridge/Lib/RingBuff.c
+++ b/Projects/XPLAINBridge/Lib/RingBuff.c
@@ -1,120 +1,120 @@
-/*
- LUFA Library
- Copyright (C) Dean Camera, 2010.
-
- dean [at] fourwalledcubicle [dot] com
- www.fourwalledcubicle.com
-*/
-
-/*
- Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
- all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
-
- The author disclaim all warranties with regard to this
- software, including all implied warranties of merchantability
- and fitness. In no event shall the author be liable for any
- special, indirect or consequential damages or any damages
- whatsoever resulting from loss of use, data or profits, whether
- in an action of contract, negligence or other tortious action,
- arising out of or in connection with the use or performance of
- this software.
-*/
-
-#include "RingBuff.h"
-
-void Buffer_Initialize(RingBuff_t* const Buffer)
-{
- BUFF_ATOMIC_BLOCK
- {
- Buffer->InPtr = (RingBuff_Data_t*)&Buffer->Buffer;
- Buffer->OutPtr = (RingBuff_Data_t*)&Buffer->Buffer;
- Buffer->Elements = 0;
- }
-}
-
-void Buffer_StoreElement(RingBuff_t* const Buffer, RingBuff_Data_t Data)
-{
- BUFF_ATOMIC_BLOCK
- {
- #if defined(BUFF_DROPOLD)
- if (Buffer->Elements == BUFF_LENGTH)
- {
- Buffer->OutPtr++;
-
- if (Buffer->OutPtr == &Buffer->Buffer[BUFF_LENGTH])
- Buffer->OutPtr = (RingBuff_Data_t*)&Buffer->Buffer;
- }
- else
- {
- Buffer->Elements++;
- }
- #elif defined(BUFF_DROPNEW)
- if (Buffer->Elements == BUFF_LENGTH)
- return;
-
- Buffer->Elements++;
- #elif defined(BUFF_NODROPCHECK)
- Buffer->Elements++;
- #endif
-
- *(Buffer->InPtr) = Data;
- Buffer->InPtr++;
-
- if (Buffer->InPtr == &Buffer->Buffer[BUFF_LENGTH])
- Buffer->InPtr = (RingBuff_Data_t*)&Buffer->Buffer;
- }
-}
-
-RingBuff_Data_t Buffer_GetElement(RingBuff_t* const Buffer)
-{
- RingBuff_Data_t BuffData;
-
- BUFF_ATOMIC_BLOCK
- {
-#if defined(BUFF_EMPTYRETURNSZERO)
- if (!(Buffer->Elements))
- return 0;
-#elif !defined(BUFF_NOEMPTYCHECK)
- #error No empty buffer check behavior specified.
-#endif
-
- BuffData = *(Buffer->OutPtr);
-
- Buffer->OutPtr++;
- Buffer->Elements--;
-
- if (Buffer->OutPtr == &Buffer->Buffer[BUFF_LENGTH])
- Buffer->OutPtr = (RingBuff_Data_t*)&Buffer->Buffer;
- }
-
- return BuffData;
-}
-
-#if defined(BUFF_USEPEEK)
-RingBuff_Data_t Buffer_PeekElement(const RingBuff_t* const Buffer)
-{
- RingBuff_Data_t BuffData;
-
- BUFF_ATOMIC_BLOCK
- {
-#if defined(BUFF_EMPTYRETURNSZERO)
- if (!(Buffer->Elements))
- return 0;
-#elif !defined(BUFF_NOEMPTYCHECK)
- #error No empty buffer check behavior specified.
-#endif
-
- BuffData = *(Buffer->OutPtr);
- }
-
- return BuffData;
-}
-#endif
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2010.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.fourwalledcubicle.com
+*/
+
+/*
+ Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+#include "RingBuff.h"
+
+void Buffer_Initialize(RingBuff_t* const Buffer)
+{
+ BUFF_ATOMIC_BLOCK
+ {
+ Buffer->InPtr = (RingBuff_Data_t*)&Buffer->Buffer;
+ Buffer->OutPtr = (RingBuff_Data_t*)&Buffer->Buffer;
+ Buffer->Elements = 0;
+ }
+}
+
+void Buffer_StoreElement(RingBuff_t* const Buffer, RingBuff_Data_t Data)
+{
+ BUFF_ATOMIC_BLOCK
+ {
+ #if defined(BUFF_DROPOLD)
+ if (Buffer->Elements == BUFF_LENGTH)
+ {
+ Buffer->OutPtr++;
+
+ if (Buffer->OutPtr == &Buffer->Buffer[BUFF_LENGTH])
+ Buffer->OutPtr = (RingBuff_Data_t*)&Buffer->Buffer;
+ }
+ else
+ {
+ Buffer->Elements++;
+ }
+ #elif defined(BUFF_DROPNEW)
+ if (Buffer->Elements == BUFF_LENGTH)
+ return;
+
+ Buffer->Elements++;
+ #elif defined(BUFF_NODROPCHECK)
+ Buffer->Elements++;
+ #endif
+
+ *(Buffer->InPtr) = Data;
+ Buffer->InPtr++;
+
+ if (Buffer->InPtr == &Buffer->Buffer[BUFF_LENGTH])
+ Buffer->InPtr = (RingBuff_Data_t*)&Buffer->Buffer;
+ }
+}
+
+RingBuff_Data_t Buffer_GetElement(RingBuff_t* const Buffer)
+{
+ RingBuff_Data_t BuffData;
+
+ BUFF_ATOMIC_BLOCK
+ {
+#if defined(BUFF_EMPTYRETURNSZERO)
+ if (!(Buffer->Elements))
+ return 0;
+#elif !defined(BUFF_NOEMPTYCHECK)
+ #error No empty buffer check behavior specified.
+#endif
+
+ BuffData = *(Buffer->OutPtr);
+
+ Buffer->OutPtr++;
+ Buffer->Elements--;
+
+ if (Buffer->OutPtr == &Buffer->Buffer[BUFF_LENGTH])
+ Buffer->OutPtr = (RingBuff_Data_t*)&Buffer->Buffer;
+ }
+
+ return BuffData;
+}
+
+#if defined(BUFF_USEPEEK)
+RingBuff_Data_t Buffer_PeekElement(const RingBuff_t* const Buffer)
+{
+ RingBuff_Data_t BuffData;
+
+ BUFF_ATOMIC_BLOCK
+ {
+#if defined(BUFF_EMPTYRETURNSZERO)
+ if (!(Buffer->Elements))
+ return 0;
+#elif !defined(BUFF_NOEMPTYCHECK)
+ #error No empty buffer check behavior specified.
+#endif
+
+ BuffData = *(Buffer->OutPtr);
+ }
+
+ return BuffData;
+}
+#endif
diff --git a/Projects/XPLAINBridge/Lib/RingBuff.h b/Projects/XPLAINBridge/Lib/RingBuff.h
index 2e03a28be..b4933aa4d 100644
--- a/Projects/XPLAINBridge/Lib/RingBuff.h
+++ b/Projects/XPLAINBridge/Lib/RingBuff.h
@@ -1,116 +1,116 @@
-/*
- LUFA Library
- Copyright (C) Dean Camera, 2010.
-
- dean [at] fourwalledcubicle [dot] com
- www.fourwalledcubicle.com
-*/
-
-/*
- Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
- all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
-
- The author disclaim all warranties with regard to this
- software, including all implied warranties of merchantability
- and fitness. In no event shall the author be liable for any
- special, indirect or consequential damages or any damages
- whatsoever resulting from loss of use, data or profits, whether
- in an action of contract, negligence or other tortious action,
- arising out of or in connection with the use or performance of
- this software.
-*/
-
-/* Buffer Configuration: */
- /* Buffer length - select static size of created ring buffers: */
- #define BUFF_STATICSIZE 128 // Set to the static ring buffer size for all ring buffers (place size after define)
-
- /* Volatile mode - uncomment to make buffers volatile, for use in ISRs, etc: */
- #define BUFF_VOLATILE // Uncomment to cause all ring buffers to become volatile (and atomic if multi-byte) in access
-
- /* Drop mode - select behaviour when Buffer_StoreElement called on a full buffer: */
- #define BUFF_DROPOLD // Uncomment to cause full ring buffers to drop the oldest character to make space when full
- // #define BUFF_DROPNEW // Uncomment to cause full ring buffers to drop the new character when full
- // #define BUFF_NODROPCHECK // Uncomment to ignore full ring buffer checks - checking left to user!
-
- /* Underflow behaviour - select behaviour when Buffer_GetElement is called with an empty ring buffer: */
- //#define BUFF_EMPTYRETURNSZERO // Uncomment to return 0 when an empty ring buffer is read
- #define BUFF_NOEMPTYCHECK // Uncomment to disable checking of empty ring buffers - checking left to user!
-
- /* Buffer storage type - set the datatype for the stored data */
- #define BUFF_DATATYPE uint8_t // Change to the data type that is going to be stored into the buffer
-
- /* Peek routine - uncomment to include the peek routine (fetches next byte without removing it from the buffer */
- //#define BUFF_USEPEEK
-
-#ifndef _RINGBUFF_H_
-#define _RINGBUFF_H_
-
- /* Includes: */
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/atomic.h>
- #include <limits.h>
-
- #include <LUFA/Common/Common.h>
-
- /* Defines and checks: */
- #if defined(BUFF_STATICSIZE)
- #define BUFF_LENGTH BUFF_STATICSIZE
- #else
- #error No buffer length specified!
- #endif
-
- #if !(defined(BUFF_DROPOLD) || defined(BUFF_DROPNEW) || defined(BUFF_NODROPCHECK))
- #error No buffer drop mode specified.
- #endif
-
- #if !defined(BUFF_DATATYPE)
- #error Ringbuffer storage data type not specified.
- #endif
-
- #if defined(BUFF_VOLATILE)
- #define BUFF_MODE volatile
- #define BUFF_ATOMIC_BLOCK ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
- #else
- #define BUFF_MODE
- #define BUFF_ATOMIC_BLOCK
- #endif
-
- #if (BUFF_STATICSIZE > LONG_MAX)
- #define RingBuff_Elements_t uint64_t
- #elif (BUFF_STATICSIZE > INT_MAX)
- #define RingBuff_Elements_t uint32_t
- #elif (BUFF_STATICSIZE > CHAR_MAX)
- #define RingBuff_Elements_t uint16_t
- #else
- #define RingBuff_Elements_t uint8_t
- #endif
-
- /* Type Defines: */
- typedef BUFF_DATATYPE RingBuff_Data_t;
-
- typedef BUFF_MODE struct
- {
- RingBuff_Data_t Buffer[BUFF_LENGTH];
- RingBuff_Data_t* InPtr;
- RingBuff_Data_t* OutPtr;
- RingBuff_Elements_t Elements;
- } RingBuff_t;
-
- /* Function Prototypes: */
- void Buffer_Initialize(RingBuff_t* const Buff);
- void Buffer_StoreElement(RingBuff_t* const Buffer, RingBuff_Data_t Data);
- RingBuff_Data_t Buffer_GetElement(RingBuff_t* const Buffer);
- #if defined(BUFF_USEPEEK)
- RingBuff_Data_t Buffer_PeekElement(const RingBuff_t* const Buffer);
- #endif
-
-#endif
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2010.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.fourwalledcubicle.com
+*/
+
+/*
+ Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/* Buffer Configuration: */
+ /* Buffer length - select static size of created ring buffers: */
+ #define BUFF_STATICSIZE 128 // Set to the static ring buffer size for all ring buffers (place size after define)
+
+ /* Volatile mode - uncomment to make buffers volatile, for use in ISRs, etc: */
+ #define BUFF_VOLATILE // Uncomment to cause all ring buffers to become volatile (and atomic if multi-byte) in access
+
+ /* Drop mode - select behaviour when Buffer_StoreElement called on a full buffer: */
+ #define BUFF_DROPOLD // Uncomment to cause full ring buffers to drop the oldest character to make space when full
+ // #define BUFF_DROPNEW // Uncomment to cause full ring buffers to drop the new character when full
+ // #define BUFF_NODROPCHECK // Uncomment to ignore full ring buffer checks - checking left to user!
+
+ /* Underflow behaviour - select behaviour when Buffer_GetElement is called with an empty ring buffer: */
+ //#define BUFF_EMPTYRETURNSZERO // Uncomment to return 0 when an empty ring buffer is read
+ #define BUFF_NOEMPTYCHECK // Uncomment to disable checking of empty ring buffers - checking left to user!
+
+ /* Buffer storage type - set the datatype for the stored data */
+ #define BUFF_DATATYPE uint8_t // Change to the data type that is going to be stored into the buffer
+
+ /* Peek routine - uncomment to include the peek routine (fetches next byte without removing it from the buffer */
+ //#define BUFF_USEPEEK
+
+#ifndef _RINGBUFF_H_
+#define _RINGBUFF_H_
+
+ /* Includes: */
+ #include <avr/io.h>
+ #include <avr/interrupt.h>
+ #include <util/atomic.h>
+ #include <limits.h>
+
+ #include <LUFA/Common/Common.h>
+
+ /* Defines and checks: */
+ #if defined(BUFF_STATICSIZE)
+ #define BUFF_LENGTH BUFF_STATICSIZE
+ #else
+ #error No buffer length specified!
+ #endif
+
+ #if !(defined(BUFF_DROPOLD) || defined(BUFF_DROPNEW) || defined(BUFF_NODROPCHECK))
+ #error No buffer drop mode specified.
+ #endif
+
+ #if !defined(BUFF_DATATYPE)
+ #error Ringbuffer storage data type not specified.
+ #endif
+
+ #if defined(BUFF_VOLATILE)
+ #define BUFF_MODE volatile
+ #define BUFF_ATOMIC_BLOCK ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
+ #else
+ #define BUFF_MODE
+ #define BUFF_ATOMIC_BLOCK
+ #endif
+
+ #if (BUFF_STATICSIZE > LONG_MAX)
+ #define RingBuff_Elements_t uint64_t
+ #elif (BUFF_STATICSIZE > INT_MAX)
+ #define RingBuff_Elements_t uint32_t
+ #elif (BUFF_STATICSIZE > CHAR_MAX)
+ #define RingBuff_Elements_t uint16_t
+ #else
+ #define RingBuff_Elements_t uint8_t
+ #endif
+
+ /* Type Defines: */
+ typedef BUFF_DATATYPE RingBuff_Data_t;
+
+ typedef BUFF_MODE struct
+ {
+ RingBuff_Data_t Buffer[BUFF_LENGTH];
+ RingBuff_Data_t* InPtr;
+ RingBuff_Data_t* OutPtr;
+ RingBuff_Elements_t Elements;
+ } RingBuff_t;
+
+ /* Function Prototypes: */
+ void Buffer_Initialize(RingBuff_t* const Buff);
+ void Buffer_StoreElement(RingBuff_t* const Buffer, RingBuff_Data_t Data);
+ RingBuff_Data_t Buffer_GetElement(RingBuff_t* const Buffer);
+ #if defined(BUFF_USEPEEK)
+ RingBuff_Data_t Buffer_PeekElement(const RingBuff_t* const Buffer);
+ #endif
+
+#endif
diff --git a/Projects/XPLAINBridge/Lib/SoftUART.c b/Projects/XPLAINBridge/Lib/SoftUART.c
index 31b11c1cf..194481d0e 100644
--- a/Projects/XPLAINBridge/Lib/SoftUART.c
+++ b/Projects/XPLAINBridge/Lib/SoftUART.c
@@ -1,143 +1,143 @@
-/*
- LUFA Library
- Copyright (C) Dean Camera, 2010.
-
- dean [at] fourwalledcubicle [dot] com
- www.fourwalledcubicle.com
-*/
-
-/*
- Copyright 2010 David Prentice (david.prentice [at] farming [dot] uk)
- Copyright 2010 Peter Danneger
- Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
- all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
-
- The author disclaim all warranties with regard to this
- software, including all implied warranties of merchantability
- and fitness. In no event shall the author be liable for any
- special, indirect or consequential damages or any damages
- whatsoever resulting from loss of use, data or profits, whether
- in an action of contract, negligence or other tortious action,
- arising out of or in connection with the use or performance of
- this software.
-*/
-
-#include "SoftUART.h"
-
-volatile uint8_t srx_done, stx_count;
-volatile uint8_t srx_data, srx_mask, srx_tmp, stx_data;
-
-uint8_t SoftUART_IsReady(void)
-{
- return !(stx_count);
-}
-
-uint8_t SoftUART_TxByte(uint8_t Byte)
-{
- while (stx_count);
-
- stx_data = ~Byte;
- stx_count = 10;
-
- return Byte;
-}
-
-uint8_t SoftUART_IsReceived(void)
-{
- return srx_done;
-}
-
-uint8_t SoftUART_RxByte(void)
-{
- while (!(srx_done));
-
- srx_done = 0;
-
- return srx_data;
-}
-
-void SoftUART_Init(void)
-{
- OCR2B = TCNT2 + 1; // force first compare
- TCCR2A = (1 << COM2B1) | (1 << COM2B0); // T1 mode 0
- TCCR2B = (1 << FOC2B) | (1 << CS21); // CLK/8, T1 mode 0
- TIMSK2 = (1 << OCIE2B); // enable tx and wait for start
- EICRA = (1 << ISC01); // -ve edge
- EIMSK = (1 << INT0); // enable INT0 interrupt
-
- stx_count = 0; // nothing to send
- srx_done = 0; // nothing received
- STXPORT |= 1 << STX; // TX output
- STXDDR |= 1 << STX; // TX output
- SRXPORT |= (1 << SRX); // pullup on INT0
-}
-
-/* ISR to detect the start of a bit being sent from the transmitter. */
-ISR(INT0_vect)
-{
- OCR2A = TCNT2 + (BIT_TIME / 8 * 3 / 2); // scan 1.5 bits after start
-
- srx_tmp = 0; // clear bit storage
- srx_mask = 1; // bit mask
-
- TIFR2 = (1 << OCF2A); // clear pending interrupt
-
- if (!(SRXPIN & (1 << SRX))) // still low
- {
- TIMSK2 = (1 << OCIE2A) | (1 << OCIE2B); // wait for first bit
- EIMSK &= ~(1 << INT0);
- }
-}
-
-/* ISR to manage the reception of bits to the transmitter. */
-ISR(TIMER2_COMPA_vect)
-{
- if (srx_mask)
- {
- if (SRXPIN & (1 << SRX))
- srx_tmp |= srx_mask;
-
- srx_mask <<= 1;
-
- OCR2A += BIT_TIME / 8; // next bit slice
- }
- else
- {
- srx_done = 1; // mark rx data valid
- srx_data = srx_tmp; // store rx data
- TIMSK2 = (1 << OCIE2B); // enable tx and wait for start
- EIMSK |= (1 << INT0); // enable START irq
- EIFR = (1 << INTF0); // clear any pending
- }
-}
-
-/* ISR to manage the transmission of bits to the receiver. */
-ISR(TIMER2_COMPB_vect)
-{
- OCR2B += BIT_TIME / 8; // next bit slice
-
- if (stx_count)
- {
- if (--stx_count != 9) // no start bit
- {
- if (!(stx_data & 1)) // test inverted data
- TCCR2A = (1 << COM2B1) | (1 << COM2B0);
- else
- TCCR2A = (1 << COM2B1);
-
- stx_data >>= 1; // shift zero in from left
- }
- else
- {
- TCCR2A = (1 << COM2B1); // START bit
- }
- }
-}
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2010.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.fourwalledcubicle.com
+*/
+
+/*
+ Copyright 2010 David Prentice (david.prentice [at] farming [dot] uk)
+ Copyright 2010 Peter Danneger
+ Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+#include "SoftUART.h"
+
+volatile uint8_t srx_done, stx_count;
+volatile uint8_t srx_data, srx_mask, srx_tmp, stx_data;
+
+uint8_t SoftUART_IsReady(void)
+{
+ return !(stx_count);
+}
+
+uint8_t SoftUART_TxByte(uint8_t Byte)
+{
+ while (stx_count);
+
+ stx_data = ~Byte;
+ stx_count = 10;
+
+ return Byte;
+}
+
+uint8_t SoftUART_IsReceived(void)
+{
+ return srx_done;
+}
+
+uint8_t SoftUART_RxByte(void)
+{
+ while (!(srx_done));
+
+ srx_done = 0;
+
+ return srx_data;
+}
+
+void SoftUART_Init(void)
+{
+ OCR2B = TCNT2 + 1; // force first compare
+ TCCR2A = (1 << COM2B1) | (1 << COM2B0); // T1 mode 0
+ TCCR2B = (1 << FOC2B) | (1 << CS21); // CLK/8, T1 mode 0
+ TIMSK2 = (1 << OCIE2B); // enable tx and wait for start
+ EICRA = (1 << ISC01); // -ve edge
+ EIMSK = (1 << INT0); // enable INT0 interrupt
+
+ stx_count = 0; // nothing to send
+ srx_done = 0; // nothing received
+ STXPORT |= 1 << STX; // TX output
+ STXDDR |= 1 << STX; // TX output
+ SRXPORT |= (1 << SRX); // pullup on INT0
+}
+
+/* ISR to detect the start of a bit being sent from the transmitter. */
+ISR(INT0_vect)
+{
+ OCR2A = TCNT2 + (BIT_TIME / 8 * 3 / 2); // scan 1.5 bits after start
+
+ srx_tmp = 0; // clear bit storage
+ srx_mask = 1; // bit mask
+
+ TIFR2 = (1 << OCF2A); // clear pending interrupt
+
+ if (!(SRXPIN & (1 << SRX))) // still low
+ {
+ TIMSK2 = (1 << OCIE2A) | (1 << OCIE2B); // wait for first bit
+ EIMSK &= ~(1 << INT0);
+ }
+}
+
+/* ISR to manage the reception of bits to the transmitter. */
+ISR(TIMER2_COMPA_vect)
+{
+ if (srx_mask)
+ {
+ if (SRXPIN & (1 << SRX))
+ srx_tmp |= srx_mask;
+
+ srx_mask <<= 1;
+
+ OCR2A += BIT_TIME / 8; // next bit slice
+ }
+ else
+ {
+ srx_done = 1; // mark rx data valid
+ srx_data = srx_tmp; // store rx data
+ TIMSK2 = (1 << OCIE2B); // enable tx and wait for start
+ EIMSK |= (1 << INT0); // enable START irq
+ EIFR = (1 << INTF0); // clear any pending
+ }
+}
+
+/* ISR to manage the transmission of bits to the receiver. */
+ISR(TIMER2_COMPB_vect)
+{
+ OCR2B += BIT_TIME / 8; // next bit slice
+
+ if (stx_count)
+ {
+ if (--stx_count != 9) // no start bit
+ {
+ if (!(stx_data & 1)) // test inverted data
+ TCCR2A = (1 << COM2B1) | (1 << COM2B0);
+ else
+ TCCR2A = (1 << COM2B1);
+
+ stx_data >>= 1; // shift zero in from left
+ }
+ else
+ {
+ TCCR2A = (1 << COM2B1); // START bit
+ }
+ }
+}
diff --git a/Projects/XPLAINBridge/Lib/SoftUART.h b/Projects/XPLAINBridge/Lib/SoftUART.h
index d6b24320f..07187c24a 100644
--- a/Projects/XPLAINBridge/Lib/SoftUART.h
+++ b/Projects/XPLAINBridge/Lib/SoftUART.h
@@ -1,60 +1,60 @@
-/*
- LUFA Library
- Copyright (C) Dean Camera, 2010.
-
- dean [at] fourwalledcubicle [dot] com
- www.fourwalledcubicle.com
-*/
-
-/*
- Copyright 2010 David Prentice (david.prentice [at] farming [dot] uk)
- Copyright 2010 Peter Danneger
- Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
-
- Permission to use, copy, modify, distribute, and sell this
- software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
- all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
-
- The author disclaim all warranties with regard to this
- software, including all implied warranties of merchantability
- and fitness. In no event shall the author be liable for any
- special, indirect or consequential damages or any damages
- whatsoever resulting from loss of use, data or profits, whether
- in an action of contract, negligence or other tortious action,
- arising out of or in connection with the use or performance of
- this software.
-*/
-
-#ifndef _SOFT_UART_
-#define _SOFT_UART_
-
- /* Includes: */
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include "SoftUART.h"
-
- /* Macros: */
- #define BAUD 9600
- #define BIT_TIME (uint16_t)((F_CPU + (BAUD / 2)) / BAUD)
-
- #define SRX PD0
- #define SRXPIN PIND
- #define SRXPORT PORTD
-
- #define STX PD1
- #define STXPORT PORTD
- #define STXDDR DDRD
-
- /* Function Prototypes: */
- uint8_t SoftUART_IsReady(void);
- uint8_t SoftUART_TxByte(uint8_t c);
- uint8_t SoftUART_IsReceived(void);
- uint8_t SoftUART_RxByte(void);
- void SoftUART_Init(void);
-
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2010.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.fourwalledcubicle.com
+*/
+
+/*
+ Copyright 2010 David Prentice (david.prentice [at] farming [dot] uk)
+ Copyright 2010 Peter Danneger
+ Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+#ifndef _SOFT_UART_
+#define _SOFT_UART_
+
+ /* Includes: */
+ #include <avr/io.h>
+ #include <avr/interrupt.h>
+ #include "SoftUART.h"
+
+ /* Macros: */
+ #define BAUD 9600
+ #define BIT_TIME (uint16_t)((F_CPU + (BAUD / 2)) / BAUD)
+
+ #define SRX PD0
+ #define SRXPIN PIND
+ #define SRXPORT PORTD
+
+ #define STX PD1
+ #define STXPORT PORTD
+ #define STXDDR DDRD
+
+ /* Function Prototypes: */
+ uint8_t SoftUART_IsReady(void);
+ uint8_t SoftUART_TxByte(uint8_t c);
+ uint8_t SoftUART_IsReceived(void);
+ uint8_t SoftUART_RxByte(void);
+ void SoftUART_Init(void);
+
#endif \ No newline at end of file