lib/rtc.txt
author Manuele Conti <conti.ma@alice.it>
Thu, 03 Jan 2013 22:54:55 +0100
changeset 788 aa56031e5cb3
parent 400 093b72cd2ac3
child 885 b2604fc6d25c
permissions -rw-r--r--
Implement Mario's suggestions:
- Clean up code replace merge algorithm with a function.
- Fix for_statement setting control variable to not a constant.
- Fix for_statement checking BY expression to get correct value for optimization
branch.

Thanks Mario.
400
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
     1
(****************************************************************
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
     2
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
     3
              RTC - Real-time clock
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
     4
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
     5
Q is a copy of IN.
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
     6
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
     7
When IN = FALSE, CDT is the current date and time as set by the
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
     8
PLC driver.
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
     9
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    10
When IN changes from FALSE to TRUE, PDT is stored. As long as IN is
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    11
TRUE, CDT is equal to PDT + the amount of time since PDT was loaded.
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    12
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    13
****************************************************************)
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    14
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    15
FUNCTION_BLOCK RTC
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    16
   VAR_INPUT
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    17
     IN : BOOL;                  (* 0 - current time, 1 - load time from 
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    18
PDT *)
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    19
     PDT : DT;                   (* Preset datetime *)
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    20
   END_VAR
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    21
   VAR_OUTPUT
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    22
     Q : BOOL := FALSE;          (* Copy of IN *)
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    23
     CDT : DT;                   (* Datetime, current or relative to PDT *)
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    24
   END_VAR
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    25
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    26
   VAR
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    27
     PREV_IN : BOOL := FALSE;
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    28
     OFFSET : TIME;
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    29
     CURRENT_TIME : DT;
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    30
   END_VAR
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    31
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    32
   {__SET_VAR(data__->,CURRENT_TIME,__CURRENT_TIME)}
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    33
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    34
   IF IN
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    35
   THEN
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    36
     IF NOT PREV_IN
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    37
     THEN
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    38
         OFFSET := PDT - CURRENT_TIME;
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    39
     END_IF;
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    40
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    41
     (* PDT + time since PDT was loaded *)
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    42
     CDT := CURRENT_TIME + OFFSET;
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    43
   ELSE
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    44
     CDT := CURRENT_TIME;
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    45
   END_IF;
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    46
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    47
   Q := IN;
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    48
   PREV_IN := IN;
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    49
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    50
END_FUNCTION_BLOCK
093b72cd2ac3 Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
Edouard Tisserant
parents:
diff changeset
    51