Up until now I have always done plain C with UCOS but now I have a need to create a single class to encapsulate serial port handling for 8 serial ports. As each port will be doing exactly the same function I don't want to write it 8 times so I have decided to try and use C++ classes for this.
The use of classes I understand but I can't seem to get the OSTaskCreate to take the pointer to the task function. I have followed the Wiki at:
http://wiki.embeddedethernet.com/Developing_in_Cpp
This is what I have so far in the header file:
Code: Select all
class InDriver {
int TXD, RXD; // eTPU TX and RX
int fd; // File descriptor
int BaudRate; // Serial baud rate
int Bits; // Number of bits
int TxPortEn; // GPIO TX Port enable
int ATSMode; // Serial protocol mode
int Port; // Which port, 0 - 7
DWORD TaskStack[USER_TASK_STK_SIZE] __attribute__( ( aligned( 4 ) ) );
public:
InDriver(int Priority, char *Name, int InitTxd, int InitRxd, int InitBaudRate, int InitBits,
int InitTxPortEn, int InitATSMode, int InitPort);
~InDriver();
private:
void InDriverTask(void *ptr);
void SetInTx();
void SetInRx();
void WaitDataOut();
int SendData(char* Data, int DataLen);
};
Code: Select all
InDriver::InDriver(int Priority, char *Name, int InitTxd, int InitRxd, int InitBaudRate,
int InitBits, int InitTxPortEn, int InitATSMode, int InitPort)
{
TXD = InitTxd;
RXD = InitRxd;
BaudRate = InitBaudRate;
Bits = InitBits;
TxPortEn = InitTxPortEn;
Port = InitPort;
if ( OSTaskCreatewName(InDriverTask,
NULL,
( void * ) (TaskStack + USER_TASK_STK_SIZE),
( void * ) TaskStack,
Priority,
Name) != OS_NO_ERR )
{
iprintf( "*** Error creating task InDriver\r\n" );
}
}
argument of type 'void (InDriver::)(void*)' does not match 'void (*)(void*)'
The task itself is written as follows (partial code onyl)
Code: Select all
void InDriver::InDriverTask(void *ptr)
{
//
// Open the serial port to input
//
fd = eTPUFDUartOpen(RXD, TXD, Bits, Bits, FS_ETPU_UART_NO_PARITY, FS_ETPU_PRIORITY_MIDDLE);
By the way, declaring the task as static void in the header files create even more errors:
cannot call member function 'void InDriver::SetInRx()' without object
cannot call member function 'void InDriver::SetInTx()' without object
from this location ats_indriver1.cpp
from this location ats_indriver1.cpp
from this location ats_indriver1.cpp
invalid use of member 'InDriver::ATSMode' in static member function
invalid use of member 'InDriver::Bits' in static member function
invalid use of member 'InDriver::fd' in static member function
invalid use of member 'InDriver::Port' in static member function