84 lines
2.8 KiB
C
84 lines
2.8 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_RTC_Clock.h
|
|
\brief Ìîäóëü ðàáîòû ñ ÷àñàìè ðåàëüíîãî âðåìåíè
|
|
\author ÎÎÎ "ÍÏÔ Âåêòîð". Âñå ïðàâà çàùèùåíû. http://motorcontrol.ru
|
|
\version v 2.0 25/03/2016
|
|
|
|
\defgroup V_rmp_ctrl Çàäàò÷èê èíòåíñèâíîñòè (ñì. TRMPCtrl)
|
|
|
|
@{
|
|
*/
|
|
#ifndef V_RTC_CLOCK_H_
|
|
#define V_RTC_CLOCK_H_
|
|
|
|
#define RTC_SLAVE_ADDRESS 0x68 // Äëÿ RTC DS1340 àäðåñ 1101 000b = 0x68 (õîòÿ â ðóêîâîäñòâå îíè åãî êàê áû äîïîëíÿþò íóë¸ì
|
|
// è ïîëó÷àþò 1101 0000b = 0xD0)
|
|
#define RTC_WRITE_ERROR 1
|
|
#define RTC_READ_ERROR 2
|
|
#define RTC_TIMEOUT_ERROR 3
|
|
|
|
#define RTC_TIMEOUT 1000 // Êîëè÷åñòâî îæèäàíèÿ øèíû
|
|
#define RTC_SECOND_WAITING_TIMEOUT 10000 // Âðåìÿ, â òå÷åíèå êîòîðîãî äîëæíà ñìåíèòüñÿ ñåêóíäà (çàäàåòñÿ â ìñ). Åñëè íå ìåíÿåòñÿ, çíà÷èò ÷àñû íå ðàáîòàþò.
|
|
|
|
struct SRTCClock{
|
|
Uint16 ms; // Íà âñÿêèé
|
|
Uint16 msInDay; // Ìèëèïèñþëè ñ íà÷àëà ñóòîê
|
|
Uint16 error; // Êîä îøèáêè
|
|
Uint16 tryCounter; // Ñ÷åò÷èê îæèäàíèé øèíû
|
|
|
|
Uint16 second;
|
|
Uint16 minute;
|
|
Uint16 hour;
|
|
|
|
Uint16 DOW; // DayOfWeek - äåíü íåäåëè (ïóñòü áóäåò, ÷òî, æàëêî ÷òî ëè?)
|
|
Uint16 day; // Date - ýòî ÷èñëî ìåñÿöà
|
|
Uint16 month;
|
|
Uint16 year;
|
|
|
|
Uint32 packed_time; // Âðåìÿ, óïàêîâàííîå â ñëîâî
|
|
Uint32 timeToSet; // Âðåìÿ, êîòîðîå íóæíî óñòàíîâèòü íà ÷àñàõ, óïàêîâàííîå â ñëîâî
|
|
|
|
Uint16 setTimeFlag;
|
|
Uint16 readTimeFlag;
|
|
|
|
Uint16 secondPrev;
|
|
Uint16 stoppedCounter;
|
|
Uint16 ClockOk;
|
|
void (*init)(volatile struct SRTCClock*); // Èíèöèàëèçàöèÿ
|
|
void (*read)(volatile struct SRTCClock*); // Ïðî÷èòàòü âðåìÿ èç ÷àñèêîâ
|
|
void (*set)(volatile struct SRTCClock*); // Ïèñüíóòü âðåìÿ â ÷àñèêè
|
|
void (*msCalc)(volatile struct SRTCClock*);
|
|
void (*slowCalc)(volatile struct SRTCClock*);
|
|
};
|
|
|
|
typedef volatile struct SRTCClock TRTCClock;
|
|
|
|
#define RTC_CLOCK_DEFAULTS {0,0,0,0, 0,0,0, 0,0,0,0, 0,0, 0,0, 0,0,0,\
|
|
RTC_Clock_Init,\
|
|
RTC_Clock_Read_Time,\
|
|
RTC_Clock_Set_Time,\
|
|
RTC_Clock_Ms_Calc,\
|
|
RTC_Clock_Slow_Calc}
|
|
|
|
void RTC_Clock_Init (TRTCClock *);
|
|
void RTC_Clock_Read_Time (TRTCClock *);
|
|
void RTC_Clock_Set_Time (TRTCClock *);
|
|
void RTC_Clock_Ms_Calc (TRTCClock *);
|
|
void RTC_Clock_Slow_Calc (TRTCClock *);
|
|
|
|
#endif /* V_I2CCLOCK_H_ */
|