/*
* ico_cobhandler.h - contains internal defines for cob handling
*
* Copyright (c) 2012-2023 emotas embedded communication GmbH
*
*-------------------------------------------------------------------
* $Id: ico_cobhandler.h 49602 2023-09-26 13:00:59Z boe $
*
*-------------------------------------------------------------------
*
*
*/

/**
* \file
* \brief dataty type header
*/

#ifndef ICO_COB_HANDLER_H
#define ICO_COB_HANDLER_H 1

#include <co_cob.h>

/* constant definitions */
#define CO_INVALID_COB_REF 0xffffu

/* datatypes */

typedef enum {
	CO_SERVICE_CANOPEN_START = 1,
	/* start of the real canopen services */
	CO_SERVICE_SDO_SERVER, CO_SERVICE_SDO_CLIENT,
	CO_SERVICE_NMT, CO_SERVICE_ERRCTRL,
	CO_SERVICE_PDO_TRANSMIT, CO_SERVICE_PDO_RECEIVE,
	CO_SERVICE_SYNC_TRANSMIT, CO_SERVICE_SYNC_RECEIVE,
	CO_SERVICE_EMCY_TRANSMIT, CO_SERVICE_EMCY_RECEIVE,
	CO_SERVICE_TIME_TRANSMIT, CO_SERVICE_TIME_RECEIVE,
	CO_SERVICE_LSS_M_TRANSMIT, CO_SERVICE_LSS_M_RECEIVE,
	CO_SERVICE_LSS_S_TRANSMIT, CO_SERVICE_LSS_S_RECEIVE,
	CO_SERVICE_GUARDING,
	CO_SERVICE_FLYMA,
	CO_SERVICE_SRD_TRANSMIT,
	CO_SERVICE_SLEEP,
	CO_SERVICE_GFC_TRANSMIT, CO_SERVICE_GFC_RECEIVE,
	CO_SERVICE_SRDO_TRANSMIT, CO_SERVICE_SRDO_RECEIVE,
	CO_SERVICE_USDO_SERVER, CO_SERVICE_USDO_CLIENT,
	CO_SERVICE_ESDO_SERVER, CO_SERVICE_ESDO_CLIENT,
	CO_SERVICE_IDNEGO_RECEIVE, CO_SERVICE_IDNEGO_TRANSMIT,
	CO_SERVICE_CANOPEN_END,
	/* end of the real canopen services */

	/* J1939 */
	CO_SERVICE_J1939_START,
	CO_SERVICE_J1939_TRANSMIT, CO_SERVICE_J1939_RECEIVE,
	CO_SERVICE_J1939_END,

	/* RAW CAN */
	CO_SERVICE_RAWCAN_START,
	CO_SERVICE_RAWCAN_TRANSMIT, CO_SERVICE_RAWCAN_RECEIVE,
	CO_SERVICE_RAWCAN_END,

	/* ISO-TP */
	CO_SERVICE_ISOTP_START,
	CO_SERVICE_ISOTP_CLIENT, CO_SERVICE_ISOTP_SERVER,
	CO_SERVICE_ISOTP_END,

	/* other services and protocols */
	CO_SERVICE_USER_START,
	CO_SERVICE_USER,
	CO_SERVICE_CAN_DEBUG,
	CO_SERVICE_USER_END,

	/* last entry */
	CO_SERVICE_LAST
} CO_SERVICE_T;

typedef UNSIGNED16	COB_REFERENZ_T;

typedef enum {
	CO_COB_TYPE_TRANSMIT, CO_COB_TYPE_RECEIVE
}	CO_COB_TYPE_T;


typedef enum {
	CO_COB_RTR_NONE, CO_COB_RTR
} CO_COB_RTR_T;


typedef struct {
	COB_REFERENZ_T	cobNr;			/* cob number */
	CO_COB_TYPE_T	type;			/* cob type */
	CO_CAN_COB_T	canCob;			/* can cob data */
	CO_SERVICE_T	service;		/* service */
	UNSIGNED16		serviceNr;		/* service number */
#ifdef CO_INHIBIT_SUPPORTED
	UNSIGNED16		inhibit;		/* inhibit time */
	CO_TIMER_T		inhibitTimer;	/* inhibit timer */
#endif /* CO_INHIBIT_SUPPORTED */
	UNSIGNED8		len;			/* msg len */
} CO_COB_T;


/* function prototypes */

COB_REFERENZ_T	icoCobCreate(CO_LINE_DECL, CO_COB_TYPE_T cobType,
					CO_SERVICE_T service, UNSIGNED16 serviceNr);
RET_T			icoCobSet(CO_LINE_DECL, COB_REFERENZ_T cobRef, UNSIGNED32 cobId,
					CO_COB_RTR_T rtr, UNSIGNED8	len);
UNSIGNED32		icoCobGet(CO_LINE_DECL, COB_REFERENZ_T cobRef);
RET_T			icoCobEnable(CO_LINE_DECL, COB_REFERENZ_T cobRef);
RET_T			icoCobDisable(CO_LINE_DECL, COB_REFERENZ_T cobRef);
CO_COB_T		*icoCobCheck(CO_LINE_DECL, const CO_CAN_REC_MSG_T *pRecMsg);
CO_COB_T		*icoCobGetPointer(CO_LINE_DECL, COB_REFERENZ_T cobRef);
RET_T			icoCobChangeType(CO_LINE_DECL, COB_REFERENZ_T	cobRef,
					CO_COB_TYPE_T cobType);
RET_T			icoCobChangeService(CO_LINE_DECL, COB_REFERENZ_T cobRef,
					CO_SERVICE_T service, UNSIGNED16 serviceNr);
RET_T			icoCobSetInhibit(CO_LINE_DECL, COB_REFERENZ_T	cobRef, UNSIGNED16 inhibit);
RET_T 			icoCobSetClassical(CO_LINE_DECL, COB_REFERENZ_T cobRef, BOOL_T classical);
RET_T			icoCobSetIgnore(CO_LINE_DECL, COB_REFERENZ_T	cobRef, UNSIGNED32 mask);
RET_T			icoCobSetLen(CO_LINE_DECL, COB_REFERENZ_T	cobRef,	UNSIGNED8 len);
void			icoCobDisableAll(CO_LINE_DECL, CO_SERVICE_T start, CO_SERVICE_T end);
BOOL_T			icoCheckRestrictedCobs(UNSIGNED32 canId,
					UNSIGNED32	exceptFirst, UNSIGNED32	exceptLast);

void			icoCobHandlerVarInit(const UNSIGNED16 *cobLineOffs);
#endif /* ICO_COB_HANDLER_H */

