Changeset 374 for asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/targets/TARGET_RENESAS/TARGET_RZA1XX/rtc_api.c
- Timestamp:
- Apr 5, 2019, 9:26:53 PM (5 years ago)
- Location:
- asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/targets/TARGET_RENESAS/TARGET_RZA1XX
- Files:
-
- 1 added
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/targets/TARGET_RENESAS/TARGET_RZA1XX/rtc_api.c
r373 r374 21 21 22 22 #include "rtc_api.h" 23 #include "rtc_iodefine.h" 24 23 #include "iodefine.h" 24 #include "mbed_drv_cfg.h" 25 #include "mbed_mktime.h" 25 26 26 27 #define RCR1_VAL_ON (0x08u) // AIE = 1 27 28 #define RCR1_VAL_OFF (0x00u) 29 #define RCR3_VAL (0x00u) 30 #define RCR5_VAL (0x00u) 31 32 #ifdef USE_RTCX1_CLK 33 #define RCR2_VAL_ALLSTOP (0x08u) 34 #define RCR2_VAL_START (0x09u) // START = 1 35 #define RCR2_VAL_RESET (0x0Au) // RESET = 1 36 #define RCR5_VAL_RTCX1 (0x00u) // RCKSEL = clock rtc from RTCX1(32.768 kHz) 37 #elif defined(USE_EXTAL_CLK) 28 38 #define RCR2_VAL_ALLSTOP (0x00u) 29 39 #define RCR2_VAL_START (0x01u) // START = 1 30 40 #define RCR2_VAL_RESET (0x02u) // RESET = 1 31 #define RCR3_VAL (0x00u) 32 #define RCR5_VAL_EXTAL (0x01u) // RCKSEL = connect EXTAL 33 #define RCR5_VAL_RTCX1 (0x00u) // RCKSEL = disconnect EXTAL 41 #define RCR5_VAL_EXTAL (0x01u) // RCKSEL = clock rtc from EXTAL 34 42 #define RFRH_VAL_13333 (0x8003u) // 13.3333MHz (= 64Hz * 0x32DCD) 35 43 #define RFRL_VAL_13333 (0x2DCDu) // 44 #elif defined(USE_RTCX3_CLK) 45 #define RCR2_VAL_ALLSTOP (0x08u) 46 #define RCR2_VAL_START (0x09u) // START = 1 47 #define RCR2_VAL_RESET (0x0Au) // RESET = 1 48 #define RCR5_VAL_RTCX3 (0x02u) // RCKSEL = clock rtc from RTCX3(4.000 MHz) 49 #define RFRH_VAL_4000 (0x8000u) // 4.000MHz (= 64Hz * 0xF424) 50 #define RFRL_VAL_4000 (0xF424u) // 51 #else 52 #error Select RTC clock input ! 53 #endif 54 36 55 #define RFRH_VAL_MAX (0x0007u) // MAX value (= 128Hz * 0x7FFFF) 37 56 #define RFRL_VAL_MAX (0xFFFFu) // … … 48 67 #define SHIFT_2BYTE (16u) 49 68 50 #define TIME_ERROR_VAL (0 xFFFFFFFFu)69 #define TIME_ERROR_VAL (0u) 51 70 52 71 static int rtc_dec8_to_hex(uint8_t dec_val, uint8_t offset, int *hex_val); … … 64 83 * None. 65 84 */ 66 void rtc_init(void) { 85 void rtc_init(void) 86 { 67 87 volatile uint8_t dummy_read; 88 89 CPG.STBCR6 &= ~(CPG_STBCR6_BIT_MSTP60); 68 90 69 91 // Set control register … … 71 93 RTC.RCR1 = RCR1_VAL_ON; 72 94 RTC.RCR3 = RCR3_VAL; 95 96 #ifdef USE_RTCX1_CLK 97 RTC.RCR5 = RCR5_VAL_RTCX1; 98 RTC.RFRH = 0; 99 RTC.RFRL = 0; 100 #elif defined(USE_EXTAL_CLK) 73 101 RTC.RCR5 = RCR5_VAL_EXTAL; 74 102 RTC.RFRH = RFRH_VAL_13333; 75 103 RTC.RFRL = RFRL_VAL_13333; 76 104 #else 105 RTC.RCR5 = RCR5_VAL_RTCX3; 106 RTC.RFRH = RFRH_VAL_4000; 107 RTC.RFRL = RFRL_VAL_4000; 108 #endif 77 109 // Dummy read 78 110 dummy_read = RTC.RCR2; 79 111 dummy_read = RTC.RCR2; 80 112 81 RTC.RCR2 = RCR2_VAL_ RESET; // RESET = 1113 RTC.RCR2 = RCR2_VAL_START; // SRART = 1 82 114 83 115 // Dummy read … … 85 117 dummy_read = RTC.RCR2; 86 118 87 // Set timer and alarm. Default value :01-01-1970 00:00:00 88 RTC.RSECCNT = 0; 89 RTC.RMINCNT = 0; 90 RTC.RHRCNT = 0; 91 RTC.RWKCNT = 0; 92 RTC.RDAYCNT = 1; 93 RTC.RMONCNT = 1; 94 RTC.RYRCNT = 0x1970; 95 RTC.RSECAR = 0; 96 RTC.RMINAR = 0; 97 RTC.RHRAR = 0; 98 RTC.RWKAR = 0; 99 RTC.RDAYAR = 1; 100 RTC.RMONAR = 1; 101 RTC.RYRAR = 0x1970; 102 103 // Dummy read 104 dummy_read = RTC.RYRCNT; 105 dummy_read = RTC.RYRCNT; 119 (void)dummy_read; 106 120 107 121 } … … 110 124 /* 111 125 * Release the RTC based on a time structure. 112 * [in] 113 * None. 114 * [out] 115 * None. 116 */ 117 void rtc_free(void) { 118 volatile uint8_t dummy_read; 119 120 // Set control register 121 RTC.RCR2 = RCR2_VAL_ALLSTOP; 122 RTC.RCR1 = RCR1_VAL_OFF; 123 RTC.RCR3 = RCR3_VAL; 124 RTC.RCR5 = RCR5_VAL_RTCX1; 125 RTC.RFRH = RFRH_VAL_MAX; 126 RTC.RFRL = RFRL_VAL_MAX; 127 128 // Dummy read 129 dummy_read = RTC.RCR2; 130 dummy_read = RTC.RCR2; 131 RTC.RCR2 = RCR2_VAL_RESET; // RESET = 1 132 133 // Dummy read 134 dummy_read = RTC.RCR2; 135 dummy_read = RTC.RCR2; 136 137 // Set timer and alarm. Default value :01-01-1970 00:00:00 138 RTC.RSECCNT = 0; 139 RTC.RMINCNT = 0; 140 RTC.RHRCNT = 0; 141 RTC.RWKCNT = 0; 142 RTC.RDAYCNT = 1; 143 RTC.RMONCNT = 1; 144 RTC.RYRCNT = 0x1970; 145 RTC.RSECAR = 0; 146 RTC.RMINAR = 0; 147 RTC.RHRAR = 0; 148 RTC.RWKAR = 0; 149 RTC.RDAYAR = 1; 150 RTC.RMONAR = 1; 151 RTC.RYRAR = 0x1970; 152 153 // Dummy read 154 dummy_read = RTC.RYRCNT; 155 dummy_read = RTC.RYRCNT; 156 126 * @note This function does not stop the RTC from counting 127 * [in] 128 * None. 129 * [out] 130 * None. 131 */ 132 void rtc_free(void) 133 { 157 134 } 158 135 … … 166 143 * 0:Disabled, 1:Enabled. 167 144 */ 168 int rtc_isenabled(void) { 145 int rtc_isenabled(void) 146 { 169 147 int ret_val = 0; 170 148 … … 184 162 * UNIX timestamp value. 185 163 */ 186 time_t rtc_read(void) { 164 time_t rtc_read(void) 165 { 187 166 188 167 struct tm timeinfo; … … 214 193 if (err == 0) { 215 194 // Convert to timestamp 216 t = mktime(&timeinfo); 195 if (_rtc_maketime(&timeinfo, &t, RTC_FULL_LEAP_YEAR_SUPPORT) == false) { 196 return TIME_ERROR_VAL; 197 } 217 198 } else { 218 199 // Error … … 233 214 * 1:Error 234 215 */ 235 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 { 236 218 int err = 0; 237 219 uint8_t ret_val; … … 267 249 * 1:Error 268 250 */ 269 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 { 270 253 int err = 0; 271 254 uint16_t ret_val; … … 302 285 * None. 303 286 */ 304 void rtc_write(time_t t) { 305 306 struct tm *timeinfo = localtime(&t); 287 void rtc_write(time_t t) 288 { 289 290 struct tm timeinfo; 291 if (_rtc_localtime(t, &timeinfo, RTC_FULL_LEAP_YEAR_SUPPORT) == false) { 292 return; 293 } 294 307 295 volatile uint16_t dummy_read; 308 296 … … 315 303 dummy_read = (uint16_t)RTC.RCR2; 316 304 317 RTC.RSECCNT = rtc_hex8_to_dec(timeinfo ->tm_sec);318 RTC.RMINCNT = rtc_hex8_to_dec(timeinfo ->tm_min);319 RTC.RHRCNT = rtc_hex8_to_dec(timeinfo ->tm_hour);320 RTC.RDAYCNT = rtc_hex8_to_dec(timeinfo ->tm_mday);321 RTC.RMONCNT = rtc_hex8_to_dec(timeinfo ->tm_mon + 1);322 RTC.RYRCNT = rtc_hex16_to_dec(timeinfo ->tm_year + 1900);305 RTC.RSECCNT = rtc_hex8_to_dec(timeinfo.tm_sec); 306 RTC.RMINCNT = rtc_hex8_to_dec(timeinfo.tm_min); 307 RTC.RHRCNT = rtc_hex8_to_dec(timeinfo.tm_hour); 308 RTC.RDAYCNT = rtc_hex8_to_dec(timeinfo.tm_mday); 309 RTC.RMONCNT = rtc_hex8_to_dec(timeinfo.tm_mon + 1); 310 RTC.RYRCNT = rtc_hex16_to_dec(timeinfo.tm_year + 1900); 323 311 dummy_read = (uint16_t)RTC.RYRCNT; 324 312 dummy_read = (uint16_t)RTC.RYRCNT; … … 328 316 dummy_read = (uint16_t)RTC.RCR2; 329 317 dummy_read = (uint16_t)RTC.RCR2; 318 (void)dummy_read; 330 319 } 331 320 } … … 338 327 * decimal value:From 0x00 to 0x99. 339 328 */ 340 static uint8_t rtc_hex8_to_dec(uint8_t hex_val) { 329 static uint8_t rtc_hex8_to_dec(uint8_t hex_val) 330 { 341 331 uint32_t calc_data; 342 332 … … 358 348 * decimal value:From 0x0000 to 0x9999. 359 349 */ 360 static uint16_t rtc_hex16_to_dec(uint16_t hex_val) { 350 static uint16_t rtc_hex16_to_dec(uint16_t hex_val) 351 { 361 352 uint32_t calc_data; 362 353 calc_data = hex_val / 1000 * 0x1000;
Note:
See TracChangeset
for help on using the changeset viewer.