250 lines
7.9 KiB
C
250 lines
7.9 KiB
C
|
/************************************************************************************
|
||
|
* arch/arm/src/stm32/stm32f40xxx_rtc.c
|
||
|
*
|
||
|
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||
|
*
|
||
|
* Redistribution and use in source and binary forms, with or without
|
||
|
* modification, are permitted provided that the following conditions
|
||
|
* are met:
|
||
|
*
|
||
|
* 1. Redistributions of source code must retain the above copyright
|
||
|
* notice, this list of conditions and the following disclaimer.
|
||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||
|
* notice, this list of conditions and the following disclaimer in
|
||
|
* the documentation and/or other materials provided with the
|
||
|
* distribution.
|
||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||
|
* used to endorse or promote products derived from this software
|
||
|
* without specific prior written permission.
|
||
|
*
|
||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||
|
*
|
||
|
************************************************************************************/
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Included Files
|
||
|
************************************************************************************/
|
||
|
|
||
|
#include <nuttx/config.h>
|
||
|
|
||
|
#include <nuttx/arch.h>
|
||
|
#include <nuttx/irq.h>
|
||
|
#include <nuttx/rtc.h>
|
||
|
|
||
|
#include <arch/board/board.h>
|
||
|
|
||
|
#include "up_arch.h"
|
||
|
|
||
|
#include "stm32_rtc.h"
|
||
|
|
||
|
#ifdef CONFIG_RTC
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Pre-processor Definitions
|
||
|
************************************************************************************/
|
||
|
/* Configuration ********************************************************************/
|
||
|
/* This RTC implementation supports only date/time RTC hardware */
|
||
|
|
||
|
#ifndef CONFIG_RTC_DATETIME
|
||
|
# error "CONFIG_RTC_DATETIME must be set to use this driver"
|
||
|
#endif
|
||
|
|
||
|
#ifndef CONFIG_RTC_HIRES
|
||
|
# error "CONFIG_RTC_HIRES must NOT be set with this driver"
|
||
|
#endif
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Private Types
|
||
|
************************************************************************************/
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Private Data
|
||
|
************************************************************************************/
|
||
|
|
||
|
/* Callback to use when the alarm expires */
|
||
|
|
||
|
#ifdef CONFIG_RTC_ALARM
|
||
|
static alarmcb_t g_alarmcb;
|
||
|
#endif
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Public Data
|
||
|
************************************************************************************/
|
||
|
|
||
|
/* g_rtc_enabled is set true after the RTC has successfully initialized */
|
||
|
|
||
|
volatile bool g_rtc_enabled = false;
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Private Functions
|
||
|
************************************************************************************/
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Name: stm32_rtc_interrupt
|
||
|
*
|
||
|
* Description:
|
||
|
* RTC interrupt service routine
|
||
|
*
|
||
|
* Input Parameters:
|
||
|
* irq - The IRQ number that generated the interrupt
|
||
|
* context - Architecture specific register save information.
|
||
|
*
|
||
|
* Returned Value:
|
||
|
* Zero (OK) on success; A negated errno value on failure.
|
||
|
*
|
||
|
************************************************************************************/
|
||
|
|
||
|
#if CONFIG_RTC_ALARM
|
||
|
static int stm32_rtc_interrupt(int irq, void *context)
|
||
|
{
|
||
|
#warning "Missing logic"
|
||
|
return OK;
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Public Functions
|
||
|
************************************************************************************/
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Name: up_rtcinitialize
|
||
|
*
|
||
|
* Description:
|
||
|
* Initialize the hardware RTC per the selected configuration. This function is
|
||
|
* called once during the OS initialization sequence
|
||
|
*
|
||
|
* Input Parameters:
|
||
|
* None
|
||
|
*
|
||
|
* Returned Value:
|
||
|
* Zero (OK) on success; a negated errno on failure
|
||
|
*
|
||
|
************************************************************************************/
|
||
|
|
||
|
int up_rtcinitialize(void)
|
||
|
{
|
||
|
/* Initialize the RTC */
|
||
|
#warning "Missing logic"
|
||
|
|
||
|
/* Configure RTC interrupt to catch alarm interrupts. */
|
||
|
|
||
|
#ifdef CONFIG_RTC_ALARM
|
||
|
irq_attach(STM32_IRQ_RTC, stm32_rtc_interrupt);
|
||
|
up_enable_irq(STM32_IRQ_RTC);
|
||
|
#endif
|
||
|
|
||
|
g_rtc_enabled = true;
|
||
|
return OK;
|
||
|
}
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Name: up_rtc_getdatetime
|
||
|
*
|
||
|
* Description:
|
||
|
* Get the current date and time from the date/time RTC. This interface
|
||
|
* is only supported by the date/time RTC hardware implementation.
|
||
|
* It is used to replace the system timer. It is only used by the RTOS during
|
||
|
* intialization to set up the system time when CONFIG_RTC and CONFIG_RTC_DATETIME
|
||
|
* are selected (and CONFIG_RTC_HIRES is not).
|
||
|
*
|
||
|
* NOTE: Some date/time RTC hardware is capability of sub-second accuracy. That
|
||
|
* sub-second accuracy is lost in this interface. However, since the system time
|
||
|
* is reinitialized on each power-up/reset, there will be no timing inaccuracy in
|
||
|
* the long run.
|
||
|
*
|
||
|
* Input Parameters:
|
||
|
* tp - The location to return the high resolution time value.
|
||
|
*
|
||
|
* Returned Value:
|
||
|
* Zero (OK) on success; a negated errno on failure
|
||
|
*
|
||
|
************************************************************************************/
|
||
|
|
||
|
int up_rtc_getdatetime(FAR const struct tm *tp)
|
||
|
{
|
||
|
#warning "Missing logic"
|
||
|
return OK;
|
||
|
}
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Name: up_rtc_settime
|
||
|
*
|
||
|
* Description:
|
||
|
* Set the RTC to the provided time. All RTC implementations must be able to
|
||
|
* set their time based on a standard timespec.
|
||
|
*
|
||
|
* Input Parameters:
|
||
|
* tp - the time to use
|
||
|
*
|
||
|
* Returned Value:
|
||
|
* Zero (OK) on success; a negated errno on failure
|
||
|
*
|
||
|
************************************************************************************/
|
||
|
|
||
|
int up_rtc_settime(FAR const struct timespec *tp)
|
||
|
{
|
||
|
/* Break out the time values */
|
||
|
#warning "Missing logic"
|
||
|
|
||
|
/* Then write the broken out values to the RTC */
|
||
|
#warning "Missing logic"
|
||
|
|
||
|
return OK;
|
||
|
}
|
||
|
|
||
|
/************************************************************************************
|
||
|
* Name: up_rtc_setalarm
|
||
|
*
|
||
|
* Description:
|
||
|
* Set up an alarm.
|
||
|
*
|
||
|
* Input Parameters:
|
||
|
* tp - the time to set the alarm
|
||
|
* callback - the function to call when the alarm expires.
|
||
|
*
|
||
|
* Returned Value:
|
||
|
* Zero (OK) on success; a negated errno on failure
|
||
|
*
|
||
|
************************************************************************************/
|
||
|
|
||
|
#ifdef CONFIG_RTC_ALARM
|
||
|
int up_rtc_setalarm(FAR const struct timespec *tp, alarmcb_t callback);
|
||
|
{
|
||
|
irqstate_t flags;
|
||
|
int ret = -EBUSY;
|
||
|
|
||
|
/* Is there already something waiting on the ALARM? */
|
||
|
|
||
|
if (g_alarmcb == NULL)
|
||
|
{
|
||
|
/* No.. Save the callback function pointer */
|
||
|
|
||
|
g_alarmcb = callback;
|
||
|
|
||
|
/* Break out the time values */
|
||
|
#warning "Missing logic"
|
||
|
|
||
|
/* The set the alarm */
|
||
|
#warning "Missing logic"
|
||
|
|
||
|
ret = OK;
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#endif /* CONFIG_RTC */
|
||
|
|