motorcontroldemo_035/Vinclude/CANOpen_drv.h
2019-07-29 08:17:46 +03:00

171 lines
6.9 KiB
C

/*!
Copyright 2017 ÀÎ "ÍÈÈÝÒ" è ÎÎÎ "ÍÏÔ ÂÅÊÒÎÐ"
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\file CANOpen_drv.h
\brief Äðàéâåð CANOpen
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
\version v 3.19 2019_03_06
\defgroup CANOpen_drv Äðàéâåð CANOpen
@{
*/
#ifndef CAN_OPEN_DRV_H
#define CAN_OPEN_DRV_H
#ifdef __cplusplus
extern "C" {
#endif
//********************************************************************************************
//
//!Âêëþ÷àòåëü CAN 1
#define CAN_1_ENABLE
//********************************************************************************************
//!Âêëþ÷àòåëü CAN 2
//#define CAN_2_ENABLE
//********************************************************************************************
/*
* Ôóíêöèè èíèöèàëèçàöèè äðàéâåðà äëÿ CAN1 è CAN2
* Äðàéâåð èñïîëüçóåò ðàáîòó ñ ïîëüçîâàòåëüñêîé ïàìÿòüþ (èíòåðôåéñ ñ êîòîðîé îïðåäåëÿåòñÿ ôóíêöèÿìè co_UserMemoryRead è co_UserMemoryWrite -
* ñì. ôàéë CANOpenUDfuncs.c), ïîýòîìó ê ìîìåíòó íà÷àëà ðàáîòû ñ äðàéâåðîì ïîëüçîâàòåëü äîëæåí ÃÀÐÀÍÒÈÐÎÂÀÒÜ,
* ÷òî äðàéâåð ïîëüçîâàòåëüñêîé ïàìÿòè ïðîèíèöèàëèçèðîâàí.
*/
extern Uint16 co1_Init(TCo_OdVars* ppc);// ñëó÷àå åñëè èíèöèàëèçàöèß íå óäàëàñü ôóíêöèß âîçâðàùàåò 0, èíà÷å 1.
extern Uint16 co2_Init(TCo_OdVars* ppc);// ñëó÷àå åñëè èíèöèàëèçàöèß íå óäàëàñü ôóíêöèß âîçâðàùàþò 0, èíà÷å 1.
//Ôóíêöèß ïåðåèíèöèàëèçàöèè CAN áåç âîññòàíîâëåíèß ïàðàìåòðîâ èç ïîëüçîâàòåëüñêîé ïàìÿòè (ìîæåò áûòü èñïîëüçîâàíà ëèøü äëß ÏÎÂÒÎÐÍÎÉ èíèöèàëèçàöèè)
extern Uint16 co_ReInit(TCo_OdVars* ppc);// ñëó÷àå åñëè èíèöèàëèçàöèß íå óäàëàñü ôóíêöèß âîçâðàùàþò 0, èíà÷å 1.
extern void propReset (void);
//Ïðîòîòèïû ôóíêöèé
extern void co_UserMemoryRead (const T_UserMemoryContext *p);
extern void co_UserMemoryWrite (const T_UserMemoryContext *p);
#ifdef CAN_1_ENABLE
extern void co_CAN1GpioInit();
extern void co_CAN1INTEnable();
extern void co_CAN1INTDisable();
#endif
#ifdef CAN_2_ENABLE
extern void co_CAN2GpioInit();
extern void co_CAN2INTDisable();
extern void co_CAN2INTEnable();
#endif
//!ôóíêöèÿ äðàéâåðà CANOpen âûçûâàåìàÿ â ïðåðûâàíèè 1 ìñ òàéìåðà, òàêòèðóþùåãî ðàáîòó äðàéâåðà
extern void co_1ms_calc(TCo_OdVars*);
//!ôóíêöèÿ îáðàáîò÷èêà äðàéâåðà CANOpen â ôîíîâîé ïðîãðàììå
extern void co_background_calc(TCo_OdVars*);
//!Ôóíêöèÿ âîññòàíîâëåíèÿ çíà÷åíèé ïàðàìåòðîâ ñëîâàðÿ îáúåêòîâ ïî óìîë÷àíèþ
/*!
Ðåçóëüòàòîì ðàáîòû ôóíêöèè ÿâëÿåòñÿ âîññòàíîâëåíèå ïàðàìåòðîâ óêàçàííîãî
òèïà è äèàïàçîíà
type - 1 rw-ïàðàìåòðû
2 rwp-ïàðàìåòðû
3 rwps-ïàðàìåòðû
range - 1 âîññòàíîâëåíèå èíäåêñîâ 1000h-1FFFh
2,3,4,5
Ôóíêöèÿ ïî âðåìåíè âûïîëíåíèÿ îòíîñèòñÿ ê äëèíûì (âûçûâàòü ñëåäóåò â ôîíå) */
extern void co_ODexpositor_instaurationDefault(TCo_OdVars* ppc, Uint16 type, Uint16 range);
//!Ôóíêöèÿ ñîõðàíåíèÿ çíà÷åíèé ïàðàìåòðîâ ñëîâàðÿ îáúåêòîâ â ÝíÎÇÓ
/*!Ðåçóëüòàòîì ðàáîòû ôóíêöèè ÿâëÿåòñÿ ñîõðàíåíèå ïàðàìåòðîâ óêàçàííîãî
òèïà è äèàïàçîíà
type - 1 rw-ïàðàìåòðû
2 rwp-ïàðàìåòðû
3 rwps-ïàðàìåòðû
range - 1 âîññòàíîâëåíèå èíäåêñîâ 1000h-1FFFh
2,3,4,5
Ôóíêöèÿ ïî âðåìåíè âûïîëíåíèÿ îòíîñèòñÿ ê äëèíûì (âûçûâàòü ñëåäóåò â ôîíå).*/
extern void co_ODexpositor_paramConservation(TCo_OdVars* ppc, Uint16 type, Uint16 range);
//!Ôóíêöèÿ âîññòàíîâëåíèÿ çíà÷åíèé ïàðàìåòðîâ ñëîâàðÿ îáúåêòîâ èç ÝíÎÇÓ
/*! Ðåçóëüòàòîì ðàáîòû ôóíêöèè ÿâëÿåòñÿ âîññòàíîâëåíèå ïàðàìåòðîâ óêàçàííîãî
òèïà è äèàïàçîíà
type - 1 rw-ïàðàìåòðû
2 rwp-ïàðàìåòðû
3 rwps-ïàðàìåòðû
range - 1 âîññòàíîâëåíèå èíäåêñîâ 1000h-1FFFh
2,3,4,5
Âíèìàíèå!!!Âîññòàíîâëåíèå ïàðàìåòðîâ 2-ãî è 3-ãî òèïîâ âîçìîæíî åñëè
ïåðåìåííàÿ co_protectBit = 0. Åñëè co_protectBit = 1 , òî ôóíêöèÿ íè÷åãî
íå "äåëàåò".
Åñëè âîññòàíîâëåíèå ïàðàìåòðîâ çàäàííîãî òèïà è äèàïàçîíà ïðîèçîøëî
íåóäà÷íî(êîíòðîëüíàÿ ñóììà íå ñîøëàñü), òî âîññòàíîâëåíèå çàäàííîãî
òèïà è äèàïàçîíà ïîâòîðÿåòñÿ.Åñëè ïîñëå òðåõ ïîïûòîê âîññòàíîâëåíèå
íå çàâåðøèëîñü óñïåõîì, òî âûïîëíÿåòñÿ âîññòàíîâëåíèå ïàðàìåòðîâ çàäàííîãî
òèïà è äèàïàçîíà ïî óìîë÷àíèþ.
Ôóíêöèÿ ïî âðåìåíè âûïîëíåíèÿ îòíîñèòñÿ ê äëèíûì (âûçûâàòü ñëåäóåò â ôîíå).*/
extern void co_ODexpositor_paramInstauration(TCo_OdVars* ppc, Uint16 type, Uint16 range);
// ôóíêöèè ñåðâèñà NMT
// äðàéâåð ìîæåò âûñòóïàòü NMT ìàñòåðîì, ëèáî áûòü NMT ñëýéâîì
//! ôóíêöèÿ äëÿ îòïðàâêè NMT (íóæíà òîëüêî äëÿ NMT ìàñòåðà)
void co_sendNMT(TCo_OdVars* ppc, Uint16 nmtCommand, Uint16 nmtNODE_ID);
//!ôóíêöèÿ ÏÎËÜÇÎÂÀÒÅËÿ äëÿ îòïðàâêè SDO çàïðîñîâ íà ÷òåíèå ïàðàìåòðîâ ñåðâåðà
extern void co_SDOrequestRead(TCo_OdVars*);
//!ôóíêöèÿ ÏÎËÜÇÎÂÀÒÅËÿ äëÿ îòïðàâêè SDO çàïðîñîâ íà çàïèñü ïàðàìåòðîâ ñåðâåðà
extern void co_SDOrequestWrite(TCo_OdVars*);
extern void Z_co_receiveSDOrequest(TCo_OdVars*, TZCanMsg*);
extern void co_CANToExtInterface_Send(TZCanMsg* MSG, Uint16 tag_CANnum);
/*!Ôóíêöèß âîçâðàùàåò àäðåñ ïåðåìåííîé ïî ïåðåäàííûì èíäåêñó
è ïîäûíäåêñó. Åñëè "ñâßçàííàß" ïåðåìåííàß 32-õ ðàçðßäíàß, òî
âîçâðàùàåòñß óêàçàòåëü íà ñòàðøóþ ÷àñòü.
ÂÍÈÌÀÍÈÅ!!!Åñëè çàïðîøåííîãî èíäåêñà è ïîäèíäåêñà íå ñóùåñòâóåò, òî
ôóíêöèß âîçâðàùàåò 0 (ýòî íóæíî îáßçàòåëüíî îòñëåæèâàòü). */
extern Uint16 * co_getAddr(TCo_OdVars* ppc, Uint32 ind_subind);
// Ôóíêöèÿ ïîëó÷åíèÿ èíôîðìàöèè îá îáúåêòå ñ çàäàííûì àäðåñîì.
// Âîçâðàùàåò 0, åñëè îáúåêò íå íàéäåí.
extern Uint16 co_getObjectInfo(
TCo_OdVars* ppc, // óêàçàòåëü íà ñòðóêòóðó èñïîëüçóåìîãî ìîäóëÿ CANopen
Uint32 ind_subind, // áèòû 16-31 - èíäåêñ, áèòû 0-7 - ïîäûíäåêñ îáúåêòà
TObjectInfo* pObjectInfo // óêàçàòåëü íà ñòðóêòóðó, êóäà áóäåò ïîìåùåíà èíôîðìàöèÿ îá îáúåêòå
);
extern void co_RPDO1_Callback(Uint16 nodeID, Uint16 tag_CANnum);
extern void co_RPDO2_Callback(Uint16 nodeID, Uint16 tag_CANnum);
extern void co_RPDO3_Callback(Uint16 nodeID, Uint16 tag_CANnum);
extern void co_RPDO4_Callback(Uint16 nodeID, Uint16 tag_CANnum);
extern void co_RPDO5_Callback(Uint16 nodeID, Uint16 tag_CANnum);
extern void co_RPDO6_Callback(Uint16 nodeID, Uint16 tag_CANnum);
extern void co_RPDO7_Callback(Uint16 nodeID, Uint16 tag_CANnum);
extern void co_RPDO8_Callback(Uint16 nodeID, Uint16 tag_CANnum);
//ôóíêöèè ÏÎËÜÇÎÂÀÒÅËÿ, èíèöèèðóþùèå ïåðåäà÷ó, èëè ïðèåì áëîêà äàííûõ ïîñðåäñòâîì
//ñåðâèñà áëî÷íîé ïåðåäà÷è
extern void CANBlockTransferInitTX(TCo_OdVars* ppc, Uint16 size, Uint16* source_ptr);
extern void CANBlockTransferInitRX(TCo_OdVars* ppc, Uint16 size, Uint16* dest_ptr);
#ifdef __cplusplus
}
#endif
#endif
/*@}*/