Skip to content

Instantly share code, notes, and snippets.

@RafaelKa RafaelKa/README.md
Last active Feb 20, 2016

Embed
What would you like to do?
Jetson TK1 integrated RTC WakeUp demo

download wake_jetson_up_in.c file and compile with following command:

wget https://gist.githubusercontent.com/RafaelKa/b1cbb4990a04134dcc03/raw/wake_jetson_up_in.c
gcc -s -Wall -Wstrict-prototypes wake_jetson_up_in.c -o wake_jetson_up_in

run

sudo ./wake_jetson_up_in 180
sudo shutdown -h now && exit

Jetson TK1 powers up by RTC WakeUp in next 3 minutes

/*
* Evidence that Jetson TK1 integrated RTC works
*
* Compile with:
* gcc -s -Wall -Wstrict-prototypes wake_jetson_up_in.c -o wake_jetson_up_in
*
* @ RafaelKa
*
*/
#include <stdio.h>
#include <linux/rtc.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char **argv) {
int fd, retval, minutes = 0, seconds = 120;
struct rtc_time rtc_tm;
struct rtc_wkalrm rtc_wake_alarm;
const char *rtc = "/dev/rtc0";
switch (argc) {
case 2:
seconds = atoi(argv[1]);
case 1:
break;
default:
fprintf(stderr, "usage: wake_jetson_up_in seconds\n");
return 1;
}
fd = open(rtc, O_RDONLY);
if (fd == -1) {
perror(rtc);
exit(errno);
}
fprintf(stderr, "\n\t\tJetson TK1 Wake-Up Demo\n\n");
/* Read current date-time from RTC device */
retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
if (retval == -1) {
perror("RTC_RD_TIME ioctl");
exit(errno);
}
fprintf(stderr, "Current time is %02d:%02d:%02d .\n\n", rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
rtc_tm.tm_sec += seconds;
if (rtc_tm.tm_sec >= 60) {
rtc_tm.tm_sec %= 60;
minutes = seconds/60;
rtc_tm.tm_min += minutes;
rtc_tm.tm_min %= 60;
}
retval = ioctl(fd, RTC_WKALM_RD, &rtc_wake_alarm);
if (retval == -1) {
perror("RTC_WKALM_RD ioctl");
exit(errno);
}
rtc_wake_alarm.enabled = 1;
rtc_wake_alarm.time = rtc_tm;
retval = ioctl(fd, RTC_WKALM_SET, &rtc_wake_alarm);
if (retval == -1) {
perror("RTC_WKALM_SET ioctl");
exit(errno);
}
fprintf(stderr, "Jetson TK1 will wake up in %02d minutes %02d seconds, \n\n Also @ %02d:%02d:%02d .\n\nPlease run: \"sudo shutdown -h now\"\n",
minutes%60, seconds%60, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
return 0;
}
@TOSHIAKI1331

This comment has been minimized.

Copy link

TOSHIAKI1331 commented Feb 20, 2016

z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.