/***************************************************************************** * * Copyright (c) 2014, Advanced Micro Devices, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 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. * * Neither the name of Advanced Micro Devices, Inc. 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 ADVANCED MICRO DEVICES, INC. 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. * * ***************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #define RTC_APP_VERSION "0.1" static const char *rtc = "/dev/rtc0"; static int rtc_fd; static int signal_recvd; static volatile int loop; char *show_prompt(void) { return "$ "; } void sighandler(int sig) { printf("\n%s", show_prompt()); } void periodicinthandler(int sig) { int ret; fprintf(stderr, "\nAborting...\n"); fflush(stderr); loop = 0; /* Turn off periodic interrupts */ ret = ioctl(rtc_fd, RTC_PIE_OFF, 0); if (ret == -1) perror("RTC_PIE_OFF ioctl"); /* Restore original handler for SIGINT */ signal(SIGINT, sighandler); } void updateinthandler(int sig) { int ret; fprintf(stderr, "\nAborting...\n"); fflush(stderr); loop = 0; /* Turn off update interrupt */ ret = ioctl(rtc_fd, RTC_UIE_OFF, 0); if (ret == -1) perror("RTC_UIE_OFF ioctl"); /* Restore original handler for SIGINT */ signal(SIGINT, sighandler); } void alarminthandler(int sig) { struct rtc_wkalrm rtc_wakealarm; int ret; signal_recvd = 1; ret = ioctl(rtc_fd, RTC_WKALM_RD, &rtc_wakealarm); if (ret == -1) { perror("RTC_WKALM_RD ioctl"); return; } /* disable alarm and set pending to 0 */ rtc_wakealarm.enabled = 0; rtc_wakealarm.pending = 0; ret = ioctl(rtc_fd, RTC_WKALM_SET, &rtc_wakealarm); if (ret == -1) { perror("RTC_WKALM_SET ioctl"); return; } /* Restore original handler for SIGINT */ signal(SIGINT, sighandler); } void show_license(void) { printf("/*****************************************************************************\n" "*\n" "* Copyright (c) 2014, Advanced Micro Devices, Inc.\n" "* All rights reserved.\n" "*\n" "* Redistribution and use in source and binary forms, with or without\n" "* modification, are permitted provided that the following conditions are met:\n" "* * Redistributions of source code must retain the above copyright\n" "* notice, this list of conditions and the following disclaimer.\n" "* * Redistributions in binary form must reproduce the above copyright\n" "* notice, this list of conditions and the following disclaimer in the\n" "* documentation and/or other materials provided with the distribution.\n" "* * Neither the name of Advanced Micro Devices, Inc. nor the names of\n" "* its contributors may be used to endorse or promote products derived\n" "* from this software without specific prior written permission.\n" "*\n" "* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n" "* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n" "* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n" "* DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY\n" "* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n" "* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n" "* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n" "* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" "* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n" "* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" "*\n" "*\n" "***************************************************************************/\n"); } void print_usage(void) { printf("\nCommands Supported ->\n"); printf(" updateinton : Turns on update interrupt\n"); printf(" updateintoff : Turns off update interrupt\n"); printf(" getrtctime : Reads the current RTC time\n"); printf(" setrtctime ,