/*
* co_emcy.h - contains defines for emcy services
*
* Copyright (c) 2012-2024 emotas embedded communication GmbH
*
*-------------------------------------------------------------------
* $Id: co_emcy.h 53986 2024-05-29 09:44:25Z boe $
*-------------------------------------------------------------------
*
*
*
*/

/**
* \brief defines for emcy services
*
* \file co_emcy.h - contains defines for emcy services
*
*/

#ifndef CO_EMCY_H
#define CO_EMCY_H 1

#include <co_datatype.h>


/* constant */

/**
* define for Emergency Error Code wrong PDO length
*/
#define CO_EMCY_ERRCODE_PDO_LEN		0x8210u

/**
* define for Emergency Error Code CAN overrun
*/
#define CO_EMCY_ERRCODE_CANOVERRUN_ERROR	0x8110u

/**
* define for Emergency Error Code CAN passive
*/
#define CO_EMCY_ERRCODE_CANPASSIVE_ERROR	0x8120u

/**
* define for Emergency Error Code Heartbeat Error
*/
#define CO_EMCY_ERRCODE_COMM_ERROR	0x8130u

/**
* define for Emergency Error Code USDO source client or source server number collision
*/
#define CO_EMCY_ERRCODE_USDO_SRC_COLLISION	0x8160u

/* datatypes */


/** \brief function pointer to emergency function
 *
 * \param errCode - emergency error code
 * \param addErrorCode - pointer to 5 bytes error code
 *
 * \return RET_T
 * \retval RET_OK
 *	send emergency
 * \retval RET_xx
 *	don't send emergency
 */
typedef RET_T (* CO_EVENT_EMCY_T)(CO_LINE_TYPE, UNSIGNED16 errCode, UNSIGNED8 *addErrorCode);



/** \brief function pointer to emergency consumer function
 *
 * \param node - node id of received emergency
 * \param errCode - emergency error code
 * \param errorRegister - emergency error register
 * \param addErrorCode - pointer to 5 bytes error code
 *
 */
typedef void (* CO_EVENT_EMCY_CONSUMER_T)(CO_LINE_TYPE, UNSIGNED8 node, UNSIGNED16 errCode, UNSIGNED8 errorRegister, UNSIGNED8 const *addErrorCode);
typedef CO_EVENT_EMCY_CONSUMER_T CO_EVENT_EMCY_CONS_T;


/* function prototypes */
EXTERN_DECL RET_T coEmcyProducerInit(CO_LINE_DECL);
EXTERN_DECL RET_T coEmcyConsumerInit(CO_LINE_DECL, UNSIGNED8 emcyCnt);
EXTERN_DECL RET_T coEmcyWriteReq(CO_LINE_DECL, UNSIGNED16 emcyErrCode,
					CO_CONST UNSIGNED8 *pData);
CO_CAN_TIMESTAMP_T coEmcyGetTimestamp(CO_LINE_DECL);

EXTERN_DECL RET_T coEventRegister_EMCY(CO_EVENT_EMCY_T pFunction);
EXTERN_DECL RET_T coEventRegister_EMCY_CONSUMER(
					CO_EVENT_EMCY_CONSUMER_T pFunction);

#endif /* CO_EMCY_H */
