motorcontroldemo_028/Vinclude/V_DIO.h

120 lines
3.3 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 V_DIO.h
\brief Ìîäóëü äèñêðåòíûõ âõîäîâ/âûõîäîâ
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
\version v 1.0 25/08/2017
\addtogroup
@{*/
#ifndef V_DIO_H
#define V_DIO_H
#ifdef __cplusplus
extern "C" {
#endif
// Ìàêðîñ óñòàíîâêè â '1' çàäàííîãî áèòà
// var - öåëåâàß ïåðåìåííàß
// index - èíäåêñ (ñìåùåíèå) óñòàíàâëèâàåìîãî áèòà
#define SET_BIT(var, index) var |= (1 << index);
// Ìàêðîñ ñáðîñà â '0' çàäàííîãî áèòà
// var - öåëåâàß ïåðåìåííàß
// index - èíäåêñ (ñìåùåíèå) î÷èùàåìîãî áèòà
#define CLEAR_BIT(var, index) var &= (~(1 << index));
// Ìàêðîñ ïðîâåðêè íåíóëåâîãî ñîñòîßíèÿ çàäàííîãî áèòà
// var - öåëåâàß ïåðåìåííàß
// index - èíäåêñ (ñìåùåíèå) ïðîâåðßåìîãî áèòà
#define BIT_IS_SET(var, index) ((var & (1 << index)) != 0)
// Ìàêðîñ ïðîâåðêè íóëåâîãî ñîñòîßíèÿ çàäàííîãî áèòà
// var - öåëåâàß ïåðåìåííàß
// index - èíäåêñ (ñìåùåíèå) ïðîâåðßåìîãî áèòà
#define BIT_IS_CLEAR(var, index) ((var & (1 << index)) == 0)
// Äåôàéíèì äèñêðåòíûå âõîäû
#ifdef HW_MCB3
//TODO ïåðåäåëàòü
#define D_IN1 ((GPIOM->DATA & (1 << 13)) == 0) //M13 Ñòàðò
#define D_IN2 ((GPIOM->DATA & (1 << 11)) == 0) //M11 Ñòîï
#define D_IN3 ((GPIOM->DATA & (1 << 10)) == 0) //M10 Ñáðîñ àâàðèé
#else
#define D_IN1 0
#define D_IN2 0
#define D_IN3 0
#endif
// Äåôàéíèì äèñêðåòíûå âûõîäû
#ifdef HW_MCB3
#define D_OUT1_ON GPIOD->DATAOUTSET = GPIO_PIN_1
#define D_OUT1_OFF GPIOD->DATAOUTCLR = GPIO_PIN_1
#define D_OUT2_ON GPIOD->DATAOUTSET = GPIO_PIN_2
#define D_OUT2_OFF GPIOD->DATAOUTCLR = GPIO_PIN_2
#define D_OUT3_ON GPIOM->DATAOUTSET = GPIO_PIN_14
#define D_OUT3_OFF GPIOM->DATAOUTCLR = GPIO_PIN_14
#else
#define D_OUT1_ON
#define D_OUT1_OFF
#define D_OUT2_ON
#define D_OUT2_OFF
#define D_OUT3_ON
#define D_OUT3_OFF
#endif
// Âåêòîð ñîñòîßíèß äèñêðåòíûõ âûõîäîâ
extern volatile Uint16 output_vect;
// Ìàñêà èíâåðòèðîâàíèß âåêòîðà ñîñòîßíèß äèñêðåòíûõ âûõîäîâ
extern volatile Uint16 output_mask;
// Âåêòîð ñîñòîßíèß äèñêðåòíûõ âõîäîâ
extern volatile Uint16 input_vect;
// Ìàñêà èíâåðòèðîâàíèß âåêòîðà ñîñòîßíèß äèñêðåòíûõ âõîäîâ
extern volatile Uint16 input_mask;
// Êîýôôèöèåíò ôèëüòðàöèè äèñêðåòíûõ âõîäîâ Kf = 0.0001/Tô
// (Tô - ïîñòîßííàß âðåìåíè ôèëüòðà, ñåê)
extern volatile _iq inputKf;
#define in_Kf inputKf // ïñåâäîíèì äëß óæå èìåþùåéñÿ ïåðåìåííîé â ñëîâàðå CANopen
// Ïîðîã ïåðåõîäà äèñêðåòíîãî âõîäà â ñîñòîßíèå OFF (0)
extern volatile _iq inputOff;
// Ïîðîã ïåðåõîäà äèñêðåòíîãî âõîäà â ñîñòîßíèå ON (1)
extern volatile _iq inputOn;
void DIO_Init();
void DIO_slow_calc(); // âûçûâàòü â ôîíîâîé ïðîãðàììå
void DIO_fast_calc(); // âûçûâàòü ñ ÷àñòîòîé 1êÃö èëè 10 êÃö
#ifdef __cplusplus
}
#endif
#endif
/*@}*/