Other Parts Discussed in Thread: SYSBIOS
Hello,
I want to use the RTC that is on the board to keep track of real time. I want to have the time updated even while it is asleep.
I read over the SYS/BIOS TI-RTOS Kernel User Guide (pg. 131) Section 5.4 to write my program. But for some reason, the time is not incrementing real time.
OUTPUT:
----------- CODE -----------
#include <stdio.h>
#include <time.h>
#include <ti/sysbios/hal/Seconds.h>
// Seconds module APIs
void Seconds_set(UInt32 seconds);
UInt32 Seconds_get(void);
// Function prototypes:
void RTC_set(UInt32 *sec);
void RTC_get();
void RTC_print();
void delay();
//Global variables
UInt32 sec;
int main(void) {
int i;
// Console prompt to ask for current time
printf("Insert current time in seconds since Epoch (Jan 1, 1970)\n");
// User input of time
scanf("%d", &sec);
// Set seconds count
RTC_set(&sec);
/* DEBUG TEST:
* GET CURRENT TIME FOR 10 ITERATIONS TO SEE IF TIME INCREMENTS REAL-TIME
* WITH A DELAY ADDED
*/
for (i=0; i < 10; i++)
{
RTC_get();
delay();
}
return 0;
}
//Functions
void delay() {
int t;
for (t = 0; t < 50000; t++) {
int i = Seconds_get(); // Bogus way of trying to get a delay
}
}
// Set the Seconds module
void RTC_set(UInt32 *sec) {
Seconds_set(*sec);
RTC_get(); //Call get function
}
// Get the current time relative to Jan 1, 1970
void RTC_get()
{
UInt32 t;
t = Seconds_get();
RTC_print(); //Call print function
}
// Print out the current time
void RTC_print()
{
time_t t1;
struct tm *ltm;
t1 = time(NULL);
ltm = localtime(&t1);
printf("Time(GMT): %02d/%02d/%04d %02d:%02d:%02d\n", ltm->tm_mon + 1, ltm->tm_mday, ltm->tm_year + 1900, ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
}
Thank you.