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 <Tamas.Ban@arm.com>
pull/4414/head
Tamas Ban 2017-05-18 15:35:43 +02:00 committed by Marc Moreno Berengue
parent fb6a2c075c
commit 439363d12a
3 changed files with 97 additions and 1 deletions

View File

@ -779,6 +779,22 @@ typedef struct
#define CMSDK_Watchdog_INTEGTESTOUTSET_Pos 1 /* CMSDK_Watchdog INTEGTESTOUTSET: Integration Test Output Set Position */
#define CMSDK_Watchdog_INTEGTESTOUTSET_Msk (0x1ul << CMSDK_Watchdog_INTEGTESTOUTSET_Pos) /* CMSDK_Watchdog INTEGTESTOUTSET: Integration Test Output Set Mask */
/*------------------------- Real Time Clock(RTC) ----------------------------------------------*/
typedef struct
{
__I uint32_t RTCDR; /* 0x00 RO RTC Data Register */
__IO uint32_t RTCMR; /* 0x04 RW RTC Match Register */
__IO uint32_t RTCLR; /* 0x08 RW RTC Load Register */
__IO uint32_t RTCCR; /* 0x0C RW RTC Control Register */
__IO uint32_t RTCIMSC; /* 0x10 RW RTC Inerrupt Mask Set and Clear Register */
__I uint32_t RTCRIS; /* 0x14 RO RTC Raw Inerrupt Status Register */
__I uint32_t RTCMIS; /* 0x18 RO RTC Masked Inerrupt Status Register */
__O uint32_t RTCICR; /* 0x1C WO RTC Interrupt Clear Register */
} CMSDK_RTC_TypeDef;
#define CMSDK_RTC_Enable_Pos 0 /* CMSDK_RTC Enable: Real Time Clock Enable Position */
#define CMSDK_RTC_Enable_Msk (0x1ul << CMSDK_RTC_Enable_Pos) /* CMSDK_RTC Enable: Real Time Clock Enable Mask */
/* -------------------- End of section using anonymous unions ------------------- */
#if defined ( __CC_ARM )
#pragma pop
@ -821,6 +837,7 @@ typedef struct
#define CMSDK_UART2_BASE (0x4002C000UL)
#define CMSDK_UART3_BASE (0x4002D000UL)
#define CMSDK_UART4_BASE (0x4002E000UL)
#define CMSDK_RTC_BASE (CMSDK_APB_BASE + 0x6000UL)
#define CMSDK_WATCHDOG_BASE (CMSDK_APB_BASE + 0x8000UL)
/* AHB peripherals */
@ -848,6 +865,7 @@ typedef struct
#define CMSDK_DUALTIMER ((CMSDK_DUALTIMER_BOTH_TypeDef *) CMSDK_DUALTIMER_BASE )
#define CMSDK_DUALTIMER1 ((CMSDK_DUALTIMER_SINGLE_TypeDef *) CMSDK_DUALTIMER_1_BASE )
#define CMSDK_DUALTIMER2 ((CMSDK_DUALTIMER_SINGLE_TypeDef *) CMSDK_DUALTIMER_2_BASE )
#define CMSDK_RTC ((CMSDK_RTC_TypeDef *) CMSDK_RTC_BASE )
#define CMSDK_WATCHDOG ((CMSDK_WATCHDOG_TypeDef *) CMSDK_WATCHDOG_BASE )
#define CMSDK_DMA ((CMSDK_PL230_TypeDef *) CMSDK_PL230_BASE )
#define CMSDK_GPIO0 ((CMSDK_GPIO_TypeDef *) CMSDK_GPIO0_BASE )

View File

@ -0,0 +1,78 @@
/*
* Copyright (c) 2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "rtc_api.h"
#include "device.h"
#include "cmsis.h"
/**
* \defgroup hal_rtc RTC hal functions
* @{
*/
/**
* \brief Initialize the RTC peripheral.
* The RTC starts counting from 0x0 at reset and increments
* with a frequency of 1hz (clock source: CLK1HZ).
* The current value can be read through the DATA register
*/
void rtc_init(void)
{
CMSDK_RTC->RTCCR |= (1 << CMSDK_RTC_Enable_Pos);
}
/**
* \brief Deinitialize the RTC peripheral
* According to DDI0224B_RTC_PL031_TRM.pdf chapter 3.3.4 there is
* no reason to implement.
*/
void rtc_free(void)
{
/* Not supported */
}
/**
* \brief Get the RTC enable status
*
* \return 0 disabled, 1 enabled
*/
int rtc_isenabled(void)
{
return (CMSDK_RTC->RTCCR & CMSDK_RTC_Enable_Msk);
}
/**
* \brief Get the current time from the RTC peripheral
*
* \return The current time in seconds
*/
time_t rtc_read(void)
{
return (time_t)CMSDK_RTC->RTCDR;
}
/**
* \brief Set the current time to the RTC peripheral, write it to LOAD register
*
* \param[in] t The current time to be set in seconds
*/
void rtc_write(time_t t)
{
CMSDK_RTC->RTCLR = (uint32_t)t;
}
/**@}*/

View File

@ -1938,7 +1938,7 @@
"supported_toolchains": ["ARM"],
"extra_labels": ["ARM_SSG", "CM3DS_MPS2"],
"macros": ["CMSDK_CM3DS"],
"device_has": ["ETHERNET","INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SPI"],
"device_has": ["ETHERNET","INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SPI", "RTC"],
"release_versions": ["2", "5"]
},
"ARM_BEETLE_SOC": {