Skip to content

Commit 439363d

Browse files
tamasbanmmorenobarm
authored andcommitted
Implement RTC(Real Time Clock) API on CM3DS target
- Modify CMSDK_CM3DS.h: add register interface - Modify targets.json: add RTC as available device to CM3DS - Create rtc_api.c: implement mandatory API functions Change-Id: I14bc1074a9ac0d5e4cbada46d3c90ca82c1e28b0 Signed-off-by: Tamas Ban <[email protected]>
1 parent fb6a2c0 commit 439363d

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/CMSDK_CM3DS.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,22 @@ typedef struct
779779
#define CMSDK_Watchdog_INTEGTESTOUTSET_Pos 1 /* CMSDK_Watchdog INTEGTESTOUTSET: Integration Test Output Set Position */
780780
#define CMSDK_Watchdog_INTEGTESTOUTSET_Msk (0x1ul << CMSDK_Watchdog_INTEGTESTOUTSET_Pos) /* CMSDK_Watchdog INTEGTESTOUTSET: Integration Test Output Set Mask */
781781

782+
/*------------------------- Real Time Clock(RTC) ----------------------------------------------*/
783+
typedef struct
784+
{
785+
__I uint32_t RTCDR; /* 0x00 RO RTC Data Register */
786+
__IO uint32_t RTCMR; /* 0x04 RW RTC Match Register */
787+
__IO uint32_t RTCLR; /* 0x08 RW RTC Load Register */
788+
__IO uint32_t RTCCR; /* 0x0C RW RTC Control Register */
789+
__IO uint32_t RTCIMSC; /* 0x10 RW RTC Inerrupt Mask Set and Clear Register */
790+
__I uint32_t RTCRIS; /* 0x14 RO RTC Raw Inerrupt Status Register */
791+
__I uint32_t RTCMIS; /* 0x18 RO RTC Masked Inerrupt Status Register */
792+
__O uint32_t RTCICR; /* 0x1C WO RTC Interrupt Clear Register */
793+
} CMSDK_RTC_TypeDef;
794+
795+
#define CMSDK_RTC_Enable_Pos 0 /* CMSDK_RTC Enable: Real Time Clock Enable Position */
796+
#define CMSDK_RTC_Enable_Msk (0x1ul << CMSDK_RTC_Enable_Pos) /* CMSDK_RTC Enable: Real Time Clock Enable Mask */
797+
782798
/* -------------------- End of section using anonymous unions ------------------- */
783799
#if defined ( __CC_ARM )
784800
#pragma pop
@@ -821,6 +837,7 @@ typedef struct
821837
#define CMSDK_UART2_BASE (0x4002C000UL)
822838
#define CMSDK_UART3_BASE (0x4002D000UL)
823839
#define CMSDK_UART4_BASE (0x4002E000UL)
840+
#define CMSDK_RTC_BASE (CMSDK_APB_BASE + 0x6000UL)
824841
#define CMSDK_WATCHDOG_BASE (CMSDK_APB_BASE + 0x8000UL)
825842

826843
/* AHB peripherals */
@@ -848,6 +865,7 @@ typedef struct
848865
#define CMSDK_DUALTIMER ((CMSDK_DUALTIMER_BOTH_TypeDef *) CMSDK_DUALTIMER_BASE )
849866
#define CMSDK_DUALTIMER1 ((CMSDK_DUALTIMER_SINGLE_TypeDef *) CMSDK_DUALTIMER_1_BASE )
850867
#define CMSDK_DUALTIMER2 ((CMSDK_DUALTIMER_SINGLE_TypeDef *) CMSDK_DUALTIMER_2_BASE )
868+
#define CMSDK_RTC ((CMSDK_RTC_TypeDef *) CMSDK_RTC_BASE )
851869
#define CMSDK_WATCHDOG ((CMSDK_WATCHDOG_TypeDef *) CMSDK_WATCHDOG_BASE )
852870
#define CMSDK_DMA ((CMSDK_PL230_TypeDef *) CMSDK_PL230_BASE )
853871
#define CMSDK_GPIO0 ((CMSDK_GPIO_TypeDef *) CMSDK_GPIO0_BASE )
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "rtc_api.h"
18+
#include "device.h"
19+
#include "cmsis.h"
20+
21+
/**
22+
* \defgroup hal_rtc RTC hal functions
23+
* @{
24+
*/
25+
26+
/**
27+
* \brief Initialize the RTC peripheral.
28+
* The RTC starts counting from 0x0 at reset and increments
29+
* with a frequency of 1hz (clock source: CLK1HZ).
30+
* The current value can be read through the DATA register
31+
*/
32+
void rtc_init(void)
33+
{
34+
CMSDK_RTC->RTCCR |= (1 << CMSDK_RTC_Enable_Pos);
35+
}
36+
37+
/**
38+
* \brief Deinitialize the RTC peripheral
39+
* According to DDI0224B_RTC_PL031_TRM.pdf chapter 3.3.4 there is
40+
* no reason to implement.
41+
*/
42+
void rtc_free(void)
43+
{
44+
/* Not supported */
45+
}
46+
47+
/**
48+
* \brief Get the RTC enable status
49+
*
50+
* \return 0 disabled, 1 enabled
51+
*/
52+
int rtc_isenabled(void)
53+
{
54+
return (CMSDK_RTC->RTCCR & CMSDK_RTC_Enable_Msk);
55+
}
56+
57+
/**
58+
* \brief Get the current time from the RTC peripheral
59+
*
60+
* \return The current time in seconds
61+
*/
62+
time_t rtc_read(void)
63+
{
64+
return (time_t)CMSDK_RTC->RTCDR;
65+
}
66+
67+
/**
68+
* \brief Set the current time to the RTC peripheral, write it to LOAD register
69+
*
70+
* \param[in] t The current time to be set in seconds
71+
*/
72+
73+
void rtc_write(time_t t)
74+
{
75+
CMSDK_RTC->RTCLR = (uint32_t)t;
76+
}
77+
/**@}*/
78+

targets/targets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@
19381938
"supported_toolchains": ["ARM"],
19391939
"extra_labels": ["ARM_SSG", "CM3DS_MPS2"],
19401940
"macros": ["CMSDK_CM3DS"],
1941-
"device_has": ["ETHERNET","INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SPI"],
1941+
"device_has": ["ETHERNET","INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SPI", "RTC"],
19421942
"release_versions": ["2", "5"]
19431943
},
19441944
"ARM_BEETLE_SOC": {

0 commit comments

Comments
 (0)