#include "Config/Include/APP_Config.h"
#include "Abstraction/Include/OS_Interface.h"

void QUEUE_Init()
{
    OS_QueueConfig tQueueConfig[] =
    {
         {  MSG_ID_LOG,     QUEUE_LENGTH_16     }
        ,{  MSG_ID_UPDATE,  QUEUE_LENGTH_16     }
		,{  MSG_ID_SPIMANAGER,     QUEUE_LENGTH_16     }
		,{  MSG_ID_SPISEND,     QUEUE_LENGTH_16     }
		,{  MSG_ID_SPIRECV,     QUEUE_LENGTH_16     }
        ,{  MSG_ID_CANAPP,  QUEUE_LENGTH_64     }
        ,{  MSG_ID_CANCYC,  QUEUE_LENGTH_8		}
		,{  MSG_ID_CANSTACK,  QUEUE_LENGTH_8		}
        ,{  MSG_ID_PCTOOLS,  QUEUE_LENGTH_64		}
		,{  MSG_ID_CANMGR,     QUEUE_LENGTH_16     }
        ,{	MSG_ID_SHARETASK,	QUEUE_LENGTH_50 	}
        ,{  MSG_ID_POWERMGR,QUEUE_LENGTH_64     }
        ,{  MSG_ID_SENSOR_APP,	QUEUE_LENGTH_32		}
        ,{  MSG_ID_SENSOR_CYC,	QUEUE_LENGTH_8		}
        ,{	MSG_ID_BACKUPBATTERY,QUEUE_LENGTH_16	}
    };

    for(size_t i = 0; i < sizeof(tQueueConfig) / sizeof(tQueueConfig[0]); ++i)
    {
        OS_createQueue(&tQueueConfig[i]);
    }
}

void TASK_Init()
{
    OS_TaskConfig tTaskConfig[] =
    {
         {  TSK_ID_POWERMGR,    TASK_STACK_NORMAL,  TASK_PRIORITY_HIGHEST,   "PowerManager",    PowerMgr_getTaskParam   }
        ,{  TSK_ID_POWERCYC,    TASK_STACK_NORMAL,  TASK_PRIORITY_ABOVE_NORMAL, "PowerCyc",    	PowerCyc_getTaskParam   }
        ,{  TSK_ID_LOG,    TASK_STACK_NORMAL,  TASK_PRIORITY_NORMAL,   "LogManager",    LOG_getTaskParam        }
        ,{  TSK_ID_UPDATE, TASK_STACK_NORMAL,  TASK_PRIORITY_NORMAL,   "UpdateManager", Update_getTaskParam     }
		,{  TSK_ID_SPIMANAGER,    TASK_STACK_NORMAL,  TASK_PRIORITY_ABOVE_NORMAL,   "SpiManager",    SpiManager_getTaskParam        }
		,{  TSK_ID_SPISEND,    TASK_STACK_NORMAL,  TASK_PRIORITY_ABOVE_NORMAL,   "SpiSend",    SpiSend_getTaskParam        }
		,{  TSK_ID_SPIRECV,    TASK_STACK_NORMAL,  TASK_PRIORITY_ABOVE_NORMAL,   "SpiRecv",    SpiRecv_getTaskParam        }
        ,{  TSK_ID_CANAPP, TASK_STACK_NORMAL,  TASK_PRIORITY_NORMAL,   "CANAPP",        CANAPP_getTaskParam     }
        ,{  TSK_ID_CANCYC, TASK_STACK_NORMAL,  TASK_PRIORITY_NORMAL,   "CANCYC",        CANCYC_getTaskParam     }
         ,{  TSK_ID_CANSTACK, TASK_STACK_NORMAL,  TASK_PRIORITY_NORMAL,   "CANSTACK",        CanStackMgr_getTaskParam     }
        ,{  TSK_ID_PCTools, TASK_STACK_NORMAL,  TASK_PRIORITY_NORMAL,   "PCTools",        PCToolsMgr_getTaskParam     }
         ,{  TSK_ID_CANMGR,    TASK_STACK_NORMAL,  TASK_PRIORITY_NORMAL,   "CANManager",    CanMgr_getTaskParam     }
		,{  TSK_ID_SHARETASK, TASK_STACK_NORMAL,  TASK_PRIORITY_NORMAL,   "ShareTaskManager", ShareTask_getTaskParam     }
        ,{  TSK_ID_SENSORAPP ,TASK_STACK_NORMAL,  TASK_PRIORITY_NORMAL,   "SensorApp",	SensorApp_getTaskParam     }
        ,{  TSK_ID_SENSORCYC, TASK_STACK_NORMAL,  TASK_PRIORITY_NORMAL,   "SensorCyc",	SensorCyc_getTaskParam     }
        ,{	TSK_ID_BACKUPBATTERY,TASK_STACK_NORMAL,TASK_PRIORITY_NORMAL,  "BkBattery",	BackupBattery_getTaskParam	}
   };

    for(size_t i = 0; i < sizeof(tTaskConfig) / sizeof(tTaskConfig[0]); ++i)
    {
        OS_createTask(&tTaskConfig[i]);
    }
}
