Skip to content

Commit f55bece

Browse files
TomoYamanakabulislaw
authored andcommitted
Implement of RTC feature for Renesas mbed boards
I implemented the RTC feature. The mainly changing is here. - rtc_init() Previously, I have initialized the time information register in the function, so the time count was cleaned by every calling rtc_init(). Currently, rtc_init() doesn't stop RTC from counting, and rtc_init() is safe to call repeatedly. Therefore in order to satisfy specifications,I removed the initialization process of the time information register in the function. - rtc_free() Previously, I have initialized the RTC related register same as rtc_init(), so the time count was cleaned by calling rtc_free(). Currently, rtc_free() doesn't stop RTC from counting. Therefore in order to satisfy specifications,I removed the process and decided not to do anything in the function. If powerdown the RTC, Supply of the clock to the RTC is stopped, cannot keeping the count.
1 parent 1e46895 commit f55bece

File tree

2 files changed

+21
-70
lines changed

2 files changed

+21
-70
lines changed

targets/TARGET_RENESAS/TARGET_RZ_A1XX/rtc_api.c

Lines changed: 20 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ static uint16_t rtc_hex16_to_dec(uint16_t hex_val);
8282
* [out]
8383
* None.
8484
*/
85-
void rtc_init(void) {
85+
void rtc_init(void)
86+
{
8687
volatile uint8_t dummy_read;
8788

8889
CPG.STBCR6 &= ~(CPG_STBCR6_BIT_MSTP60);
@@ -109,84 +110,27 @@ void rtc_init(void) {
109110
dummy_read = RTC.RCR2;
110111
dummy_read = RTC.RCR2;
111112

112-
RTC.RCR2 = RCR2_VAL_RESET; // RESET = 1
113+
RTC.RCR2 = RCR2_VAL_START; // SRART = 1
113114

114115
// Dummy read
115116
dummy_read = RTC.RCR2;
116117
dummy_read = RTC.RCR2;
117118

118-
// Set timer and alarm. Default value :01-01-1970 00:00:00
119-
RTC.RSECCNT = 0;
120-
RTC.RMINCNT = 0;
121-
RTC.RHRCNT = 0;
122-
RTC.RWKCNT = 0;
123-
RTC.RDAYCNT = 1;
124-
RTC.RMONCNT = 1;
125-
RTC.RYRCNT = 0x1970;
126-
RTC.RSECAR = 0;
127-
RTC.RMINAR = 0;
128-
RTC.RHRAR = 0;
129-
RTC.RWKAR = 0;
130-
RTC.RDAYAR = 1;
131-
RTC.RMONAR = 1;
132-
RTC.RYRAR = 0x1970;
133-
134-
// Dummy read
135-
dummy_read = RTC.RYRCNT;
136-
dummy_read = RTC.RYRCNT;
137119
(void)dummy_read;
138120

139121
}
140122

141123

142124
/*
143125
* Release the RTC based on a time structure.
126+
* @note This function does not stop the RTC from counting
144127
* [in]
145128
* None.
146129
* [out]
147130
* None.
148131
*/
149-
void rtc_free(void) {
150-
volatile uint8_t dummy_read;
151-
152-
// Set control register
153-
RTC.RCR2 = RCR2_VAL_ALLSTOP;
154-
RTC.RCR1 = RCR1_VAL_OFF;
155-
RTC.RCR3 = RCR3_VAL;
156-
RTC.RCR5 = RCR5_VAL;
157-
RTC.RFRH = RFRH_VAL_MAX;
158-
RTC.RFRL = RFRL_VAL_MAX;
159-
160-
// Dummy read
161-
dummy_read = RTC.RCR2;
162-
dummy_read = RTC.RCR2;
163-
RTC.RCR2 = RCR2_VAL_RESET; // RESET = 1
164-
165-
// Dummy read
166-
dummy_read = RTC.RCR2;
167-
dummy_read = RTC.RCR2;
168-
169-
// Set timer and alarm. Default value :01-01-1970 00:00:00
170-
RTC.RSECCNT = 0;
171-
RTC.RMINCNT = 0;
172-
RTC.RHRCNT = 0;
173-
RTC.RWKCNT = 0;
174-
RTC.RDAYCNT = 1;
175-
RTC.RMONCNT = 1;
176-
RTC.RYRCNT = 0x1970;
177-
RTC.RSECAR = 0;
178-
RTC.RMINAR = 0;
179-
RTC.RHRAR = 0;
180-
RTC.RWKAR = 0;
181-
RTC.RDAYAR = 1;
182-
RTC.RMONAR = 1;
183-
RTC.RYRAR = 0x1970;
184-
185-
// Dummy read
186-
dummy_read = RTC.RYRCNT;
187-
dummy_read = RTC.RYRCNT;
188-
(void)dummy_read;
189-
132+
void rtc_free(void)
133+
{
190134
}
191135

192136

@@ -198,7 +142,8 @@ void rtc_free(void) {
198142
* [out]
199143
* 0:Disabled, 1:Enabled.
200144
*/
201-
int rtc_isenabled(void) {
145+
int rtc_isenabled(void)
146+
{
202147
int ret_val = 0;
203148

204149
if ((RTC.RCR1 & RCR1_VAL_ON) != 0) { // RTC ON ?
@@ -216,7 +161,8 @@ int rtc_isenabled(void) {
216161
* [out]
217162
* UNIX timestamp value.
218163
*/
219-
time_t rtc_read(void) {
164+
time_t rtc_read(void)
165+
{
220166

221167
struct tm timeinfo;
222168
int err = 0;
@@ -267,7 +213,8 @@ time_t rtc_read(void) {
267213
* 0:Success
268214
* 1:Error
269215
*/
270-
static int rtc_dec8_to_hex(uint8_t dec_val, uint8_t offset, int *hex_val) {
216+
static int rtc_dec8_to_hex(uint8_t dec_val, uint8_t offset, int *hex_val)
217+
{
271218
int err = 0;
272219
uint8_t ret_val;
273220

@@ -301,7 +248,8 @@ static int rtc_dec8_to_hex(uint8_t dec_val, uint8_t offset, int *hex_val) {
301248
* 0:Success
302249
* 1:Error
303250
*/
304-
static int rtc_dec16_to_hex(uint16_t dec_val, uint16_t offset, int *hex_val) {
251+
static int rtc_dec16_to_hex(uint16_t dec_val, uint16_t offset, int *hex_val)
252+
{
305253
int err = 0;
306254
uint16_t ret_val;
307255

@@ -336,7 +284,8 @@ static int rtc_dec16_to_hex(uint16_t dec_val, uint16_t offset, int *hex_val) {
336284
* [out]
337285
* None.
338286
*/
339-
void rtc_write(time_t t) {
287+
void rtc_write(time_t t)
288+
{
340289

341290
struct tm timeinfo;
342291
if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) {
@@ -377,7 +326,8 @@ void rtc_write(time_t t) {
377326
* [out]
378327
* decimal value:From 0x00 to 0x99.
379328
*/
380-
static uint8_t rtc_hex8_to_dec(uint8_t hex_val) {
329+
static uint8_t rtc_hex8_to_dec(uint8_t hex_val)
330+
{
381331
uint32_t calc_data;
382332

383333
calc_data = hex_val / 10 * 0x10;
@@ -397,7 +347,8 @@ static uint8_t rtc_hex8_to_dec(uint8_t hex_val) {
397347
* [out]
398348
* decimal value:From 0x0000 to 0x9999.
399349
*/
400-
static uint16_t rtc_hex16_to_dec(uint16_t hex_val) {
350+
static uint16_t rtc_hex16_to_dec(uint16_t hex_val)
351+
{
401352
uint32_t calc_data;
402353
calc_data = hex_val / 1000 * 0x1000;
403354
calc_data += ((hex_val / 100) % 10) * 0x100;

targets/targets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2785,7 +2785,7 @@
27852785
"core": "Cortex-A9",
27862786
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
27872787
"extra_labels": ["RENESAS", "RZ_A1XX"],
2788-
"device_has": ["SLEEP", "USTICKER", "ANALOGIN", "CAN", "ETHERNET", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
2788+
"device_has": ["SLEEP", "USTICKER", "RTC", "ANALOGIN", "CAN", "ETHERNET", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
27892789
"features": ["LWIP"],
27902790
"program_cycle_s": 2,
27912791
"overrides": {

0 commit comments

Comments
 (0)