/*
 * port_control.c
 *
 * Created: 25.4.2014 18:51:42
 *  Author: xp
 */ 

#include "default.h"

typedef struct {
	xQueueHandle control_pipe;	
} DEFAULT_TASK_NAME_task_param_t;

const char *const DEFAULT_TASK_NAME_type_str[] = {
	FOREACH_DEFAULT_TASK_NAME_msg_type(GENERATE_STRING)
};

status_code_t DEFAULT_TASK_NAME_init(DEFAULT_TASK_NAME_handle_t * task_handle)
{
	status_code_t ret;
	portBASE_TYPE retTask;
	
	static DEFAULT_TASK_NAME_task_param_t task_param;
  
	task_param.control_pipe = 0;
	
	task_handle->task_handle = NULL;
	task_handle->control_pipe = 0;
	
	/* Create FreeRTOS queue for task control pipe */
	task_param.control_pipe = xQueueCreate(TASK_DEFAULT_TASK_NAME_CONTROL_PIPE_LEN, sizeof(DEFAULT_TASK_NAME_task_param_t));
	if (task_param.control_pipe == 0) {
		return ERR_NO_MEMORY;
	}
	task_handle->control_pipe = task_param.control_pipe;

	/* Create the task. */
	retTask = xTaskCreate(DEFAULT_TASK_NAME_task, (const signed char *const) TASK_DEFAULT_TASK_NAME_NAME,
		TASK_DEFAULT_TASK_NAME_STACK_DEPTH_WORDS, (void *)(& task_param), TASK_DEFAULT_TASK_NAME_PRIORITY, &(task_handle->task_handle));
		
	if ((retTask != pdPASS) || (task_handle->task_handle == NULL))	{
		return ERR_NO_MEMORY;
	}
	
	return STATUS_OK;
}

void DEFAULT_TASK_NAME_task(void *pvParameters)
{
	DEFAULT_TASK_NAME_task_param_t * task_param = (DEFAULT_TASK_NAME_task_param_t *)pvParameters;
	DEFAULT_TASK_NAME_msg_t control_msg;
	
	for(;;)	{
		if (xQueueReceive(task_param->control_pipe, (void *)(&control_msg) , portMAX_DELAY) == pdPASS) { /* Nothing to do if queue is empty */
			
		}
	}

	/* If all is well, the following line will never be reached. */
	vTaskDelete(NULL);
}
