Skip to content

Commit

Permalink
[Closes #83] UART RX and TX functional in cog modes
Browse files Browse the repository at this point in the history
`virtual` keyword disabled via preprocessor macro when compiled in COG
mode to decrease code size
  • Loading branch information
DavidZemon committed Apr 7, 2016
1 parent 2c4e967 commit 1334a4a
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 76 deletions.
1 change: 0 additions & 1 deletion Examples/GettingStarted/GettingStarted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ int main () {
pwOut << "Hello, world!";
return 0;
}

2 changes: 2 additions & 0 deletions PropWare/hmi/input/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
#include <PropWare/hmi/input/scanner.h>
#include <PropWare/serial/uart/uartrx.h>

#ifndef __PROPELLER_COG__
PropWare::UARTRX _g_uartrx;
PropWare::Scanner pwIn(_g_uartrx, &pwOut);
#endif
2 changes: 2 additions & 0 deletions PropWare/hmi/input/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,6 @@ class Scanner {

}

#ifndef __PROPELLER_COG__
extern PropWare::Scanner pwIn;
#endif
3 changes: 3 additions & 0 deletions PropWare/hmi/output/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
#include <PropWare/serial/uart/uarttx.h>

const PropWare::Printer::Format PropWare::Printer::DEFAULT_FORMAT;

#ifndef __PROPELLER_COG__
PropWare::UARTTX _g_uarttx;
const PropWare::Printer pwOut(_g_uarttx);
#endif
2 changes: 2 additions & 0 deletions PropWare/hmi/output/printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,10 @@ class Printer {

}

#ifndef __PROPELLER_COG__
/**
* @brief Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for
* multi-threaded printing)
*/
extern const PropWare::Printer pwOut;
#endif
2 changes: 2 additions & 0 deletions PropWare/hmi/output/synchronousprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <PropWare/hmi/output/synchronousprinter.h>
#include <PropWare/serial/uart/shareduarttx.h>

#ifndef __PROPELLER_COG__
PropWare::SharedUARTTX _g_sharedSimplexUart;
const PropWare::Printer _g_printer(_g_sharedSimplexUart);
const PropWare::SynchronousPrinter pwSyncOut(_g_printer);
#endif
51 changes: 0 additions & 51 deletions PropWare/serial/uart/halfduplexuart.h

This file was deleted.

2 changes: 1 addition & 1 deletion PropWare/serial/uart/shareduarttx.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file PropWare/serial/uart/sharedsimplexuart.h
* @file PropWare/serial/uart/shareduarttx.h
*
* @author David Zemon
*
Expand Down
10 changes: 9 additions & 1 deletion PropWare/serial/uart/uart.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file PropWare/serial/uart/abstractsimplexuart.h
* @file PropWare/serial/uart/uart.h
*
* @author David Zemon
*
Expand Down Expand Up @@ -29,6 +29,10 @@

namespace PropWare {

#ifdef __PROPELLER_COG__
#define virtual
#endif

/**
* @brief Abstract base class for all unbuffered UART devices
*
Expand Down Expand Up @@ -236,4 +240,8 @@ class UART {
uint8_t m_totalBits;
};

#ifdef __PROPELLER_COG__
#undef virtual
#endif

}
25 changes: 16 additions & 9 deletions PropWare/serial/uart/uartrx.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file PropWare/serial/uart/abstractduplexuart.h
* @file PropWare/serial/uart/uartrx.h
*
* @author David Zemon
*
Expand Down Expand Up @@ -31,18 +31,21 @@

namespace PropWare {

#ifdef __PROPELLER_COG__
#define virtual
#endif

/**
* @brief A base class for any non-buffered UART that is capable of both transmitting and receiving
*
* @note Abstract classes should not be used by end users. For unbuffered UART communication, take a look at
* `PropWare::FullDuplexUART` and `PropWare::HalfDuplexUART` for concrete classes, and consider using them with
* the `PropWare::Printer` class
* @brief Receive routines for basic UART communication
*/
class UARTRX : public UART,
public ScanCapable {
class UARTRX : public UART
#ifndef __PROPELLER_COG__
, public ScanCapable
#endif
{
public:
/**
* @see PropWare::SimplexUART::AbstractSimplexUART()
* @see PropWare::UART::UART()
*/
UARTRX () {
// Can't rely on parent constructor because the setters are virtual
Expand Down Expand Up @@ -445,4 +448,8 @@ class UARTRX : public UART,
uint8_t m_receivableBits;
};

#ifdef __PROPELLER_COG__
#undef virtual
#endif

}
37 changes: 24 additions & 13 deletions PropWare/serial/uart/uarttx.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@

namespace PropWare {

class UARTTX : public UART,
public PrintCapable {
#ifdef __PROPELLER_COG__
#define virtual
#endif

class UARTTX : public UART
#ifndef __PROPELLER_COG__
, public PrintCapable
#endif
{
public:
UARTTX ()
: UART() {
Expand Down Expand Up @@ -94,8 +101,8 @@ class UARTTX : public UART,
case UART::NO_PARITY:
__asm__ volatile (
FC_START("SendArrayStart%=", "SendArrayEnd%=")
// Prepare next word
"sendArrayLoop%=: \n\t"
// Prepare next word
"sendArrayLoop%=: \n\t"
" rdbyte %[_data], %[_arrayPtr] \n\t"
// Set start & stop bits
" or %[_data], %[_stopBitMask] \n\t"
Expand All @@ -114,7 +121,7 @@ class UARTTX : public UART,
// Increment the pointer and loop
" add %[_arrayPtr], #1 \n\t"
" djnz %[_words], #" FC_ADDR("sendArrayLoop%=", "SendArrayStart%=") " \n\t"
FC_END("SendArrayEnd%=")
FC_END("SendArrayEnd%=")
: [_data] "+r"(data),
[_waitCycles] "+r"(waitCycles),
[_arrayPtr] "+r"(arrayPtr),
Expand All @@ -128,8 +135,8 @@ class UARTTX : public UART,
case UART::ODD_PARITY:
__asm__ volatile (
FC_START("SendArrayStart%=", "SendArrayEnd%=")
// Prepare next word
"sendArrayLoop%=:"
// Prepare next word
"sendArrayLoop%=:"
" rdbyte %[_data], %[_arrayPtr] \n\t"
// Set parity
" test %[_data], %[_dataMask] wc \n\t"
Expand All @@ -151,7 +158,7 @@ class UARTTX : public UART,
// Increment the pointer and loop
" add %[_arrayPtr], #1 \n\t"
" djnz %[_words], #" FC_ADDR("sendArrayLoop%=", "SendArrayStart%=") " \n\t"
FC_END("SendArrayEnd%=")
FC_END("SendArrayEnd%=")
: [_data] "+r"(data),
[_waitCycles] "+r"(waitCycles),
[_arrayPtr] "+r"(arrayPtr),
Expand All @@ -167,8 +174,8 @@ class UARTTX : public UART,
case UART::EVEN_PARITY:
__asm__ volatile (
FC_START("SendArrayStart%=", "SendArrayEnd%=")
// Prepare next word
"sendArrayLoop%=:"
// Prepare next word
"sendArrayLoop%=:"
" rdbyte %[_data], %[_arrayPtr] \n\t"
// Set parity
" test %[_data], %[_dataMask] wc \n\t"
Expand All @@ -190,7 +197,7 @@ class UARTTX : public UART,
// Increment the pointer and loop
" add %[_arrayPtr], #1 \n\t"
" djnz %[_words], #" FC_ADDR("sendArrayLoop%=", "SendArrayStart%=") " \n\t"
FC_END("SendArrayEnd%=")
FC_END("SendArrayEnd%=")
: [_data] "+r"(data),
[_waitCycles] "+r"(waitCycles),
[_arrayPtr] "+r"(arrayPtr),
Expand Down Expand Up @@ -232,14 +239,14 @@ class UARTTX : public UART,
volatile uint32_t waitCycles = bitCycles;
__asm__ volatile (
FC_START("ShiftOutDataStart%=", "ShiftOutDataEnd%=")
" add %[_waitCycles], CNT \n\t"
" add %[_waitCycles], CNT \n\t"

"loop%=: \n\t"
" waitcnt %[_waitCycles], %[_bitCycles] \n\t"
" shr %[_data],#1 wc \n\t"
" muxc outa, %[_mask] \n\t"
" djnz %[_bits], #" FC_ADDR("loop%=", "ShiftOutDataStart%=") " \n\t"
FC_END("ShiftOutDataEnd%=")
FC_END("ShiftOutDataEnd%=")
: [_data] "+r"(data),
[_waitCycles] "+r"(waitCycles),
[_bits] "+r"(bits)
Expand All @@ -252,4 +259,8 @@ class UARTTX : public UART,
Pin m_pin;
};

#ifdef __PROPELLER_COG__
#undef virtual
#endif

}

0 comments on commit 1334a4a

Please sign in to comment.