rtt.c
Go to the documentation of this file.
1 
33 /*
34  * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
35  */
36 
37 #include "rtt.h"
38 
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 
58 /*
59  * In follow series chip, the bit RTC1HZ and RTTDIS in RTT_MR are write only.
60  * So we use a variable to record status of these bits.
61  */
62 #if (SAM4N || SAM4S || SAM4E || SAM4C || SAMG51 || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
63 static uint32_t g_wobits_in_rtt_mr = 0;
64 #endif
65 
78 uint32_t rtt_init(Rtt *p_rtt, uint16_t us_prescaler)
79 {
80 #if (SAM4N || SAM4S || SAM4E || SAM4C || SAMG51 || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
81  p_rtt->RTT_MR = (us_prescaler | RTT_MR_RTTRST | g_wobits_in_rtt_mr);
82 #else
83  p_rtt->RTT_MR = (us_prescaler | RTT_MR_RTTRST);
84 #endif
85  return 0;
86 }
87 
88 #if (SAM4N || SAM4S || SAM4E || SAM4C || SAMG51 || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
89 
95 void rtt_sel_source(Rtt *p_rtt, bool is_rtc_sel)
96 {
97  if(is_rtc_sel) {
98  g_wobits_in_rtt_mr |= RTT_MR_RTC1HZ;
99  p_rtt->RTT_MR |= g_wobits_in_rtt_mr;
100  } else {
101  g_wobits_in_rtt_mr &= ~RTT_MR_RTC1HZ;
102  p_rtt->RTT_MR |= g_wobits_in_rtt_mr;
103  }
104 }
105 
111 void rtt_enable(Rtt *p_rtt)
112 {
113  g_wobits_in_rtt_mr &= ~RTT_MR_RTTDIS;
114  p_rtt->RTT_MR |= g_wobits_in_rtt_mr;
115 }
121 void rtt_disable(Rtt *p_rtt)
122 {
123  g_wobits_in_rtt_mr |= RTT_MR_RTTDIS;
124  p_rtt->RTT_MR |= g_wobits_in_rtt_mr;
125 }
126 #elif (SAMG53 || SAMG54 || SAMG55)
127 void rtt_sel_source(Rtt *p_rtt, bool is_rtc_sel)
128 {
129  if(is_rtc_sel) {
130  p_rtt->RTT_MR |= RTT_MR_RTC1HZ;
131  } else {
132  p_rtt->RTT_MR &= ~RTT_MR_RTC1HZ;
133  }
134 }
135 
136 void rtt_enable(Rtt *p_rtt)
137 {
138  p_rtt->RTT_MR &= ~RTT_MR_RTTDIS;
139 }
145 void rtt_disable(Rtt *p_rtt)
146 {
147  p_rtt->RTT_MR |= RTT_MR_RTTDIS;
148 }
149 #endif
150 
157 void rtt_enable_interrupt(Rtt *p_rtt, uint32_t ul_sources)
158 {
159  uint32_t temp;
160 
161  temp = p_rtt->RTT_MR;
162  temp |= ul_sources;
163 #if (SAM4N || SAM4S || SAM4E || SAM4C || SAMG51 || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
164  temp |= g_wobits_in_rtt_mr;
165 #endif
166  p_rtt->RTT_MR = temp;
167 }
168 
175 void rtt_disable_interrupt(Rtt *p_rtt, uint32_t ul_sources)
176 {
177  uint32_t temp = 0;
178 
179  temp = p_rtt->RTT_MR;
180  temp &= (~ul_sources);
181 #if (SAM4N || SAM4S || SAM4E || SAM4C || SAMG51 || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
182  temp |= g_wobits_in_rtt_mr;
183 #endif
184  p_rtt->RTT_MR = temp;
185 }
186 
194 uint32_t rtt_read_timer_value(Rtt *p_rtt)
195 {
196  uint32_t rtt_val = p_rtt->RTT_VR;
197 
198  while (rtt_val != p_rtt->RTT_VR) {
199  rtt_val = p_rtt->RTT_VR;
200  }
201 
202  return rtt_val;
203 }
204 
212 uint32_t rtt_get_status(Rtt *p_rtt)
213 {
214  return p_rtt->RTT_SR;
215 }
216 
227 uint32_t rtt_write_alarm_time(Rtt *p_rtt, uint32_t ul_alarm_time)
228 {
229  uint32_t flag;
230 
231  flag = p_rtt->RTT_MR & RTT_MR_ALMIEN;
232 
234 
239  if(ul_alarm_time == 0) {
240  p_rtt->RTT_AR = 0xFFFFFFFF;
241  }
242  else {
243  p_rtt->RTT_AR = ul_alarm_time - 1;
244  }
245 
246  if (flag) {
248  }
249 
250  return 0;
251 }
252 
254 
256 
257 #ifdef __cplusplus
258 }
259 #endif
260 
261 
__I uint32_t RTT_SR
(Rtt Offset: 0x0C) Status Register
uint32_t rtt_init(Rtt *p_rtt, uint16_t us_prescaler)
Initialize the given RTT.
Definition: rtt.c:78
void rtt_enable_interrupt(Rtt *p_rtt, uint32_t ul_sources)
Enable RTT interrupts.
Definition: rtt.c:157
Real-time Timer (RTT) driver for SAM.
#define RTT_MR_RTTRST
(RTT_MR) Real-time Timer Restart
#define RTT_MR_ALMIEN
(RTT_MR) Alarm Interrupt Enable
__IO uint32_t RTT_AR
(Rtt Offset: 0x04) Alarm Register
uint32_t rtt_read_timer_value(Rtt *p_rtt)
Read the current value of the RTT timer value.
Definition: rtt.c:194
#define RTT
(RTT ) Base Address
Definition: same70j19.h:534
#define RTT_MR_RTC1HZ
(RTT_MR) Real-Time Clock 1Hz Clock Selection
uint32_t rtt_write_alarm_time(Rtt *p_rtt, uint32_t ul_alarm_time)
Configure the RTT to generate an alarm at the given time. alarm happens when CRTV value equals ALMV+1...
Definition: rtt.c:227
__I uint32_t RTT_VR
(Rtt Offset: 0x08) Value Register
Rtt hardware registers.
uint32_t rtt_get_status(Rtt *p_rtt)
Get the status register value of the given RTT.
Definition: rtt.c:212
#define RTT_MR_RTTDIS
(RTT_MR) Real-time Timer Disable
void rtt_disable_interrupt(Rtt *p_rtt, uint32_t ul_sources)
Disable RTT interrupts.
Definition: rtt.c:175
__IO uint32_t RTT_MR
(Rtt Offset: 0x00) Mode Register


inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:04