johnniewhite wrote on Friday, November 08, 2019:
My FreeRTOS Task (vTaskCode) Only Executes Once and can’t figure out why.
Here’s the source code:
/*
- Empty C++ Application
*/
#include
#include
#include “FreeRTOS.h”
#include “task.h”
void * operator new( size_t size )
{
return pvPortMalloc( size );
}
void * operator new[]( size_t size )
{
return pvPortMalloc(size);
}
void operator delete( void * ptr )
{
vPortFree ( ptr );
}
void operator delete[]( void * ptr )
{
vPortFree ( ptr );
}
#define STACK_SIZE 4096
/* Task to be created. /
void vTaskCode( void * pvParameters )
{
/ The parameter value is expected to be 1 as 1 is passed in the
pvParameters value in the call to xTaskCreate() below. */
configASSERT( ( ( uint32_t ) pvParameters ) == 1 );
/* Block for 500ms. */
//const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
for( ;; )
{
std::cout << "Hello World" << std::endl;
//vTaskDelay( xDelay );
}
}
/* Function that creates a task. */
void vOtherFunction( void )
{
BaseType_t xReturned;
TaskHandle_t xHandle = NULL;
/* Create the task, storing the handle. */
xReturned = xTaskCreate(
vTaskCode, /* Function that implements the task. */
"NAME", /* Text name for the task. */
STACK_SIZE, /* Stack size in words, not bytes. */
( void * ) 1, /* Parameter passed into the task. */
tskIDLE_PRIORITY,/* Priority at which the task is created. */
&xHandle ); /* Used to pass out the created task's handle. */
if( xReturned == pdPASS )
{
/* The task was created. Use the task's handle to delete the task. */
//vTaskDelete( xHandle );
}
}
int main ()
{
// constructors used in the same order as described above:
std::list first; // empty list of ints
std::list second (4,100); // four ints with value 100
std::list third (second.begin(),second.end()); // iterating through second
std::list fourth (third); // a copy of third
// the iterator constructor can also be used to construct from arrays:
int myints[] = {16,2,77,29};
std::list fifth (myints, myints + sizeof(myints) / sizeof(int) );
std::cout << "The contents of fifth are: ";
for (std::list::iterator it = fifth.begin(); it != fifth.end(); it++)
std::cout << *it << ’ ';
std::cout << ‘\n’;
vOtherFunction();
vTaskStartScheduler();
while(1);
return 0;
}