Adding interface for RTC drivers
This commit is contained in:
parent
9b20e5010c
commit
99b2280f76
|
|
@ -1,5 +1,7 @@
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2020 by Silvano Seva IU2KWO and Niccolò Izzo IU2KIN *
|
* Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
|
||||||
|
* Niccolò Izzo IU2KIN *
|
||||||
|
* Silvano Seva IU2KWO *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
|
@ -19,14 +21,13 @@
|
||||||
#define RTC_H
|
#define RTC_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "stm32f4xx.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Driver for STM32 real time clock, providing both calendar and clock
|
* Standard interface for real time clock drivers, providing both calendar and
|
||||||
* functionalities.
|
* clock functionalities.
|
||||||
*
|
*
|
||||||
* RTC is active also when radio is powered off, thanks to the internal
|
* Depending on hardware, RTC is active also when radio is powered off, thanks
|
||||||
* lithium backup battery.
|
* to the internal lithium backup battery.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
@ -42,14 +43,12 @@ typedef struct
|
||||||
}curTime_t;
|
}curTime_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise and start RTC, which uses as clock source the external 32.768kHz
|
* Initialise and start RTC.
|
||||||
* crystal connected to PC14 and PC15 (indicated with LSE in STM32 reference
|
|
||||||
* manual).
|
|
||||||
*/
|
*/
|
||||||
void rtc_init();
|
void rtc_init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shutdown RTC and external 32.768kHz clock source.
|
* Shutdown RTC.
|
||||||
*/
|
*/
|
||||||
void rtc_shutdown();
|
void rtc_shutdown();
|
||||||
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2020 by Silvano Seva IU2KWO and Niccolò Izzo IU2KIN *
|
* Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
|
||||||
|
* Niccolò Izzo IU2KIN *
|
||||||
|
* Silvano Seva IU2KWO *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
|
@ -15,9 +17,9 @@
|
||||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <os.h>
|
||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
#include "FreeRTOS.h"
|
#include "stm32f4xx.h"
|
||||||
#include "task.h"
|
|
||||||
|
|
||||||
void rtc_init()
|
void rtc_init()
|
||||||
{
|
{
|
||||||
|
|
@ -65,13 +67,13 @@ void rtc_setTime(curTime_t t)
|
||||||
time &= RTC_TR_HT | RTC_TR_HU | RTC_TR_MNT | RTC_TR_MNU | RTC_TR_ST | RTC_TR_SU;
|
time &= RTC_TR_HT | RTC_TR_HU | RTC_TR_MNT | RTC_TR_MNU | RTC_TR_ST | RTC_TR_SU;
|
||||||
|
|
||||||
/* Enter initialisation mode and update registers */
|
/* Enter initialisation mode and update registers */
|
||||||
taskENTER_CRITICAL();
|
CPU_CRITICAL_ENTER();
|
||||||
RTC->ISR |= RTC_ISR_INIT;
|
RTC->ISR |= RTC_ISR_INIT;
|
||||||
while((RTC->ISR & RTC_ISR_INITF) == 0) ;
|
while((RTC->ISR & RTC_ISR_INITF) == 0) ;
|
||||||
RTC->TR = time;
|
RTC->TR = time;
|
||||||
RTC->DR = date;
|
RTC->DR = date;
|
||||||
RTC->ISR &= ~RTC_ISR_INIT;
|
RTC->ISR &= ~RTC_ISR_INIT;
|
||||||
taskEXIT_CRITICAL();
|
CPU_CRITICAL_EXIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
void rtc_setHour(uint8_t hours, uint8_t minutes, uint8_t seconds)
|
void rtc_setHour(uint8_t hours, uint8_t minutes, uint8_t seconds)
|
||||||
|
|
@ -118,17 +120,17 @@ void rtc_dstSet()
|
||||||
{
|
{
|
||||||
/* If BKP bit is set, DST has been already set */
|
/* If BKP bit is set, DST has been already set */
|
||||||
if(RTC->CR & RTC_CR_BCK) return;
|
if(RTC->CR & RTC_CR_BCK) return;
|
||||||
taskENTER_CRITICAL();
|
CPU_CRITICAL_ENTER();
|
||||||
RTC->CR |= RTC_CR_BCK | RTC_CR_ADD1H;
|
RTC->CR |= RTC_CR_BCK | RTC_CR_ADD1H;
|
||||||
taskEXIT_CRITICAL();
|
CPU_CRITICAL_EXIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
void rtc_dstClear()
|
void rtc_dstClear()
|
||||||
{
|
{
|
||||||
/* If BKP bit is cleared, DST has been already removed */
|
/* If BKP bit is cleared, DST has been already removed */
|
||||||
if((RTC->CR & RTC_CR_BCK) == 0) return;
|
if((RTC->CR & RTC_CR_BCK) == 0) return;
|
||||||
taskENTER_CRITICAL();
|
CPU_CRITICAL_ENTER();
|
||||||
RTC->CR &= ~RTC_CR_BCK;
|
RTC->CR &= ~RTC_CR_BCK;
|
||||||
RTC->CR |= RTC_CR_SUB1H;
|
RTC->CR |= RTC_CR_SUB1H;
|
||||||
taskEXIT_CRITICAL();
|
CPU_CRITICAL_EXIT();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue