motorcontroldemo_028/Vsrc/V_led.c
2019-07-29 08:18:57 +03:00

80 lines
2.0 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 Vled.c
\brief Óïðàâëåíèå ñâåòîäèîäàìè
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
\version v 2.0 25/03/2016
\addtogroup led
*/
#include "DSP.h"
#include "main.h"
#define RUN_LED_TOGGLE GPIOK->DATAOUTTGL = 1 << 15
#define RUN_LED_OFF GPIOK->DATAOUTSET = 1 << 15
#define RUN_LED_ON GPIOK->DATAOUTCLR = 1 << 15
#define FAULT_LED_TOGGLE GPIOK->DATAOUTTGL = 1 << 14
#define FAULT_LED_OFF GPIOK->DATAOUTSET = 1 << 14
#define FAULT_LED_ON GPIOK->DATAOUTCLR = 1 << 14
void LED_init(Tled *p) {
// Â src/GpioPeripheralInit()
}
// Îäèí äèîä ìèãàåò ìåäëåííî â ñòîïå è áûñòðî â ðàíå
// Äðóãîé ìèãàåò åñëè àâàðèÿ è íå ìèãàåò åñëè íå àâàðèé
void LED_msCalc(Tled *p) {
// Òàéìåðà ñ÷èòàþò ñåáå è ñ÷èòàþò
p->timerRunLed++;
p->timerFaultLed++;
// Â çàâèñèìîñòè îò ñòàòóñà ïðèâîäà âûñòàâëÿåì ïåðèîäû ìèãàíèé
if (drv_status.bit.running == 0) p->prdRunLed = 1000;
else p->prdRunLed = 200;
if (drv_status.bit.fault == 0) p->prdFaultLed = 0;
else p->prdFaultLed = 200;
// Åñëè ïåðèîä íîëü - íå ìèãàòü âîîáùå, èíà÷å - ïåðåêëþ÷àòü ïî ïåðèîäó
if (p->prdFaultLed == 0) FAULT_LED_OFF;
else if (p->timerFaultLed >= p->prdFaultLed) {
p->timerFaultLed = 0;
FAULT_LED_TOGGLE;
}
if (p->prdRunLed == 0) RUN_LED_OFF;
else if (p->timerRunLed >= p->prdRunLed) {
p->timerRunLed = 0;
RUN_LED_TOGGLE;
}
}