/*
 * comm.h
 *
 *  Created on: 01-08-2013
 *      Author: Krzysztof Jakubczyk
 */

#ifndef COMM_H_
#define COMM_H_

/*
#include <ti/ipc/MessageQ.h>
#include <ti/sysbios/hal/Timer.h>
*/
#include "tdefs.h"

#define DSP_CMD_INIT_COMM				0x01
#define DSP_CMD_GET_ANALOG_BUF			0x02
#define DSP_CMD_GET_IO_BUF				0x03
#define DSP_CMD_GET_SHARED_BUF			0x04
#define DSP_CMD_UPDATE_CFG				0x05
#define DSP_CMD_GET_REG_INF				0x06
#define DSP_CMD_ACK_REG					0x07
#define DSP_CMD_TIME_SYNC				0x08
#define DSP_CMD_LOGMAN_STOP				0x09
#define DSP_CMD_LOGMAN_RESET			0x0A
#define DSP_CMD_LOGMAN_PUSHFUN			0x0B
#define DSP_CMD_LOGMAN_START			0x0C
#define DSP_CMD_LOGMAN_STATS			0x0D
#define DSP_CMD_GET_REG_MULTIPLIERS		0x0E
#define DSP_CMD_GET_REG_MULTIPLIERS_DDR	0x0F
#define DSP_CMD_GET_EV_BUF				0x10
#define DSP_CMD_GET_MEASURANDS			0x11
#define DSP_CMD_GET_LEDS_VIRT_IN		0x12
#define DSP_CMD_SET_VIRT_IN				0x13
#define DSP_CMD_GET_NET_BUF				0x14
#define DSP_CMD_GET_GI					0x15
#define DSP_CMD_GET_FWVER				0x16
#define DSP_CMD_FORCE_OUT_STATES		0x17
#define DSP_CMD_FORCE_BIN_STATES		0x18
#define DSP_CMD_GET_DDR_REG_INF			0x19
#define DSP_CMD_ACK_DDR_REG				0x1A
#define DSP_CMD_FORCE_AN_STATES			0x1B
#define DSP_CMD_GET_AN_STATES			0x1C
#define DSP_CMD_SET_EVENT_FILTER		0x1D
#define DSP_CMD_CFG_STATE				0x1E
#define DSP_CMD_CLEAR_RELAYS			0x1F
#define DSP_CMD_SET_VIRT_IN2			0x20
#define DSP_CMD_ETH_ON					0x21
#define DSP_CMD_ETH_OFF					0x22
#define DSP_CMD_GET_PROFILE_BUF			0x23
#define DSP_CMD_START_PROFILER			0x24
#define DSP_CMD_STOP_PROFILER			0x25
#define DSP_CMD_ETH_OFF_ACK				0x26
#define DSP_CMD_GET_LOGIC_EL_PARAMS		0x27
#define DSP_CMD_DEBUGLOG				0xFE

#define SET_CFG_CHANGE					0x01
#define SET_CFG_OK						0x02
#define SET_CFG_ERR						0x03

#define CMD_ACK					0xD5
#define CMD_ERR					0xE0

struct msg_data
{
	MessageQ_MsgHeader hdr;
	UInt32 cmd;
	UInt32 p1;
	UInt32 p2;
	UInt32 p3;
};

struct notify_data
{
    UInt16          remoteProcId;
    UInt16          lineId;
    UInt32          eventId;
};

struct dfr_an_comtrade_params
{
	double multiplier;
	double primary;
	double secondary;
	long unit;
}__attribute__((__packed__));

extern struct notify_data notify;
extern struct broadcast_info bcast_nfo;
extern volatile struct ping_info ping_nfo;
extern volatile u8 saved_bank;

#define ZPRAE_MLB12_TYPE	43

struct broadcast_info {
	u8 id[3];
	u8 mlb_type;
	u8 dev_name[21];
	u8 dev_type;
	u16 dev_num;
	u8 mac[6];
}__attribute__((__packed__));

struct ping_info {
	u8 adr;
	u8 seq;
	u16 tstamp;
	u32 pwmval;
}__attribute__((__packed__));

struct eth_data
{
	u32 ip;
	u32 netmask;
	u32 gateway;
	u8 hwaddr[6];
	u32 flags;
	u8 name[21];
	u16 dev_no;
	u32 unicast_ip;
}__attribute__((__packed__));

// eth flags
#define ETH_NOT_INITIALIZED		0x00
#define ETH_INITIALIZED			0x01
#define ETH_ACTIVE				0x02
#define ETH_GOT_SETTINGS		0x04
#define ETH_UDP_INITIALIZED		0x08
#define ETH_OFF_ACK				0x10

extern struct eth_data eth;

#define NOTIFY_INIT			0x00000001
#define NOTIFY_NEW_EVENTS	0x00000002
#define NOTIFY_NEW_DFR_REG	0x00000003
#define NOTIFY_SEL_BANK0	0x00000004
#define NOTIFY_SEL_BANK1	0x00000005
#define NOTIFY_SEL_BANK2	0x00000006
#define NOTIFY_SEL_BANK3	0x00000007
#define NOTIFY_SEL_BANK4	0x00000008
#define NOTIFY_NEW_DDR_REG	0x00000009
#define NOTIFY_ETH_ON		0x0000000a
#define NOTIFY_ETH_OFF		0x0000000b
#define NOTIFY_SEL_BANK5	0x0000000c

extern Timer_Handle tick_timer_handle;
extern u32 tick_timer_period;

extern Void commFxn(UArg a0, UArg a1);

#endif /* COMM_H_ */
