/**************************************************************************************************
	Filename:       OSAL_Common.c
  
	Description:    This file contains all the settings and other functions
                  that the user should set and change.
				  
	Copyright 2013, Unizen Technologies Pvt Ltd.
**************************************************************************************************/

/*********************************************************************
 * INCLUDES
 */
#include "ZComDef.h"
#include "hal_drivers.h"
#include "OSAL.h"
#include "OSAL_Tasks.h"
#if defined ( MT_TASK )
  #include "MT.h"
  #include "MT_TASK.h"
#endif
#include "nwk.h"
#include "APS.h"
#include "ZDApp.h"
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
  #include "ZDNwkMgr.h"
#endif
#if defined ( ZIGBEE_FRAGMENTATION )
  #include "aps_frag.h"
#endif

#include "zcl_HumiSensor.h"
#include "zcl_TempSensor.h"
#include "zcl_Common_data.h"
#include "Sensor.h"

/*********************************************************************
 * GLOBAL VARIABLES
 */
// The order in this table must be identical to the task initialization calls below in osalInitTask.
const pTaskEventHandlerFn tasksArr[] = {
  macEventLoop,
  nwk_event_loop,
  Hal_ProcessEvent,
#if defined( MT_TASK )
  MT_ProcessEvent,
#endif
  APS_event_loop,
#if defined ( ZIGBEE_FRAGMENTATION )
  APSF_ProcessEvent,
#endif
  ZDApp_event_loop,
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
  ZDNwkMgr_event_loop,
#endif
  zcl_event_loop,
zclSensor_event_loop,
    zclHumiSensor_event_loop,
  zclTempSensor_event_loop
};

const uint8 tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[INIT_VAL] );
uint16 *tasksEvents;

/*********************************************************************
 * FUNCTIONS
 *********************************************************************/

/*********************************************************************
 * @fn      osalInitTasks
 *
 * @brief   This function invokes the initialization function for each task.
 *
 * @param   void
 *
 * @return  none
 */
void osalInitTasks( void )
{
	uint8 taskID = INIT_VAL;

	tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
	osal_memset( tasksEvents, INIT_VAL, (sizeof( uint16 ) * tasksCnt));
	macTaskInit( taskID++ );
	nwk_init( taskID++ );
	Hal_Init( taskID++ );
	#if defined( MT_TASK )
	MT_TaskInit( taskID++ );
	#endif
	APS_Init( taskID++ );
	#if defined ( ZIGBEE_FRAGMENTATION )
	APSF_Init( taskID++ );
	#endif
	ZDApp_Init( taskID++ );
	#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
	ZDNwkMgr_Init( taskID++ );
	#endif
	zcl_Init( taskID++ );
	zcl_SensorInit( taskID++ );
	zclHumiSensor_Init(taskID++);
	zclTempSensor_Init(taskID);
}

/*********************************************************************
*********************************************************************/
