MotorControlModuleSDFM_TMS3.../Projects/EFC_EcatDriver/include/efc_ecat.h

160 lines
5.1 KiB
C
Raw Normal View History

2024-06-07 11:11:23 +03:00
/*
* efc_ecat.h
*
* Created on: 20 Nov 2023
* Author: titov
*/
#ifndef INCLUDE_EFC_ECAT_H_
#define INCLUDE_EFC_ECAT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
#include "../src/ssc/applInterface.h"
/**
* @defgroup Api API
*
* @{
*/
/**
* @defgroup Common Общий API
*
* @{
*/
/**
* @brief Инициализация EtherCat драйвера
*
* Вызов функции инициализации должен предшествовать всем оставльным функциям драйвера
*
* @return @c true при успешной инициализации; иначе @c false
*/
bool efc_ecat_init(void);
/**
* @brief Денициализация EtherCat драйвера
*
* После вызова драйвера обращения к его функциям запрещено
*
* @return @c void
*/
void efc_ecat_fini(void);
/**
* @brief Обработчик циклических задач EtherCat драйвера
*
* Обработчик должен исполняться в низкоприоритетном потоке
*
* @return void
*/
void efc_ecat_loop(void);
/** @} */ /* Common */
/**
* @defgroup EthercatStateMachine Обработка событий машины состояния API
*
* @{
*/
typedef enum ESMS1 {
PreOp = 1,
SafeOp = 2,
Op = 3
} EcatStateMachineStates;
bool efc_ecat_state_pending( EcatStateMachineStates state );
void efc_ecat_state_approve( EcatStateMachineStates state );
typedef void (*efc_ecat_state_pend_handler)( EcatStateMachineStates state );
void efc_ecat_set_state_pend_handler( efc_ecat_state_pend_handler pf );
/** @} */ /* EthercatStateMachine */
typedef void (*efc_ecat_update_sync0_time)( uint32_t time_in_us );
void efc_ecat_set_sync0_time_update_handler( efc_ecat_update_sync0_time pf );
void efc_ecat_set_device_id( uint16_t device_id );
typedef void (*efc_ecat_application_handler)( void );
void efc_ecat_set_application_handler( efc_ecat_application_handler pf );
/**
* @defgroup ProcessDataInterface Обработка данных реального времени
*
* @{
*/
/** @} */ /* ProcessDataInterface */
/**
* @defgroup ServiceDataInterface Обработка сервисных данных
*
* @{
*/
typedef UINT16 Index;
typedef UINT8 SubIndex;
typedef UINT32 Size;
typedef UINT8 CompliteAccess;
typedef UINT16 Data;
typedef UINT8 ResultType;
enum ResultCode {
Done = 0x00, //!<Успешное завершение.
ToggleBitNotChanged = 0x01, /**< Index of "Toggle bit not changed" */
SdoProtocolTimeout = 0x02, /**< Index of "SDO timeout" */
CommandSpecifierUnknown = 0x03, /**< Index of "Command specifier unknown" */
OutOfMemory = 0x04, /**< Index of "Out of memory" */
UnsupportedAccess = 0x05, /**< Index of "Unsupported Access" */
WriteOnlyEntry = 0x06, /**< Index of "Write only entry" */
ReadOnlyEntry = 0x07, /**< Index of "Read only entry" */
ObjectNotExisting = 0x08, /**< Index of "Object not existing" */
ObjectCantBePdoMapped = 0x09, /**< Index of "Object can not be mapped to PDO" */
MappedObjectsExceedPdo = 0x0A, /**< Index of "Mapped Object exceeds PDO" */
ParamIsIncompatible = 0x0B, /**< Index of "Parameter is incompatible" */
InternalDeviceIncompatibility = 0x0C, /**< Index of "Device incompatibility" */
HardwareError = 0x0D, /**< Index of "Hardware error" */
ParamLengthError = 0x0E, /**< Index of "Parameter length error" */
ParamLengthTooLong = 0x0F, /**< Index of "Parameter is too long" */
ParamLengthTooShort = 0x10, /**< Index of "Parameter is too short" */
SubindexNotExisting = 0x11, /**< Index of "Subindex (Entry) not exists" */
ValueExceeded = 0x12, /**< Index of "Value exceeds" */
ValueTooGreat = 0x13, /**< Index of "Value is too great" */
ValueTooSmall = 0x14, /**< Index of "Value is too small" */
ModuleIdListNotMatch = 0x15, /**< Index of "Unequal Module Id list" */
MaxValueIsLessThanMinValue = 0x16, /**< Index of "Value is less than minimum value" */
GeneralError = 0x17, /**< Index of "General error" */
DataCannotBeReadWrite = 0x18, /**< Index of "Data can not be read or written" */
DataCannotBeAccessedWithLocalControl = 0x19, /**< Index of "Data can not be accessed because of local control" */
DataCannotBeReadWriteInCurrentState = 0x1A, /**< Index of "Data can not be read or written in the current state" */
NoObjectDictionaryIsPresent = 0x1B, /**< Index of "Object is not in the object dictionary" */
EntryCantBeWrittenSi0Not0 = 0x1C, /**< Index of "Entry can not be written because Subindex0 is not 0" */
CompleteAccessNotSupported = 0x1D, /**< The object can not be accessed via complete access */
Working = 0xFF /**< Index of application is handling the SDO request */
};
typedef ResultType (* InterfaceRead)( Index index, SubIndex subindex, Size size, Data * data, CompliteAccess complete_access );
typedef ResultType (* InterfaceWrite)( Index index, SubIndex subindex, Size size, Data * data, CompliteAccess complete_access );
/** @} */ /* Api */
#ifdef __cplusplus
}
#endif
#endif /* INCLUDE_EFC_ECAT_H_ */