Skip to content

Commit 7ef3fbd

Browse files
committed
mbed RTC HAL for K64F
1 parent e40332f commit 7ef3fbd

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/PeripheralNames.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
extern "C" {
2323
#endif
2424

25+
typedef enum {
26+
OSC32KCLK = 0,
27+
} RTCName;
28+
2529
typedef enum {
2630
UART_0 = (int)UART0_BASE,
2731
UART_1 = (int)UART1_BASE,

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/rtc_api.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,29 @@
1414
* limitations under the License.
1515
*/
1616
#include "rtc_api.h"
17+
#include "fsl_rtc_driver.h"
1718

18-
static void init(void) {
19-
20-
}
19+
const PinMap PinMap_RTC[] = {
20+
{NC, OSC32KCLK, 0},
21+
};
2122

2223
void rtc_init(void) {
24+
rtc_init_config_t config={0};
25+
rtc_hal_init_config_t hal_config = {0};
26+
27+
hal_config.disableClockOutToPeripheral = true;
28+
if (PinMap_RTC[0].pin == NC) {
29+
hal_config.enable32kOscillator = true;
30+
}
31+
hal_config.startSecondsCounterAt = 1; /* TSR = 1 */
32+
config.general_config = &hal_config;
33+
rtc_init(&config);
2334

35+
// select RTC clock source
36+
SIM->SOPT1 &= ~SIM_SOPT1_OSC32KSEL_MASK;
37+
SIM->SOPT1 |= SIM_SOPT1_OSC32KSEL(PinMap_RTC[0].peripheral);
38+
39+
rtc_start_time_counter();
2440
}
2541

2642
void rtc_free(void) {
@@ -32,13 +48,19 @@ void rtc_free(void) {
3248
* 0 = Disabled, 1 = Enabled
3349
*/
3450
int rtc_isenabled(void) {
35-
return 1;
51+
clock_manager_set_gate(kClockModuleRTC, 0U, true);
52+
return (int)rtc_hal_is_counter_enabled();
3653
}
3754

3855
time_t rtc_read(void) {
39-
return 1;
56+
return BR_RTC_TSR_TSR;
4057
}
4158

4259
void rtc_write(time_t t) {
43-
60+
if (t == 0) {
61+
t = 1;
62+
}
63+
rtc_hal_counter_enable(false);
64+
BW_RTC_TSR_TSR(t);
65+
rtc_hal_counter_enable(true);
4466
}

0 commit comments

Comments
 (0)