//----------------------------------------------------------------------------------
// <copyright file="lrstat.h" company="LiquidRobotics">
//	Copyright (c) Liquid Robotics Corporation.  All rights reserved.
// </copyright>
//
// <summary>
// 	Header file for LRSTAT.C, an alternate implementation of the statistics task
// </summary>
//
// <owner>Mike Cookson</owner>
//---------------------------------------------------------------------------------

#ifndef __LRSTAT_H__
# define __LRSTAT_H__

// given a TCB (task control block) pointer, returns a reference to the LRStatTaskData_t
// with corresponding additional data
#define TCBTOLRSTATDATA(ptcb) lrstatTaskData[(ptcb)-OSTCBTbl]

#define LRSTAT_DELAY (OS_TICKS_PER_SEC / 10)	// length of each pass thru the statistics task
#define LRSTAT_CALCULATION_PERIOD (10)			// number of passes thru the statistics task before CPU usage is calculated

// this structure contains extended data for this version of the statistics task; there
// needs to be one entry per task
typedef struct
{
	uint16_t accumTime;				// time being attributed in the current period
	uint16_t accumTimeSave;			// time attributed in the last interval
} LRStatTaskData_t;

extern uint16_t lrstatIdleCtr;					// time spent in Idle task during last time period
extern uint16_t lrstatRunCtr;					// total time accumulated during the last time period
extern uint16_t lrstatRunningAccumulated;		// time accumulating during this time period

// additional counters per task used for accumulated time during the last time
// period and accumulating in the current time period
extern LRStatTaskData_t lrstatTaskData[OS_MAX_TASKS + OS_N_SYS_TASKS];

// Function Prototypes

void LRStat_AttributeTime(OS_TCB* ptcb);
uint16_t LRState_CalculateAccumulatedTime(void);

#endif
