/*******************************************************************************
* vTraceEnable
*
* Function that enables the tracing and creates the control task. It will halt
* execution until a Start command has been received if haltUntilStart is true.
*
******************************************************************************/
void vTraceEnable(int startOption)
{
int32_t bytes = 0;
int32_t status;
extern uint32_t RecorderEnabled;
TracealyzerCommandType msg;
/* Only do this first time...*/
if (HandleTzCtrl == NULL)
{
TRC_STREAM_PORT_INIT();
/* Note: Requires that TRC_CFG_INCLUDE_USER_EVENTS is 1. */
trcWarningChannel = xTraceRegisterString("Warnings from Recorder");
/* Creates the TzCtrl task - receives trace commands (start, stop, ...) */
#if defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION == 1)
HandleTzCtrl = xTaskCreateStatic(TzCtrl, STRING_CAST("TzCtrl"), TRC_CFG_CTRL_TASK_STACK_SIZE, NULL, TRC_CFG_CTRL_TASK_PRIORITY, stackTzCtrl, &tcbTzCtrl);
#else
xTaskCreate( TzCtrl, STRING_CAST("TzCtrl"), TRC_CFG_CTRL_TASK_STACK_SIZE, NULL, TRC_CFG_CTRL_TASK_PRIORITY, &HandleTzCtrl );
#endif
if (HandleTzCtrl == NULL)
{
prvTraceError(PSF_ERROR_TZCTRLTASK_NOT_CREATED);
}
}
if (startOption == TRC_START_AWAIT_HOST)
{
/* We keep trying to read commands until the recorder has been started */
do
{
bytes = 0;
status = TRC_STREAM_PORT_READ_DATA(&msg, sizeof(TracealyzerCommandType), (int32_t*)&bytes);
if (status != 0)
{
prvTraceWarning(PSF_WARNING_STREAM_PORT_READ);
}
if ((status == 0) && (bytes == sizeof(TracealyzerCommandType)))
{
if (prvIsValidCommand(&msg))
{
if (msg.cmdCode == CMD_SET_ACTIVE && msg.param1 == 1)
{
/* On start, init and reset the timestamping */
TRC_PORT_SPECIFIC_INIT();
}
prvProcessCommand(&msg);
}
}
}
while (RecorderEnabled == 0);
}
else if (startOption == TRC_START)
{
/* We start streaming directly - this assumes that the interface is ready! */
TRC_PORT_SPECIFIC_INIT();
msg.cmdCode = CMD_SET_ACTIVE;
msg.param1 = 1;
prvProcessCommand(&msg);
}
else
{
/* On TRC_INIT */
TRC_PORT_SPECIFIC_INIT();
}
}
* vTraceEnable
*
* Function that enables the tracing and creates the control task. It will halt
* execution until a Start command has been received if haltUntilStart is true.
*
******************************************************************************/
void vTraceEnable(int startOption)
{
int32_t bytes = 0;
int32_t status;
extern uint32_t RecorderEnabled;
TracealyzerCommandType msg;
/* Only do this first time...*/
if (HandleTzCtrl == NULL)
{
TRC_STREAM_PORT_INIT();
/* Note: Requires that TRC_CFG_INCLUDE_USER_EVENTS is 1. */
trcWarningChannel = xTraceRegisterString("Warnings from Recorder");
/* Creates the TzCtrl task - receives trace commands (start, stop, ...) */
#if defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION == 1)
HandleTzCtrl = xTaskCreateStatic(TzCtrl, STRING_CAST("TzCtrl"), TRC_CFG_CTRL_TASK_STACK_SIZE, NULL, TRC_CFG_CTRL_TASK_PRIORITY, stackTzCtrl, &tcbTzCtrl);
#else
xTaskCreate( TzCtrl, STRING_CAST("TzCtrl"), TRC_CFG_CTRL_TASK_STACK_SIZE, NULL, TRC_CFG_CTRL_TASK_PRIORITY, &HandleTzCtrl );
#endif
if (HandleTzCtrl == NULL)
{
prvTraceError(PSF_ERROR_TZCTRLTASK_NOT_CREATED);
}
}
if (startOption == TRC_START_AWAIT_HOST)
{
/* We keep trying to read commands until the recorder has been started */
do
{
bytes = 0;
status = TRC_STREAM_PORT_READ_DATA(&msg, sizeof(TracealyzerCommandType), (int32_t*)&bytes);
if (status != 0)
{
prvTraceWarning(PSF_WARNING_STREAM_PORT_READ);
}
if ((status == 0) && (bytes == sizeof(TracealyzerCommandType)))
{
if (prvIsValidCommand(&msg))
{
if (msg.cmdCode == CMD_SET_ACTIVE && msg.param1 == 1)
{
/* On start, init and reset the timestamping */
TRC_PORT_SPECIFIC_INIT();
}
prvProcessCommand(&msg);
}
}
}
while (RecorderEnabled == 0);
}
else if (startOption == TRC_START)
{
/* We start streaming directly - this assumes that the interface is ready! */
TRC_PORT_SPECIFIC_INIT();
msg.cmdCode = CMD_SET_ACTIVE;
msg.param1 = 1;
prvProcessCommand(&msg);
}
else
{
/* On TRC_INIT */
TRC_PORT_SPECIFIC_INIT();
}
}