demo_watchdog.c
Go to the documentation of this file.
00001 /****************************************************************************
00002 * Copyright (c) Advantech Co., Ltd. All Rights Reserved
00003 *
00004 * File Name:
00005 *       demo_watchdog.c
00006 *
00007 * Programmers:
00008 *       Neo Lo
00009 *
00010 ****************************************************************************/
00011 
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 
00015 #include "REL_Linux_SUSI.H"
00016 
00017 
00018 // Return 0 if platform infomation is correctly obtained.
00019 // Otherwise, return 1.
00020 int show_platform_info(void)
00021 {
00022         int result;
00023         DWORD major, minor, year, month, date;
00024         const int BUF_LENGTH = 128;
00025         TCHAR buf[BUF_LENGTH];  // Buffer length includes the null character.
00026 
00027         SusiDllGetVersion(&major, &minor);
00028     year    = minor/10000;
00029     month   = minor%10000/100;
00030     date    = minor%100;
00031         printf("Version: %li (20%02li/%02li/%02li)\n", major, year, month, date);
00032 
00033         // Get platform name.
00034         result = SusiGetPlatformName(buf, BUF_LENGTH);
00035         if (result < 0) {
00036                 printf("SusiGetPlatformName() failed\n");
00037                 return 1;
00038         }
00039         else if (result > 0) {
00040                 printf("SusiGetPlatformName(): buffer is too short\n");
00041                 return 1;
00042         }
00043         else
00044                 printf("Platform name: %s\n", buf);
00045 
00046         // Get BIOS version.
00047         result = SusiGetBIOSVersion(buf, BUF_LENGTH);
00048         if (result < 0) {
00049                 return 1;
00050         }
00051         else if (result > 0) {
00052                 printf("SusiGetBIOSVersion(): buffer is too short\n");
00053                 return 1;
00054         }
00055         else
00056                 printf("BIOS version: %s\n", buf);
00057 
00058         return 0;
00059 }
00060 
00061 void show_menu(void)
00062 {
00063         printf("\n");
00064         printf("0) Terminate this program\n");
00065         printf("1) Set Watchdog timeout value\n");
00066         printf("2) Ping/Trigger the Watchdog\n");
00067         printf("3) Stop/Disable the Watchdog\n");
00068         printf("Enter your choice: ");
00069 }
00070 
00071 void get_delay_timeout(DWORD min, DWORD max, DWORD step, DWORD *delay, DWORD *timeout)
00072 {
00073         int done = 0;
00074 
00075         printf("Delay (in m-sec): ");
00076         if (scanf("%li", delay) <= 0)
00077                 return;
00078         if (step) {
00079                 while (! done) {
00080                         printf("Timeout (in m-sec): ");
00081                         if ((scanf("%li", timeout) <= 0) || *timeout < min || *timeout > max) {
00082                                 printf("\"Timeout\" should be between ");
00083                                 printf("%li and %li\n", min, max);
00084                                 continue;
00085                         }
00086                         done = 1;
00087                 }
00088         }
00089         else {
00090                 printf("This Watchdog does not support stepping.\n");
00091                 printf("Set \"timeout\" to the default value.\n");
00092                 *timeout = min;
00093         }
00094 }
00095 
00096 int main(void)
00097 {
00098         int result, done, op;
00099         DWORD delay, timeout;
00100         DWORD min, max, step;
00101 
00102         result = SusiDllInit();
00103         if (result == FALSE) {
00104                 printf("SusiDllInit() failed\n");
00105                 return 1;
00106         }
00107 
00108         result = SusiWDAvailable();
00109         if (result == 0) {
00110                 printf("SusiWDTAvailable() failed\n");
00111                 SusiDllUnInit();
00112                 return 1;
00113         }
00114 
00115         result = show_platform_info();
00116 
00117         result = SusiWDGetRange(&min, &max, &step);
00118         if (result == FALSE) {
00119                 printf("SusiWDTGetRange() failed\n");
00120                 SusiDllUnInit();
00121                 return 1;
00122         }
00123         else
00124                 printf("Timeout value: (min, max, step) = (%ld, %ld, %ld)\n", min, max, step);
00125 
00126         done = 0;
00127         while (! done) {
00128                 show_menu();
00129                 if (scanf("%i", &op) <= 0)
00130                         op = -1;
00131 
00132                 switch(op) {
00133                 case 0:
00134                         done = 1;
00135                         continue;
00136                 case 1:
00137                         get_delay_timeout(min, max, step, &delay, &timeout);
00138                         result = SusiWDSetConfigEx(WDTOUT0, delay, timeout);
00139                         break;
00140                 case 2:
00141                         result = SusiWDTriggerEx(WDTOUT0);
00142                         break;
00143                 case 3:
00144                         result = SusiWDDisableEx(WDTOUT0);
00145                         break;
00146                 default:
00147                         printf("\nUnknown choice!\n\n");
00148                         continue;
00149                 }
00150                 if (result == FALSE) {
00151                         SusiDllUnInit();
00152                         return 1;
00153                 }
00154         }
00155 
00156         result = SusiDllUnInit();
00157         if (result == FALSE) {
00158                 printf("SusiDllUnInit() failed\n");
00159                 return 1;
00160         }
00161         return 0;
00162 }
00163 


advantech
Author(s):
autogenerated on Fri Feb 7 2014 11:36:51