FreeRTOS V8.1.2, MSP432P401R Demo project, CCS Version: 6.1.0.00104
I am try to make a general C++ class for working with tasks. I have a base class that contains the static function for xTaskCreate, which is used by the derived class when creating the task. The derived class
this pointer is passed to xTaskCreate and eventually used by the static function to call a derived class method. But in the call to the derived class method, a hard fault is generated. Anyone have any suggestions on where to look to resolve this issue?
TaskBase.h
…
class TaskBase {
public:
TaskBase();
virtual ~TaskBase();
virtual void createTask() = 0;
virtual void run();
static void runTask(void* param);
protected:
string m
taskName;
unsigned short mtaskStackSize;
unsigned long m
taskPriority;
unsigned long mtickDelay;
};
TaskBase.cpp
…
TaskBase::TaskBase():
m
taskName(“Base”),
mtaskStackSize(512),
m
taskPriority(tskIDLEPRIORITY + 1),
m
tickDelay(pdMSTO_TICKS(100))
{
}
TaskBase::~TaskBase()
{
}
void TaskBase::runTask(void* param)
{
TaskBase* basePtr = static_cast<TaskBase*>(param);
if (basePtr != NULL)
basePtr->run();** // HARD FAULT HERE**
}
void TaskBase::run()
{
}
TaskSystemData.h
…
class TaskSystemData: public TaskBase {
public:
TaskSystemData();
virtual ~TaskSystemData();
virtual void createTask();
virtual void run();
virtual unsigned long getTickDelay() {return m_tickDelay;}
};
TaskSystemData.cpp
TaskSystemData::TaskSystemData()
{
}
TaskSystemData::~TaskSystemData()
{
}
void TaskSystemData::createTask()
{
xTaskCreate((TaskFunction
t) &TaskBase::runTask, // The function that implements the task.
mtaskName.c
str(), // The text name assigned to the task – for debug only as it is not used by the kernel.
mtaskStackSize, // The size of the stack to allocate to the task.
this, // The parameter passed to the task.
m_taskPriority, // The priority assigned to the task.
NULL);
}
void TaskSystemData::run()
{
unsigned long sequenceIndex = 0;
unsigned long sequenceValue = 0;
unsigned long tickDelay = pdMS
TOTICKS(100);
// more code....
}
main.cpp
// more code...
TaskSystemData systemDataTask;
systemDataTask.createTask();
//Start real time scheduler
vTaskStartScheduler();