197 lines
5.8 KiB
C
197 lines
5.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 Global_time.h
|
|
\brief Ìîäóëü ðàáîòû ñî âðåìåíåì
|
|
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
|
|
\version v 1.1 2010_02_24
|
|
|
|
*/
|
|
|
|
#ifndef GLOBAL_TIME_H
|
|
#define GLOBAL_TIME_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#include "DSP.h"
|
|
|
|
#define GLOBAL_TIME_CALC_FREQ 10 //!<êÃö ÷àñòîòà âûçîâà ôóíêöèè calc
|
|
//#define USE_ABSOLUTE_TIME_CLOCK //ðàñêîìåíòèðîâàòü åñëè èñïîëüçóþòñß ÷àñû ðåàëüíîãî âðåìåíè
|
|
|
|
|
|
|
|
#define GLOBAL_TIME_SPI_START_ADDR 6500 //!<íà÷àëüíûé àäðåñ â SPI
|
|
|
|
#define GLOBAL_TIME_POWER_ON_TIME_ADDR GLOBAL_TIME_SPI_START_ADDR
|
|
#define GLOBAL_TIME_OPERATIONAL_TIME_ADDR GLOBAL_TIME_SPI_START_ADDR + 4
|
|
|
|
|
|
//!Àáñîëþòíîå âðåìß
|
|
struct SABSOLUTE_TIME
|
|
{
|
|
int16 second;
|
|
int16 minute;
|
|
int16 hour;
|
|
int16 day;
|
|
int16 year;
|
|
};
|
|
typedef volatile struct SABSOLUTE_TIME ABSOLUTE_TIME;
|
|
|
|
//!Îòíîñèòåëüíàß äàòà
|
|
typedef struct
|
|
{
|
|
int16 millisecond;
|
|
int16 second;
|
|
int16 minute;
|
|
int32 hour;
|
|
}RELATIVE_DATE;
|
|
|
|
|
|
//!Îòíîñèòåëüíîå âðåìß
|
|
struct SRELATIVE_TIME
|
|
{
|
|
int ON;
|
|
Uint32 tic_isr;
|
|
Uint32 millisecond_counter;
|
|
Uint32 second_counter;
|
|
int16 delta_millisecond;
|
|
int16 delta_second;
|
|
RELATIVE_DATE relative_date;
|
|
};
|
|
typedef volatile struct SRELATIVE_TIME RELATIVE_TIME;
|
|
|
|
|
|
|
|
/*! \class TGlobalTime
|
|
\brief Ìîäóëü ðàáîòû ñî âðåìåíåì.
|
|
|
|
Êëàññ \a TGlobalTime, îñíîâàííûé íà ñòðóêòóðå SGlobalTime, ñîäåðæèò ìåòîäû
|
|
äëß ðàáîòû ñî âðåìåíåì.Îòñ÷èòûâàåò âðåìß â:\n
|
|
äëß îòñ÷åòà âðåìåíè ðàáîòû è ò.ä.:\n
|
|
ìèëèñåêóíäû: 0-999\n
|
|
ñåêóíäû: 0-59\n
|
|
ìèíóòû: 0-59\n
|
|
÷àñû: 0-23\n
|
|
äíè: 0-364\n
|
|
ãîäà: 0-ïðèìåðíî äî 160 ëåò\n
|
|
äëß îòñ÷åòà äåëüò (ïðèðàùåíèé âðåìåíè):\n
|
|
ìèëèñåêóíäû: 0-0xFFFFFFFF - ñîîòâåòñòâóåò ïðèìåðíî 1.5 ìåñßöàì\n
|
|
ñåêóíäû: 0-0xFFFFFFFF - ñîîòâåòñòâóåò ïðèìåðíî 160 ãîäàì\n
|
|
|
|
Åñòü ñïåöèàëüíûé ñïîñîá, ïîçâîëßþùèé îòñ÷èòûâàòü âûäåðæêè âðåìåíè ñ òî÷íîñòüþ
|
|
äî ìèëëèñåêóíä â ïåðûâàíèè ØÈÌ. Èñïîëüçóåòñß ïåðåìåííàß delta_millisecond,
|
|
êîòîðàß âîçâîäèòñß â åäèíèöó êàæäóþ ìèëëèñåêóíäó è íà ñëåäóþùåì ïåðèîäå ØÈÌ
|
|
ñáðàñûâàåòñß. Òîãäà ìîæíî â íåîáõîäèìûé ñ÷åò÷èê äîáàâèòü counter+=delta_millisecond è
|
|
ïîëó÷èòü â counter ñ÷åò÷èê ìèëëèñåêóíä. Àíàëîãè÷íî delta_second.
|
|
|
|
ÏÐÈÌÅ×ÀÍÈÅ: 1. ìîäóëü íå òðåáóåò èíèöèàëèçàöèè
|
|
2. àâòîìàòè÷åñêè ïåðåíàñòðàèâàåòñß ïðè èçìåíåíèè íåñóùåé ÷àñòîòû
|
|
|
|
ÄËß ÊÎÐÐÅÊÒÍÎÉ ÐÀÁÎÒÛ ÌÎÄÓËß ÏÎËÜÇÎÂÀÒÅËÜ ÄÎËÆÅÍ:
|
|
1. â ìàêðîñå GLOBAL_TIME_CALC_FREQ ïðàâèëüíî óêàçàòü íåñóùóþ ÷àñòîòó âûçîâà ôóíêöèè ðàñ÷åòà.
|
|
Ñëåäóåò îòìåòèòü, ÷òî çíà÷åíèå GLOBAL_TIME_CALC_FREQ öåëî÷èñëåííîå, ïîýòîìó
|
|
ìîäóëü êîððåêòíî ðàáîòàåò òîëüêî ïðè öåëûõ çíà÷åíèßõ íåñóùåé ÷àñòîòû (â êÃö).
|
|
Íåäîñòàòîê ñâßçàí ñ êîíêðåòíîé ðåàëèçàöèåé ìîäóëß.
|
|
*/
|
|
|
|
//! ñì. TGlobalTime
|
|
struct SGlobalTime
|
|
{
|
|
RELATIVE_TIME relative_time1;//!îòíîñèòåëüíîå âðåìß 1
|
|
RELATIVE_TIME relative_time2;//!îòíîñèòåëüíîå âðåìß 2
|
|
ABSOLUTE_TIME absolute_time;//!àáñîëþòíîå âðåìß
|
|
int16 time_type;//!÷àñû ðåàëüíîãî âðåìåíè (1 - åñòü)
|
|
int32 PowerOn_time; //!<Îáùåå âðåìß íàðàáîòêè
|
|
int32 PowerOn_time_min; //!<Îáùåå âðåìß íàðàáîòêè â ìèíóòàõ
|
|
int32 operational_time; //!<Îáùåå âðåìß âêëþ÷åííîãî ñîñòîßíèß
|
|
int32 operational_time_min; //!<Îáùåå âðåìß âêëþ÷åííîãî ñîñòîßíèß â ìèíóòàõ
|
|
int16 WtiteSPI_flag;
|
|
int32 PrevWriteSPIHour;
|
|
void (*init)(volatile struct SGlobalTime*);
|
|
void (*calc)(volatile struct SGlobalTime*);
|
|
void (*ms_calc)(volatile struct SGlobalTime*);
|
|
void (*slow_calc)(volatile struct SGlobalTime*);
|
|
void (*read_PowerOn_time)(volatile struct SGlobalTime*);
|
|
void (*write_PowerOn_time)(volatile struct SGlobalTime*);
|
|
void (*read_oper_time) (volatile struct SGlobalTime*);
|
|
void (*write_oper_time)(volatile struct SGlobalTime*);
|
|
};
|
|
|
|
typedef volatile struct SGlobalTime TGlobalTime;
|
|
|
|
//!Èíèöàëèçàòîð îòíîñèòåëüíîé äàòû.
|
|
#define RELATIVE_DATE_DEFAULTS {0,0,0,0}
|
|
|
|
//!Èíèöèàëèçàòîð îòíîñèòåëüíîãî âðåìåíè.
|
|
#define RELATIVE_TIME_DEFAULTS {0,\
|
|
0,0,0,0,0,\
|
|
RELATIVE_DATE_DEFAULTS,\
|
|
}
|
|
//!Èíèöèàëèçàòîð àáñîëþòíîãî âðåìåíè.
|
|
#define ABSOLUTE_TIME_DEFAULTS {0,0,0,0,0}
|
|
|
|
//!Èíèöèàëèçàòîð TGlobalTime.
|
|
#define GLOBAL_TIME_DEFAULTS { RELATIVE_TIME_DEFAULTS,\
|
|
RELATIVE_TIME_DEFAULTS,\
|
|
ABSOLUTE_TIME_DEFAULTS,\
|
|
1,0,0,0,0,0,0,\
|
|
GlobalTime_init,\
|
|
GlobalTime_calc,\
|
|
GlobalTime_ms_calc,\
|
|
GlobalTime_slow_calc,\
|
|
GlobalTime_read_PowerOn_time, \
|
|
GlobalTime_write_PowerOn_time, \
|
|
GlobalTime_read_oper_time, \
|
|
GlobalTime_write_oper_time,\
|
|
}
|
|
|
|
//! \memberof TGlobalTime
|
|
void GlobalTime_init(TGlobalTime*);
|
|
//! \memberof TGlobalTime
|
|
void GlobalTime_calc(TGlobalTime*);
|
|
//! \memberof TGlobalTime
|
|
void GlobalTime_ms_calc(TGlobalTime*);
|
|
//! \memberof TGlobalTime
|
|
void GlobalTime_slow_calc(TGlobalTime*);
|
|
|
|
//! \memberof TGlobalTime
|
|
void GlobalTime_REL_TIME_calc(RELATIVE_TIME *p);
|
|
|
|
//! \memberof TGlobalTime
|
|
void GlobalTime_read_PowerOn_time(TGlobalTime*);
|
|
//! \memberof TGlobalTime
|
|
void GlobalTime_write_PowerOn_time(TGlobalTime*);
|
|
//! \memberof TGlobalTime
|
|
void GlobalTime_read_oper_time(TGlobalTime*);
|
|
//! \memberof TGlobalTime
|
|
void GlobalTime_write_oper_time(TGlobalTime*);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*@}*/
|
|
|