• Welcome to Andy's Workshop Forums. Please login or sign up.
 
April 26, 2024, 12:48:42 pm

News:

SMF - Just Installed!


passing reference...

Started by mhel, November 25, 2015, 05:47:46 pm

Previous topic - Next topic

mhel

Hi,
This is likely a throw in the dark. (I can't even think of a proper title for the subject).
I'm trying to use interrupt driven Usart, I'm having a hardtime figuring out how
I can access the interrupt features from another class. I'm using Usart6.
like so:
Usat6<Usart6InterruptFeature> usart6
with usart6 passed as parameter in a constructor. I could point to it using:
Usart& _usart = usart6
but I don't have access to enable/disableInterrupts.
How would one go about it?

Andy Brown

You can pass around the whole type as a reference if you want. Typedefs make that less clunky to look at:


typedef  Usart6<Usart6InterruptFeature> MyUsart;
MyUsart usart6;

MyUsart _usart=usart6;


Is that all you need? If you were looking to write a class that's more generic and doesn't need to know that it's operating specifically on Usart6 then consider making it a template that takes your Usart type as a template parameter.
It's worse than that, it's physics Jim!

mhel

Thanks. That's just what I need. I'll also try to use it with a template.
I'll post back my result later, right now I'm battling with transmit interrupt (recieve works though).

Thanks again.

mhel

November 27, 2015, 09:59:19 am #3 Last Edit: November 30, 2015, 04:57:15 pm by mhel
Well I'm doing it wrong :(

Here's my simple class


template<class TUsart>
class SerialUsartIO {
private:
/* This should not be in here */
//   typedef Usart6InterruptFeature UsartIRQ;
//   Usart6<UsartIRQ> _usart;
TUsart _usart;

CircularBuffer<uint8_t, 128> RxBuffer;
CircularBuffer<uint8_t, 128> TxBuffer;

public:

SerialUsartIO(uint32_t baud) : _usart(baud) { Init(); }

void Init();
void onInterrupt(UsartEventType uet);

void PutChar(uint8_t c);
void PutStr(const char*);
uint8_t GetChar(void);
};

I get undefined reference on all my member function like this,

undefined reference to `SerialUsartIO<stm32plus::Usart6<stm32plus::UsartInterruptFeature<(unsigned char)6> > >::GetChar()

In my main I do this,

typedef Usart6<Usart6InterruptFeature> MyUsart;
SerialUsartIO<MyUsart> console(115200);
ch = console.GetChar();

I just want to be able to have access to some methods in Usart6 that I could also
pass to another class in case I have to.
What would be the correct way of doing it?


EDIT:
I just found out that templated definitions can't go in a separate .cpp file must be in the .h along with the declarations.
Did I mention I'm new to C++ :-)

I also discovered the existense of CircularBufferInputOutputStream and used that instead. It's somewhat working with receive interrupt,
but hangs after a while. I still can't get the transmit interrupt working it hangs as soon as I enabled it. (Feel free to point me in the right direction with this one)

Thanks.