-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtc.c
55 lines (47 loc) · 1.55 KB
/
rtc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "inc/hw_hibernate.h"
#include "driverlib/hibernate.h"
#include "utils/ustdlib.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
extern xSemaphoreHandle g_pRTCSemaphore;
time_t rtcSeconds; /* date/time in unix SECONDS past 1-Jan-70 */
/* initializes the hibernation RTC module */
void Rtc_Init(void)
{
unsigned long ui32SysClock;
SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
HibernateEnableExpClk(ui32SysClock);
HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);
HibernateRTCEnable();
}
/* gets the number of seconds from the hibernation counter register and converts it to calendar format */
/* use this function to get the current time and date*/
void Rtc_GetDate( struct tm *tm_ptr )
{
xSemaphoreTake( g_pRTCSemaphore, portMAX_DELAY );
ulocaltime( HibernateRTCGet(), tm_ptr );
xSemaphoreGive( g_pRTCSemaphore );
}
/* converts a date/time format to seconds to be loaded into the hibernation counter register */
/* use this function to set the current time and date*/
void Rtc_SetDate( struct tm *tm_ptr )
{
xSemaphoreTake( g_pRTCSemaphore, portMAX_DELAY );
HibernateRTCSet( umktime( tm_ptr ) );
xSemaphoreGive( g_pRTCSemaphore );
}
/* use this code to convert time to ascii for display on terminal or LCD
format the output for uart
strftime((char *)buf_rz, 32, "%c\r\n", &tm2);
UARTSend((uint8_t *)buf_rz, 32);
*/