#include <asf.h>
#include <spi.h>

#ifndef _CONFIGFILE_H_
#define _CONFIGFILE_H_
//******************************************************************************
// Defines Board number
//******************************************************************************
#define CONFIG_HEADER_BOARD_1	0//(1)						/**! \brief Value for 1. board 0000 0001*/
#define CONFIG_HEADER_BOARD_2	1//(1 << 1)				/**! \brief Value for 2. board 0000 0010*/
#define CONFIG_HEADER_BOARD_3	2//(1 << 2)				/**! \brief Value for 3. board 0000 0100*/
#define CONFIG_HEADER_BOARD_4	3//(1 << 3)				/**! \brief Value for 4. board 0000 1000*/
#define CONFIG_HEADER_BOARD_5	4//(1 << 4)				/**! \brief Value for 5. board 0001 0000*/
#define CONFIG_HEADER_BOARD_6	5//(1 << 5)				/**! \brief Value for 6. board 0010 0000*/
//******************************************************************************
// Defines Sensor number
//******************************************************************************
#define CONFIG_HEADER_SENSOR_1	(1 << 0)				/**! \brief Value for 1. sensor 0000 0001*/
#define CONFIG_HEADER_SENSOR_2	(1 << 1)				/**! \brief Value for 2. sensor 0000 0010*/
#define CONFIG_HEADER_SENSOR_3	(1 << 2)				/**! \brief Value for 3. sensor 0000 0100*/
#define CONFIG_HEADER_SENSOR_4	(1 << 3)				/**! \brief Value for 4. sensor 0000 1000*/
#define CONFIG_HEADER_SENSOR_5	(1 << 4)				/**! \brief Value for 5. sensor 0001 0000*/
#define CONFIG_HEADER_SENSOR_6	(1 << 5)				/**! \brief Value for 6. sensor 0010 0000*/
#define CONFIG_HEADER_SENSOR_7	(1 << 6)				/**! \brief Value for 7. sensor 0100 0000*/
#define CONFIG_HEADER_SENSOR_8	(1 << 7)				/**! \brief Value for 1. sensor 0000 0001*/
#define CONFIG_HEADER_SENSOR_9	(1 << 8)				/**! \brief Value for 2. sensor 0000 0010*/
#define CONFIG_HEADER_SENSOR_10	(1 << 9)				/**! \brief Value for 3. sensor 0000 0100*/
#define CONFIG_HEADER_SENSOR_11	(1 << 10)				/**! \brief Value for 4. sensor 0000 1000*/
#define CONFIG_HEADER_SENSOR_12	(1 << 11)				/**! \brief Value for 5. sensor 0001 0000*/
#define CONFIG_HEADER_SENSOR_13	(1 << 12)				/**! \brief Value for 6. sensor 0010 0000*/
#define CONFIG_HEADER_SENSOR_14	(1 << 13)				/**! \brief Value for 7. sensor 0100 0000*/
#define CONFIG_HEADER_SENSOR_15	(1 << 14)				/**! \brief Value for 7. sensor 0100 0000*/
//******************************************************************************
// Defines Axis(Orientation) of iSTP
//******************************************************************************
#define CONFIG_HEADER_AXIS_X	0						/**! \brief Value for orientation x axis 0000 0001*/
#define CONFIG_HEADER_AXIS_Y	1						/**! \brief Value for orientation y axis 0000 0010*/
#define CONFIG_HEADER_AXIS_Z	2						/**! \brief Value for orientation z axis 0000 0100*/

#define DEFAULT_AXIS_LENGTH		7
#define DEFAULT_TEMP_LENGTH		5

#define EEPROM_ERROR			0xFFFF					/**! \brief Value for error from EEPROM*/
//******************************************************************************
// Typedefs
//******************************************************************************
typedef struct SensorMemory
{
	int8_t		Active;	
	uint16_t	Axis;
	uint16_t	Board;
	uint32_t	Sensor;
	uint32_t	Driver;
	uint64_t	ConfigNumber;
	uint32_t	LengthData;
}SensorMemory_t;

sensor_axis_e GetAxis(int aAxis);
sensor_board_e GetBoard(int aBoard);
void SendDataFromEEPROMs(SensorMemory_t *p_sens);
uint8_t ReadEEPROM(SensorMemory_t * ap_Sens,uint32_t aID, sensor_axis_e aAxis, sensor_board_e aBoard, uint16_t *ap_Address, int *ap_poprve);
void SendConfigMSG(uint32_t aType, uint8_t *ap_Data, int aEndIndex, uint32_t aID, int aStartIndex);
uint16_t ConvertBoard(sensor_board_e bo);
uint16_t ConvertAxis(sensor_axis_e ax);
void toggleLeds (Pio* port, uint32_t pin);
void WriteNewParam(sensor_axis_e aAxis, sensor_board_e aBoard, uint32_t aNewConf);
#endif