annotate gsm-fw/bsp/rtc/rtc_functions.c @ 161:98be4841eeb7

gsm-fw: RTC code hooked into the build
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 18 Nov 2013 00:08:43 +0000
parents dbfc9ff4e8d2
children 595192258bc9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
160
dbfc9ff4e8d2 gsm-fw: starting to compile RTC code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 159
diff changeset
1 /******************************************************************************/
dbfc9ff4e8d2 gsm-fw: starting to compile RTC code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 159
diff changeset
2 /* rtc_functions.c : contains low level function for the rtc */
dbfc9ff4e8d2 gsm-fw: starting to compile RTC code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 159
diff changeset
3 /* */
dbfc9ff4e8d2 gsm-fw: starting to compile RTC code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 159
diff changeset
4 /* */
dbfc9ff4e8d2 gsm-fw: starting to compile RTC code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 159
diff changeset
5 /* Author: Laurent Sollier */
dbfc9ff4e8d2 gsm-fw: starting to compile RTC code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 159
diff changeset
6 /* */
dbfc9ff4e8d2 gsm-fw: starting to compile RTC code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 159
diff changeset
7 /* version: 1.0 */
dbfc9ff4e8d2 gsm-fw: starting to compile RTC code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 159
diff changeset
8 /* */
dbfc9ff4e8d2 gsm-fw: starting to compile RTC code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 159
diff changeset
9 /* Date: 03/20/01 */
dbfc9ff4e8d2 gsm-fw: starting to compile RTC code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 159
diff changeset
10 /******************************************************************************/
159
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11
161
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
12 #include "../../include/config.h"
159
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include <string.h> /* needed for memset */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
161
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
16 #include "rtc_messages_i.h"
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
17 #include "rtc_api.h"
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
18 #include "rtc_i.h"
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
19 #include "rtc_config.h"
159
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
161
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
21 #include "../../riviera/rvm/rvm_use_id_list.h"
159
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22
161
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
23 #include "../mem.h"
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
24 #include "../iq.h"
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
25 #include "../ulpd.h"
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
26 #include "../inth.h"
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
27
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
28 #include "../../nucleus/nucleus.h"
159
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 /* ----- Macro ----- */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 /* RTC_STOP */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 /* Functionality : Stop the RTC (STOP_RTC is cleared) */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 #define RTC_STOP (* (volatile UINT8 *) RTC_CTRL_REG &= ~RTC_START_RTC)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 /* RTC_START */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 /* Functionality : Start the RTC */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 #define RTC_START (* (volatile UINT8 *) RTC_CTRL_REG |= RTC_START_RTC)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 /* RTC_SET_32_CNT */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 /* Functionality : Set the SET_32_COUNTER bit */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 #define RTC_SET_32_CNT (* (volatile UINT8 *) RTC_CTRL_REG |= RTC_SET_32_COUNTER)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 /* RTC_RESET_32_CNT */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 /* Functionality : Reset the SET_32_COUNTER bit */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 #define RTC_RESET_32_CNT (* (volatile UINT8 *) RTC_CTRL_REG &= ~RTC_SET_32_COUNTER)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 /* RTC_SET_TEST_MODE */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 /* Functionality : Set the TEST_MODE bit */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 #define RTC_SET_TEST_MODE (* (volatile UINT8 *) RTC_CTRL_REG |= RTC_TEST_MODE)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 /* RTC_ENABLE_IT_ALARM */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 /* Functionality : Enable the IT_ALARM */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 #define RTC_ENABLE_IT_ALARM (* (volatile UINT8 *) RTC_INTERRUPTS_REG |= RTC_IT_ALARM)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 /* RTC_DISABLE_IT_ALARM */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 /* Functionality : Disable the IT_ALARM */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 #define RTC_DISABLE_IT_ALARM (* (volatile UINT8 *) RTC_INTERRUPTS_REG &= ~RTC_IT_ALARM)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 /* RTC_ENABLE_IT_TIMER */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 /* Functionality : Enable the IT_TIMER */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 #define RTC_ENABLE_IT_TIMER (* (volatile UINT8 *) RTC_INTERRUPTS_REG |= RTC_IT_TIMER)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 /* RTC_DISABLE_IT_TIMER */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 /* Functionality : Disable the IT_TIMER */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 #define RTC_DISABLE_IT_TIMER (* (volatile UINT8 *) RTC_INTERRUPTS_REG &= ~RTC_IT_TIMER)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 /* RTC_SET_EVENT_TIMER */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 /* Parameters : event to enable or disable */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 /* Functionality : Set the event for the IT_TIMER */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 /* Enable or disable IT */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 #define RTC_SET_EVENT_TIMER(x) (* (volatile UINT8 *) RTC_INTERRUPTS_REG = (* (volatile UINT8 *) RTC_INTERRUPTS_REG & 0xfffc) | (x))
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 /* RTC_TEST_BUSY */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 /* Functionality : Return the RTC state busy signal */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 #define RTC_TEST_BUSY ((* (volatile UINT8 *) RTC_STATUS_REG) & RTC_BUSY)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 /* RTC_RUN_STATE */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 /* Functionality : Return the RTC run state */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 #define RTC_RUN_STATE ((* (volatile UINT8 *) RTC_STATUS_REG) & RTC_RUN)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 /* RTC_FREE_AL_ITLINE */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 /* Functionality : free it AL line */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 #define RTC_FREE_AL_ITLINE ((* (volatile UINT8 *) RTC_STATUS_REG) |= RTC_ALARM)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 /* RTC_FREE_POWER_UP */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 /* Functionality : clear reset event */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 #define RTC_FREE_POWER_UP ((* (volatile UINT8 *) RTC_STATUS_REG) |= RTC_POWER_UP)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 /* RTC_GET_EVENT_TIMER */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 /* Parameters : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 /* Functionality : Get the event status for the IT_TIMER */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 /*-------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 #define RTC_GET_EVENT_TIMER ((* (volatile UINT8 *) RTC_STATUS_REG & 0x3c))
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 /* ----- Global variables ----- */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 static T_RTC_DATE_TIME rtc_date_time_alarm = {0};
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 static T_RV_RETURN rtc_return_path = {RVF_INVALID_ADDR_ID, NULL};
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177 static T_RTC_ALARM* rtc_msg_alarm_event = NULL;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179 extern T_RTC_ENV_CTRL_BLK* rtc_env_ctrl_blk;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 /* Number of 32 Khz clock */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
182 static UINT32 rtc_nb_32khz = 0;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
183
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184 /* Number of high frequency clock */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
185 static UINT32 rtc_nb_hf = 0;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
186
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
187 static NU_HISR hisr;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
188 char hisrStack[512];
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
189
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
190 // UINT16 toto = 0; tmp
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
191
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
192 void HisrEntryFunc(void)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
193 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
194 if (rtc_msg_alarm_event)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 rvf_send_msg(rtc_env_ctrl_blk->addr_id, rtc_msg_alarm_event);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196 //char comp[15];
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197 /* sprintf(comp,"%d",toto);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 LCDG_WriteString( 4, 0, " ");
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199 LCDG_WriteString( 3, 0, (char*) comp); //tmp */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 /*---------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204 /* conv_bin DCB => B */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 /*---------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 /* Parameters : value to be convert */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
207 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208 /* Functionality : BCD et binary conversion function */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
209 /*---------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211 static UINT8 conv_bin(UINT8 value)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
213 return (10*(value>>4) + ( value & 0x0f));
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
214 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216 /*---------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217 /* conv_bcd B => DCB */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218 /*---------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 /* Parameters : value to be convert */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
220 /* Return : none */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
221 /* Functionality : Binary to BCD conversion function */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
222 /*---------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
223
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
224 static UINT8 conv_bcd(UINT8 value)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
225 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
226 return ((value%10) | ( (value/10) <<4));
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
227 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
228
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
229
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
230
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
231 /*---------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
232 /* format_date_available */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
233 /*---------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
234 /* Parameters : T_RTC_DATE_TIME structure */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
235 /* Return : TRUE if format is available */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
236 /* FALSE else */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
237 /* Functionality : test if date and time format is available */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
238 /*---------------------------------------------------------------*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
239
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
240 BOOL format_date_available(T_RTC_DATE_TIME date_time)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
241 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
242 UINT8 m;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
243
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
244 if (date_time.second < 0 || date_time.second > 59)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
245 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
246 if (date_time.minute < 0 || date_time.minute > 59)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
247 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
248 if (date_time.mode_12_hour == FALSE)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
249 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
250 if (date_time.hour < 0 || date_time.hour > 23)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
251 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
252 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
253 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
254 if (date_time.hour < 1 || date_time.hour > 12)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
255 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
256
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
257 if (date_time.month < 1 || date_time.month > 12)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
258 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
259 if (date_time.year < 0 || date_time.year > 99)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
260 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
261 if (date_time.wday < 0 || date_time.wday > 6)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
262 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
263 m = date_time.month;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
264 if (m == 1||m == 3||m == 5||m == 7||m == 8||m == 10||m == 12)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
265 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
266 if (date_time.day < 1 || date_time.day > 31)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
267 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
268 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
269 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
270 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
271 if (m == 4||m == 6||m == 9||m == 11)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
272 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
273 if (date_time.day < 1 || date_time.day > 30)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
274 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
275 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
276 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
277 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
278 if (date_time.year%4)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
279 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
280 if (date_time.day < 1 || date_time.day > 28)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
281 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
282 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
283 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
284 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
285 if (date_time.day < 1 || date_time.day > 29)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
286 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
287 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
288 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
289 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
290 return TRUE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
291 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
292
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
293
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
294
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
295 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
296 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
297 * RTC_Initialize
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
298 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
299 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
300
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
301
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
302
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
303 T_RVF_RET RTC_Initialize(void)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
304 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
305 T_RVF_MB_STATUS mb_status;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
306
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
307 /* Reserve memory for alarm event */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
308 mb_status = rvf_get_buf (rtc_env_ctrl_blk->prim_id, sizeof (T_RTC_ALARM ), (void **) &rtc_msg_alarm_event);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
309
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
310 if ((mb_status == RVF_GREEN) || (mb_status == RVF_YELLOW)) /* Memory allocation success */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
311 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
312 rtc_msg_alarm_event->os_hdr.msg_id = RTC_ALARM_EVT;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
313 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
314 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
315 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
316 rtc_msg_alarm_event = NULL;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
317 return RVF_MEMORY_ERR;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
318 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
319
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
320 rtc_env_ctrl_blk->msg_alarm_event = rtc_msg_alarm_event;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
321
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
322
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
323 /* Start RTC module */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
324 if (RTC_RUN_STATE == 0)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
325 RTC_START;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
326
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
327 /* Enable auto compensation */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
328 //*(volatile UINT8*) RTC_CTRL_REG |= RTC_AUTO_COMP;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
329 /* Disable auto compensation */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
330 *(volatile UINT8*) RTC_CTRL_REG &= ~RTC_AUTO_COMP;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
331
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
332 /* For CHIPSET = 7, 9, 10 or 11, set analog baseband type */
161
98be4841eeb7 gsm-fw: RTC code hooked into the build
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 160
diff changeset
333 #if (((CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 10) || (CHIPSET == 11)) && (ANALOG == 1))
159
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
334 *(volatile UINT8*) RTC_CTRL_REG |= RTC_nDELTA_OMEGA;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
335 #endif
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
336
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
337 /* Activate periodic interrupt every minute*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
338 /* Disable all IT before accessing register */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
339 rvf_disable(25);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
340
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
341 /* Enable IRQ9 and IRQ10 */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
342 #if (CHIPSET == 12)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
343 F_INTH_ENABLE_ONE_IT(C_INTH_RTC_TIMER_IT);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
344 F_INTH_ENABLE_ONE_IT(C_INTH_RTC_ALARM_IT);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
345 #else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
346 IQ_Unmask(IQ_RTC_TIMER);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
347 IQ_Unmask(IQ_RTC_ALARM);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
348 #endif
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
349
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
350 while (RTC_TEST_BUSY);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
351 RTC_SET_EVENT_TIMER(RTC_EVERY_MIN); /* Set timer every minute */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
352 RTC_ENABLE_IT_TIMER;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
353 RTC_DISABLE_IT_ALARM;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
354
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
355 rvf_enable();
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
356
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
357 /* The stack is entirely filled with the pattern 0xFE. */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
358 memset (hisrStack, 0xFE, sizeof(hisrStack));
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
359
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
360 /* Temporary modification: create HISR to diplay compensation value */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
361 NU_Create_HISR(&hisr, "RTC_HISR", HisrEntryFunc, 2, hisrStack, sizeof(hisrStack)); // lowest prty
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
362 /* end temporary modification */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
363
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
364 return RVF_OK;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
365 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
366 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
367 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
368 * RTC_RtcReset
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
369 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
370 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
371
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
372 BOOL RTC_RtcReset(void)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
373 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
374
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
375 /* Read POWER UP bit to inform MMI of a possible RTC reset */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
376 if ( ((* (volatile UINT8*) RTC_STATUS_REG) & RTC_POWER_UP) )
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
377 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
378 RTC_FREE_POWER_UP;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
379 return TRUE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
380 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
381 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
382 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
383
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
384 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
385
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
386
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
387 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
388 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
389 * RTC_GetDateTime
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
390 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
391 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
392
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
393 T_RVF_RET RTC_GetDateTime(T_RTC_DATE_TIME* date_time)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
394 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
395 UINT8 sec;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
396 UINT8 min;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
397 UINT8 hour;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
398 UINT8 day;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
399 UINT8 month;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
400 UINT8 year;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
401 UINT8 wday;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
402 UINT8 hr_reg;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
403
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
404 /* Disable all IT before reading register */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
405 rvf_disable(25);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
406
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
407 if (RTC_TEST_BUSY)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
408 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
409 rvf_enable();
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
410 return RVF_NOT_READY;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
411 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
412 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
413 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
414 day = * (volatile UINT8 *) RTC_DAYS_REG;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
415 month = * (volatile UINT8 *) RTC_MONTHS_REG;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
416 year = * (volatile UINT8 *) RTC_YEARS_REG;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
417 wday = * (volatile UINT8 *) RTC_WEEK_REG;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
418 sec = * (volatile UINT8 *) RTC_SECONDS_REG;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
419 min = * (volatile UINT8 *) RTC_MINUTES_REG;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
420 hr_reg = * (volatile UINT8 *) RTC_HOURS_REG;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
421 rvf_enable();
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
422 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
423
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
424 hour = (0x7f & hr_reg);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
425
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
426 date_time->second = conv_bin(sec);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
427 date_time->minute = conv_bin(min);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
428 date_time->hour = conv_bin(hour);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
429
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
430 if ( (* (volatile UINT8 *)RTC_CTRL_REG & RTC_MODE_12_24 ) == 0)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
431 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
432 /* 24 hour mode */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
433 date_time->mode_12_hour = FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
434 date_time->PM_flag = FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
435 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
436 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
437 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
438 /* 12 hour mode */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
439 date_time->mode_12_hour = TRUE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
440 if ((hr_reg & 0x80) == 0)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
441 date_time->PM_flag = FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
442 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
443 date_time->PM_flag = TRUE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
444 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
445
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
446 date_time->day = conv_bin(day);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
447 date_time->month = conv_bin(month);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
448 date_time->year = conv_bin(year);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
449 date_time->wday = conv_bin(wday);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
450
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
451 return RVF_OK;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
452 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
453
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
454
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
455 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
456 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
457 * RTC_SetDateTime
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
458 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
459 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
460
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
461 T_RVF_RET RTC_SetDateTime(T_RTC_DATE_TIME date_time)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
462 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
463 UINT8 sec;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
464 UINT8 min;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
465 UINT8 hour;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
466 UINT8 day;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
467 UINT8 month;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
468 UINT8 year;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
469 UINT8 wday;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
470
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
471 /* testing parameter range validity */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
472 if (!format_date_available(date_time))
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
473 return RVF_INVALID_PARAMETER;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
474
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
475
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
476 sec = conv_bcd(date_time.second);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
477 min = conv_bcd(date_time.minute);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
478 if (date_time.mode_12_hour == FALSE)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
479 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
480 * (volatile UINT8 *)RTC_CTRL_REG &= ~RTC_MODE_12_24;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
481 hour = conv_bcd(date_time.hour);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
482 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
483 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
484 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
485 * (volatile UINT8 *)RTC_CTRL_REG |= RTC_MODE_12_24;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
486 hour = conv_bcd(date_time.hour);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
487 if (date_time.PM_flag != FALSE)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
488 hour |= (0x80);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
489 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
490
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
491 day = conv_bcd(date_time.day);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
492 month = conv_bcd(date_time.month);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
493 year = conv_bcd(date_time.year);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
494 wday = conv_bcd(date_time.wday);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
495
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
496 /* Disable all IT before reading register */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
497 rvf_disable(25);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
498
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
499 if (RTC_TEST_BUSY)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
500 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
501 rvf_enable();
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
502 return RVF_NOT_READY;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
503 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
504 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
505 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
506 * (volatile UINT8 *) RTC_DAYS_REG = day;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
507 * (volatile UINT8 *) RTC_MONTHS_REG = month;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
508 * (volatile UINT8 *) RTC_YEARS_REG = year;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
509 * (volatile UINT8 *) RTC_WEEK_REG = wday;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
510 * (volatile UINT8 *) RTC_SECONDS_REG = sec;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
511 * (volatile UINT8 *) RTC_MINUTES_REG = min;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
512 * (volatile UINT8 *) RTC_HOURS_REG = hour;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
513
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
514 rvf_enable();
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
515 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
516
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
517 return RVF_OK;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
518 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
519
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
520
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
521 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
522 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
523 * RTC_GetAlarm
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
524 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
525 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
526
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
527 T_RVF_RET RTC_GetAlarm(T_RTC_DATE_TIME* date_time)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
528 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
529 date_time->second = rtc_date_time_alarm.second;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
530 date_time->minute = rtc_date_time_alarm.minute;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
531 date_time->hour = rtc_date_time_alarm.hour;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
532 date_time->day = rtc_date_time_alarm.day;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
533 date_time->month = rtc_date_time_alarm.month;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
534 date_time->year = rtc_date_time_alarm.year;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
535 date_time->wday = rtc_date_time_alarm.wday;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
536 date_time->mode_12_hour = rtc_date_time_alarm.mode_12_hour;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
537 date_time->PM_flag = rtc_date_time_alarm.PM_flag;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
538 return RVF_OK;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
539 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
540
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
541
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
542 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
543 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
544 * RTC_SetAlarm
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
545 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
546 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
547
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
548 T_RVF_RET RTC_SetAlarm(T_RTC_DATE_TIME date_time, T_RV_RETURN return_path)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
549 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
550 UINT8 sec;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
551 UINT8 min;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
552 UINT8 hour;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
553 UINT8 day;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
554 UINT8 month;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
555 UINT8 year;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
556 UINT8 wday;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
557
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
558
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
559 /* testing parameter range validity */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
560 if (!format_date_available(date_time))
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
561 return RVF_INVALID_PARAMETER;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
562
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
563 sec = conv_bcd(date_time.second);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
564 min = conv_bcd(date_time.minute);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
565
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
566 if (date_time.mode_12_hour == FALSE)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
567 hour = conv_bcd(date_time.hour);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
568 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
569 hour = conv_bcd(date_time.hour) | (date_time.PM_flag << 7);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
570
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
571 day = conv_bcd(date_time.day);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
572 month = conv_bcd(date_time.month);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
573 year = conv_bcd(date_time.year);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
574 wday = conv_bcd(date_time.wday);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
575
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
576
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
577 /* Disable all IT before reading register */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
578 rvf_disable(25);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
579
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
580 if (RTC_TEST_BUSY)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
581 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
582 rvf_enable();
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
583 return RVF_NOT_READY;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
584 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
585 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
586 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
587 *(volatile UINT8*) RTC_ALARM_DAYS_REG = day;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
588 *(volatile UINT8*) RTC_ALARM_MONTHS_REG = month;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
589 *(volatile UINT8*) RTC_ALARM_YEARS_REG = year;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
590 *(volatile UINT8*) RTC_ALARM_SECONDS_REG = sec;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
591 *(volatile UINT8*) RTC_ALARM_MINUTES_REG = min;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
592 *(volatile UINT8*) RTC_ALARM_HOURS_REG = hour;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
593
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
594 /* Enable alarm*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
595 RTC_ENABLE_IT_ALARM;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
596 rvf_enable();
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
597
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
598 /* Save callback */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
599 rtc_return_path.callback_func = return_path.callback_func;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
600 rtc_return_path.addr_id = return_path.addr_id;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
601 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
602 return RVF_OK;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
603 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
604
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
605
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
606 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
607 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
608 * RTC_UnsetAlarm
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
609 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
610 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
611
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
612 T_RVF_RET RTC_UnsetAlarm(void)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
613 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
614 /* Disable all IT before reading register */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
615 rvf_disable(25);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
616
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
617 if (RTC_TEST_BUSY)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
618 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
619 rvf_enable();
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
620 return RVF_NOT_READY;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
621 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
622 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
623 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
624 /* Disable alarm*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
625 RTC_DISABLE_IT_ALARM;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
626 rvf_enable();
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
627 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
628 return RVF_OK;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
629 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
630
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
631
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
632 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
633 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
634 * RTC_Rounding30s
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
635 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
636 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
637
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
638 void RTC_Rounding30s(void)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
639 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
640 *(UINT8*) RTC_CTRL_REG |= RTC_ROUND_30S;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
641 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
642
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
643
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
644 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
645 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
646 * RTC_Set12HourMode
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
647 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
648 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
649
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
650 void RTC_Set12HourMode(BOOL Mode12Hour)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
651 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
652 if ( Mode12Hour == FALSE)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
653 * (volatile UINT8*) RTC_CTRL_REG &= 0xf7;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
654 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
655 * (volatile UINT8*) RTC_CTRL_REG |= 0x08;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
656
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
657 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
658
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
659
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
660 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
661 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
662 * RTC_Is12HourMode
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
663 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
664 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
665
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
666 BOOL RTC_Is12HourMode(void)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
667 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
668 if ( (*(volatile UINT8*) RTC_CTRL_REG & RTC_MODE_12_24) )
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
669 return TRUE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
670 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
671 return FALSE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
672 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
673
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
674
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
675 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
676 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
677 * RTC_ItTimerHandle
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
678 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
679 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
680
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
681 void RTC_ItTimerHandle(void)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
682 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
683 static double compensation = 0;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
684 static UINT8 nb_sample = 0;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
685 double delta;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
686 UINT16 value = 0;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
687 INT16 tmp_value = 0;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
688 UINT8 cmp[15];
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
689
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
690 /* Evaluate average on one hour max */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
691 if ( nb_sample < 60)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
692 nb_sample++;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
693
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
694 /* perform calculation of auto compensation each minute and evaluate an
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
695 average on one hour */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
696 /* Number of 32 kHz clock lost in one second */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
697 /* Accurate operation is : delta = CLK_32 - rtc_nb_32khz*CLK_PLL/g_nb_hf */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
698 /* with CLK_32 = 32768 Hz and CLK_PLL depend on chipset */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
699 delta = RTC_CLOCK_32K - rtc_nb_32khz*RTC_CLOCK_HF/rtc_nb_hf;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
700
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
701 /* Number of 32 kHz clock lost in one hour */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
702 delta *= 3600.0;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
703
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
704 /* Average of the compensation to load */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
705 compensation = (compensation*(nb_sample-1) + delta)/nb_sample;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
706
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
707 if (compensation >= 0x7FFF)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
708 tmp_value = 0x7FFE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
709 else if (compensation <= -0x7FFF)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
710 tmp_value = -0x7FFE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
711 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
712 tmp_value = (INT16) compensation;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
713
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
714 if (tmp_value > 0) /* if 32 Khz clock is slow */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
715 value = tmp_value;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
716 if (tmp_value < 0) /* if 32 Khz clock is fast */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
717 value = 0xFFFF + tmp_value + 1;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
718
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
719 /* Set value in compensation register */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
720 if (!RTC_TEST_BUSY)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
721 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
722 *(volatile UINT8*) RTC_COMP_MSB_REG = (UINT8) (value >> 8);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
723 *(volatile UINT8*) RTC_COMP_LSB_REG = (UINT8) (value & 0xFF);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
724 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
725 /*toto = value; tmp*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
726 /*NU_Activate_HISR(&hisr); tmp*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
727
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
728 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
729
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
730
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
731 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
732 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
733 * RTC_ItAlarmHandle
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
734 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
735 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
736
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
737 void RTC_ItAlarmHandle(void)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
738 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
739 /* Sending alarm event */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
740 /* Post alarm event in RTC mailbox */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
741 NU_Activate_HISR(&hisr);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
742
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
743 /*if (rtc_msg_alarm_event)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
744 rvf_send_msg(rtc_env_ctrl_blk->task_id, rtc_env_ctrl_blk->mbox_id, rtc_msg_alarm_event);*/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
745
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
746 /* Free alarm IT line */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
747 RTC_FREE_AL_ITLINE;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
748 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
749
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
750 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
751 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
752 * RTC_GaugingHandler
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
753 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
754 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
755 void RTC_GaugingHandler(void)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
756 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
757 /* Number of 32 Khz clock at the end of the gauging */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
758 rtc_nb_32khz = ((*(volatile UINT16 *)ULDP_COUNTER_32_MSB_REG) * 0x10000) +
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
759 (*(volatile UINT16 *)ULDP_COUNTER_32_LSB_REG);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
760
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
761 /* Number of high frequency clock at the end of the gauging */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
762 /* To convert in nbr of 13 Mhz clocks (5*13=65Mhz) */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
763 rtc_nb_hf = ( ((*(volatile UINT16 *)ULDP_COUNTER_HI_FREQ_MSB_REG) * 0x10000) +
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
764 (*(volatile UINT16 *)ULDP_COUNTER_HI_FREQ_LSB_REG) );
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
765 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
766
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
767
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
768 /*******************************************************************************
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
769 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
770 * RTC_ProcessAlarmEvent
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
771 *
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
772 ******************************************************************************/
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
773
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
774 void RTC_ProcessAlarmEvent(void)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
775 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
776 T_RVF_MB_STATUS mb_status;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
777 T_RTC_ALARM* msg_alarm;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
778
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
779 /* Call MMI */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
780 if (rtc_return_path.callback_func != NULL)
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
781 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
782 rtc_return_path.callback_func(NULL);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
783 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
784 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
785 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
786 /* Reserve memory for alarm event */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
787 mb_status = rvf_get_buf (rtc_env_ctrl_blk->prim_id, sizeof (T_RTC_ALARM ), (void **) &msg_alarm);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
788
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
789 if ((mb_status == RVF_GREEN) || (mb_status == RVF_YELLOW)) /* Memory allocation success */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
790 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
791 msg_alarm->os_hdr.msg_id = RTC_ALARM_EVT;
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
792 /* Send event in the mailbox */
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
793 rvf_send_msg(rtc_return_path.addr_id, msg_alarm);
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
794 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
795 else
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
796 {
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
797 rvf_send_trace("Memory allocation error",23, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RTC_USE_ID );
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
798 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
799 }
3c42e6e5fc04 gsm-fw/bsp/rtc: initial import from Leonardo TCS211 semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
800 }